`OUT_DIR` variable not set #3368

Closed
Razican opened this Issue Dec 4, 2016 · 24 comments

Projects

None yet

8 participants

@Razican
Razican commented Dec 4, 2016

Some Travis jobs are not compiling due to OUT_DIR not being present on nightly on my build.rs script. Is this an expected behaviour? how could it be fixed?

Example failure: https://travis-ci.org/SUPERAndroidAnalyzer/super/jobs/181113222#L146

@joshtriplett
Member

I can reproduce this with "cargo install ripgrep" using a cargo built from latest cargo git. Debugging...

@joshtriplett
Member

Looks like commit 41579ba caused this issue.

@upsuper
Contributor
upsuper commented Dec 7, 2016

This breaks building servo/rust-bindgen as well.

@JIghtuse
Contributor
JIghtuse commented Dec 7, 2016

cargo even has failing test for me with the same symptoms: http://paste.fedoraproject.org/500936/48110771/

Can't build ripgrep too.

@SimonSapin
Contributor

I’ve managed to build bindgen by replacing env! in the build script with std::env::var: servo/rust-bindgen#323

@SimonSapin
Contributor

Still, it looks like this is a breaking change. So Cargo should probably revert to providing these variables when compiling a build script. At least for a while, with a warning that this will change.

@joshtriplett
Member

It looks like commit 95193ca clarified the documentation to state that Cargo doesn't set these environment variables when building the build script, only when running it, even though Cargo did actually set them when building the build script as well. A later commit in Cargo then made the behavior match the documentation.

This does indeed represent a breaking change from the existing behavior, and existing build.rs scripts relied on the existing behavior.

@knight42 knight42 added a commit to uutils/coreutils that referenced this issue Dec 8, 2016
@knight42 knight42 Temporary fix for testing errors
The errors were caused by the missing env $OUT_DIR which should be set by
cargo, see [here](rust-lang/cargo#3368).
c000059
@knight42 knight42 added a commit to uutils/coreutils that referenced this issue Dec 8, 2016
@knight42 knight42 Temporary fix for errors in testing
The errors were caused by the missing env $OUT_DIR which should be set by
cargo.

[Related issue](rust-lang/cargo#3368).
a0ff0f6
@knight42 knight42 referenced this issue in uutils/coreutils Dec 8, 2016
Merged

Temporary fix for errors in testing #1011

@alexcrichton
Member

Ah this is definitely an accidental regression! Yes env!("OUT_DIR") is likely not what you want but rather std::env::var is correct in build scripts. The env! version is the out dir that the build script was built with, and the env::var version is for when the build script is being run.

I'm kinda surprised that env! ever worked...

@alexcrichton
Member

Well... so this was a "regression" but also a bug fix at the same time. The OUT_DIR environment variable can be different when the build script is being compiled compared to when the build script is being run. Notably during cross compilation these two can be different. This means that crates which use env!("OUT_DIR") I believe are broken for cross compiles where crates which use env::var("OUT_DIR") will correctly work with cross compiles.

To those hitting this issue, could you confirm that the crate hasn't been used for cross compiles? And perhaps if it has have weird issues arisen?

We could add a fix for this but I'm tempted to avoid doing so if we can (as it's "incorrect" to rely on the old behavior). If it's possible to fixup the packages in question quickly that'd be best, but if there's ongoing pain then I can change Cargo back to the previous behavior.

@joshtriplett
Member
joshtriplett commented Dec 9, 2016 edited

@alexcrichton I've seen various crates get fixed for this change (which, at a minimum, needs documentation in release notes).

It'd be good to be able to build existing packages with new Cargo. For the most part, Cargo has maintained backward compatibility across many versions. On the other hand, I do agree that crates shouldn't rely on the old behavior, and it would indeed have broken cross-compiles.

I don't see an obvious way to work-but-warn in this case, without awful hacks (such as somehow substituting in a version of env! that checks the environment variable name and produces a warning).

@alexcrichton
Member

Yes my only worry is if crates can't be updated. Crates can use std::env::var and work across all versions of Cargo, so if a crate can be proactively updated I'm not too worried about it.

@SimonSapin
Contributor

Can crater be used to find out what on crates.io is broken by this change?

@alexcrichton
Member

@SimonSapin I believe so, yes, we should see it in the next crater run (as soon as it's working)

@brendanzab brendanzab added a commit to brendanzab/gluon that referenced this issue Dec 18, 2016
@brendanzab brendanzab Fix build failure due to missing environment var
Caused by rust-lang/cargo#3368.

See rust-lang/cargo#3368 (comment) for more information.
a30f6c2
@alexcrichton alexcrichton added a commit to alexcrichton/rust-pinyin that referenced this issue Dec 28, 2016
@alexcrichton alexcrichton Use env::var_os intead of env! in build script
The env! method pulls the variable at *compile time* as opposed to runtime. This
can cause breakage in scenarios with cross compilation, for example. Currently
there's also a pending change to Cargo on the beta release of Rust which breaks
the usage of env! (rust-lang/cargo#3368).

We may roll that change back, but I figured it'd be good to head off future
breakage anyway!
ccd997d
@alexcrichton alexcrichton referenced this issue in mozillazg/rust-pinyin Dec 28, 2016
Merged

Use env::var_os intead of env! in build script #5

@alexcrichton alexcrichton added a commit to alexcrichton/rust-pinyin that referenced this issue Dec 28, 2016
@alexcrichton alexcrichton Use env::var_os intead of env! in build script
The env! method pulls the variable at *compile time* as opposed to runtime. This
can cause breakage in scenarios with cross compilation, for example. Currently
there's also a pending change to Cargo on the beta release of Rust which breaks
the usage of env! (rust-lang/cargo#3368).

We may roll that change back, but I figured it'd be good to head off future
breakage anyway!
ab2d4cd
@alexcrichton alexcrichton added a commit to alexcrichton/zip_codes that referenced this issue Dec 28, 2016
@alexcrichton alexcrichton Use env::var_os intead of env! in build script
The env! method pulls the variable at *compile time* as opposed to runtime. This
can cause breakage in scenarios with cross compilation, for example. Currently
there's also a pending change to Cargo on the beta release of Rust which breaks
the usage of env! (rust-lang/cargo#3368).

We may roll that change back, but I figured it'd be good to head off future
breakage anyway!
10f7cc6
@alexcrichton alexcrichton referenced this issue in SkylerLipthay/zip_codes Dec 28, 2016
Merged

Use env::var_os intead of env! in build script #2

@brson
Contributor
brson commented Dec 29, 2016

gazetta-bin-0.1.6 hits this.

@alexcrichton alexcrichton added a commit to alexcrichton/gazetta-bin that referenced this issue Dec 29, 2016
@alexcrichton alexcrichton Use env::var intead of env! in build script
The env! method pulls the variable at *compile time* as opposed to runtime. This
can cause breakage in scenarios with cross compilation, for example. Currently
there's also a pending change to Cargo on the beta release of Rust which breaks
the usage of env! (rust-lang/cargo#3368).

We may roll that change back, but I figured it'd be good to head off future
breakage anyway!
a06de3d
@alexcrichton alexcrichton referenced this issue in Stebalien/gazetta-bin Dec 29, 2016
Merged

Use env::var intead of env! in build script #1

@alexcrichton
Member
@brson
Contributor
brson commented Dec 30, 2016 edited

pinyin-0.0.5 hits this. (Edit: oh you've fixed pinyin)

@brson
Contributor
brson commented Dec 30, 2016

zip_codes-0.0.1 is affected cc @SkylerLipthay

@SkylerLipthay

Alex fixed this with SkylerLipthay/zip_codes#2, which has been merged! zip_codes 0.1.0 was subsequently released.

@brson
Contributor
brson commented Dec 31, 2016

Great @SkylerLipthay! Sorry for the inconvenience.

@alexcrichton
Member

@brson I think pinyin and rasen were both addressed here -- rust-lang/rust#38391 (comment)

@brson
Contributor
brson commented Jan 5, 2017 edited

lmdb-rs 0.7.3's test suite is affected. cc @vhbit

@vhbit vhbit added a commit to vhbit/lmdb-rs that referenced this issue Jan 5, 2017
@vhbit vhbit Fixes broken tests on nightly
Caused by rust-lang/cargo#3368.
Now the method for determining path for DB tests is exact copy
from `cargo`.
25c1fdc
@alexcrichton
Member

@brson looks like that was fixed by vhbit/lmdb-rs@25c1fdc

@alexcrichton
Member

Ok we've decided to close this as working as intended, but if any projects need help migrating please just let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment