Skip to content

Commit 6a44cf0

Browse files
committed
rustbuild: Fix optimizing native code
The default flags printed out by gcc-rs indicate the optimization level, but we want to defer that until later when the build script is actually running so don't pass them down from the top level.
1 parent 023dcd3 commit 6a44cf0

File tree

5 files changed

+71
-26
lines changed

5 files changed

+71
-26
lines changed

src/bootstrap/build/check.rs

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ pub fn compiletest(build: &Build,
7373
// FIXME: CFG_PYTHON should probably be detected more robustly elsewhere
7474
cmd.arg("--python").arg("python");
7575

76+
if let Some(ref vers) = build.gdb_version {
77+
cmd.arg("--gdb-version").arg(vers);
78+
}
79+
if let Some(ref vers) = build.lldb_version {
80+
cmd.arg("--lldb-version").arg(vers);
81+
}
82+
7683
cmd.args(&build.flags.args);
7784

7885
if build.config.verbose || build.flags.verbose {

src/bootstrap/build/dist.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -195,29 +195,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
195195
cp_r(&build.src.join("man"), &image.join("share/man/man1"));
196196

197197
// Debugger scripts
198-
let cp_debugger_script = |file: &str| {
199-
let dst = image.join("lib/rustlib/etc");
200-
t!(fs::create_dir_all(&dst));
201-
install(&build.src.join("src/etc/").join(file), &dst, 0o644);
202-
};
203-
if host.contains("windows") {
204-
// no debugger scripts
205-
} else if host.contains("darwin") {
206-
// lldb debugger scripts
207-
install(&build.src.join("src/etc/rust-lldb"), &image.join("bin"),
208-
0o755);
209-
210-
cp_debugger_script("lldb_rust_formatters.py");
211-
cp_debugger_script("debugger_pretty_printers_common.py");
212-
} else {
213-
// gdb debugger scripts
214-
install(&build.src.join("src/etc/rust-gdb"), &image.join("bin"),
215-
0o755);
216-
217-
cp_debugger_script("gdb_load_rust_pretty_printers.py");
218-
cp_debugger_script("gdb_rust_pretty_printing.py");
219-
cp_debugger_script("debugger_pretty_printers_common.py");
220-
}
198+
debugger_scripts(build, &image, host);
221199

222200
// Misc license info
223201
let cp = |file: &str| {
@@ -231,6 +209,35 @@ pub fn rustc(build: &Build, stage: u32, host: &str) {
231209
}
232210
}
233211

212+
pub fn debugger_scripts(build: &Build,
213+
sysroot: &Path,
214+
host: &str) {
215+
let cp_debugger_script = |file: &str| {
216+
let dst = sysroot.join("lib/rustlib/etc");
217+
t!(fs::create_dir_all(&dst));
218+
install(&build.src.join("src/etc/").join(file), &dst, 0o644);
219+
};
220+
if host.contains("windows") {
221+
// no debugger scripts
222+
} else if host.contains("darwin") {
223+
// lldb debugger scripts
224+
install(&build.src.join("src/etc/rust-lldb"), &sysroot.join("bin"),
225+
0o755);
226+
227+
cp_debugger_script("lldb_rust_formatters.py");
228+
cp_debugger_script("debugger_pretty_printers_common.py");
229+
} else {
230+
// gdb debugger scripts
231+
install(&build.src.join("src/etc/rust-gdb"), &sysroot.join("bin"),
232+
0o755);
233+
234+
cp_debugger_script("gdb_load_rust_pretty_printers.py");
235+
cp_debugger_script("gdb_rust_pretty_printing.py");
236+
cp_debugger_script("debugger_pretty_printers_common.py");
237+
}
238+
}
239+
240+
234241
pub fn std(build: &Build, compiler: &Compiler, target: &str) {
235242
println!("Dist std stage{} ({} -> {})", compiler.stage, compiler.host,
236243
target);

src/bootstrap/build/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ pub struct Build {
8080
package_vers: String,
8181
bootstrap_key: String,
8282

83+
// Probed tools at runtime
84+
gdb_version: Option<String>,
85+
lldb_version: Option<String>,
86+
8387
// Runtime state filled in later on
8488
cc: HashMap<String, (gcc::Tool, PathBuf)>,
8589
cxx: HashMap<String, gcc::Tool>,
@@ -128,6 +132,8 @@ impl Build {
128132
cc: HashMap::new(),
129133
cxx: HashMap::new(),
130134
compiler_rt_built: RefCell::new(HashMap::new()),
135+
gdb_version: None,
136+
lldb_version: None,
131137
}
132138
}
133139

@@ -291,6 +297,13 @@ impl Build {
291297
DistRustc { stage } => dist::rustc(self, stage, target.target),
292298
DistStd { compiler } => dist::std(self, &compiler, target.target),
293299

300+
DebuggerScripts { stage } => {
301+
let compiler = Compiler::new(stage, target.target);
302+
dist::debugger_scripts(self,
303+
&self.sysroot(&compiler),
304+
target.target);
305+
}
306+
294307
Dist { .. } |
295308
Doc { .. } | // pseudo-steps
296309
Check { .. } => {}
@@ -588,8 +601,11 @@ impl Build {
588601
}
589602

590603
fn cflags(&self, target: &str) -> Vec<String> {
604+
// Filter out -O and /O (the optimization flags) that we picked up from
605+
// gcc-rs because the build scripts will determine that for themselves.
591606
let mut base = self.cc[target].0.args().iter()
592607
.map(|s| s.to_string_lossy().into_owned())
608+
.filter(|s| !s.starts_with("-O") && !s.starts_with("/O"))
593609
.collect::<Vec<_>>();
594610

595611
// If we're compiling on OSX then we add a few unconditional flags

src/bootstrap/build/sanity.rs

+10
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,14 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
137137
target);
138138
}
139139
}
140+
141+
let version = |cmd: &str| {
142+
Command::new(cmd).arg("--version").output().map(|output| {
143+
String::from_utf8_lossy(&output.stdout)
144+
.lines().next().unwrap()
145+
.to_string()
146+
})
147+
};
148+
build.gdb_version = version("gdb").ok();
149+
build.lldb_version = version("lldb").ok();
140150
}

src/bootstrap/build/step.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ macro_rules! targets {
6262
(llvm, Llvm { _dummy: () }),
6363
(compiler_rt, CompilerRt { _dummy: () }),
6464
(test_helpers, TestHelpers { _dummy: () }),
65+
(debugger_scripts, DebuggerScripts { stage: u32 }),
6566

6667
// Steps for various pieces of documentation that we can generate,
6768
// the 'doc' step is just a pseudo target to depend on a bunch of
@@ -289,6 +290,7 @@ impl<'a> Step<'a> {
289290
}
290291
Source::Llvm { _dummy } => Vec::new(),
291292
Source::TestHelpers { _dummy } => Vec::new(),
293+
Source::DebuggerScripts { stage: _ } => Vec::new(),
292294

293295
// Note that all doc targets depend on artifacts from the build
294296
// architecture, not the target (which is where we're generating
@@ -355,9 +357,12 @@ impl<'a> Step<'a> {
355357
Source::CheckCFail { compiler } |
356358
Source::CheckRPassValgrind { compiler } |
357359
Source::CheckRPass { compiler } => {
358-
vec![self.libtest(compiler),
359-
self.tool_compiletest(compiler.stage),
360-
self.test_helpers(())]
360+
vec![
361+
self.libtest(compiler),
362+
self.tool_compiletest(compiler.stage),
363+
self.test_helpers(()),
364+
self.debugger_scripts(compiler.stage),
365+
]
361366
}
362367
Source::CheckRPassFull { compiler } |
363368
Source::CheckCFailFull { compiler } => {

0 commit comments

Comments
 (0)