Search code examples
debuggingmacrosreleasenim-lang

How do I compile a binary with a const string in debug and change it in release?


I would like to create a binary that is storing some configuration data that will be supplied at compile time and built into the binary that I don't want present in the release versions.

In C I would do this like

#ifdef DEBUG
#define LOOKUP_TABLE "{this:is:test:json}"
#else
#define LOOKUP_TABLE "{this:is:release:json}"
#endif

Below I can get it defined for runtime...but I dont want the debug string in there at all

#debug
when not defined(release):
  const LOOKUP_TABLE: string = "{this:is:test:json}"
#release
when defined(release):
  const LOOKUP_TABLE: string = "{this:is:release:json}"

Solution

  • It seems you already know about when and you are rather looking for a way to not insert the value of the lookup table directly into source code. Maybe you are looking for the staticRead macro?

    const LOOKUP_TABLE =
        when defined(release):
            staticRead("release.json")
        else:
            staticRead("debug.json")
    
    echo LOOKUP_TABLE