Skip to content

Commit

Permalink
targets are more now
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Jul 3, 2020
1 parent f32b33e commit f296258
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 284 deletions.
61 changes: 31 additions & 30 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::time::{Duration, Instant};

use build_helper::{output, t};

use crate::config::TargetSelection;
use crate::cache::{Cache, Interned, INTERNER};
use crate::check;
use crate::compile;
Expand Down Expand Up @@ -86,8 +87,8 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {

pub struct RunConfig<'a> {
pub builder: &'a Builder<'a>,
pub host: Interned<String>,
pub target: Interned<String>,
pub host: TargetSelection,
pub target: TargetSelection,
pub path: PathBuf,
}

Expand Down Expand Up @@ -573,7 +574,7 @@ impl<'a> Builder<'a> {
/// not take `Compiler` since all `Compiler` instances are meant to be
/// obtained through this function, since it ensures that they are valid
/// (i.e., built and assembled).
pub fn compiler(&self, stage: u32, host: Interned<String>) -> Compiler {
pub fn compiler(&self, stage: u32, host: TargetSelection) -> Compiler {
self.ensure(compile::Assemble { target_compiler: Compiler { stage, host } })
}

Expand All @@ -591,8 +592,8 @@ impl<'a> Builder<'a> {
pub fn compiler_for(
&self,
stage: u32,
host: Interned<String>,
target: Interned<String>,
host: TargetSelection,
target: TargetSelection,
) -> Compiler {
if self.build.force_use_stage1(Compiler { stage, host }, target) {
self.compiler(1, self.config.build)
Expand All @@ -610,12 +611,12 @@ impl<'a> Builder<'a> {
pub fn sysroot_libdir(
&self,
compiler: Compiler,
target: Interned<String>,
target: TargetSelection,
) -> Interned<PathBuf> {
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct Libdir {
compiler: Compiler,
target: Interned<String>,
target: TargetSelection,
}
impl Step for Libdir {
type Output = Interned<PathBuf>;
Expand All @@ -625,14 +626,14 @@ impl<'a> Builder<'a> {
}

fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
let target = crate::hackit(&self.target);
let target = self.target;

let lib = builder.sysroot_libdir_relative(self.compiler);
let sysroot = dbg!(dbg!(builder
.sysroot(self.compiler))
let sysroot = builder
.sysroot(self.compiler)
.join(lib)
.join("rustlib"))
.join(target)
.join("rustlib")
.join(target.triple)
.join("lib");
let _ = fs::remove_dir_all(&sysroot);
eprintln!("{}", sysroot.display());
Expand All @@ -656,7 +657,7 @@ impl<'a> Builder<'a> {
Some(relative_libdir) if compiler.stage >= 1 => {
self.sysroot(compiler).join(relative_libdir)
}
_ => self.sysroot(compiler).join(libdir(&compiler.host)),
_ => self.sysroot(compiler).join(libdir(compiler.host)),
}
}
}
Expand All @@ -668,11 +669,11 @@ impl<'a> Builder<'a> {
/// Windows.
pub fn libdir_relative(&self, compiler: Compiler) -> &Path {
if compiler.is_snapshot(self) {
libdir(&self.config.build).as_ref()
libdir(self.config.build).as_ref()
} else {
match self.config.libdir_relative() {
Some(relative_libdir) if compiler.stage >= 1 => relative_libdir,
_ => libdir(&compiler.host).as_ref(),
_ => libdir(compiler.host).as_ref(),
}
}
}
Expand Down Expand Up @@ -707,7 +708,7 @@ impl<'a> Builder<'a> {
if compiler.is_snapshot(self) {
self.initial_rustc.clone()
} else {
self.sysroot(compiler).join("bin").join(exe("rustc", &compiler.host))
self.sysroot(compiler).join("bin").join(exe("rustc", compiler.host))
}
}

Expand Down Expand Up @@ -741,7 +742,7 @@ impl<'a> Builder<'a> {
///
/// Note that this returns `None` if LLVM is disabled, or if we're in a
/// check build or dry-run, where there's no need to build all of LLVM.
fn llvm_config(&self, target: Interned<String>) -> Option<PathBuf> {
fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
if self.config.llvm_enabled() && self.kind != Kind::Check && !self.config.dry_run {
let llvm_config = self.ensure(native::Llvm { target });
if llvm_config.is_file() {
Expand All @@ -762,7 +763,7 @@ impl<'a> Builder<'a> {
&self,
compiler: Compiler,
mode: Mode,
target: Interned<String>,
target: TargetSelection,
cmd: &str,
) -> Cargo {
let mut cargo = Command::new(&self.initial_cargo);
Expand Down Expand Up @@ -793,7 +794,7 @@ impl<'a> Builder<'a> {
}

if cmd != "install" {
cargo.arg("--target").arg(target);
cargo.arg("--target").arg(target.rustc_target_arg());
} else {
assert_eq!(target, compiler.host);
}
Expand All @@ -819,7 +820,7 @@ impl<'a> Builder<'a> {
compiler.stage
};

let mut rustflags = Rustflags::new(&target);
let mut rustflags = Rustflags::new(target);
if stage != 0 {
if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") {
cargo.args(s.split_whitespace());
Expand Down Expand Up @@ -1000,7 +1001,7 @@ impl<'a> Builder<'a> {
// argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
// fun to pass a flag to a tool to pass a flag to pass a flag to a tool
// to change a flag in a binary?
if self.config.rust_rpath && util::use_host_linker(&target) {
if self.config.rust_rpath && util::use_host_linker(target) {
let rpath = if target.contains("apple") {
// Note that we need to take one extra step on macOS to also pass
// `-Wl,-instal_name,@rpath/...` to get things to work right. To
Expand Down Expand Up @@ -1028,7 +1029,7 @@ impl<'a> Builder<'a> {
}

if let Some(target_linker) = self.linker(target, can_use_lld) {
let target = crate::envify(&target);
let target = crate::envify(&target.triple);
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
}
if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
Expand Down Expand Up @@ -1181,21 +1182,21 @@ impl<'a> Builder<'a> {
}
};
let cc = ccacheify(&self.cc(target));
cargo.env(format!("CC_{}", target), &cc);
cargo.env(format!("CC_{}", target.triple), &cc);

let cflags = self.cflags(target, GitRepo::Rustc).join(" ");
cargo.env(format!("CFLAGS_{}", target), cflags.clone());
cargo.env(format!("CFLAGS_{}", target.triple), cflags.clone());

if let Some(ar) = self.ar(target) {
let ranlib = format!("{} s", ar.display());
cargo.env(format!("AR_{}", target), ar).env(format!("RANLIB_{}", target), ranlib);
cargo.env(format!("AR_{}", target.triple), ar).env(format!("RANLIB_{}", target.triple), ranlib);
}

if let Ok(cxx) = self.cxx(target) {
let cxx = ccacheify(&cxx);
cargo
.env(format!("CXX_{}", target), &cxx)
.env(format!("CXXFLAGS_{}", target), cflags);
.env(format!("CXX_{}", target.triple), &cxx)
.env(format!("CXXFLAGS_{}", target.triple), cflags);
}
}

Expand Down Expand Up @@ -1229,7 +1230,7 @@ impl<'a> Builder<'a> {
// Environment variables *required* throughout the build
//
// FIXME: should update code to not require this env var
cargo.env("CFG_COMPILER_HOST_TRIPLE", target);
cargo.env("CFG_COMPILER_HOST_TRIPLE", target.triple);

// Set this for all builds to make sure doc builds also get it.
cargo.env("CFG_RELEASE_CHANNEL", &self.config.channel);
Expand Down Expand Up @@ -1385,15 +1386,15 @@ mod tests;
struct Rustflags(String);

impl Rustflags {
fn new(target: &str) -> Rustflags {
fn new(target: TargetSelection) -> Rustflags {
let mut ret = Rustflags(String::new());

// Inherit `RUSTFLAGS` by default ...
ret.env("RUSTFLAGS");

// ... and also handle target-specific env RUSTFLAGS if they're
// configured.
let target_specific = format!("CARGO_TARGET_{}_RUSTFLAGS", crate::envify(target));
let target_specific = format!("CARGO_TARGET_{}_RUSTFLAGS", crate::envify(&target.triple));
ret.env(&target_specific);

ret
Expand Down
35 changes: 17 additions & 18 deletions src/bootstrap/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ use std::{env, iter};

use build_helper::output;

use crate::cache::Interned;
use crate::config::Target;
use crate::config::{TargetSelection, Target};
use crate::{Build, GitRepo};

// The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
// so use some simplified logic here. First we respect the environment variable `AR`, then
// try to infer the archiver path from the C compiler path.
// In the future this logic should be replaced by calling into the `cc` crate.
fn cc2ar(cc: &Path, target: &str) -> Option<PathBuf> {
if let Some(ar) = env::var_os(format!("AR_{}", target.replace("-", "_"))) {
fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace("-", "_"))) {
Some(PathBuf::from(ar))
} else if let Some(ar) = env::var_os("AR") {
Some(PathBuf::from(ar))
Expand Down Expand Up @@ -79,8 +78,8 @@ pub fn find(build: &mut Build) {
.opt_level(2)
.warnings(false)
.debug(false)
.target(&target)
.host(&build.build);
.target(&target.triple)
.host(&build.build.triple);
match build.crt_static(target) {
Some(a) => {
cfg.static_crt(a);
Expand All @@ -106,10 +105,10 @@ pub fn find(build: &mut Build) {
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
ar
} else {
cc2ar(compiler.path(), &target)
cc2ar(compiler.path(), target)
};

build.cc.insert(target, compiler);
build.cc.insert(target, compiler.clone());
let cflags = build.cflags(target, GitRepo::Rustc);

// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
Expand All @@ -120,8 +119,8 @@ pub fn find(build: &mut Build) {
.warnings(false)
.debug(false)
.cpp(true)
.target(&target)
.host(&build.build);
.target(&target.triple)
.host(&build.build.triple);

let cxx_configured = if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
Expand All @@ -138,14 +137,14 @@ pub fn find(build: &mut Build) {
build.cxx.insert(target, compiler);
}

build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
build.verbose(&format!("CFLAGS_{} = {:?}", &target, cflags));
build.verbose(&format!("CC_{} = {:?}", &target.triple, build.cc(target)));
build.verbose(&format!("CFLAGS_{} = {:?}", &target.triple, cflags));
if let Ok(cxx) = build.cxx(target) {
build.verbose(&format!("CXX_{} = {:?}", &target, cxx));
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target, cflags));
build.verbose(&format!("CXX_{} = {:?}", &target.triple, cxx));
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target.triple, cflags));
}
if let Some(ar) = ar {
build.verbose(&format!("AR_{} = {:?}", &target, ar));
build.verbose(&format!("AR_{} = {:?}", &target.triple, ar));
build.ar.insert(target, ar);
}
}
Expand All @@ -154,17 +153,17 @@ pub fn find(build: &mut Build) {
fn set_compiler(
cfg: &mut cc::Build,
compiler: Language,
target: Interned<String>,
target: TargetSelection,
config: Option<&Target>,
build: &Build,
) {
match &*target {
match &*target.triple {
// 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
let target = target.triple
.replace("armv7neon", "arm")
.replace("armv7", "arm")
.replace("thumbv7neon", "arm")
Expand Down
18 changes: 9 additions & 9 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
use crate::config::TargetSelection;
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::Interned;
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
use crate::tool::{prepare_tool_cargo, SourceType};
use crate::{Compiler, Mode};
use std::path::PathBuf;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Std {
pub target: Interned<String>,
pub target: TargetSelection,
}

fn args(kind: Kind) -> Vec<String> {
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Step for Std {

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Rustc {
pub target: Interned<String>,
pub target: TargetSelection,
}

impl Step for Rustc {
Expand Down Expand Up @@ -116,7 +116,7 @@ macro_rules! tool_check_step {
($name:ident, $path:expr) => {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct $name {
pub target: Interned<String>,
pub target: TargetSelection,
}

impl Step for $name {
Expand Down Expand Up @@ -152,8 +152,8 @@ macro_rules! tool_check_step {
println!(
"Checking {} artifacts ({} -> {})",
stringify!($name).to_lowercase(),
&compiler.host,
target
&compiler.host.triple,
target.triple
);
run_cargo(
builder,
Expand All @@ -173,7 +173,7 @@ macro_rules! tool_check_step {
fn stamp(
builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
target: TargetSelection,
) -> PathBuf {
builder
.cargo_out(compiler, Mode::ToolRustc, target)
Expand All @@ -189,12 +189,12 @@ tool_check_step!(Clippy, "src/tools/clippy");

/// Cargo's output path for the standard library in a given stage, compiled
/// by a particular compiler for the specified target.
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
fn libstd_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
builder.cargo_out(compiler, Mode::Std, target).join(".libstd-check.stamp")
}

/// Cargo's output path for librustc in a given stage, compiled by a particular
/// compiler for the specified target.
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
}
2 changes: 1 addition & 1 deletion src/bootstrap/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn clean(build: &Build, all: bool) {
rm_rf(&build.out.join("dist"));

for host in &build.hosts {
let entries = match build.out.join(host).read_dir() {
let entries = match build.out.join(host.triple).read_dir() {
Ok(iter) => iter,
Err(_) => continue,
};
Expand Down
Loading

0 comments on commit f296258

Please sign in to comment.