rust-lang / cmake-rs

Rust build dependency for running cmake
https://docs.rs/cmake
Apache License 2.0
305 stars 121 forks source link

Allow per-target cmake toolchain #120

Closed roblabla closed 3 years ago

roblabla commented 3 years ago

This would help cross-compilation a bit, allowing the user to have some global environment variables set up for each of their cross-compilation toolchain.

The get_target_env_var function is taken from cc-rs::get_var function.

alexcrichton commented 3 years ago

Thanks! Could this be done for most other env var accesses as well? Additionally, like cc-rs, could this print out the results of what env vars are inspected (sometimes very helpful for debugging failures)

roblabla commented 3 years ago

Could this be done for most other env var accesses as well?

Right, so here are the two other environment variables where I think it'd make sense to make them per-target:

The other two, I'm not so sure:

alexcrichton commented 3 years ago

For DEP_* those are cargo-specific things so they should avoid this function (although it might be nice to print out that they're being accessed like cc-rs does), but for CMAKE I'd just throw it into the same function for consistency, but I agree that it's pretty doubtful anyone will use a target-specific variable for that.

roblabla commented 3 years ago

How does this look? It should now get the per-target environment variable for CMAKE, CMAKE_GENERATOR, CMAKE_PREFIX_PATH and CMAKE_TOOLCHAIN_FILE, and print on access. The same env_cache logic found in cc-rs was used here to make sure we only print once per env variable.

alexcrichton commented 3 years ago

Thanks!