use util::{exe, libdir, is_dylib, copy};
use {Build, Compiler, Mode};
-// for (krate, path, _default) in krates("std") {
-// rules.build(&krate.build_step, path)
-// .dep(|s| s.name("startup-objects"))
-// .dep(move |s| s.name("rustc").host(&build.build).target(s.host))
-// .run(move |s| compile::std(build, s.target, &s.compiler()));
-// }
-// for (krate, path, _default) in krates("test") {
-// rules.build(&krate.build_step, path)
-// .dep(|s| s.name("libstd-link"))
-// .run(move |s| compile::test(build, s.target, &s.compiler()));
-// }
-// for (krate, path, _default) in krates("rustc-main") {
-// rules.build(&krate.build_step, path)
-// .dep(|s| s.name("libtest-link"))
-// .dep(move |s| s.name("llvm").host(&build.build).stage(0))
-// .dep(|s| s.name("may-run-build-script"))
-// .run(move |s| compile::rustc(build, s.target, &s.compiler()));
-// }
//
// // Crates which have build scripts need to rely on this rule to ensure that
// // the necessary prerequisites for a build script are linked and located in
rule
}
-/// 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(build: &Build, target: &str, compiler: &Compiler) {
- let libdir = build.sysroot_libdir(compiler, target);
- t!(fs::create_dir_all(&libdir));
-
- let _folder = build.fold_output(|| format!("stage{}-std", compiler.stage));
- println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
- compiler.host, target);
-
- let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
- build.clear_if_dirty(&out_dir, &build.compiler_path(compiler));
- let mut cargo = build.cargo(compiler, Mode::Libstd, target, "build");
- let mut features = build.std_features();
-
- if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
- cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
- }
+// rules.build("libstd", "src/libstd")
+// .dep(|s| s.name("rustc").target(s.host))
+// .dep(|s| s.name("libstd-link"));
+// for (krate, path, _default) in krates("std") {
+// rules.build(&krate.build_step, path)
+// .dep(|s| s.name("startup-objects"))
+// .dep(move |s| s.name("rustc").host(&build.build).target(s.host))
+// .run(move |s| compile::std(build, s.target, &s.compiler()));
+// }
+#[derive(Serialize)]
+pub struct Std<'a> {
+ pub target: &'a str,
+ pub compiler: &'a Compiler<'a>,
+}
+
+impl<'a> Step<'a> for Std<'a> {
+ type Output = ();
+ const DEFAULT: bool = true;
- // When doing a local rebuild we tell cargo that we're stage1 rather than
- // stage0. This works fine if the local rust and being-built rust have the
- // same view of what the default allocator is, but fails otherwise. Since
- // we don't have a way to express an allocator preference yet, work
- // around the issue in the case of a local rebuild with jemalloc disabled.
- if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc {
- features.push_str(" force_alloc_system");
+ fn should_run(builder: &Builder, path: &Path) -> bool {
+ path.ends_with("src/libstd") ||
+ builder.crates("std").into_iter().any(|(_, krate_path)| {
+ path.ends_with(krate_path)
+ })
}
- if compiler.stage != 0 && build.config.sanitizers {
- // This variable is used by the sanitizer runtime crates, e.g.
- // rustc_lsan, to build the sanitizer runtime from C code
- // When this variable is missing, those crates won't compile the C code,
- // so we don't set this variable during stage0 where llvm-config is
- // missing
- // We also only build the runtimes when --enable-sanitizers (or its
- // config.toml equivalent) is used
- cargo.env("LLVM_CONFIG", build.llvm_config(target));
+ fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, target: &str) {
+ builder.ensure(Std {
+ compiler: builder.compiler(builder.top_stage, host),
+ target,
+ })
}
- cargo.arg("--features").arg(features)
- .arg("--manifest-path")
- .arg(build.src.join("src/libstd/Cargo.toml"));
- if let Some(target) = build.config.target_config.get(target) {
- if let Some(ref jemalloc) = target.jemalloc {
- cargo.env("JEMALLOC_OVERRIDE", jemalloc);
+ /// 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.
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let target = self.target;
+ let compiler = self.compiler;
+
+ builder.ensure(StartupObjects { compiler, target });
+
+ if build.force_use_stage1(compiler, target) {
+ let from = builder.compiler(1, &build.build);
+ builder.ensure(Std {
+ compiler: from,
+ target: target,
+ });
+ println!("Uplifting stage1 std ({} -> {})", from.host, target);
+ builder.ensure(StdLink {
+ compiler: from,
+ target_compiler: compiler,
+ target: target,
+ });
+ return;
}
- }
- if target.contains("musl") {
- if let Some(p) = build.musl_root(target) {
- cargo.env("MUSL_ROOT", p);
+
+ let _folder = build.fold_output(|| format!("stage{}-std", compiler.stage));
+ println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
+ compiler.host, target);
+
+ let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
+ build.clear_if_dirty(&out_dir, &build.compiler_path(compiler));
+ let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
+ let mut features = build.std_features();
+
+ if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
+ cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
}
- }
- run_cargo(build,
- &mut cargo,
- &libstd_stamp(build, &compiler, target));
+ // When doing a local rebuild we tell cargo that we're stage1 rather than
+ // stage0. This works fine if the local rust and being-built rust have the
+ // same view of what the default allocator is, but fails otherwise. Since
+ // we don't have a way to express an allocator preference yet, work
+ // around the issue in the case of a local rebuild with jemalloc disabled.
+ if compiler.stage == 0 && build.local_rebuild && !build.config.use_jemalloc {
+ features.push_str(" force_alloc_system");
+ }
+
+ if compiler.stage != 0 && build.config.sanitizers {
+ // This variable is used by the sanitizer runtime crates, e.g.
+ // rustc_lsan, to build the sanitizer runtime from C code
+ // When this variable is missing, those crates won't compile the C code,
+ // so we don't set this variable during stage0 where llvm-config is
+ // missing
+ // We also only build the runtimes when --enable-sanitizers (or its
+ // config.toml equivalent) is used
+ cargo.env("LLVM_CONFIG", build.llvm_config(target));
+ }
+
+ cargo.arg("--features").arg(features)
+ .arg("--manifest-path")
+ .arg(build.src.join("src/libstd/Cargo.toml"));
+
+ if let Some(target) = build.config.target_config.get(target) {
+ if let Some(ref jemalloc) = target.jemalloc {
+ cargo.env("JEMALLOC_OVERRIDE", jemalloc);
+ }
+ }
+ if target.contains("musl") {
+ if let Some(p) = build.musl_root(target) {
+ cargo.env("MUSL_ROOT", p);
+ }
+ }
+
+ run_cargo(build,
+ &mut cargo,
+ &libstd_stamp(build, &compiler, target));
+
+ builder.ensure(StdLink {
+ compiler: builder.compiler(compiler.stage, &build.build),
+ target_compiler: compiler,
+ target: target,
+ });
+ }
}
// compile::std_link)
// .dep(|s| s.name("startup-objects"))
// .dep(|s| s.name("create-sysroot").target(s.host));
-/// Link all libstd rlibs/dylibs into the sysroot location.
-///
-/// Links those artifacts generated by `compiler` to a the `stage` compiler's
-/// sysroot for the specified `host` and `target`.
-///
-/// Note that this assumes that `compiler` has already generated the libstd
-/// libraries for `target`, and this method will find them in the relevant
-/// output directory.
-pub fn std_link(build: &Build,
- compiler: &Compiler,
- target_compiler: &Compiler,
- target: &str) {
- println!("Copying stage{} std from stage{} ({} -> {} / {})",
- target_compiler.stage,
- compiler.stage,
- compiler.host,
- target_compiler.host,
- target);
- let libdir = build.sysroot_libdir(target_compiler, target);
- add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
-
- if target.contains("musl") && !target.contains("mips") {
- copy_musl_third_party_objects(build, target, &libdir);
- }
- if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
- // The sanitizers are only built in stage1 or above, so the dylibs will
- // be missing in stage0 and causes panic. See the `std()` function above
- // for reason why the sanitizers are not built in stage0.
- copy_apple_sanitizer_dylibs(&build.native_dir(target), "osx", &libdir);
+#[derive(Serialize)]
+struct StdLink<'a> {
+ pub compiler: Compiler<'a>,
+ pub target_compiler: Compiler<'a>,
+ pub target: &'a str,
+}
+
+impl<'a> Step<'a> for StdLink<'a> {
+ type Output = ();
+
+ /// Link all libstd rlibs/dylibs into the sysroot location.
+ ///
+ /// Links those artifacts generated by `compiler` to a the `stage` compiler's
+ /// sysroot for the specified `host` and `target`.
+ ///
+ /// Note that this assumes that `compiler` has already generated the libstd
+ /// libraries for `target`, and this method will find them in the relevant
+ /// output directory.
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let compiler = self.compiler;
+ let target_compiler = self.target_compiler;
+ let target = self.target;
+ println!("Copying stage{} std from stage{} ({} -> {} / {})",
+ target_compiler.stage,
+ compiler.stage,
+ compiler.host,
+ target_compiler.host,
+ target);
+ let libdir = build.sysroot_libdir(target_compiler, target);
+ add_to_sysroot(&libdir, &libstd_stamp(build, compiler, target));
+
+ if target.contains("musl") && !target.contains("mips") {
+ copy_musl_third_party_objects(build, target, &libdir);
+ }
+
+ if build.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
+ // The sanitizers are only built in stage1 or above, so the dylibs will
+ // be missing in stage0 and causes panic. See the `std()` function above
+ // for reason why the sanitizers are not built in stage0.
+ copy_apple_sanitizer_dylibs(&build.native_dir(target), "osx", &libdir);
+ }
}
}
// .dep(|s| s.name("create-sysroot").target(s.host))
// .run(move |s| compile::build_startup_objects(build, &s.compiler(), s.target));
-/// Build and prepare startup objects like rsbegin.o and rsend.o
-///
-/// These are primarily used on Windows right now for linking executables/dlls.
-/// 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).
-pub fn build_startup_objects(build: &Build, for_compiler: &Compiler, target: &str) {
- if !target.contains("pc-windows-gnu") {
- return
+#[derive(Serialize)]
+pub struct StartupObjects<'a> {
+ pub for_compiler: Compiler<'a>,
+ pub target: &'a str,
+}
+
+impl<'a> Step<'a> for StartupObjects<'a> {
+ type Output = ();
+
+ fn should_run(_builder: &Builder, path: &Path) -> bool {
+ path.ends_with("src/rtstartup")
}
- let compiler = Compiler::new(0, &build.build);
- let compiler_path = build.compiler_path(&compiler);
- let src_dir = &build.src.join("src/rtstartup");
- let dst_dir = &build.native_dir(target).join("rtstartup");
- let sysroot_dir = &build.sysroot_libdir(for_compiler, target);
- t!(fs::create_dir_all(dst_dir));
- t!(fs::create_dir_all(sysroot_dir));
-
- for file in &["rsbegin", "rsend"] {
- let src_file = &src_dir.join(file.to_string() + ".rs");
- let dst_file = &dst_dir.join(file.to_string() + ".o");
- if !up_to_date(src_file, dst_file) {
- let mut cmd = Command::new(&compiler_path);
- build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
- .arg("--cfg").arg(format!("stage{}", compiler.stage))
- .arg("--target").arg(target)
- .arg("--emit=obj")
- .arg("--out-dir").arg(dst_dir)
- .arg(src_file));
- }
-
- copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
+ fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, target: &str) {
+ builder.ensure(StartupObjects {
+ compiler: builder.compiler(builder.top_stage, host),
+ target,
+ })
}
- for obj in ["crt2.o", "dllcrt2.o"].iter() {
- copy(&compiler_file(build.cc(target), obj), &sysroot_dir.join(obj));
+ /// Build and prepare startup objects like rsbegin.o and rsend.o
+ ///
+ /// These are primarily used on Windows right now for linking executables/dlls.
+ /// 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 run(self, builder: &Builder) {
+ let build = builder.build;
+ let for_compiler = self.for_compiler;
+ let target = self.target;
+ if !target.contains("pc-windows-gnu") {
+ return
+ }
+
+ let compiler = Compiler::new(0, &build.build);
+ let compiler_path = build.compiler_path(&compiler);
+ let src_dir = &build.src.join("src/rtstartup");
+ let dst_dir = &build.native_dir(target).join("rtstartup");
+ let sysroot_dir = &build.sysroot_libdir(for_compiler, target);
+ t!(fs::create_dir_all(dst_dir));
+ t!(fs::create_dir_all(sysroot_dir));
+
+ for file in &["rsbegin", "rsend"] {
+ let src_file = &src_dir.join(file.to_string() + ".rs");
+ let dst_file = &dst_dir.join(file.to_string() + ".o");
+ if !up_to_date(src_file, dst_file) {
+ let mut cmd = Command::new(&compiler_path);
+ build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
+ .arg("--cfg").arg(format!("stage{}", compiler.stage))
+ .arg("--target").arg(target)
+ .arg("--emit=obj")
+ .arg("--out-dir").arg(dst_dir)
+ .arg(src_file));
+ }
+
+ copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
+ }
+
+ for obj in ["crt2.o", "dllcrt2.o"].iter() {
+ copy(&compiler_file(build.cc(target), obj), &sysroot_dir.join(obj));
+ }
}
}
-/// Build libtest.
-///
-/// 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(build: &Build, target: &str, compiler: &Compiler) {
- let _folder = build.fold_output(|| format!("stage{}-test", compiler.stage));
- println!("Building stage{} test artifacts ({} -> {})", compiler.stage,
- compiler.host, target);
- let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
- build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target));
- let mut cargo = build.cargo(compiler, Mode::Libtest, target, "build");
- if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
- cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
+// for (krate, path, _default) in krates("test") {
+// rules.build(&krate.build_step, path)
+// .dep(|s| s.name("libstd-link"))
+// .run(move |s| compile::test(build, s.target, &s.compiler()));
+// }
+#[derive(Serialize)]
+pub struct Test<'a> {
+ pub compiler: Compiler<'a>,
+ pub target: &'a str,
+}
+
+impl<'a> Step<'a> for Test<'a> {
+ type Output = ();
+ const DEFAULT: bool = true;
+
+ fn should_run(builder: &Builder, path: &Path) -> bool {
+ path.ends_with("src/libtest") ||
+ builder.crates("test").into_iter().any(|(_, krate_path)| {
+ path.ends_with(krate_path)
+ })
+ }
+
+ fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, target: &str) {
+ builder.ensure(Test {
+ compiler: builder.compiler(builder.top_stage, host),
+ target,
+ })
+ }
+
+ /// Build libtest.
+ ///
+ /// 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.
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let target = self.target;
+ let compiler = self.compiler;
+
+ builder.ensure(Std { compiler, target });
+
+ if build.force_use_stage1(compiler, target) {
+ builder.ensure(Test {
+ compiler: builder.compiler(1, &build.build),
+ target: target,
+ });
+ println!("Uplifting stage1 test ({} -> {})", &build.build, target);
+ builder.ensure(TestLink {
+ compiler: builder.compiler(1, &build.build),
+ target_compiler: compiler,
+ target: target,
+ });
+ return;
+ }
+
+ let _folder = build.fold_output(|| format!("stage{}-test", compiler.stage));
+ println!("Building stage{} test artifacts ({} -> {})", compiler.stage,
+ compiler.host, target);
+ let out_dir = build.cargo_out(compiler, Mode::Libtest, target);
+ build.clear_if_dirty(&out_dir, &libstd_stamp(build, compiler, target));
+ let mut cargo = build.cargo(compiler, Mode::Libtest, target, "build");
+ if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
+ cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
+ }
+ cargo.arg("--manifest-path")
+ .arg(build.src.join("src/libtest/Cargo.toml"));
+ run_cargo(build,
+ &mut cargo,
+ &libtest_stamp(build, compiler, target));
+
+ builder.ensure(TestLink {
+ compiler: builder.compiler(1, &build.build),
+ target_compiler: compiler,
+ target: target,
+ });
}
- cargo.arg("--manifest-path")
- .arg(build.src.join("src/libtest/Cargo.toml"));
- run_cargo(build,
- &mut cargo,
- &libtest_stamp(build, compiler, target));
}
// compile::test_link)
// .dep(|s| s.name("libstd-link"));
-/// Same as `std_link`, only for libtest
-pub fn test_link(build: &Build,
- compiler: &Compiler,
- target_compiler: &Compiler,
- target: &str) {
- println!("Copying stage{} test from stage{} ({} -> {} / {})",
- target_compiler.stage,
- compiler.stage,
- compiler.host,
- target_compiler.host,
- target);
- add_to_sysroot(&build.sysroot_libdir(target_compiler, target),
- &libtest_stamp(build, compiler, target));
+#[derive(Serialize)]
+pub struct TestLink<'a> {
+ pub compiler: Compiler<'a>,
+ pub target_compiler: Compiler<'a>,
+ pub target: &'a str,
}
-/// Build the compiler.
-///
-/// 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(build: &Build, target: &str, compiler: &Compiler) {
- let _folder = build.fold_output(|| format!("stage{}-rustc", compiler.stage));
- println!("Building stage{} compiler artifacts ({} -> {})",
- compiler.stage, compiler.host, target);
-
- let out_dir = build.cargo_out(compiler, Mode::Librustc, target);
- build.clear_if_dirty(&out_dir, &libtest_stamp(build, compiler, target));
-
- let mut cargo = build.cargo(compiler, Mode::Librustc, target, "build");
- cargo.arg("--features").arg(build.rustc_features())
- .arg("--manifest-path")
- .arg(build.src.join("src/rustc/Cargo.toml"));
-
- // Set some configuration variables picked up by build scripts and
- // the compiler alike
- cargo.env("CFG_RELEASE", build.rust_release())
- .env("CFG_RELEASE_CHANNEL", &build.config.channel)
- .env("CFG_VERSION", build.rust_version())
- .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());
-
- if compiler.stage == 0 {
- cargo.env("CFG_LIBDIR_RELATIVE", "lib");
- } else {
- let libdir_relative = build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib"));
- cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
+impl<'a> Step<'a> for Step<'a> {
+ type Output = ();
+
+ /// Same as `std_link`, only for libtest
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let compiler = self.compiler;
+ let target_compiler = self.target_compiler;
+ let target = self.target;
+ println!("Copying stage{} test from stage{} ({} -> {} / {})",
+ target_compiler.stage,
+ compiler.stage,
+ compiler.host,
+ target_compiler.host,
+ target);
+ add_to_sysroot(&build.sysroot_libdir(target_compiler, target),
+ &libtest_stamp(build, compiler, target));
}
+}
- // If we're not building a compiler with debugging information then remove
- // these two env vars which would be set otherwise.
- if build.config.rust_debuginfo_only_std {
- cargo.env_remove("RUSTC_DEBUGINFO");
- cargo.env_remove("RUSTC_DEBUGINFO_LINES");
- }
+// for (krate, path, _default) in krates("rustc-main") {
+// rules.build(&krate.build_step, path)
+// .dep(|s| s.name("libtest-link"))
+// .dep(move |s| s.name("llvm").host(&build.build).stage(0))
+// .dep(|s| s.name("may-run-build-script"))
+// .run(move |s| compile::rustc(build, s.target, &s.compiler()));
+// }
- if let Some(ref ver_date) = build.rust_info.commit_date() {
- cargo.env("CFG_VER_DATE", ver_date);
- }
- if let Some(ref ver_hash) = build.rust_info.sha() {
- cargo.env("CFG_VER_HASH", ver_hash);
- }
- if !build.unstable_features() {
- cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
- }
- // Flag that rust llvm is in use
- if build.is_rust_llvm(target) {
- cargo.env("LLVM_RUSTLLVM", "1");
- }
- cargo.env("LLVM_CONFIG", build.llvm_config(target));
- let target_config = build.config.target_config.get(target);
- if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
- cargo.env("CFG_LLVM_ROOT", s);
- }
- // Building with a static libstdc++ is only supported on linux right now,
- // not for MSVC or macOS
- if build.config.llvm_static_stdcpp &&
- !target.contains("windows") &&
- !target.contains("apple") {
- cargo.env("LLVM_STATIC_STDCPP",
- compiler_file(build.cxx(target).unwrap(), "libstdc++.a"));
- }
- if build.config.llvm_link_shared {
- cargo.env("LLVM_LINK_SHARED", "1");
+#[derive(Serialize)]
+pub struct Rustc<'a> {
+ pub compiler: Compiler<'a>,
+ pub target: &'a str,
+}
+
+impl<'a> Step<'a> for Rustc<'a> {
+ type Output = ();
+ const ONLY_HOSTS: bool = true;
+ const DEFAULT: bool = true;
+
+ fn should_run(builder: &Builder, path: &Path) -> bool {
+ path.ends_with("src/librustc") ||
+ builder.crates("rustc-main").into_iter().any(|(_, krate_path)| {
+ path.ends_with(krate_path)
+ })
}
- if let Some(ref s) = build.config.rustc_default_linker {
- cargo.env("CFG_DEFAULT_LINKER", s);
+
+ fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, target: &str) {
+ builder.ensure(Rustc {
+ compiler: builder.compiler(builder.top_stage, host),
+ target,
+ })
}
- if let Some(ref s) = build.config.rustc_default_ar {
- cargo.env("CFG_DEFAULT_AR", s);
+
+ /// Build the compiler.
+ ///
+ /// 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.
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let compiler = self.compiler;
+ let target = self.target;
+
+ builder.ensure(Test { compiler, target });
+
+ // Build LLVM for our target. This will implicitly build the host LLVM
+ // if necessary.
+ builder.ensure(native::Llvm { target });
+
+ if build.force_use_stage1(compiler, target) {
+ builder.ensure(Rustc {
+ compiler: builder.compiler(1, &build.build),
+ target: target,
+ });
+ println!("Uplifting stage1 rustc ({} -> {})", &build.build, target);
+ builder.ensure(RustcLink {
+ compiler: builder.compiler(1, &build.build),
+ target_compiler: compiler,
+ target,
+ });
+ return;
+ }
+
+ // Ensure that build scripts have a std to link against.
+ builder.ensure(Std {
+ compiler: builder.compiler(self.compiler.stage, &build.build),
+ target: &build.build,
+ });
+
+ let _folder = build.fold_output(|| format!("stage{}-rustc", compiler.stage));
+ println!("Building stage{} compiler artifacts ({} -> {})",
+ compiler.stage, compiler.host, target);
+
+ let out_dir = build.cargo_out(compiler, Mode::Librustc, target);
+ build.clear_if_dirty(&out_dir, &libtest_stamp(build, compiler, target));
+
+ let mut cargo = build.cargo(compiler, Mode::Librustc, target, "build");
+ cargo.arg("--features").arg(build.rustc_features())
+ .arg("--manifest-path")
+ .arg(build.src.join("src/rustc/Cargo.toml"));
+
+ // Set some configuration variables picked up by build scripts and
+ // the compiler alike
+ cargo.env("CFG_RELEASE", build.rust_release())
+ .env("CFG_RELEASE_CHANNEL", &build.config.channel)
+ .env("CFG_VERSION", build.rust_version())
+ .env("CFG_PREFIX", build.config.prefix.clone().unwrap_or_default());
+
+ if compiler.stage == 0 {
+ cargo.env("CFG_LIBDIR_RELATIVE", "lib");
+ } else {
+ let libdir_relative = build.config.libdir_relative.clone().unwrap_or(PathBuf::from("lib"));
+ cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
+ }
+
+ // If we're not building a compiler with debugging information then remove
+ // these two env vars which would be set otherwise.
+ if build.config.rust_debuginfo_only_std {
+ cargo.env_remove("RUSTC_DEBUGINFO");
+ cargo.env_remove("RUSTC_DEBUGINFO_LINES");
+ }
+
+ if let Some(ref ver_date) = build.rust_info.commit_date() {
+ cargo.env("CFG_VER_DATE", ver_date);
+ }
+ if let Some(ref ver_hash) = build.rust_info.sha() {
+ cargo.env("CFG_VER_HASH", ver_hash);
+ }
+ if !build.unstable_features() {
+ cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
+ }
+ // Flag that rust llvm is in use
+ if build.is_rust_llvm(target) {
+ cargo.env("LLVM_RUSTLLVM", "1");
+ }
+ cargo.env("LLVM_CONFIG", build.llvm_config(target));
+ let target_config = build.config.target_config.get(target);
+ if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
+ cargo.env("CFG_LLVM_ROOT", s);
+ }
+ // Building with a static libstdc++ is only supported on linux right now,
+ // not for MSVC or macOS
+ if build.config.llvm_static_stdcpp &&
+ !target.contains("windows") &&
+ !target.contains("apple") {
+ cargo.env("LLVM_STATIC_STDCPP",
+ compiler_file(build.cxx(target).unwrap(), "libstdc++.a"));
+ }
+ if build.config.llvm_link_shared {
+ cargo.env("LLVM_LINK_SHARED", "1");
+ }
+ if let Some(ref s) = build.config.rustc_default_linker {
+ cargo.env("CFG_DEFAULT_LINKER", s);
+ }
+ if let Some(ref s) = build.config.rustc_default_ar {
+ cargo.env("CFG_DEFAULT_AR", s);
+ }
+ run_cargo(build,
+ &mut cargo,
+ &librustc_stamp(build, compiler, target));
+
+ builder.ensure(RustcLink {
+ compiler: builder.compiler(compiler.stage, &build.build),
+ target_compiler: compiler,
+ target,
+ });
}
- run_cargo(build,
- &mut cargo,
- &librustc_stamp(build, compiler, target));
}
// crate_rule(build,
// "build-crate-rustc-main",
// compile::rustc_link)
// .dep(|s| s.name("libtest-link"));
-/// Same as `std_link`, only for librustc
-pub fn rustc_link(build: &Build,
- compiler: &Compiler,
- target_compiler: &Compiler,
- target: &str) {
- println!("Copying stage{} rustc from stage{} ({} -> {} / {})",
- target_compiler.stage,
- compiler.stage,
- compiler.host,
- target_compiler.host,
- target);
- add_to_sysroot(&build.sysroot_libdir(target_compiler, target),
- &librustc_stamp(build, compiler, target));
+#[derive(Serialize)]
+struct RustcLink<'a> {
+ pub compiler: Compiler<'a>,
+ pub target_compiler: Compiler<'a>,
+ pub target: &'a str,
+}
+
+impl<'a> Step<'a> for RustcLink<'a> {
+ type Output = ();
+
+ /// Same as `std_link`, only for librustc
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let compiler = self.compiler;
+ let target_compiler = self.target_compiler;
+ let target = self.target;
+ println!("Copying stage{} rustc from stage{} ({} -> {} / {})",
+ target_compiler.stage,
+ compiler.stage,
+ compiler.host,
+ target_compiler.host,
+ target);
+ add_to_sysroot(&build.sysroot_libdir(target_compiler, target),
+ &librustc_stamp(build, compiler, target));
+ }
}
/// 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 {
+pub fn libstd_stamp(build: &Build, compiler: &Compiler, target: &str) -> 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 {
+pub fn libtest_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
build.cargo_out(compiler, Mode::Libtest, target).join(".libtest.stamp")
}
/// Cargo's output path for librustc in a given stage, compiled by a particular
/// compiler for the specified target.
-fn librustc_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
+pub fn librustc_stamp(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
build.cargo_out(compiler, Mode::Librustc, target).join(".librustc.stamp")
}
// rules.build("create-sysroot", "path/to/nowhere")
// .run(move |s| compile::create_sysroot(build, &s.compiler()));
-pub fn create_sysroot(build: &Build, compiler: &Compiler) {
- let sysroot = build.sysroot(compiler);
- let _ = fs::remove_dir_all(&sysroot);
- t!(fs::create_dir_all(&sysroot));
+
+#[derive(Serialize)]
+pub struct Sysroot<'a> {
+ pub compiler: Compiler<'a>,
+}
+
+impl<'a> Step<'a> for Sysroot<'a> {
+ type Output = PathBuf;
+
+ /// Returns the sysroot for the `compiler` specified that *this build system
+ /// generates*.
+ ///
+ /// That is, the sysroot for the stage0 compiler is not what the compiler
+ /// thinks it is by default, but it's the same as the default for stages
+ /// 1-3.
+ fn run(self, builder: &Builder) -> PathBuf {
+ let build = builder.build;
+ let compiler = self.compiler;
+ let sysroot = if compiler.stage == 0 {
+ build.out.join(compiler.host).join("stage0-sysroot")
+ } else {
+ build.out.join(compiler.host).join(format!("stage{}", compiler.stage))
+ };
+ let _ = fs::remove_dir_all(&sysroot);
+ t!(fs::create_dir_all(&sysroot));
+ sysroot
+ }
}
// the compiler with no target libraries ready to go
// }
// })
// .run(move |s| compile::assemble_rustc(build, s.stage, s.target));
-/// Prepare a new compiler from the artifacts in `stage`
-///
-/// This will assemble a compiler in `build/$host/stage$stage`. The compiler
-/// must have been previously produced by the `stage - 1` build.build
-/// compiler.
-pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
- // nothing to do in stage0
- if stage == 0 {
- return
- }
- println!("Copying stage{} compiler ({})", stage, host);
+#[derive(Serialize)]
+pub struct Assemble<'a> {
+ /// The compiler which we will produce in this step. Assemble itself will
+ /// take care of ensuring that the necessary prerequisites to do so exist,
+ /// that is, this target can be a stage2 compiler and Assemble will build
+ /// previous stages for you.
+ pub target_compiler: Compiler<'a>,
+}
- // The compiler that we're assembling
- let target_compiler = Compiler::new(stage, host);
+impl<'a> Step<'a> for Assemble<'a> {
+ type Output = ();
+
+ /// Prepare a new compiler from the artifacts in `stage`
+ ///
+ /// This will assemble a compiler in `build/$host/stage$stage`. The compiler
+ /// must have been previously produced by the `stage - 1` build.build
+ /// compiler.
+ fn run(self, builder: &Builder) {
+ let build = builder.build;
+ let target_compiler = self.target_compiler;
+
+ if target_compiler.stage == 0 {
+ assert_eq!(build.build, target_compiler.host,
+ "Cannot obtain compiler for non-native build triple at stage 0");
+ // The stage 0 compiler for the build triple is always pre-built.
+ return target_compiler;
+ }
- // The compiler that compiled the compiler we're assembling
- let build_compiler = Compiler::new(stage - 1, &build.build);
+ // Get the compiler that we'll use to bootstrap ourselves.
+ let build_compiler = if target_compiler.host != build.build {
+ // Build a compiler for the host platform. We cannot use the stage0
+ // compiler for the host platform for this because it doesn't have
+ // the libraries we need. FIXME: Perhaps we should download those
+ // libraries? It would make builds faster...
+ builder.ensure(Assemble {
+ target_compiler: Compiler {
+ // FIXME: It may be faster if we build just a stage 1
+ // compiler and then use that to bootstrap this compiler
+ // forward.
+ stage: target_compiler.stage - 1,
+ host: &build.build
+ },
+ })
+ } else {
+ // Build the compiler we'll use to build the stage requested. This
+ // may build more than one compiler (going down to stage 0).
+ builder.ensure(Assemble {
+ target_compiler: target_compiler.with_stage(target_compiler.stage - 1),
+ })
+ };
- // Link in all dylibs to the libdir
- let sysroot = build.sysroot(&target_compiler);
- let sysroot_libdir = sysroot.join(libdir(host));
- t!(fs::create_dir_all(&sysroot_libdir));
- let src_libdir = build.sysroot_libdir(&build_compiler, host);
- for f in t!(fs::read_dir(&src_libdir)).map(|f| t!(f)) {
- let filename = f.file_name().into_string().unwrap();
- if is_dylib(&filename) {
- copy(&f.path(), &sysroot_libdir.join(&filename));
+ // Build the libraries for this compiler to link to (i.e., the libraries
+ // it uses at runtime). NOTE: Crates the target compiler compiles don't
+ // link to these. (FIXME: Is that correct? It seems to be correct most
+ // of the time but I think we do link to these for stage2/bin compilers
+ // when not performing a full bootstrap).
+ builder.ensure(Rustc { compiler: build_compiler, target: target_compiler.host });
+
+ let stage = target_compiler.stage;
+ let host = target_compiler.host;
+ println!("Assembling stage{} compiler ({})", stage, host);
+
+ // Link in all dylibs to the libdir
+ let sysroot = build.sysroot(&target_compiler);
+ let sysroot_libdir = sysroot.join(libdir(host));
+ t!(fs::create_dir_all(&sysroot_libdir));
+ let src_libdir = build.sysroot_libdir(&build_compiler, host);
+ for f in t!(fs::read_dir(&src_libdir)).map(|f| t!(f)) {
+ let filename = f.file_name().into_string().unwrap();
+ if is_dylib(&filename) {
+ copy(&f.path(), &sysroot_libdir.join(&filename));
+ }
}
- }
- let out_dir = build.cargo_out(&build_compiler, Mode::Librustc, host);
-
- // Link the compiler binary itself into place
- let rustc = out_dir.join(exe("rustc", host));
- let bindir = sysroot.join("bin");
- t!(fs::create_dir_all(&bindir));
- let compiler = build.compiler_path(&target_compiler);
- let _ = fs::remove_file(&compiler);
- copy(&rustc, &compiler);
-
- // See if rustdoc exists to link it into place
- let rustdoc = exe("rustdoc", host);
- let rustdoc_src = out_dir.join(&rustdoc);
- let rustdoc_dst = bindir.join(&rustdoc);
- if fs::metadata(&rustdoc_src).is_ok() {
- let _ = fs::remove_file(&rustdoc_dst);
- copy(&rustdoc_src, &rustdoc_dst);
+ let out_dir = build.cargo_out(&build_compiler, Mode::Librustc, host);
+
+ // Link the compiler binary itself into place
+ let rustc = out_dir.join(exe("rustc", host));
+ let bindir = sysroot.join("bin");
+ t!(fs::create_dir_all(&bindir));
+ let compiler = build.compiler_path(&target_compiler);
+ let _ = fs::remove_file(&compiler);
+ copy(&rustc, &compiler);
+
+ // See if rustdoc exists to link it into place
+ let rustdoc = exe("rustdoc", host);
+ let rustdoc_src = out_dir.join(&rustdoc);
+ let rustdoc_dst = bindir.join(&rustdoc);
+ if fs::metadata(&rustdoc_src).is_ok() {
+ let _ = fs::remove_file(&rustdoc_dst);
+ copy(&rustdoc_src, &rustdoc_dst);
+ }
}
}
}
}
-//// ========================================================================
-//// Build tools
-////
-//// Tools used during the build system but not shipped
-//// "pseudo rule" which represents completely cleaning out the tools dir in
-//// one stage. This needs to happen whenever a dependency changes (e.g.
-//// libstd, libtest, librustc) and all of the tool compilations above will
-//// be sequenced after this rule.
-//rules.build("maybe-clean-tools", "path/to/nowhere")
-// .after("librustc-tool")
-// .after("libtest-tool")
-// .after("libstd-tool");
-//
-//rules.build("librustc-tool", "path/to/nowhere")
-// .dep(|s| s.name("librustc"))
-// .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Librustc));
-//rules.build("libtest-tool", "path/to/nowhere")
-// .dep(|s| s.name("libtest"))
-// .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Libtest));
-//rules.build("libstd-tool", "path/to/nowhere")
-// .dep(|s| s.name("libstd"))
-// .run(move |s| compile::maybe_clean_tools(build, s.stage, s.target, Mode::Libstd));
-//
-/// Build a tool in `src/tools`
-///
-/// This will build the specified tool with the specified `host` compiler in
-/// `stage` into the normal cargo output directory.
-pub fn maybe_clean_tools(build: &Build, stage: u32, target: &str, mode: Mode) {
- let compiler = Compiler::new(stage, &build.build);
-
- let stamp = match mode {
- Mode::Libstd => libstd_stamp(build, &compiler, target),
- Mode::Libtest => libtest_stamp(build, &compiler, target),
- Mode::Librustc => librustc_stamp(build, &compiler, target),
- _ => panic!(),
- };
- let out_dir = build.cargo_out(&compiler, Mode::Tool, target);
- build.clear_if_dirty(&out_dir, &stamp);
-}
-
-
-// rules.build("tool-rustbook", "src/tools/rustbook")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("librustc-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "rustbook"));
-// rules.build("tool-error-index", "src/tools/error_index_generator")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("librustc-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "error_index_generator"));
-// rules.build("tool-unstable-book-gen", "src/tools/unstable-book-gen")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "unstable-book-gen"));
-// rules.build("tool-tidy", "src/tools/tidy")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "tidy"));
-// rules.build("tool-linkchecker", "src/tools/linkchecker")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "linkchecker"));
-// rules.build("tool-cargotest", "src/tools/cargotest")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "cargotest"));
-// rules.build("tool-compiletest", "src/tools/compiletest")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libtest-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "compiletest"));
-// rules.build("tool-build-manifest", "src/tools/build-manifest")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "build-manifest"));
-// rules.build("tool-remote-test-server", "src/tools/remote-test-server")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "remote-test-server"));
-// rules.build("tool-remote-test-client", "src/tools/remote-test-client")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "remote-test-client"));
-// rules.build("tool-rust-installer", "src/tools/rust-installer")
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .run(move |s| compile::tool(build, s.stage, s.target, "rust-installer"));
-// rules.build("tool-cargo", "src/tools/cargo")
-// .host(true)
-// .default(build.config.extended)
-// .dep(|s| s.name("maybe-clean-tools"))
-// .dep(|s| s.name("libstd-tool"))
-// .dep(|s| s.stage(0).host(s.target).name("openssl"))
-// .dep(move |s| {
-// // Cargo depends on procedural macros, which requires a full host
-// // compiler to be available, so we need to depend on that.
-// s.name("librustc-link")
-// .target(&build.build)
-// .host(&build.build)
-// })
-// .run(move |s| compile::tool(build, s.stage, s.target, "cargo"));
-// rules.build("tool-rls", "src/tools/rls")
-// .host(true)
-// .default(build.config.extended)
-// .dep(|s| s.name("librustc-tool"))
-// .dep(|s| s.stage(0).host(s.target).name("openssl"))
-// .dep(move |s| {
-// // rls, like cargo, uses procedural macros
-// s.name("librustc-link")
-// .target(&build.build)
-// .host(&build.build)
-// })
-// .run(move |s| compile::tool(build, s.stage, s.target, "rls"));
-//
-
-/// Build a tool in `src/tools`
-///
-/// 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, target: &str, tool: &str) {
- let _folder = build.fold_output(|| format!("stage{}-{}", stage, tool));
- println!("Building stage{} tool {} ({})", stage, tool, target);
-
- let compiler = Compiler::new(stage, &build.build);
-
- let mut cargo = build.cargo(&compiler, Mode::Tool, target, "build");
- let dir = build.src.join("src/tools").join(tool);
- cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
-
- // We don't want to build tools dynamically as they'll be running across
- // stages and such and it's just easier if they're not dynamically linked.
- cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
-
- if let Some(dir) = build.openssl_install_dir(target) {
- cargo.env("OPENSSL_STATIC", "1");
- cargo.env("OPENSSL_DIR", dir);
- cargo.env("LIBZ_SYS_STATIC", "1");
- }
-
- cargo.env("CFG_RELEASE_CHANNEL", &build.config.channel);
-
- let info = GitInfo::new(&dir);
- if let Some(sha) = info.sha() {
- cargo.env("CFG_COMMIT_HASH", sha);
- }
- if let Some(sha_short) = info.sha_short() {
- cargo.env("CFG_SHORT_COMMIT_HASH", sha_short);
- }
- if let Some(date) = info.commit_date() {
- cargo.env("CFG_COMMIT_DATE", date);
- }
-
- build.run(&mut cargo);
-}
-
-
// Avoiding a dependency on winapi to keep compile times down
#[cfg(unix)]
fn stderr_isatty() -> bool {