Allow to set environment variables from build script #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
system-deps
provides many environment variables to configure its options. This is great for end users, but it doesn't allow libraries to provide defaults or configure them programmatically.An improvement could be to have a
add_env
method in the build script configuration that will add certain values to its environment (it doesn't set the real env variable). Sincesystem-deps
already had aMock
variable type tests, we can reuse it, providing a fallback to the environment in the case of build scripts and not doing so in tests.Use cases
system-deps
options using crate features. For example, a crate could have a feature that determines if it is statically or dynamically linked, and usingadd_env
we can set the relevant variable from the build script.SOME_CONFIG
, it can now also set neededsystem-deps
variables.Considered alternatives
.cargo/config.toml
to set[env]
variables per target. However, rust doesn't allow to use features to configure these values, and dependencies can't share this with users.system-deps
).TODO:
system-deps
. They can read the environment and decide whether to use it or not.Note: This was originally part of the PR for supporting prebuilt binaries (ADD LINK). However, in an effort to make reviewing easy, I separated this feature since it works independently.