How to specify a environment variable in rustc flags

Hi All,

I'm building rust code to run on a raspberry pico. I need to generate a map file to better understand how variables are allocated.
The flag is passed below.

rustflags = [
 "-C", "link-arg=--nmagic",
 "-C", "link-arg=-Tlink.x",
 "-C", "link-args=-Map=target/led_blink.map",
]

Is there a way to make sure that the map is always generated in the same folder as the final binary?
i.e. for release builds under target/thumbv6m-none-eabi/release and target/thumbv6m-none-eabi/releasefor debug build.

I don't know or found a way to pass the current output directory to the rustflags.
I'm looking for something like
"-C", "link-args=-Map=${OUT_DIR}/led_blink.map"

If nothing else works, you can write a build.rs to read CARGO_TARGET_DIR and set link-args that way.

That is a good idea! Thanks for the hint. Is this the most commonly followed method ? i.e. to define the flags as a part of the build.rs ?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.