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

different feature sets use the same output directory ($OUT_DIR) #3302

Closed
japaric opened this issue Nov 18, 2016 · 3 comments · Fixed by #3310
Closed

different feature sets use the same output directory ($OUT_DIR) #3302

japaric opened this issue Nov 18, 2016 · 3 comments · Fixed by #3310

Comments

@japaric
Copy link
Member

japaric commented Nov 18, 2016

they should use different output directory so build scripts that generate files whose contents vary with Cargo features will work correctly (otherwise you will only one instance of such files across different builds that use different feature sets)

cc @alexcrichton

japaric pushed a commit to japaric/f3 that referenced this issue Nov 18, 2016
@japaric
Copy link
Member Author

japaric commented Nov 18, 2016

Example where you can observe this bug:

$ tail -n5 Cargo.toml
build = "build.rs"

[features]
a = []
default = ["a"]

$ cat build.rs
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
    let outfile = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("foo.txt");

    writeln!(File::create(outfile).unwrap(),
             "{:?}",
             env::var_os("CARGO_FEATURE_A")).unwrap();

    println!("cargo:rerun-if-changed=build.rs");
}

$ cargo clean

$ cargo build

$ cat **/foo.txt
Some("1")

$ cargo build --no-default-features

$ cat **/foo.txt
None

$ cargo build

# Expected `Some("1")`!
$ cat **/foo.txt
None

@japaric
Copy link
Member Author

japaric commented Nov 18, 2016

To elaborate: The second cargo build command doesn't run the build script and that's fine. The problem is that both feature sets, "a" (the default) and "" (no-default-features), use the same $OUT_DIR so the cargo build --no-default-features command overwrites the foo.txt file that cargo build generated.

@alexcrichton
Copy link
Member

Fixed in #3310

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Nov 28, 2016
We now much more aggressively cache the output of the compiler based on feature
sets and profile configuration. Unfortunately we forgot to extend this caching
to build script output directories as well so this commit ensures that build
script outputs are cached the same way with a directory per configuration of
features and output settings.

Closes rust-lang#3302
bors added a commit that referenced this issue Dec 2, 2016
Apply new fingerprinting to build dir outputs

We now much more aggressively cache the output of the compiler based on feature
sets and profile configuration. Unfortunately we forgot to extend this caching
to build script output directories as well so this commit ensures that build
script outputs are cached the same way with a directory per configuration of
features and output settings.

Closes #3302
@bors bors closed this as completed in #3310 Dec 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants