Hello,
I'd like to build a binary with a staticRead but I'd like to modify the path of the file to be read compile time.
I have my config.nims
task build_that_binary, "...":
let sourceFile = paramStr(paramCount() -1 )
let firmwareFile = paramStr(paramCount())
# Somehow insert the firmwareFile into THE_FILENAME spot.
selfExec("c " & sourceFile)
And my source file:
const firmwareFile = staticRead(THE_FILENAME)
I'd like to control THE_FILENAME from the compiling command.
nim build_that_binary main.nim firmware.elf
How should I go about it? Should I at all? ;)
you can use a strdefine:
const FirmwarePath {.strdefine.} = "defaultPath.elf"
const FirmwareData = staticRead FirmwarePath
then compile with nim c -d:FirmwarePath=abc.elf file.nim
you can use compile-time define pragmas
something like:
const
myFilename {.strdefine.} = "firmware.elf" # default value
firmwareFile = staticRead(myFilename)
called with nim c -d:myFilename=firmwareAlt.elf main.nim