16
16
//! never get replaced.
17
17
18
18
use std::env;
19
- use std::ffi::OsString;
20
19
use std::io;
21
20
use std::path::PathBuf;
22
21
use std::process::Command;
23
22
use std::str::FromStr;
24
23
use std::time::Instant;
25
24
26
25
fn main() {
27
- let mut args = env::args_os().skip(1).collect::<Vec<_>>();
28
-
29
- // Append metadata suffix for internal crates. See the corresponding entry
30
- // in bootstrap/lib.rs for details.
31
- if let Ok(s) = env::var("RUSTC_METADATA_SUFFIX") {
32
- for i in 1..args.len() {
33
- // Dirty code for borrowing issues
34
- let mut new = None;
35
- if let Some(current_as_str) = args[i].to_str() {
36
- if (&*args[i - 1] == "-C" && current_as_str.starts_with("metadata")) ||
37
- current_as_str.starts_with("-Cmetadata") {
38
- new = Some(format!("{}-{}", current_as_str, s));
39
- }
40
- }
41
- if let Some(new) = new { args[i] = new.into(); }
42
- }
43
- }
26
+ let args = env::args_os().skip(1).collect::<Vec<_>>();
44
27
45
28
// Detect whether or not we're a build script depending on whether --target
46
29
// is passed (a bit janky...)
@@ -93,92 +76,19 @@ fn main() {
93
76
}
94
77
}
95
78
96
- // Non-zero stages must all be treated uniformly to avoid problems when attempting to uplift
97
- // compiler libraries and such from stage 1 to 2.
98
- //
99
- // FIXME: the fact that core here is excluded is due to core_arch from our stdarch submodule
100
- // being broken on the beta compiler with bootstrap passed, so this is a temporary workaround
101
- // (we've just snapped, so there are no cfg(bootstrap) related annotations in core).
102
- if stage == "0" {
103
- if crate_name != Some("core") {
104
- cmd.arg("--cfg").arg("bootstrap");
105
- } else {
106
- // NOTE(eddyb) see FIXME above, except now we need annotations again in core.
107
- cmd.arg("--cfg").arg("boostrap_stdarch_ignore_this");
108
- }
109
- }
110
-
111
79
// Print backtrace in case of ICE
112
80
if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() {
113
81
cmd.env("RUST_BACKTRACE", "1");
114
82
}
115
83
116
- cmd.env("RUSTC_BREAK_ON_ICE", "1");
117
-
118
- if let Ok(debuginfo_level) = env::var("RUSTC_DEBUGINFO_LEVEL") {
119
- cmd.arg(format!("-Cdebuginfo={}", debuginfo_level));
120
- }
121
-
122
- if env::var_os("RUSTC_EXTERNAL_TOOL").is_none() {
123
- // When extending this list, add the new lints to the RUSTFLAGS of the
124
- // build_bootstrap function of src/bootstrap/bootstrap.py as well as
125
- // some code doesn't go through this `rustc` wrapper.
126
- cmd.arg("-Wrust_2018_idioms");
127
- cmd.arg("-Wunused_lifetimes");
128
- if use_internal_lints(crate_name) {
129
- cmd.arg("-Zunstable-options");
130
- cmd.arg("-Wrustc::internal");
131
- }
132
- if env::var_os("RUSTC_DENY_WARNINGS").is_some() {
133
- cmd.arg("-Dwarnings");
134
- }
135
- }
136
-
137
- if let Some(target) = target {
84
+ if target.is_some() {
138
85
// The stage0 compiler has a special sysroot distinct from what we
139
86
// actually downloaded, so we just always pass the `--sysroot` option,
140
87
// unless one is already set.
141
88
if !args.iter().any(|arg| arg == "--sysroot") {
142
89
cmd.arg("--sysroot").arg(&sysroot);
143
90
}
144
91
145
- cmd.arg("-Zexternal-macro-backtrace");
146
-
147
- // Link crates to the proc macro crate for the target, but use a host proc macro crate
148
- // to actually run the macros
149
- if env::var_os("RUST_DUAL_PROC_MACROS").is_some() {
150
- cmd.arg("-Zdual-proc-macros");
151
- }
152
-
153
- // When we build Rust dylibs they're all intended for intermediate
154
- // usage, so make sure we pass the -Cprefer-dynamic flag instead of
155
- // linking all deps statically into the dylib.
156
- if env::var_os("RUSTC_NO_PREFER_DYNAMIC").is_none() {
157
- cmd.arg("-Cprefer-dynamic");
158
- }
159
-
160
- // Help the libc crate compile by assisting it in finding various
161
- // sysroot native libraries.
162
- if let Some(s) = env::var_os("MUSL_ROOT") {
163
- if target.contains("musl") {
164
- let mut root = OsString::from("native=");
165
- root.push(&s);
166
- root.push("/lib");
167
- cmd.arg("-L").arg(&root);
168
- }
169
- }
170
- if let Some(s) = env::var_os("WASI_ROOT") {
171
- let mut root = OsString::from("native=");
172
- root.push(&s);
173
- root.push("/lib/wasm32-wasi");
174
- cmd.arg("-L").arg(&root);
175
- }
176
-
177
- // Override linker if necessary.
178
- if let Ok(target_linker) = env::var("RUSTC_TARGET_LINKER") {
179
- cmd.arg(format!("-Clinker={}", target_linker));
180
- }
181
-
182
92
// If we're compiling specifically the `panic_abort` crate then we pass
183
93
// the `-C panic=abort` option. Note that we do not do this for any
184
94
// other crate intentionally as this is the only crate for now that we
@@ -205,82 +115,18 @@ fn main() {
205
115
206
116
// The compiler builtins are pretty sensitive to symbols referenced in
207
117
// libcore and such, so we never compile them with debug assertions.
118
+ //
119
+ // FIXME(rust-lang/cargo#7253) we should be doing this in `builder.rs`
120
+ // with env vars instead of doing it here in this script.
208
121
if crate_name == Some("compiler_builtins") {
209
122
cmd.arg("-C").arg("debug-assertions=no");
210
123
} else {
211
124
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
212
125
}
213
-
214
- if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {
215
- cmd.arg("-C").arg(format!("codegen-units={}", s));
216
- }
217
-
218
- // Emit save-analysis info.
219
- if env::var("RUSTC_SAVE_ANALYSIS") == Ok("api".to_string()) {
220
- cmd.arg("-Zsave-analysis");
221
- cmd.env("RUST_SAVE_ANALYSIS_CONFIG",
222
- "{\"output_file\": null,\"full_docs\": false,\
223
- \"pub_only\": true,\"reachable_only\": false,\
224
- \"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}");
225
- }
226
-
227
- // Dealing with rpath here is a little special, so let's go into some
228
- // detail. First off, `-rpath` is a linker option on Unix platforms
229
- // which adds to the runtime dynamic loader path when looking for
230
- // dynamic libraries. We use this by default on Unix platforms to ensure
231
- // that our nightlies behave the same on Windows, that is they work out
232
- // of the box. This can be disabled, of course, but basically that's why
233
- // we're gated on RUSTC_RPATH here.
234
- //
235
- // Ok, so the astute might be wondering "why isn't `-C rpath` used
236
- // here?" and that is indeed a good question to task. This codegen
237
- // option is the compiler's current interface to generating an rpath.
238
- // Unfortunately it doesn't quite suffice for us. The flag currently
239
- // takes no value as an argument, so the compiler calculates what it
240
- // should pass to the linker as `-rpath`. This unfortunately is based on
241
- // the **compile time** directory structure which when building with
242
- // Cargo will be very different than the runtime directory structure.
243
- //
244
- // All that's a really long winded way of saying that if we use
245
- // `-Crpath` then the executables generated have the wrong rpath of
246
- // something like `$ORIGIN/deps` when in fact the way we distribute
247
- // rustc requires the rpath to be `$ORIGIN/../lib`.
248
- //
249
- // So, all in all, to set up the correct rpath we pass the linker
250
- // argument manually via `-C link-args=-Wl,-rpath,...`. Plus isn't it
251
- // fun to pass a flag to a tool to pass a flag to pass a flag to a tool
252
- // to change a flag in a binary?
253
- if env::var("RUSTC_RPATH") == Ok("true".to_string()) {
254
- let rpath = if target.contains("apple") {
255
-
256
- // Note that we need to take one extra step on macOS to also pass
257
- // `-Wl,-instal_name,@rpath/...` to get things to work right. To
258
- // do that we pass a weird flag to the compiler to get it to do
259
- // so. Note that this is definitely a hack, and we should likely
260
- // flesh out rpath support more fully in the future.
261
- cmd.arg("-Z").arg("osx-rpath-install-name");
262
- Some("-Wl,-rpath,@loader_path/../lib")
263
- } else if !target.contains("windows") &&
264
- !target.contains("wasm32") &&
265
- !target.contains("fuchsia") {
266
- Some("-Wl,-rpath,$ORIGIN/../lib")
267
- } else {
268
- None
269
- };
270
- if let Some(rpath) = rpath {
271
- cmd.arg("-C").arg(format!("link-args={}", rpath));
272
- }
273
- }
274
-
275
- if let Ok(s) = env::var("RUSTC_CRT_STATIC") {
276
- if s == "true" {
277
- cmd.arg("-C").arg("target-feature=+crt-static");
278
- }
279
- if s == "false" {
280
- cmd.arg("-C").arg("target-feature=-crt-static");
281
- }
282
- }
283
126
} else {
127
+ // FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
128
+ // here, but rather Cargo should know what flags to pass rustc itself.
129
+
284
130
// Override linker if necessary.
285
131
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
286
132
cmd.arg(format!("-Clinker={}", host_linker));
@@ -308,10 +154,6 @@ fn main() {
308
154
cmd.arg("-Z").arg("force-unstable-if-unmarked");
309
155
}
310
156
311
- if env::var_os("RUSTC_PARALLEL_COMPILER").is_some() {
312
- cmd.arg("--cfg").arg("parallel_compiler");
313
- }
314
-
315
157
if verbose > 1 {
316
158
eprintln!(
317
159
"rustc command: {:?}={:?} {:?}",
@@ -362,14 +204,6 @@ fn main() {
362
204
std::process::exit(code);
363
205
}
364
206
365
- // Rustc crates for which internal lints are in effect.
366
- fn use_internal_lints(crate_name: Option<&str>) -> bool {
367
- crate_name.map_or(false, |crate_name| {
368
- crate_name.starts_with("rustc") || crate_name.starts_with("syntax") ||
369
- ["arena", "fmt_macros"].contains(&crate_name)
370
- })
371
- }
372
-
373
207
#[cfg(unix)]
374
208
fn exec_cmd(cmd: &mut Command) -> io::Result<i32> {
375
209
use std::os::unix::process::CommandExt;
0 commit comments