mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Fix parsing of comma separated values in --crate-type flag
According to the documentation the --crate-type flag accepts a comma separated list of crate types. However, these are never actually split into individual items and passed verbatim to rustc. Since cargo fails to associate cases such as 'staticlib,cdylib' to a specific crate type internally, it has to invoke rustc to determine the output file types for this unknown crate type, which returns only the first file type of the first crate type in the list. Consequently cargo will be looking only for a single '.a' artifact on Linux to be copied to the target directory. Fix this by splitting the list of provided crate types into individual items before further processing them.
This commit is contained in:
parent
978b4fefe7
commit
fb672fa2a9
@ -91,7 +91,16 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
|
||||
ops::print(&ws, &compile_opts, opt_value)?;
|
||||
return Ok(());
|
||||
}
|
||||
let crate_types = values(args, CRATE_TYPE_ARG_NAME);
|
||||
|
||||
let crate_types = args
|
||||
.get_many::<String>(CRATE_TYPE_ARG_NAME)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flat_map(|s| s.split(','))
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(String::from)
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
compile_opts.target_rustc_crate_types = if crate_types.is_empty() {
|
||||
None
|
||||
} else {
|
||||
|
@ -238,7 +238,7 @@ fn build_with_crate_types_for_foo() {
|
||||
p.cargo("rustc -v --crate-type lib,cdylib")
|
||||
.with_stderr_data(str![[r#"
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib,cdylib [..]`
|
||||
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib --crate-type cdylib [..]`
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
@ -302,7 +302,7 @@ fn build_with_crate_types_to_example() {
|
||||
.with_stderr_data(str![[r#"
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib [..]`
|
||||
[RUNNING] `rustc --crate-name ex --edition=2015 examples/ex.rs [..]--crate-type lib,cdylib [..]`
|
||||
[RUNNING] `rustc --crate-name ex --edition=2015 examples/ex.rs [..]--crate-type lib --crate-type cdylib [..]`
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
@ -338,7 +338,7 @@ fn build_with_crate_types_to_one_of_multi_examples() {
|
||||
.with_stderr_data(str![[r#"
|
||||
[COMPILING] foo v0.0.1 ([ROOT]/foo)
|
||||
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib [..]`
|
||||
[RUNNING] `rustc --crate-name ex1 --edition=2015 examples/ex1.rs [..]--crate-type lib,cdylib [..]`
|
||||
[RUNNING] `rustc --crate-name ex1 --edition=2015 examples/ex1.rs [..]--crate-type lib --crate-type cdylib [..]`
|
||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||
|
||||
"#]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user