|
10 | 10 |
|
11 | 11 | //! Implementation of compiling the compiler and standard library, in "check" mode.
|
12 | 12 |
|
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; |
14 | 15 | use builder::{RunConfig, Builder, ShouldRun, Step};
|
15 | 16 | use {Compiler, Mode};
|
16 |
| -use cache::Interned; |
| 17 | +use native; |
| 18 | +use cache::{INTERNER, Interned}; |
17 | 19 | use std::path::PathBuf;
|
18 | 20 |
|
19 | 21 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
@@ -104,6 +106,97 @@ impl Step for Rustc {
|
104 | 106 | }
|
105 | 107 | }
|
106 | 108 |
|
| 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 | + |
107 | 200 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
108 | 201 | pub struct Test {
|
109 | 202 | pub target: Interned<String>,
|
|
0 commit comments