Skip to content

Create newtype for platform triple in bootstrap. #36696

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

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 10 additions & 10 deletions src/bootstrap/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::process::Command;
use build_helper::{cc2ar, output};
use gcc;

use Build;
use {Build, Triple};
use config::Target;

pub fn find(build: &mut Build) {
Expand All @@ -45,7 +45,7 @@ pub fn find(build: &mut Build) {
for target in build.config.target.iter() {
let mut cfg = gcc::Config::new();
cfg.cargo_metadata(false).opt_level(0).debug(false)
.target(target).host(&build.config.build);
.target(&target.0).host(&build.config.build.0);

let config = build.config.target_config.get(target);
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
Expand All @@ -55,19 +55,19 @@ pub fn find(build: &mut Build) {
}

let compiler = cfg.get_compiler();
let ar = cc2ar(compiler.path(), target);
let ar = cc2ar(compiler.path(), &target.0);
build.verbose(&format!("CC_{} = {:?}", target, compiler.path()));
if let Some(ref ar) = ar {
build.verbose(&format!("AR_{} = {:?}", target, ar));
}
build.cc.insert(target.to_string(), (compiler, ar));
build.cc.insert(target.clone(), (compiler, ar));
}

// For all host triples we need to find a C++ compiler as well
for host in build.config.host.iter() {
let mut cfg = gcc::Config::new();
cfg.cargo_metadata(false).opt_level(0).debug(false).cpp(true)
.target(host).host(&build.config.build);
.target(&host.0).host(&build.config.build.0);
let config = build.config.target_config.get(host);
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
Expand All @@ -76,29 +76,29 @@ pub fn find(build: &mut Build) {
}
let compiler = cfg.get_compiler();
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
build.cxx.insert(host.to_string(), compiler);
build.cxx.insert(host.clone(), compiler);
}
}

fn set_compiler(cfg: &mut gcc::Config,
gnu_compiler: &str,
target: &str,
target: &Triple,
config: Option<&Target>) {
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") => {
t if t.is_android() => {
if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
let target = target.replace("armv7", "arm");
let target = target.0.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") => {
t if t.is_openbsd() => {
let c = cfg.get_compiler();
if !c.path().ends_with(gnu_compiler) {
return
Expand Down
32 changes: 16 additions & 16 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::process::Command;

use build_helper::output;

use {Build, Compiler, Mode};
use {Build, Compiler, Mode, Triple};
use util::{self, dylib_path, dylib_path_var};

const ADB_TEST_DIR: &'static str = "/data/tmp";
Expand All @@ -30,7 +30,7 @@ const ADB_TEST_DIR: &'static str = "/data/tmp";
///
/// This tool in `src/tools` will verify the validity of all our links in the
/// documentation to ensure we don't have a bunch of dead ones.
pub fn linkcheck(build: &Build, stage: u32, host: &str) {
pub fn linkcheck(build: &Build, stage: u32, host: &Triple) {
println!("Linkcheck stage{} ({})", stage, host);
let compiler = Compiler::new(stage, host);
build.run(build.tool_cmd(&compiler, "linkchecker")
Expand All @@ -41,7 +41,7 @@ pub fn linkcheck(build: &Build, stage: u32, host: &str) {
///
/// This tool in `src/tools` will check out a few Rust projects and run `cargo
/// test` to ensure that we don't regress the test suites there.
pub fn cargotest(build: &Build, stage: u32, host: &str) {
pub fn cargotest(build: &Build, stage: u32, host: &Triple) {
let ref compiler = Compiler::new(stage, host);

// Configure PATH to find the right rustc. NB. we have to use PATH
Expand Down Expand Up @@ -69,14 +69,14 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
/// This tool in `src/tools` checks up on various bits and pieces of style and
/// otherwise just implements a few lint-like checks that are specific to the
/// compiler itself.
pub fn tidy(build: &Build, stage: u32, host: &str) {
pub fn tidy(build: &Build, stage: u32, host: &Triple) {
println!("tidy check stage{} ({})", stage, host);
let compiler = Compiler::new(stage, host);
build.run(build.tool_cmd(&compiler, "tidy")
.arg(build.src.join("src")));
}

fn testdir(build: &Build, host: &str) -> PathBuf {
fn testdir(build: &Build, host: &Triple) -> PathBuf {
build.out.join(host).join("test")
}

Expand All @@ -87,7 +87,7 @@ fn testdir(build: &Build, host: &str) -> PathBuf {
/// "run-pass" or `suite` can be something like `debuginfo`.
pub fn compiletest(build: &Build,
compiler: &Compiler,
target: &str,
target: &Triple,
mode: &str,
suite: &str) {
println!("Check compiletest {} ({} -> {})", suite, compiler.host, target);
Expand Down Expand Up @@ -130,7 +130,7 @@ pub fn compiletest(build: &Build,
let python_default = "python";
cmd.arg("--docck-python").arg(python_default);

if build.config.build.ends_with("apple-darwin") {
if build.config.build.is_apple_darwin() {
// Force /usr/bin/python on OSX for LLDB tests because we're loading the
// LLDB plugin's compiled module which only works with the system python
// (namely not Homebrew-installed python)
Expand Down Expand Up @@ -178,7 +178,7 @@ pub fn compiletest(build: &Build,

// Running a C compiler on MSVC requires a few env vars to be set, to be
// sure to set them here.
if target.contains("msvc") {
if target.is_msvc() {
for &(ref k, ref v) in build.cc[target].0.env() {
if k != "PATH" {
cmd.env(k, v);
Expand All @@ -189,7 +189,7 @@ pub fn compiletest(build: &Build,

cmd.arg("--adb-path").arg("adb");
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
if target.contains("android") {
if target.is_android() {
// Assume that cc for this target comes from the android sysroot
cmd.arg("--android-cross-path")
.arg(build.cc(target).parent().unwrap().parent().unwrap());
Expand Down Expand Up @@ -262,7 +262,7 @@ fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
/// arguments, and those arguments are discovered from `Cargo.lock`.
pub fn krate(build: &Build,
compiler: &Compiler,
target: &str,
target: &Triple,
mode: Mode) {
let (name, path, features) = match mode {
Mode::Libstd => ("libstd", "src/rustc/std_shim", build.std_features()),
Expand Down Expand Up @@ -320,7 +320,7 @@ pub fn krate(build: &Build,
dylib_path.insert(0, build.sysroot_libdir(compiler, target));
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());

if target.contains("android") {
if target.is_android() {
build.run(cargo.arg("--no-run"));
krate_android(build, compiler, target, mode);
} else {
Expand All @@ -331,7 +331,7 @@ pub fn krate(build: &Build,

fn krate_android(build: &Build,
compiler: &Compiler,
target: &str,
target: &Triple,
mode: Mode) {
let mut tests = Vec::new();
let out_dir = build.cargo_out(compiler, mode, target);
Expand Down Expand Up @@ -372,24 +372,24 @@ fn krate_android(build: &Build,
}

fn find_tests(dir: &Path,
target: &str,
target: &Triple,
dst: &mut Vec<PathBuf>) {
for e in t!(dir.read_dir()).map(|e| t!(e)) {
let file_type = t!(e.file_type());
if !file_type.is_file() {
continue
}
let filename = e.file_name().into_string().unwrap();
if (target.contains("windows") && filename.ends_with(".exe")) ||
(!target.contains("windows") && !filename.contains(".")) {
if (target.is_windows() && filename.ends_with(".exe")) ||
(!target.is_windows() && !filename.contains(".")) {
dst.push(e.path());
}
}
}

pub fn android_copy_libs(build: &Build,
compiler: &Compiler,
target: &str) {
target: &Triple) {
println!("Android copy libs to emulator ({})", target);
build.run(Command::new("adb").arg("remount"));
build.run(Command::new("adb").args(&["shell", "rm", "-r", ADB_TEST_DIR]));
Expand Down
39 changes: 21 additions & 18 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use build_helper::output;
use filetime::FileTime;

use util::{exe, staticlib, libdir, mtime, is_dylib, copy};
use {Build, Compiler, Mode};
use {Build, Compiler, Mode, Triple};

/// Build the standard library.
///
/// This will build the standard library for a particular stage of the build
/// using the `compiler` targeting the `target` architecture. The artifacts
/// created will also be linked into the sysroot directory.
pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
pub fn std<'a>(build: &'a Build, target: &Triple, compiler: &Compiler<'a>) {
println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
compiler.host, target);

Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
cargo.env("JEMALLOC_OVERRIDE", jemalloc);
}
}
if target.contains("musl") {
if target.is_musl() {
if let Some(p) = build.musl_root(target) {
cargo.env("MUSL_ROOT", p);
}
Expand All @@ -87,9 +87,9 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
/// Links those artifacts generated in the given `stage` for `target` produced
/// by `compiler` into `host`'s sysroot.
pub fn std_link(build: &Build,
target: &str,
target: &Triple,
compiler: &Compiler,
host: &str) {
host: &Triple) {
let target_compiler = Compiler::new(compiler.stage, host);
let libdir = build.sysroot_libdir(&target_compiler, target);
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
Expand All @@ -103,7 +103,7 @@ pub fn std_link(build: &Build,
}
add_to_sysroot(&out_dir, &libdir);

if target.contains("musl") && !target.contains("mips") {
if target.is_musl() && !target.is_mips() {
copy_musl_third_party_objects(build, &libdir);
}
}
Expand All @@ -123,8 +123,8 @@ fn copy_musl_third_party_objects(build: &Build, into: &Path) {
/// They don't require any library support as they're just plain old object
/// files, so we just use the nightly snapshot compiler to always build them (as
/// no other compilers are guaranteed to be available).
fn build_startup_objects(build: &Build, target: &str, into: &Path) {
if !target.contains("pc-windows-gnu") {
fn build_startup_objects(build: &Build, target: &Triple, into: &Path) {
if !target.is_pc_windows_gnu() {
return
}
let compiler = Compiler::new(0, &build.config.build);
Expand All @@ -150,7 +150,8 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) {
/// This will build libtest and supporting libraries for a particular stage of
/// the build using the `compiler` targeting the `target` architecture. The
/// artifacts created will also be linked into the sysroot directory.
pub fn test<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
pub fn test<'a>(build: &'a Build, target: &Triple,
compiler: &Compiler<'a>) {
println!("Building stage{} test artifacts ({} -> {})", compiler.stage,
compiler.host, target);
let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
Expand All @@ -168,9 +169,9 @@ pub fn test<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
/// Links those artifacts generated in the given `stage` for `target` produced
/// by `compiler` into `host`'s sysroot.
pub fn test_link(build: &Build,
target: &str,
target: &Triple,
compiler: &Compiler,
host: &str) {
host: &Triple) {
let target_compiler = Compiler::new(compiler.stage, host);
let libdir = build.sysroot_libdir(&target_compiler, target);
let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
Expand All @@ -182,7 +183,7 @@ pub fn test_link(build: &Build,
/// This will build the compiler for a particular stage of the build using
/// the `compiler` targeting the `target` architecture. The artifacts
/// created will also be linked into the sysroot directory.
pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
pub fn rustc<'a>(build: &'a Build, target: &Triple, compiler: &Compiler<'a>) {
println!("Building stage{} compiler artifacts ({} -> {})",
compiler.stage, compiler.host, target);

Expand Down Expand Up @@ -241,9 +242,9 @@ pub fn rustc<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
/// Links those artifacts generated in the given `stage` for `target` produced
/// by `compiler` into `host`'s sysroot.
pub fn rustc_link(build: &Build,
target: &str,
target: &Triple,
compiler: &Compiler,
host: &str) {
host: &Triple) {
let target_compiler = Compiler::new(compiler.stage, host);
let libdir = build.sysroot_libdir(&target_compiler, target);
let out_dir = build.cargo_out(compiler, Mode::Librustc, target);
Expand All @@ -252,13 +253,15 @@ pub fn rustc_link(build: &Build,

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
fn libstd_stamp(build: &Build, compiler: &Compiler,
target: &Triple) -> PathBuf {
build.cargo_out(compiler, Mode::Libstd, target).join(".libstd.stamp")
}

/// Cargo's output path for libtest in a given stage, compiled by a particular
/// compiler for the specified target.
fn libtest_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
fn libtest_stamp(build: &Build, compiler: &Compiler,
target: &Triple) -> PathBuf {
build.cargo_out(compiler, Mode::Libtest, target).join(".libtest.stamp")
}

Expand All @@ -273,7 +276,7 @@ fn compiler_file(compiler: &Path, file: &str) -> PathBuf {
/// This will assemble a compiler in `build/$host/stage$stage`. The compiler
/// must have been previously produced by the `stage - 1` build.config.build
/// compiler.
pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
pub fn assemble_rustc(build: &Build, stage: u32, host: &Triple) {
assert!(stage > 0, "the stage0 compiler isn't assembled, it's downloaded");
// The compiler that we're assembling
let target_compiler = Compiler::new(stage, host);
Expand Down Expand Up @@ -360,7 +363,7 @@ fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) {
///
/// This will build the specified tool with the specified `host` compiler in
/// `stage` into the normal cargo output directory.
pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) {
pub fn tool(build: &Build, stage: u32, host: &Triple, tool: &str) {
println!("Building stage{} tool {} ({})", stage, tool, host);

let compiler = Compiler::new(stage, host);
Expand Down
Loading