Skip to content

Commit 624ee9b

Browse files
committed
rust: avoid using nightly for sanitizer (ASAN, TSAN).
Use Rust stable for ASAN with RUSTC_BOOTSTRAP environment variable. RUSTC_BOOTSTRAP is discouraged, but we want to have some stability on the different compilers that we want to use. Change-Id: Ia1a9978cb49e1bec5925d3747cf6031637dba069 Priv-Id: fbcda92854c98f4864d32f82b5a8de6197ca729b
1 parent 170ade8 commit 624ee9b

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

build/tests/zcargo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ def get_cargo_test_cmd(pkg: str, argv: list[str]) -> list[str]:
260260
# and
261261
# https://github.com/rust-lang/wg-cargo-std-aware/issues/29#issuecomment-549950466
262262
# for panic-abort strategy.
263-
cmd.extend(['+nightly', '-Zbuild-std=panic_abort,std',
264-
'-Zpanic-abort-tests'])
263+
cmd.extend(['-Zbuild-std=panic_abort,std', '-Zpanic-abort-tests'])
265264

266265
cmd.append('test')
267266

@@ -285,6 +284,11 @@ def run_cargo_test_for_pkg(pkg: str, argv: list[str]) -> None:
285284
env = os.environ.copy()
286285
env['CARGO_TERM_COLOR'] = 'never'
287286

287+
if 'USE_SANITIZER' in os.environ:
288+
# In order to use unstable features on stable Rust.
289+
# See https://doc.rust-lang.org/beta/unstable-book/compiler-environment-variables/RUSTC_BOOTSTRAP.html#rustc_bootstrap
290+
env['RUSTC_BOOTSTRAP'] = '1'
291+
288292
# Use a suppression file to avoid leak in rustlib:
289293
# https://github.com/rust-lang/rust/issues/151367
290294
prev_lsan_opts = env.get('LSAN_OPTIONS', '')

build/waftools/rust.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,17 @@ def run_cargo(self) -> None:
291291
]
292292

293293
# When using a sanitizer, we need to:
294-
# - Use nightly with '+nightly' passed before the command.
294+
# - Set 'RUSTC_BOOTSTRAP' to use unstable features on stable Rust.
295+
# See https://doc.rust-lang.org/beta/unstable-book/compiler-environment-variables/RUSTC_BOOTSTRAP.html#rustc_bootstrap
295296
# - Set the environment variable 'RUSTFLAGS' and 'RUSTDOCFLAGS' to
296297
# '-Zsanitizer={sanitizer}'.
297298
# - Build the standard Rust library itself with '-Z build-std'.
298299
# - Set the explicit target 'x86_64-unknown-linux-gnu'.
299300
if self.env.USE_SANITIZER and not self.env.USE_PIC:
300-
cargo_exec_cmd += [
301-
'+nightly',
302-
]
303301
sanitizer = self.env.SANITIZER
304302
old_rustflags = os.environ.get('RUSTFLAGS', '')
305303
old_rustdocflags = os.environ.get('RUSTDOCFLAGS', '')
304+
cmd_env['RUSTC_BOOTSTRAP'] = '1'
306305
cmd_env['RUSTFLAGS'] = f'-Zsanitizer={sanitizer} {old_rustflags}'
307306
cmd_env['RUSTDOCFLAGS'] = (
308307
f'-Zsanitizer={sanitizer} {old_rustdocflags}'
@@ -553,7 +552,6 @@ def sanitizer_add_toolchain(ctx: ConfigurationContext) -> None:
553552
# '-Zbuild-std=panic_abort,std'.
554553
ctx.exec_command(ctx.env.RUSTUP + [
555554
'component', 'add', 'rust-src',
556-
'--toolchain', 'nightly-x86_64-unknown-linux-gnu',
557555
], stdout=None, stderr=None)
558556

559557

0 commit comments

Comments
 (0)