cargo/tests/testsuite/lto.rs

281 lines
7.8 KiB
Rust
Raw Normal View History

Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
use cargo_test_support::project;
use cargo_test_support::registry::Package;
#[cargo_test]
fn with_deps() {
if !cargo_test_support::is_nightly() {
return;
}
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
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")
.with_stderr_contains("[..]`rustc[..]--crate-name bar[..]-Clinker-plugin-lto[..]`")
.with_stderr_contains("[..]`rustc[..]--crate-name test[..]-C lto[..]`")
.run();
}
#[cargo_test]
fn shared_deps() {
if !cargo_test_support::is_nightly() {
return;
}
Package::new("bar", "0.0.1").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"
[dependencies]
bar = "*"
[build-dependencies]
bar = "*"
[profile.release]
lto = true
"#,
)
.file("build.rs", "extern crate bar; fn main() {}")
.file("src/main.rs", "extern crate bar; fn main() {}")
.build();
p.cargo("build -v --release")
.with_stderr_contains("[..]`rustc[..]--crate-name test[..]-C lto[..]`")
.run();
}
#[cargo_test]
fn build_dep_not_ltod() {
if !cargo_test_support::is_nightly() {
return;
}
Package::new("bar", "0.0.1").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"
[build-dependencies]
bar = "*"
[profile.release]
lto = true
"#,
)
.file("build.rs", "extern crate bar; fn main() {}")
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build -v --release")
.with_stderr_contains("[..]`rustc[..]--crate-name bar[..]-Cembed-bitcode=no[..]`")
.with_stderr_contains("[..]`rustc[..]--crate-name test[..]-C lto[..]`")
.run();
}
#[cargo_test]
fn complicated() {
if !cargo_test_support::is_nightly() {
return;
}
Package::new("dep-shared", "0.0.1")
.file("src/lib.rs", "pub fn foo() {}")
.publish();
Package::new("dep-normal2", "0.0.1")
.file("src/lib.rs", "pub fn foo() {}")
.publish();
Package::new("dep-normal", "0.0.1")
.dep("dep-shared", "*")
.dep("dep-normal2", "*")
.file(
"src/lib.rs",
"
pub fn foo() {
dep_shared::foo();
dep_normal2::foo();
}
",
)
.publish();
Package::new("dep-build2", "0.0.1")
.file("src/lib.rs", "pub fn foo() {}")
.publish();
Package::new("dep-build", "0.0.1")
.dep("dep-shared", "*")
.dep("dep-build2", "*")
.file(
"src/lib.rs",
"
pub fn foo() {
dep_shared::foo();
dep_build2::foo();
}
",
)
.publish();
Package::new("dep-proc-macro2", "0.0.1")
.file("src/lib.rs", "pub fn foo() {}")
.publish();
Package::new("dep-proc-macro", "0.0.1")
.proc_macro(true)
.dep("dep-shared", "*")
.dep("dep-proc-macro2", "*")
.file(
"src/lib.rs",
"
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn foo(_: TokenStream, a: TokenStream) -> TokenStream {
dep_shared::foo();
dep_proc_macro2::foo();
a
}
",
)
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"
[lib]
crate-type = ['cdylib', 'staticlib']
[dependencies]
dep-normal = "*"
dep-proc-macro = "*"
[build-dependencies]
dep-build = "*"
[profile.release]
lto = true
"#,
)
.file("build.rs", "fn main() { dep_build::foo() }")
.file(
"src/main.rs",
"#[dep_proc_macro::foo] fn main() { dep_normal::foo() }",
)
.file(
"src/lib.rs",
"#[dep_proc_macro::foo] pub fn foo() { dep_normal::foo() }",
)
.build();
p.cargo("build -v --release")
// normal deps and their transitive dependencies do not need object
// code, so they should have linker-plugin-lto specified
.with_stderr_contains("[..]`rustc[..]--crate-name dep_normal2 [..]-Clinker-plugin-lto[..]`")
.with_stderr_contains("[..]`rustc[..]--crate-name dep_normal [..]-Clinker-plugin-lto[..]`")
// build dependencies and their transitive deps don't need any bitcode,
// so embedding should be turned off
.with_stderr_contains("[..]`rustc[..]--crate-name dep_build2 [..]-Cembed-bitcode=no[..]`")
.with_stderr_contains("[..]`rustc[..]--crate-name dep_build [..]-Cembed-bitcode=no[..]`")
.with_stderr_contains(
"[..]`rustc[..]--crate-name build_script_build [..]-Cembed-bitcode=no[..]`",
)
// proc macro deps are the same as build deps here
.with_stderr_contains(
"[..]`rustc[..]--crate-name dep_proc_macro2 [..]-Cembed-bitcode=no[..]`",
)
.with_stderr_contains(
"[..]`rustc[..]--crate-name dep_proc_macro [..]-Cembed-bitcode=no[..]`",
)
.with_stderr_contains("[..]`rustc[..]--crate-name test [..]--crate-type bin[..]-C lto[..]`")
.with_stderr_contains(
"[..]`rustc[..]--crate-name test [..]--crate-type cdylib[..]-C lto[..]`",
)
.with_stderr_contains("[..]`rustc[..]--crate-name dep_shared [..]`")
.with_stderr_does_not_contain("[..]--crate-name dep_shared[..]-C lto[..]")
.with_stderr_does_not_contain("[..]--crate-name dep_shared[..]-Clinker-plugin-lto[..]")
.with_stderr_does_not_contain("[..]--crate-name dep_shared[..]-Cembed-bitcode[..]")
.run();
}
#[cargo_test]
fn off_in_manifest_works() {
if !cargo_test_support::is_nightly() {
return;
}
Package::new("bar", "0.0.1")
.file("src/lib.rs", "pub fn foo() {}")
.publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"
[dependencies]
bar = "*"
[profile.release]
lto = "off"
"#,
)
.file("src/main.rs", "fn main() { bar::foo() }")
.build();
p.cargo("build -v --release").run();
}
#[cargo_test]
fn between_builds() {
if !cargo_test_support::is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.0.0"
[profile.release]
lto = true
"#,
)
.file("src/lib.rs", "pub fn foo() {}")
.file("src/main.rs", "fn main() { test::foo() }")
.build();
p.cargo("build -v --release --lib").run();
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
p.cargo("build -v --release").run();
}