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

option_env does not get updated when rebuilding and value of the key changed. #8306

Closed
jschwe opened this issue Jun 2, 2020 · 2 comments
Closed
Labels
A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug

Comments

@jschwe
Copy link
Contributor

jschwe commented Jun 2, 2020

Problem
I expected to see this happen:
Recompiling with cargo build / cargo run should update the value received from option_env to the current value of the key in the environment. Setting CARGO_INCREMENTAL=0 doesn't seem to affect this. It only causes a recompile the first time around since incremental compilation is turned on by default.

Instead, this happened:
The value received from option_env only changes when running cargo clean before.

Steps

This is a minimum example.

fn main() {
    let var = option_env!("TEST_OPT_ENV");
    match var{
        Some(str) => println!("{}", str),
        None => println!("Hello, World!"),
    }
}
$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.36s
     Running `target\debug\hello_world.exe`
Hello, World!
$ TEST_OPT_ENV="Using Option Env" cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target\debug\hello_world.exe`
Hello, World!
$ cargo clean
$ TEST_OPT_ENV="Using Option Env" cargo run
   Compiling hello_world v0.1.0 (C:\Users\jschw\CLionProjects\hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s
     Running `target\debug\hello_world.exe`
Using Option Env
$ CARGO_INCREMENTAL=0 TEST_OPT_ENV="Using Option Env Test 2" cargo run
   Compiling hello_world v0.1.0 (C:\Users\jschw\CLionProjects\hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s
     Running `target\debug\hello_world.exe`
Using Option Env Test 2
$ CARGO_INCREMENTAL=0 TEST_OPT_ENV="Using Option Env Test 3" cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target\debug\hello_world.exe`
Using Option Env Test 2

Possible Solution(s)

rust-lang/rust#71858 should provide the necessary information once it is merged.

Why I think I need this:
I'm compiling (and linking to) a rust library from a build script (different target) and want the option_env to get updated when I rebuild with a different value set for the key specified in the option_env.

Notes

Output of cargo version:
cargo 1.45.0-nightly (9fcb8c1d2 2020-05-25)

rustc --version --verbose:

rustc 1.45.0-nightly (ad4bc3323 2020-06-01)
binary: rustc
commit-hash: ad4bc3323b9299d867697e9653dcea1b5e1ad283
commit-date: 2020-06-01
host: x86_64-pc-windows-msvc
release: 1.45.0-nightly
LLVM version: 10.0
@jschwe jschwe added the C-bug Category: bug label Jun 2, 2020
@ehuss ehuss added A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting labels Jun 2, 2020
@alexcrichton
Copy link
Member

Thanks for the report! Indeed there's not a whole lot Cargo can do about this, but rust-lang/rust#71858 is targeted at fixing Cargo.

@ehuss
Copy link
Contributor

ehuss commented Jul 2, 2020

This is now fixed by #8421.

@ehuss ehuss closed this as completed Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants