From 0b6766d8d7461a1a8d632ff62ba2024be87fed76 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Sep 2019 10:17:38 -0700 Subject: Allow adding `RUSTFLAGS` after `Builder::cargo` This commit changes the return type of `Builder::cargo` to return a builder that allows dynamically adding more `RUSTFLAGS` values after-the-fact. While not used yet, this will later be used to delete more of `rustc.rs` --- src/bootstrap/tool.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/bootstrap/tool.rs') diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 54fe26f18e7..553adb0ebb6 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -8,7 +8,7 @@ use build_helper::t; use crate::Mode; use crate::Compiler; -use crate::builder::{Step, RunConfig, ShouldRun, Builder}; +use crate::builder::{Step, RunConfig, ShouldRun, Builder, Cargo as CargoCommand}; use crate::util::{exe, add_lib_path, CiEnv}; use crate::compile; use crate::channel::GitInfo; @@ -63,7 +63,7 @@ impl Step for ToolBuild { _ => panic!("unexpected Mode for tool build") } - let mut cargo = prepare_tool_cargo( + let cargo = prepare_tool_cargo( builder, compiler, self.mode, @@ -76,7 +76,7 @@ impl Step for ToolBuild { builder.info(&format!("Building stage{} tool {} ({})", compiler.stage, tool, target)); let mut duplicates = Vec::new(); - let is_expected = compile::stream_cargo(builder, &mut cargo, vec![], &mut |msg| { + let is_expected = compile::stream_cargo(builder, cargo, vec![], &mut |msg| { // Only care about big things like the RLS/Cargo for now match tool { | "rls" @@ -229,7 +229,7 @@ pub fn prepare_tool_cargo( path: &'static str, source_type: SourceType, extra_features: &[String], -) -> Command { +) -> CargoCommand { let mut cargo = builder.cargo(compiler, mode, target, command); let dir = builder.src.join(path); cargo.arg("--manifest-path").arg(dir.join("Cargo.toml")); @@ -517,7 +517,7 @@ impl Step for Rustdoc { // libraries here. The intuition here is that If we've built a compiler, we should be able // to build rustdoc. - let mut cargo = prepare_tool_cargo( + let cargo = prepare_tool_cargo( builder, build_compiler, Mode::ToolRustc, @@ -530,7 +530,7 @@ impl Step for Rustdoc { builder.info(&format!("Building rustdoc for stage{} ({})", target_compiler.stage, target_compiler.host)); - builder.run(&mut cargo); + builder.run(&mut cargo.into()); // Cargo adds a number of paths to the dylib search path on windows, which results in // the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool" -- cgit 1.4.1-3-g733a5 From 385470b8bb1250ac11276fa57a3d1fc1d9ffb710 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Sep 2019 10:31:22 -0700 Subject: Move handling of `-Cprefer-dynamic` into `builder.rs` This logic is *super* old and can be tweaked and moved into `builder.rs` --- src/bootstrap/bin/rustc.rs | 7 ------- src/bootstrap/builder.rs | 10 ++++++++++ src/bootstrap/test.rs | 4 ---- src/bootstrap/tool.rs | 4 ---- 4 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/bootstrap/tool.rs') diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 528e7787610..0abfa023add 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -89,13 +89,6 @@ fn main() { cmd.arg("--sysroot").arg(&sysroot); } - // When we build Rust dylibs they're all intended for intermediate - // usage, so make sure we pass the -Cprefer-dynamic flag instead of - // linking all deps statically into the dylib. - if env::var_os("RUSTC_NO_PREFER_DYNAMIC").is_none() { - cmd.arg("-Cprefer-dynamic"); - } - // If we're compiling specifically the `panic_abort` crate then we pass // the `-C panic=abort` option. Note that we do not do this for any // other crate intentionally as this is the only crate for now that we diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 076947f8781..428926e106b 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1227,6 +1227,16 @@ impl<'a> Builder<'a> { self.ci_env.force_coloring_in_ci(&mut cargo); + // When we build Rust dylibs they're all intended for intermediate + // usage, so make sure we pass the -Cprefer-dynamic flag instead of + // linking all deps statically into the dylib. + match mode { + Mode::Std | Mode::Rustc | Mode::Codegen => { + rustflags.arg("-Cprefer-dynamic"); + } + _ => {} + } + Cargo { command: cargo, rustflags, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 90d1d9d6b7c..b7ce9c7b397 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1814,10 +1814,6 @@ impl Step for Crate { .expect("nodejs not configured"), ); } else if target.starts_with("wasm32") { - // On the wasm32-unknown-unknown target we're using LTO which is - // incompatible with `-C prefer-dynamic`, so disable that here - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); - let node = builder .config .nodejs diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 553adb0ebb6..f1baeafe26a 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -234,10 +234,6 @@ pub fn prepare_tool_cargo( let dir = builder.src.join(path); cargo.arg("--manifest-path").arg(dir.join("Cargo.toml")); - // We don't want to build tools dynamically as they'll be running across - // stages and such and it's just easier if they're not dynamically linked. - cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1"); - if source_type == SourceType::Submodule { cargo.env("RUSTC_EXTERNAL_TOOL", "1"); } -- cgit 1.4.1-3-g733a5