From 7694ca419b3ade48e22982b69dec90eb45d8da73 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 22 Sep 2017 21:34:27 -0700 Subject: Update to the `cc` crate This is the name the `gcc` crate has moved to --- src/bootstrap/Cargo.toml | 2 +- src/bootstrap/bin/sccache-plus-cl.rs | 4 +- src/bootstrap/cc.rs | 147 ----------------------------------- src/bootstrap/cc_detect.rs | 147 +++++++++++++++++++++++++++++++++++ src/bootstrap/lib.rs | 12 +-- src/bootstrap/native.rs | 4 +- src/bootstrap/tool.rs | 4 + 7 files changed, 162 insertions(+), 158 deletions(-) delete mode 100644 src/bootstrap/cc.rs create mode 100644 src/bootstrap/cc_detect.rs (limited to 'src/bootstrap') diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 85e3b65c195..3f1d03b1872 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -34,7 +34,7 @@ cmake = "0.1.23" filetime = "0.1" num_cpus = "1.0" getopts = "0.2" -gcc = "0.3.54" +cc = "1.0" libc = "0.2" serde = "1.0.8" serde_derive = "1.0.8" diff --git a/src/bootstrap/bin/sccache-plus-cl.rs b/src/bootstrap/bin/sccache-plus-cl.rs index 266dffa5c92..8584014d48d 100644 --- a/src/bootstrap/bin/sccache-plus-cl.rs +++ b/src/bootstrap/bin/sccache-plus-cl.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate gcc; +extern crate cc; use std::env; use std::process::{self, Command}; @@ -18,7 +18,7 @@ fn main() { // Locate the actual compiler that we're invoking env::remove_var("CC"); env::remove_var("CXX"); - let mut cfg = gcc::Build::new(); + let mut cfg = cc::Build::new(); cfg.cargo_metadata(false) .out_dir("/") .target(&target) diff --git a/src/bootstrap/cc.rs b/src/bootstrap/cc.rs deleted file mode 100644 index c77e609d70b..00000000000 --- a/src/bootstrap/cc.rs +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! C-compiler probing and detection. -//! -//! This module will fill out the `cc` and `cxx` maps of `Build` by looking for -//! C and C++ compilers for each target configured. A compiler is found through -//! a number of vectors (in order of precedence) -//! -//! 1. Configuration via `target.$target.cc` in `config.toml`. -//! 2. Configuration via `target.$target.android-ndk` in `config.toml`, if -//! applicable -//! 3. Special logic to probe on OpenBSD -//! 4. The `CC_$target` environment variable. -//! 5. The `CC` environment variable. -//! 6. "cc" -//! -//! Some of this logic is implemented here, but much of it is farmed out to the -//! `gcc` crate itself, so we end up having the same fallbacks as there. -//! Similar logic is then used to find a C++ compiler, just some s/cc/c++/ is -//! used. -//! -//! It is intended that after this module has run no C/C++ compiler will -//! ever be probed for. Instead the compilers found here will be used for -//! everything. - -use std::process::Command; -use std::iter; - -use build_helper::{cc2ar, output}; -use gcc; - -use Build; -use config::Target; -use cache::Interned; - -pub fn find(build: &mut Build) { - // For all targets we're going to need a C compiler for building some shims - // and such as well as for being a linker for Rust code. - for target in build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build)) { - let mut cfg = gcc::Build::new(); - cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false) - .target(&target).host(&build.build); - - let config = build.config.target_config.get(&target); - if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { - cfg.compiler(cc); - } else { - set_compiler(&mut cfg, "gcc", target, config, build); - } - - let compiler = cfg.get_compiler(); - let ar = cc2ar(compiler.path(), &target); - build.verbose(&format!("CC_{} = {:?}", &target, compiler.path())); - if let Some(ref ar) = ar { - build.verbose(&format!("AR_{} = {:?}", &target, ar)); - } - build.cc.insert(target, (compiler, ar)); - } - - // For all host triples we need to find a C++ compiler as well - for host in build.hosts.iter().cloned().chain(iter::once(build.build)) { - let mut cfg = gcc::Build::new(); - cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false).cpp(true) - .target(&host).host(&build.build); - let config = build.config.target_config.get(&host); - if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) { - cfg.compiler(cxx); - } else { - set_compiler(&mut cfg, "g++", host, config, build); - } - let compiler = cfg.get_compiler(); - build.verbose(&format!("CXX_{} = {:?}", host, compiler.path())); - build.cxx.insert(host, compiler); - } -} - -fn set_compiler(cfg: &mut gcc::Build, - gnu_compiler: &str, - target: Interned, - config: Option<&Target>, - build: &Build) { - match &*target { - // When compiling for android we may have the NDK configured in the - // config.toml in which case we look there. Otherwise the default - // compiler already takes into account the triple in question. - t if t.contains("android") => { - if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) { - let target = target.replace("armv7", "arm"); - let compiler = format!("{}-{}", target, gnu_compiler); - cfg.compiler(ndk.join("bin").join(compiler)); - } - } - - // The default gcc version from OpenBSD may be too old, try using egcc, - // which is a gcc version from ports, if this is the case. - t if t.contains("openbsd") => { - let c = cfg.get_compiler(); - if !c.path().ends_with(gnu_compiler) { - return - } - - let output = output(c.to_command().arg("--version")); - let i = match output.find(" 4.") { - Some(i) => i, - None => return, - }; - match output[i + 3..].chars().next().unwrap() { - '0' ... '6' => {} - _ => return, - } - let alternative = format!("e{}", gnu_compiler); - if Command::new(&alternative).output().is_ok() { - cfg.compiler(alternative); - } - } - - "mips-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mips-linux-musl-gcc"); - } - } - "mipsel-unknown-linux-musl" => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - cfg.compiler("mipsel-linux-musl-gcc"); - } - } - - t if t.contains("musl") => { - if let Some(root) = build.musl_root(target) { - let guess = root.join("bin/musl-gcc"); - if guess.exists() { - cfg.compiler(guess); - } - } - } - - _ => {} - } -} diff --git a/src/bootstrap/cc_detect.rs b/src/bootstrap/cc_detect.rs new file mode 100644 index 00000000000..08df65c7611 --- /dev/null +++ b/src/bootstrap/cc_detect.rs @@ -0,0 +1,147 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! C-compiler probing and detection. +//! +//! This module will fill out the `cc` and `cxx` maps of `Build` by looking for +//! C and C++ compilers for each target configured. A compiler is found through +//! a number of vectors (in order of precedence) +//! +//! 1. Configuration via `target.$target.cc` in `config.toml`. +//! 2. Configuration via `target.$target.android-ndk` in `config.toml`, if +//! applicable +//! 3. Special logic to probe on OpenBSD +//! 4. The `CC_$target` environment variable. +//! 5. The `CC` environment variable. +//! 6. "cc" +//! +//! Some of this logic is implemented here, but much of it is farmed out to the +//! `cc` crate itself, so we end up having the same fallbacks as there. +//! Similar logic is then used to find a C++ compiler, just some s/cc/c++/ is +//! used. +//! +//! It is intended that after this module has run no C/C++ compiler will +//! ever be probed for. Instead the compilers found here will be used for +//! everything. + +use std::process::Command; +use std::iter; + +use build_helper::{cc2ar, output}; +use cc; + +use Build; +use config::Target; +use cache::Interned; + +pub fn find(build: &mut Build) { + // For all targets we're going to need a C compiler for building some shims + // and such as well as for being a linker for Rust code. + for target in build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build)) { + let mut cfg = cc::Build::new(); + cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false) + .target(&target).host(&build.build); + + let config = build.config.target_config.get(&target); + if let Some(cc) = config.and_then(|c| c.cc.as_ref()) { + cfg.compiler(cc); + } else { + set_compiler(&mut cfg, "gcc", target, config, build); + } + + let compiler = cfg.get_compiler(); + let ar = cc2ar(compiler.path(), &target); + build.verbose(&format!("CC_{} = {:?}", &target, compiler.path())); + if let Some(ref ar) = ar { + build.verbose(&format!("AR_{} = {:?}", &target, ar)); + } + build.cc.insert(target, (compiler, ar)); + } + + // For all host triples we need to find a C++ compiler as well + for host in build.hosts.iter().cloned().chain(iter::once(build.build)) { + let mut cfg = cc::Build::new(); + cfg.cargo_metadata(false).opt_level(0).warnings(false).debug(false).cpp(true) + .target(&host).host(&build.build); + let config = build.config.target_config.get(&host); + if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) { + cfg.compiler(cxx); + } else { + set_compiler(&mut cfg, "g++", host, config, build); + } + let compiler = cfg.get_compiler(); + build.verbose(&format!("CXX_{} = {:?}", host, compiler.path())); + build.cxx.insert(host, compiler); + } +} + +fn set_compiler(cfg: &mut cc::Build, + gnu_compiler: &str, + target: Interned, + config: Option<&Target>, + build: &Build) { + match &*target { + // When compiling for android we may have the NDK configured in the + // config.toml in which case we look there. Otherwise the default + // compiler already takes into account the triple in question. + t if t.contains("android") => { + if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) { + let target = target.replace("armv7", "arm"); + let compiler = format!("{}-{}", target, gnu_compiler); + cfg.compiler(ndk.join("bin").join(compiler)); + } + } + + // The default gcc version from OpenBSD may be too old, try using egcc, + // which is a gcc version from ports, if this is the case. + t if t.contains("openbsd") => { + let c = cfg.get_compiler(); + if !c.path().ends_with(gnu_compiler) { + return + } + + let output = output(c.to_command().arg("--version")); + let i = match output.find(" 4.") { + Some(i) => i, + None => return, + }; + match output[i + 3..].chars().next().unwrap() { + '0' ... '6' => {} + _ => return, + } + let alternative = format!("e{}", gnu_compiler); + if Command::new(&alternative).output().is_ok() { + cfg.compiler(alternative); + } + } + + "mips-unknown-linux-musl" => { + if cfg.get_compiler().path().to_str() == Some("gcc") { + cfg.compiler("mips-linux-musl-gcc"); + } + } + "mipsel-unknown-linux-musl" => { + if cfg.get_compiler().path().to_str() == Some("gcc") { + cfg.compiler("mipsel-linux-musl-gcc"); + } + } + + t if t.contains("musl") => { + if let Some(root) = build.musl_root(target) { + let guess = root.join("bin/musl-gcc"); + if guess.exists() { + cfg.compiler(guess); + } + } + } + + _ => {} + } +} diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 06c7c4c2faf..83aa08366df 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -126,7 +126,7 @@ extern crate lazy_static; extern crate serde_json; extern crate cmake; extern crate filetime; -extern crate gcc; +extern crate cc; extern crate getopts; extern crate num_cpus; extern crate toml; @@ -148,7 +148,7 @@ use build_helper::{run_silent, run_suppressed, try_run_silent, try_run_suppresse use util::{exe, libdir, OutputFolder, CiEnv}; -mod cc; +mod cc_detect; mod channel; mod check; mod clean; @@ -241,9 +241,9 @@ pub struct Build { // Runtime state filled in later on // target -> (cc, ar) - cc: HashMap, (gcc::Tool, Option)>, + cc: HashMap, (cc::Tool, Option)>, // host -> (cc, ar) - cxx: HashMap, gcc::Tool>, + cxx: HashMap, cc::Tool>, crates: HashMap, Crate>, is_sudo: bool, ci_env: CiEnv, @@ -350,7 +350,7 @@ impl Build { } self.verbose("finding compilers"); - cc::find(self); + cc_detect::find(self); self.verbose("running sanity check"); sanity::check(self); // If local-rust is the same major.minor as the current version, then force a local-rebuild @@ -619,7 +619,7 @@ impl Build { /// specified. fn cflags(&self, target: Interned) -> Vec { // Filter out -O and /O (the optimization flags) that we picked up from - // gcc-rs because the build scripts will determine that for themselves. + // cc-rs because the build scripts will determine that for themselves. let mut base = self.cc[&target].0.args().iter() .map(|s| s.to_string_lossy().into_owned()) .filter(|s| !s.starts_with("-O") && !s.starts_with("/O")) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 99077d03dbe..29376ff25e4 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -27,7 +27,7 @@ use std::process::Command; use build_helper::output; use cmake; -use gcc; +use cc; use Build; use util; @@ -289,7 +289,7 @@ impl Step for TestHelpers { let _folder = build.fold_output(|| "build_test_helpers"); println!("Building test helpers"); t!(fs::create_dir_all(&dst)); - let mut cfg = gcc::Build::new(); + let mut cfg = cc::Build::new(); // We may have found various cross-compilers a little differently due to our // extra configuration, so inform gcc of these compilers. Note, though, that diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 19879ab2ade..a05e58e6a22 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -126,6 +126,10 @@ pub fn prepare_tool_cargo( cargo.env("LIBZ_SYS_STATIC", "1"); } + // if tools are using lzma we want to force the build script to build its + // own copy + cargo.env("LZMA_API_STATIC", "1"); + cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel); cargo.env("CFG_VERSION", build.rust_version()); -- cgit 1.4.1-3-g733a5