Skip to content

Commit f4e4ec7

Browse files
committed
rustbuild: Pass -O to tests based on configuration
Currently rustbuild isn't detecting the `-O` flag for tests via the `--disable-optimize-tests` or not command line flag to `./configure`, and this commit patches up the support to pass `-O` by default.
1 parent bdadad8 commit f4e4ec7

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/bootstrap/build/check.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,18 @@ pub fn compiletest(build: &Build,
105105
cmd.arg("--host").arg(compiler.host);
106106
cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.config.build));
107107

108+
let mut flags = format!("-Crpath");
109+
if build.config.rust_optimize_tests {
110+
flags.push_str(" -O");
111+
}
112+
if build.config.rust_debuginfo_tests {
113+
flags.push_str(" -g");
114+
}
115+
116+
cmd.arg("--host-rustcflags").arg(&flags);
117+
108118
let linkflag = format!("-Lnative={}", build.test_helpers_out(target).display());
109-
cmd.arg("--host-rustcflags").arg("-Crpath");
110-
cmd.arg("--target-rustcflags").arg(format!("-Crpath {}", linkflag));
119+
cmd.arg("--target-rustcflags").arg(format!("{} {}", flags, linkflag));
111120

112121
// FIXME: needs android support
113122
cmd.arg("--android-cross-path").arg("");

src/bootstrap/build/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub struct Config {
5959
pub rust_rpath: bool,
6060
pub rustc_default_linker: Option<String>,
6161
pub rustc_default_ar: Option<String>,
62+
pub rust_optimize_tests: bool,
63+
pub rust_debuginfo_tests: bool,
6264

6365
pub build: String,
6466
pub host: Vec<String>,
@@ -136,6 +138,8 @@ struct Rust {
136138
channel: Option<String>,
137139
musl_root: Option<String>,
138140
rpath: Option<bool>,
141+
optimize_tests: Option<bool>,
142+
debuginfo_tests: Option<bool>,
139143
}
140144

141145
/// TOML representation of how each build target is configured.
@@ -154,6 +158,7 @@ impl Config {
154158
config.llvm_optimize = true;
155159
config.use_jemalloc = true;
156160
config.rust_optimize = true;
161+
config.rust_optimize_tests = true;
157162
config.submodules = true;
158163
config.docs = true;
159164
config.rust_rpath = true;
@@ -219,6 +224,8 @@ impl Config {
219224
set(&mut config.rust_debug_assertions, rust.debug_assertions);
220225
set(&mut config.rust_debuginfo, rust.debuginfo);
221226
set(&mut config.rust_optimize, rust.optimize);
227+
set(&mut config.rust_optimize_tests, rust.optimize_tests);
228+
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
222229
set(&mut config.rust_rpath, rust.rpath);
223230
set(&mut config.debug_jemalloc, rust.debug_jemalloc);
224231
set(&mut config.use_jemalloc, rust.use_jemalloc);
@@ -306,6 +313,8 @@ impl Config {
306313
("JEMALLOC", self.use_jemalloc),
307314
("DEBUG_JEMALLOC", self.debug_jemalloc),
308315
("RPATH", self.rust_rpath),
316+
("OPTIMIZE_TESTS", self.rust_optimize_tests),
317+
("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
309318
}
310319

311320
match key {

src/bootstrap/config.toml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@
122122
# desired in distributions, for example.
123123
#rpath = true
124124

125+
# Flag indicating whether tests are compiled with optimizations (the -O flag) or
126+
# with debuginfo (the -g flag)
127+
#optimize-tests = true
128+
#debuginfo-tests = true
129+
125130
# =============================================================================
126131
# Options for specific targets
127132
#

0 commit comments

Comments
 (0)