Skip to content

Commit f296258

Browse files
committed
targets are more now
1 parent f32b33e commit f296258

File tree

16 files changed

+339
-284
lines changed

16 files changed

+339
-284
lines changed

src/bootstrap/builder.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::time::{Duration, Instant};
1313

1414
use build_helper::{output, t};
1515

16+
use crate::config::TargetSelection;
1617
use crate::cache::{Cache, Interned, INTERNER};
1718
use crate::check;
1819
use crate::compile;
@@ -86,8 +87,8 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
8687

8788
pub struct RunConfig<'a> {
8889
pub builder: &'a Builder<'a>,
89-
pub host: Interned<String>,
90-
pub target: Interned<String>,
90+
pub host: TargetSelection,
91+
pub target: TargetSelection,
9192
pub path: PathBuf,
9293
}
9394

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

@@ -591,8 +592,8 @@ impl<'a> Builder<'a> {
591592
pub fn compiler_for(
592593
&self,
593594
stage: u32,
594-
host: Interned<String>,
595-
target: Interned<String>,
595+
host: TargetSelection,
596+
target: TargetSelection,
596597
) -> Compiler {
597598
if self.build.force_use_stage1(Compiler { stage, host }, target) {
598599
self.compiler(1, self.config.build)
@@ -610,12 +611,12 @@ impl<'a> Builder<'a> {
610611
pub fn sysroot_libdir(
611612
&self,
612613
compiler: Compiler,
613-
target: Interned<String>,
614+
target: TargetSelection,
614615
) -> Interned<PathBuf> {
615616
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
616617
struct Libdir {
617618
compiler: Compiler,
618-
target: Interned<String>,
619+
target: TargetSelection,
619620
}
620621
impl Step for Libdir {
621622
type Output = Interned<PathBuf>;
@@ -625,14 +626,14 @@ impl<'a> Builder<'a> {
625626
}
626627

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

630631
let lib = builder.sysroot_libdir_relative(self.compiler);
631-
let sysroot = dbg!(dbg!(builder
632-
.sysroot(self.compiler))
632+
let sysroot = builder
633+
.sysroot(self.compiler)
633634
.join(lib)
634-
.join("rustlib"))
635-
.join(target)
635+
.join("rustlib")
636+
.join(target.triple)
636637
.join("lib");
637638
let _ = fs::remove_dir_all(&sysroot);
638639
eprintln!("{}", sysroot.display());
@@ -656,7 +657,7 @@ impl<'a> Builder<'a> {
656657
Some(relative_libdir) if compiler.stage >= 1 => {
657658
self.sysroot(compiler).join(relative_libdir)
658659
}
659-
_ => self.sysroot(compiler).join(libdir(&compiler.host)),
660+
_ => self.sysroot(compiler).join(libdir(compiler.host)),
660661
}
661662
}
662663
}
@@ -668,11 +669,11 @@ impl<'a> Builder<'a> {
668669
/// Windows.
669670
pub fn libdir_relative(&self, compiler: Compiler) -> &Path {
670671
if compiler.is_snapshot(self) {
671-
libdir(&self.config.build).as_ref()
672+
libdir(self.config.build).as_ref()
672673
} else {
673674
match self.config.libdir_relative() {
674675
Some(relative_libdir) if compiler.stage >= 1 => relative_libdir,
675-
_ => libdir(&compiler.host).as_ref(),
676+
_ => libdir(compiler.host).as_ref(),
676677
}
677678
}
678679
}
@@ -707,7 +708,7 @@ impl<'a> Builder<'a> {
707708
if compiler.is_snapshot(self) {
708709
self.initial_rustc.clone()
709710
} else {
710-
self.sysroot(compiler).join("bin").join(exe("rustc", &compiler.host))
711+
self.sysroot(compiler).join("bin").join(exe("rustc", compiler.host))
711712
}
712713
}
713714

@@ -741,7 +742,7 @@ impl<'a> Builder<'a> {
741742
///
742743
/// Note that this returns `None` if LLVM is disabled, or if we're in a
743744
/// check build or dry-run, where there's no need to build all of LLVM.
744-
fn llvm_config(&self, target: Interned<String>) -> Option<PathBuf> {
745+
fn llvm_config(&self, target: TargetSelection) -> Option<PathBuf> {
745746
if self.config.llvm_enabled() && self.kind != Kind::Check && !self.config.dry_run {
746747
let llvm_config = self.ensure(native::Llvm { target });
747748
if llvm_config.is_file() {
@@ -762,7 +763,7 @@ impl<'a> Builder<'a> {
762763
&self,
763764
compiler: Compiler,
764765
mode: Mode,
765-
target: Interned<String>,
766+
target: TargetSelection,
766767
cmd: &str,
767768
) -> Cargo {
768769
let mut cargo = Command::new(&self.initial_cargo);
@@ -793,7 +794,7 @@ impl<'a> Builder<'a> {
793794
}
794795

795796
if cmd != "install" {
796-
cargo.arg("--target").arg(target);
797+
cargo.arg("--target").arg(target.rustc_target_arg());
797798
} else {
798799
assert_eq!(target, compiler.host);
799800
}
@@ -819,7 +820,7 @@ impl<'a> Builder<'a> {
819820
compiler.stage
820821
};
821822

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

10301031
if let Some(target_linker) = self.linker(target, can_use_lld) {
1031-
let target = crate::envify(&target);
1032+
let target = crate::envify(&target.triple);
10321033
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
10331034
}
10341035
if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
@@ -1181,21 +1182,21 @@ impl<'a> Builder<'a> {
11811182
}
11821183
};
11831184
let cc = ccacheify(&self.cc(target));
1184-
cargo.env(format!("CC_{}", target), &cc);
1185+
cargo.env(format!("CC_{}", target.triple), &cc);
11851186

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

11891190
if let Some(ar) = self.ar(target) {
11901191
let ranlib = format!("{} s", ar.display());
1191-
cargo.env(format!("AR_{}", target), ar).env(format!("RANLIB_{}", target), ranlib);
1192+
cargo.env(format!("AR_{}", target.triple), ar).env(format!("RANLIB_{}", target.triple), ranlib);
11921193
}
11931194

11941195
if let Ok(cxx) = self.cxx(target) {
11951196
let cxx = ccacheify(&cxx);
11961197
cargo
1197-
.env(format!("CXX_{}", target), &cxx)
1198-
.env(format!("CXXFLAGS_{}", target), cflags);
1198+
.env(format!("CXX_{}", target.triple), &cxx)
1199+
.env(format!("CXXFLAGS_{}", target.triple), cflags);
11991200
}
12001201
}
12011202

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

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

13871388
impl Rustflags {
1388-
fn new(target: &str) -> Rustflags {
1389+
fn new(target: TargetSelection) -> Rustflags {
13891390
let mut ret = Rustflags(String::new());
13901391

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

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

13991400
ret

src/bootstrap/cc_detect.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ use std::{env, iter};
2828

2929
use build_helper::output;
3030

31-
use crate::cache::Interned;
32-
use crate::config::Target;
31+
use crate::config::{TargetSelection, Target};
3332
use crate::{Build, GitRepo};
3433

3534
// The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
3635
// so use some simplified logic here. First we respect the environment variable `AR`, then
3736
// try to infer the archiver path from the C compiler path.
3837
// In the future this logic should be replaced by calling into the `cc` crate.
39-
fn cc2ar(cc: &Path, target: &str) -> Option<PathBuf> {
40-
if let Some(ar) = env::var_os(format!("AR_{}", target.replace("-", "_"))) {
38+
fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
39+
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace("-", "_"))) {
4140
Some(PathBuf::from(ar))
4241
} else if let Some(ar) = env::var_os("AR") {
4342
Some(PathBuf::from(ar))
@@ -79,8 +78,8 @@ pub fn find(build: &mut Build) {
7978
.opt_level(2)
8079
.warnings(false)
8180
.debug(false)
82-
.target(&target)
83-
.host(&build.build);
81+
.target(&target.triple)
82+
.host(&build.build.triple);
8483
match build.crt_static(target) {
8584
Some(a) => {
8685
cfg.static_crt(a);
@@ -106,10 +105,10 @@ pub fn find(build: &mut Build) {
106105
let ar = if let ar @ Some(..) = config.and_then(|c| c.ar.clone()) {
107106
ar
108107
} else {
109-
cc2ar(compiler.path(), &target)
108+
cc2ar(compiler.path(), target)
110109
};
111110

112-
build.cc.insert(target, compiler);
111+
build.cc.insert(target, compiler.clone());
113112
let cflags = build.cflags(target, GitRepo::Rustc);
114113

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

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

141-
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
142-
build.verbose(&format!("CFLAGS_{} = {:?}", &target, cflags));
140+
build.verbose(&format!("CC_{} = {:?}", &target.triple, build.cc(target)));
141+
build.verbose(&format!("CFLAGS_{} = {:?}", &target.triple, cflags));
143142
if let Ok(cxx) = build.cxx(target) {
144-
build.verbose(&format!("CXX_{} = {:?}", &target, cxx));
145-
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target, cflags));
143+
build.verbose(&format!("CXX_{} = {:?}", &target.triple, cxx));
144+
build.verbose(&format!("CXXFLAGS_{} = {:?}", &target.triple, cflags));
146145
}
147146
if let Some(ar) = ar {
148-
build.verbose(&format!("AR_{} = {:?}", &target, ar));
147+
build.verbose(&format!("AR_{} = {:?}", &target.triple, ar));
149148
build.ar.insert(target, ar);
150149
}
151150
}
@@ -154,17 +153,17 @@ pub fn find(build: &mut Build) {
154153
fn set_compiler(
155154
cfg: &mut cc::Build,
156155
compiler: Language,
157-
target: Interned<String>,
156+
target: TargetSelection,
158157
config: Option<&Target>,
159158
build: &Build,
160159
) {
161-
match &*target {
160+
match &*target.triple {
162161
// When compiling for android we may have the NDK configured in the
163162
// config.toml in which case we look there. Otherwise the default
164163
// compiler already takes into account the triple in question.
165164
t if t.contains("android") => {
166165
if let Some(ndk) = config.and_then(|c| c.ndk.as_ref()) {
167-
let target = target
166+
let target = target.triple
168167
.replace("armv7neon", "arm")
169168
.replace("armv7", "arm")
170169
.replace("thumbv7neon", "arm")

src/bootstrap/check.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3+
use crate::config::TargetSelection;
34
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
4-
use crate::cache::Interned;
55
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, std_cargo};
66
use crate::tool::{prepare_tool_cargo, SourceType};
77
use crate::{Compiler, Mode};
88
use std::path::PathBuf;
99

1010
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1111
pub struct Std {
12-
pub target: Interned<String>,
12+
pub target: TargetSelection,
1313
}
1414

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

6666
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
6767
pub struct Rustc {
68-
pub target: Interned<String>,
68+
pub target: TargetSelection,
6969
}
7070

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

122122
impl Step for $name {
@@ -152,8 +152,8 @@ macro_rules! tool_check_step {
152152
println!(
153153
"Checking {} artifacts ({} -> {})",
154154
stringify!($name).to_lowercase(),
155-
&compiler.host,
156-
target
155+
&compiler.host.triple,
156+
target.triple
157157
);
158158
run_cargo(
159159
builder,
@@ -173,7 +173,7 @@ macro_rules! tool_check_step {
173173
fn stamp(
174174
builder: &Builder<'_>,
175175
compiler: Compiler,
176-
target: Interned<String>,
176+
target: TargetSelection,
177177
) -> PathBuf {
178178
builder
179179
.cargo_out(compiler, Mode::ToolRustc, target)
@@ -189,12 +189,12 @@ tool_check_step!(Clippy, "src/tools/clippy");
189189

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

196196
/// Cargo's output path for librustc in a given stage, compiled by a particular
197197
/// compiler for the specified target.
198-
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: Interned<String>) -> PathBuf {
198+
fn librustc_stamp(builder: &Builder<'_>, compiler: Compiler, target: TargetSelection) -> PathBuf {
199199
builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc-check.stamp")
200200
}

src/bootstrap/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn clean(build: &Build, all: bool) {
2323
rm_rf(&build.out.join("dist"));
2424

2525
for host in &build.hosts {
26-
let entries = match build.out.join(host).read_dir() {
26+
let entries = match build.out.join(host.triple).read_dir() {
2727
Ok(iter) => iter,
2828
Err(_) => continue,
2929
};

0 commit comments

Comments
 (0)