Adding some more thing like build.rs but execut it before building the dependencies

How to set an env variable using config.toml or Cargo.toml that lasts for the end of the building time.

Setting it in config.toml doesn't help because I want to use some combined values as follows.

[env]
VAR="${pwd}/d --g ${pwd}/aaa"

Note that I can't use build.rs too because I want the env var to be set until the building finishes.


I think rust devs shoulld add some more thing like build.rs but execut it before building the dependencies.

If you need to set more, you should wrap cargo in an external build system, e.g. Makefile.

I don't expect Cargo to expand capabilities of build scripts and global variables. These are already very problematic for integration with other build systems and package managers (due to build.rs being arbitrary code, which is a problem for security, reproducibility, and ability to analayze and define builds declaratively). Environmental variables are a global mutable state, also opaque to the rest of the build system.

4 Likes

If anything, we'd love to make it easier to do more things without build scripts.

3 Likes

Could you give us some additional details about what variable you're wanting to set and what dependency you need it to affect?

As one example, we do want to handle native dependencies better, and we need some better ways to let the top-level crate determine whether to build them from source or use a system version. I'd love to work with someone interested in improving that.

Also, depending on the nature of the issue, you might be able to have your dependency set it in its build script.

1 Like

One downside of that approach is that it makes integration with e.g. rust-analyzer harder.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.