Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass environment variables to dependencies. #97

Closed
TyOverby opened this issue Jun 30, 2014 · 21 comments · Fixed by #712
Closed

Pass environment variables to dependencies. #97

TyOverby opened this issue Jun 30, 2014 · 21 comments · Fixed by #712
Labels
A-features Area: features — conditional compilation

Comments

@TyOverby
Copy link

For cargo's build scripts, it would be handy to be able to pass arguments to them via environment variables.

Usage would look something like:

[dependency.foo]
git = "......"
env = ["BAR", "BAZ", "A=B"]
@alexcrichton
Copy link
Member

What sort of variables were you thinking of passing? I'd rather give more variables by default than add custom ones, but I could see both happening.

@TyOverby
Copy link
Author

In my case it would be for building C libraries. The user could pass environment variable to my shell script that cargo runs when it runs the build command for my package. My shell script would decide what do do, and continue with compilation.

(The build command that I'm referring to is called "The build Field" on http://crates.io/manifest.html).

@TyOverby
Copy link
Author

As an example, gl-rs uses environment variables during the library build phase.

@alexcrichton
Copy link
Member

Do you have an idea of what specific environment variables you'd want to put in Cargo.toml and not elsewhere? It seems odd to have cargo pass per-project specific environment variables.

@TyOverby
Copy link
Author

TyOverby commented Jul 1, 2014

I'd like to use environment variables to tell my build script what libraries to build. I could see them being used to configure almost any project that has a build script generating native code.

@alexcrichton
Copy link
Member

I'm not understanding the cargo-specific functionality you want here. Why would cargo pass different environment variables than, for example, make?

@TyOverby
Copy link
Author

TyOverby commented Jul 1, 2014

I'd want the users of my library to be able to set environment variables for my projects via Cargo.

Different libraries would have different environment variables used in their build scripts, so I don't see the reason to have them set for everything.

@TyOverby
Copy link
Author

TyOverby commented Jul 7, 2014

Another use case would be to inform a library that it should expect a dependency to be either statically or dynamically linked.

Right now, (as far as I understand), if a library uses #[link(name="foo", kind="dylib")], then there is no way to provide that library statically or vice versa.

@wycats
Copy link
Contributor

wycats commented Jul 8, 2014

Right now, (as far as I understand), if a library uses #[link(name="foo", kind="dylib")], then there is no way to provide that library statically or vice versa.

@alexcrichton and I are planning on solving this problem through a syntax extension. More to come!

@alexcrichton
Copy link
Member

I've started working on said syntax extension here: https://github.com/alexcrichton/link-config

@alexcrichton alexcrichton added the A-features Area: features — conditional compilation label Oct 13, 2014
alexcrichton added a commit to alexcrichton/cargo that referenced this issue Oct 16, 2014
Closes rust-lang#97
Closes rust-lang#601 (this is an equivalent solution for that problem)
bors added a commit that referenced this issue Oct 17, 2014
As pointed in #633, it's currently not possible for a package to reexport the
feature of another package due to the limitations of how features are defined.

This commit adds support for this ability by allowing features of the form
`foo/bar` in the `features` section of the manifest. This form indicates that
the dependency `foo` should have its `bar` feature enabled. Additionally, it is
not required that `foo` is an optional dependency.

This does not allow features of the form `foo/bar` in a `[dependencies]`
features section as dependencies shouldn't be enabling features for other
dependencies.

At the same time, this passes through features to build commands to solve a few more issues.

Closes #97
Closes #601 (this is an equivalent solution for that problem)
Closes #633
Closes #674
@bors bors closed this as completed in #712 Oct 17, 2014
@ccll
Copy link

ccll commented May 3, 2017

I found a use case, the rust-ffmpeg-sys has a custom build.rs which allows you to pass a environment variable 'FFMPEG_DIR' to specify the path to the pre-compiled header/lib of FFMPEG.
So when my project depends on 'rust-ffmpeg-sys', it's better to allow the developer define the env var 'FFMPEG_DIR' directly in Cargo.toml, instead of define it outside of Cargo ecosystem.
Does that sound legitimate?

@alexcrichton
Copy link
Member

@ccll note that this is a super old issue, dependencies today can pass env vars to each other

@ccll
Copy link

ccll commented May 9, 2017

@alexcrichton Thanks for the tip, but it doesn't look like what I want.

image

What I want is to set env vars for libfoo from libbar's config/manifest/buildscript, not the other way around, while I have control over libbar, but not libfoo. Also the env var name is distorted a bit automatically.
Is there any way to pass arbitrarily named env vars to any upstream dependencies (not necessarily immediate ones)?

@alexcrichton
Copy link
Member

Correct yeah, that feature is covered by #3544

@ccll
Copy link

ccll commented May 22, 2017

@alexcrichton I'm afraid it's still not quite the same feature.
What DEP_name_key does: down stream <-- set env <-- upstream
What I want: down stream --> set env --> upstream (to control the building behavior of upstream lib)

#3544 only eliminate the mandatory requirements on 'links' key, but still not solving the control flow direction, right? Am I correct on understanding DEP_name_key and #3544 ?

@alexcrichton
Copy link
Member

@ccll functionality like that is typically exposed through features on crates, rather than programmatic access to env vars I believe.

@ccll
Copy link

ccll commented May 23, 2017

@alexcrichton 'feature' works like a Boolean flag, but sometimes a String value is needed.
In the rust-ffmpeg-sys package, the package needs to know where to find the pre-built binaries and header files of FFMpeg, so the down-stream application code who uses the package needs to fill a env var 'FFMPEG_DIR' to tell it.

I think this is a very valid use case, especially in code involving FFI with existing C library.

@alexcrichton
Copy link
Member

Ah yes that's currently not supported, but if you'd like to open an issue that'd be great!

@ccll
Copy link

ccll commented May 26, 2017

@alexcrichton How about re-opening this issue? No?

@alexcrichton
Copy link
Member

Mind opening a new one? This one's got a fair bit of semi-unlreated discussion now unfortunately :(

@ccll
Copy link

ccll commented Jun 5, 2017

@alexcrichton Sure, moved to #4121 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features Area: features — conditional compilation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants