What happens when you output the same variable with `cargo::metadata` in a build script?

The links documentation doesn't mention what happens when the same variable is set with cargo::metadata in a build script.

For example in a build.rs file:

println!("cargo::metadata=MYVAR=1");
println!("cargo::metadata=MYVAR=2");
// ...

Scanning the cargo code, it looks like the latest print statement will overrule all others before it and my experimentation appears to confirm this; downstream build scripts will see DEP_<LINKS_NAME>_MYVAR set to 2 only. Perhaps this gap should be documented in the cargo documentation?

I noticed the openssl-sys crate had a scenario where this cargo directive was being printed in a loop which I found confusing (I know it isn't explicitly printing cargo::metadata but this is just the old way to set metadata). Why not just print the last one since the last one overrules all the others?

Include paths are supposed to be an array of paths to find a header in, so presumably this was always broken and only coincidentally worked with files in the last path (or only had one)

You'd have to find the other side to find out how it expects to read these though: I assume it's eventually cc but that doesn't seem to consume these itself.

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.