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

Add support for -Cembed-bitcode=no #8066

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,14 @@ impl Execs {
}
MatchKind::Unordered => {
let mut a = actual.lines().collect::<Vec<_>>();
// match more-constrained lines first, although in theory we'll
// need some sort of recursive match here. This handles the case
// that you expect "a\n[..]b" and two lines are printed out,
// "ab\n"a", where technically we do match unordered but a naive
// search fails to find this. This simple sort at least gets the
// test suite to pass for now, but we may need to get more fancy
// if tests start failing again.
a.sort_by_key(|s| s.len());
let e = out.lines();

for e_line in e {
Expand Down
10 changes: 10 additions & 0 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct TargetInfo {
pub rustflags: Vec<String>,
/// Extra flags to pass to `rustdoc`, see `env_args`.
pub rustdocflags: Vec<String>,
/// REmove this when it hits stable (1.44)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extraneous upper-case 'E'.

pub supports_embed_bitcode: Option<bool>,
}

/// Kind of each file generated by a Unit, part of `FileType`.
Expand Down Expand Up @@ -103,6 +105,13 @@ impl TargetInfo {
.args(&rustflags)
.env_remove("RUSTC_LOG");

let mut embed_bitcode_test = process.clone();
embed_bitcode_test.arg("-Cembed-bitcode");
let supports_embed_bitcode = match kind {
CompileKind::Host => Some(rustc.cached_output(&embed_bitcode_test).is_ok()),
_ => None,
};

if let CompileKind::Target(target) = kind {
process.arg("--target").arg(target.rustc_target());
}
Expand Down Expand Up @@ -187,6 +196,7 @@ impl TargetInfo {
"RUSTDOCFLAGS",
)?,
cfg,
supports_embed_bitcode,
})
}

Expand Down
26 changes: 21 additions & 5 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,16 +801,32 @@ fn build_base_args<'a, 'cfg>(

// Disable LTO for host builds as prefer_dynamic and it are mutually
// exclusive.
if unit.target.can_lto() && !unit.target.for_host() {
match *lto {
Lto::Bool(false) => {}
Lto::Bool(true) => {
let lto_possible = unit.target.can_lto() && !unit.target.for_host();
match lto {
Lto::Bool(true) => {
if lto_possible {
cmd.args(&["-C", "lto"]);
}
Lto::Named(ref s) => {
}
Lto::Named(s) => {
if lto_possible {
cmd.arg("-C").arg(format!("lto={}", s));
}
}
// If LTO isn't being enabled then there's no need for bitcode to be
// present in the intermediate artifacts, so shave off some build time
// by removing it.
Lto::Bool(false) => {
if cx
.bcx
.target_data
.info(CompileKind::Host)
.supports_embed_bitcode
.unwrap()
{
cmd.arg("-Cembed-bitcode=no");
}
}
}

if let Some(n) = codegen_units {
Expand Down
42 changes: 21 additions & 21 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,13 +1149,13 @@ fn cargo_default_env_metadata_env_var() {
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
--emit=[..]link \
-C prefer-dynamic -C debuginfo=2 \
-C prefer-dynamic[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
Expand All @@ -1177,13 +1177,13 @@ fn cargo_default_env_metadata_env_var() {
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type dylib \
--emit=[..]link \
-C prefer-dynamic -C debuginfo=2 \
-C prefer-dynamic[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
Expand Down Expand Up @@ -1581,7 +1581,7 @@ fn verbose_build() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
Expand All @@ -1599,8 +1599,8 @@ fn verbose_release_build() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link \
-C opt-level=3 \
--emit=[..]link[..]\
-C opt-level=3[..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps`
Expand Down Expand Up @@ -1650,15 +1650,15 @@ fn verbose_release_build_deps() {
[RUNNING] `rustc --crate-name foo foo/src/lib.rs [..]\
--crate-type dylib --crate-type rlib \
--emit=[..]link \
-C prefer-dynamic \
-C opt-level=3 \
-C prefer-dynamic[..]\
-C opt-level=3[..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps`
[COMPILING] test v0.0.0 ([CWD])
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
--emit=[..]link \
-C opt-level=3 \
--emit=[..]link[..]\
-C opt-level=3[..]\
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps \
Expand Down Expand Up @@ -4205,15 +4205,15 @@ fn build_filter_infer_profile() {
p.cargo("build -v --test=t1")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 [..]",
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]--emit=[..]link \
"[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]--emit=[..]link[..]\
-C debuginfo=2 [..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
--emit=[..]link -C debuginfo=2 [..]",
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.run();

Expand All @@ -4222,16 +4222,16 @@ fn build_filter_infer_profile() {
p.cargo("build -v --bench=b1")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 [..]",
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.with_stderr_contains(
"[RUNNING] `rustc --crate-name b1 benches/b1.rs [..]--emit=[..]link \
"[RUNNING] `rustc --crate-name b1 benches/b1.rs [..]--emit=[..]link[..]\
-C debuginfo=2 [..]",
)
.with_stderr_does_not_contain("opt-level")
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin \
--emit=[..]link -C debuginfo=2 [..]",
--emit=[..]link[..]-C debuginfo=2 [..]",
)
.run();
}
Expand All @@ -4252,7 +4252,7 @@ fn targets_selected_default() {
)
// Unit tests.
.with_stderr_does_not_contain(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
-C debuginfo=2 --test [..]",
)
.run();
Expand All @@ -4269,7 +4269,7 @@ fn targets_selected_all() {
)
// Unit tests.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
-C debuginfo=2 --test [..]",
)
.run();
Expand All @@ -4286,7 +4286,7 @@ fn all_targets_no_lib() {
)
// Unit tests.
.with_stderr_contains(
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link \
"[RUNNING] `rustc --crate-name foo src/main.rs [..]--emit=[..]link[..]\
-C debuginfo=2 --test [..]",
)
.run();
Expand Down Expand Up @@ -4726,7 +4726,7 @@ fn build_lib_only() {
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,19 +1139,19 @@ fn build_cmd_with_a_build_cmd() {
[RUNNING] `rustc [..] a/build.rs [..] --extern b=[..]`
[RUNNING] `[..]/a-[..]/build-script-build`
[RUNNING] `rustc --crate-name a [..]lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..]target/debug/deps \
-L [..]target/debug/deps`
[COMPILING] foo v0.5.0 ([CWD])
[RUNNING] `rustc --crate-name build_script_build build.rs [..]--crate-type bin \
--emit=[..]link \
--emit=[..]link[..]\
-C debuginfo=2 -C metadata=[..] --out-dir [..] \
-L [..]target/debug/deps \
--extern a=[..]liba[..].rlib`
[RUNNING] `[..]/foo-[..]/build-script-build`
[RUNNING] `rustc --crate-name foo [..]lib.rs [..]--crate-type lib \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L [..]target/debug/deps`
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn linker() {
"\
[COMPILING] foo v0.5.0 ([CWD])
[RUNNING] `rustc --crate-name foo src/foo.rs [..]--crate-type bin \
--emit=[..]link -C debuginfo=2 \
--emit=[..]link[..]-C debuginfo=2 \
-C metadata=[..] \
--out-dir [CWD]/target/{target}/debug/deps \
--target {target} \
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ fn reuse_panic_pm() {
.with_stderr_unordered(
"\
[COMPILING] bar [..]
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C debuginfo=2 [..]
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort -C debuginfo=2 [..]
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C debuginfo=2 [..]
[RUNNING] `rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C debuginfo=2 [..]
[COMPILING] somepm [..]
[RUNNING] `rustc --crate-name somepm [..]
[COMPILING] foo [..]
Expand Down
26 changes: 26 additions & 0 deletions tests/testsuite/lto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use cargo_test_support::project;
use cargo_test_support::registry::Package;

#[cargo_test]
fn with_deps() {
Package::new("bar", "0.0.1").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"

[dependencies]
bar = "*"

[profile.release]
lto = true
"#,
)
.file("src/main.rs", "extern crate bar; fn main() {}")
.build();
p.cargo("build -v --release").run();
}
1 change: 1 addition & 0 deletions tests/testsuite/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mod local_registry;
mod locate_project;
mod lockfile_compat;
mod login;
mod lto;
mod member_errors;
mod message_format;
mod metabuild;
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/profile_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn profile_config_override_precedence() {
.with_stderr(
"\
[COMPILING] bar [..]
[RUNNING] `rustc --crate-name bar [..] -C opt-level=2 -C codegen-units=2 [..]
[RUNNING] `rustc --crate-name bar [..] -C opt-level=2[..]-C codegen-units=2 [..]
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo [..]-C codegen-units=2 [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
Expand Down
14 changes: 7 additions & 7 deletions tests/testsuite/profile_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ fn profile_override_hierarchy() {
p.cargo("build -v").with_stderr_unordered("\
[COMPILING] m3 [..]
[COMPILING] dep [..]
[RUNNING] `rustc --crate-name m3 m3/src/lib.rs [..] --crate-type lib --emit=[..]link -C codegen-units=4 [..]
[RUNNING] `rustc --crate-name dep [..]dep/src/lib.rs [..] --crate-type lib --emit=[..]link -C codegen-units=3 [..]
[RUNNING] `rustc --crate-name m3 m3/src/lib.rs [..] --crate-type lib --emit=[..]link -C codegen-units=1 [..]
[RUNNING] `rustc --crate-name build_script_build m1/build.rs [..] --crate-type bin --emit=[..]link -C codegen-units=4 [..]
[RUNNING] `rustc --crate-name m3 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=4 [..]
[RUNNING] `rustc --crate-name dep [..]dep/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=3 [..]
[RUNNING] `rustc --crate-name m3 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]
[RUNNING] `rustc --crate-name build_script_build m1/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=4 [..]
[COMPILING] m2 [..]
[RUNNING] `rustc --crate-name build_script_build m2/build.rs [..] --crate-type bin --emit=[..]link -C codegen-units=2 [..]
[RUNNING] `rustc --crate-name build_script_build m2/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=2 [..]
[RUNNING] `[..]/m1-[..]/build-script-build`
[RUNNING] `[..]/m2-[..]/build-script-build`
[RUNNING] `rustc --crate-name m2 m2/src/lib.rs [..] --crate-type lib --emit=[..]link -C codegen-units=2 [..]
[RUNNING] `rustc --crate-name m2 m2/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=2 [..]
[COMPILING] m1 [..]
[RUNNING] `rustc --crate-name m1 m1/src/lib.rs [..] --crate-type lib --emit=[..]link -C codegen-units=1 [..]
[RUNNING] `rustc --crate-name m1 m1/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]
[FINISHED] dev [unoptimized + debuginfo] [..]
",
)
Expand Down
Loading