Skip to content

Commit b53468f

Browse files
committed
Add rustc_trans to x.py check
1 parent 23561c6 commit b53468f

File tree

3 files changed

+100
-7
lines changed

3 files changed

+100
-7
lines changed

src/bootstrap/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a> Builder<'a> {
310310
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
311311
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc, tool::Clippy,
312312
native::Llvm, tool::Rustfmt, tool::Miri, native::Lld),
313-
Kind::Check => describe!(check::Std, check::Test, check::Rustc),
313+
Kind::Check => describe!(check::Std, check::Test, check::Rustc, check::CodegenBackend),
314314
Kind::Test => describe!(test::Tidy, test::Bootstrap, test::Ui, test::RunPass,
315315
test::CompileFail, test::ParseFail, test::RunFail, test::RunPassValgrind,
316316
test::MirOpt, test::Codegen, test::CodegenUnits, test::Incremental, test::Debuginfo,
@@ -834,7 +834,7 @@ impl<'a> Builder<'a> {
834834
cargo
835835
}
836836

837-
/// Ensure that a given step is built, returning it's output. This will
837+
/// Ensure that a given step is built, returning its output. This will
838838
/// cache the step, so it is safe (and good!) to call this as often as
839839
/// needed to ensure that all dependencies are built.
840840
pub fn ensure<S: Step>(&'a self, step: S) -> S::Output {

src/bootstrap/check.rs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
//! Implementation of compiling the compiler and standard library, in "check" mode.
1212
13-
use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, add_to_sysroot};
13+
use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env, add_to_sysroot};
14+
use compile::compiler_file;
1415
use builder::{RunConfig, Builder, ShouldRun, Step};
1516
use {Compiler, Mode};
16-
use cache::Interned;
17+
use native;
18+
use cache::{INTERNER, Interned};
1719
use std::path::PathBuf;
1820

1921
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -104,6 +106,97 @@ impl Step for Rustc {
104106
}
105107
}
106108

109+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
110+
pub struct CodegenBackend {
111+
pub target: Interned<String>,
112+
pub backend: Interned<String>,
113+
}
114+
115+
impl Step for CodegenBackend {
116+
type Output = ();
117+
const ONLY_HOSTS: bool = true;
118+
const DEFAULT: bool = true;
119+
120+
fn should_run(run: ShouldRun) -> ShouldRun {
121+
run.all_krates("rustc_trans")
122+
}
123+
124+
fn make_run(run: RunConfig) {
125+
let backend = run.builder.config.rust_codegen_backends.get(0);
126+
let backend = backend.cloned().unwrap_or_else(|| {
127+
INTERNER.intern_str("llvm")
128+
});
129+
run.builder.ensure(CodegenBackend {
130+
target: run.target,
131+
backend,
132+
});
133+
}
134+
135+
fn run(self, builder: &Builder) {
136+
let build = builder.build;
137+
let compiler = builder.compiler(0, build.build);
138+
let target = self.target;
139+
140+
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "check");
141+
let mut features = build.rustc_features().to_string();
142+
cargo.arg("--manifest-path").arg(build.src.join("src/librustc_trans/Cargo.toml"));
143+
rustc_cargo_env(build, &mut cargo);
144+
145+
match &*self.backend {
146+
"llvm" | "emscripten" => {
147+
// Build LLVM for our target. This will implicitly build the
148+
// host LLVM if necessary.
149+
let llvm_config = builder.ensure(native::Llvm {
150+
target,
151+
emscripten: self.backend == "emscripten",
152+
});
153+
154+
if self.backend == "emscripten" {
155+
features.push_str(" emscripten");
156+
}
157+
158+
// Pass down configuration from the LLVM build into the build of
159+
// librustc_llvm and librustc_trans.
160+
if build.is_rust_llvm(target) {
161+
cargo.env("LLVM_RUSTLLVM", "1");
162+
}
163+
cargo.env("LLVM_CONFIG", &llvm_config);
164+
if self.backend != "emscripten" {
165+
let target_config = build.config.target_config.get(&target);
166+
if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
167+
cargo.env("CFG_LLVM_ROOT", s);
168+
}
169+
}
170+
// Building with a static libstdc++ is only supported on linux right now,
171+
// not for MSVC or macOS
172+
if build.config.llvm_static_stdcpp &&
173+
!target.contains("freebsd") &&
174+
!target.contains("windows") &&
175+
!target.contains("apple") {
176+
let file = compiler_file(build,
177+
build.cxx(target).unwrap(),
178+
target,
179+
"libstdc++.a");
180+
cargo.env("LLVM_STATIC_STDCPP", file);
181+
}
182+
if build.config.llvm_link_shared {
183+
cargo.env("LLVM_LINK_SHARED", "1");
184+
}
185+
}
186+
_ => panic!("unknown backend: {}", self.backend),
187+
}
188+
189+
let tmp_stamp = build.cargo_out(compiler, Mode::Librustc, target)
190+
.join(".tmp.stamp");
191+
192+
let _folder = build.fold_output(|| format!("stage{}-rustc_trans", compiler.stage));
193+
run_cargo(build,
194+
cargo.arg("--features").arg(features),
195+
&tmp_stamp,
196+
true);
197+
}
198+
}
199+
107200
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
108201
pub struct Test {
109202
pub target: Interned<String>,

src/bootstrap/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub fn rustc_cargo(builder: &Builder, cargo: &mut Command) {
519519
rustc_cargo_env(builder, cargo);
520520
}
521521

522-
fn rustc_cargo_env(builder: &Builder, cargo: &mut Command) {
522+
pub fn rustc_cargo_env(builder: &Builder, cargo: &mut Command) {
523523
// Set some configuration variables picked up by build scripts and
524524
// the compiler alike
525525
cargo.env("CFG_RELEASE", builder.rust_release())
@@ -614,7 +614,7 @@ impl Step for CodegenBackend {
614614
run.builder.ensure(CodegenBackend {
615615
compiler: run.builder.compiler(run.builder.top_stage, run.host),
616616
target: run.target,
617-
backend
617+
backend,
618618
});
619619
}
620620

@@ -803,7 +803,7 @@ fn codegen_backend_stamp(builder: &Builder,
803803
.join(format!(".librustc_trans-{}.stamp", backend))
804804
}
805805

806-
fn compiler_file(builder: &Builder,
806+
pub fn compiler_file(builder: &Builder,
807807
compiler: &Path,
808808
target: Interned<String>,
809809
file: &str) -> PathBuf {

0 commit comments

Comments
 (0)