Ability to specify the output name for a bin target different from the crate name by whereistejas · Pull Request #9627 · rust-lang/cargo (original) (raw)
Hi @ehuss,
Check that the
CARGO_BIN_EXE_$name
environment variable is set correctly for integration tests.
Writing the test and fix checking CARGO_BIN_EXE_<name>
is indeed, tricky. I think, it would be best if let it be as it is. We can mention this inconsistency in the documentation.
From what I can tell, it is kind of tricky to assign the value we get from filename
parameter to the env <name>
variable. This is happening in the following piece of code:
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 1687a5d2a..6501231c9 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -980,7 +980,11 @@ fn build_base_args( let exe_path = cx .files() .bin_link_for_target(bin_target, unit.kind, cx.bcx)?;
let key = format!("CARGO_BIN_EXE_{}", bin_target.name());
let name = unit
.target
.get_binary_name()
.unwrap_or(bin_target.name().to_string());
}let key = format!("CARGO_BIN_EXE_{}", name); cmd.env(&key, exe_path); }
This code is called once for each unit as we are looping over each root
present in the build context (bcx
). Our source code from the src/
directory forms the first unit and integretion tests from tests/
directory form the second unit. The filename
parameter is not available to us in the second unit, as the target_type
of this unit is test
and not bin
. The filename parameter is only available for bin
target type. I think, we are moving into really slippy territory here.
Would it be problematic if we had $CARGO_BIN_EXE_foo
when the actual executable name is 007bar
?
One possible alternative, is to use add the filename
parameter to the [[test]]
section, also. We can throw an error if the filename
parameters from both the sections [[bin]]
and [[test]]
don't match. This also gives us the opportunity to cater @alexcrichton's suggestion of generalizing the filename
parameter to all types of targets.