If you are interested in debug logs (i.e., it’s not just a toy example that you used as a substitute for another, more complex problem), then there is a @debug macro that can be controlled by an environment variable: Logging · The Julia Language
Copy-pasting an example from the referenced documentation:
julia> foo() = @debug "foo"
foo (generic function with 1 method)
julia> foo()
julia> ENV["JULIA_DEBUG"] = Main
Main
julia> foo()
┌ Debug: foo
└ @ Main REPL[1]:1
The closest analogue of C’s #ifdef in Julia is probably @static if. But you rarely need this — usually relying on the compiler for constant propagation suffices, and there are other ways to enable debugging logs as noted above.
Note that this doesn’t do what the OP wanted though. The @debug code is still in the compiled function whether or now you have ENV["JULIA_DEBUG"] = Main, it’s just not displaying.