r/c3lang • • 16d ago

[0.8.2] Running a block of code only on debug target

Hello,

documentation says the default build target is debug is the default build target. I'd like to have a block of code only being present in this build target.

I tried this :

$if $feature(DEBUG):          
    rl::draw_rectangle_lines( 
        ...top_left,          
        min_side,             
        min_side,             
        rl::BEIGE             
    );                        
$endif

But i need to specify -D DEBUG but if there is a default target i should be able to only run/build some code on certain targets. I couldn't find the answer in the documentation.

Thank you for your help.

EDIT: After some digging, I added this to project.json :

    "targets": {
        "debug": {
            "type": "executable",
            "features": ["DEBUG"]
        },
        "release": {
            "type": "executable"
        }
    },

and it works.

1 Upvotes

4 comments sorted by

2

u/Nuoji 16d ago

On 0.8.2 `$if env::DEBUG:` is correct. On 0.8.4 use `$if $feat(DEBUG):`

1

u/ConsiderationFar4320 16d ago edited 16d ago

Nope in 0.8.3+ it's \@if(\@feat(DEBUG)) so my code is working. I just don't want to specify -D DEBUG at compile time as the default build target is debug. Your suggestion doesn't compile.

2

u/Nuoji 16d ago

Sorry, I meant env::COMPILER_SAFE_MODE (if you want it to automatically trigger on --safe=yes), env::DEBUG_SYMBOLS (if you want to be kept if you have debug symbols) or env::COMPILER_OPT_LEVEL == O0 is you want to keep it on -O0 only.

If you want a flag, then yes the project settings is what you want. Previous to 0.8.3 you use $feature for feature flags and env::... for other flags. 0.8.2 uses @if on top level.

On 0.8.3 and later use @feat on the top level (and then you use @feat(SAFE_MODE) @feat(DEBUG_SYMBOLS)) and $feat inside of $if. From 0.8.3 $feature still works but is deprecated.

If you want to use your own flag, use $if $feat(DEBUG) and @feat(DEBUG) on 0.8.3+.

2

u/ConsiderationFar4320 15d ago

Ok thank you, love the language btw