Skip to content

Commit 00183a7

Browse files
committed
ci: Pass RUSTFLAGS on its own rather than via env
Prepare for needing to set different `RUSTFLAGS` per-invocation.
1 parent b03b7c9 commit 00183a7

1 file changed

Lines changed: 48 additions & 14 deletions

File tree

ci/verify-build.py

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,18 @@ def run(
242242
args: Sequence[str | Path],
243243
*,
244244
env: Optional[dict[str, str]] = None,
245+
rustflags: Optional[str] = None,
245246
check: bool = True,
246247
) -> sp.CompletedProcess:
248+
"""Run a command. `env` will replace the environment and `rustflags` will replace
249+
`RUSTFLAGS` (they do not append).
250+
"""
251+
if env is None:
252+
env = os.environ.copy()
253+
254+
if rustflags is not None:
255+
env["RUSTFLAGS"] = rustflags
256+
247257
xtrace(args, env=env)
248258
return sp.run(args, env=env, check=check)
249259

@@ -292,8 +302,10 @@ def do_semver_checks(cfg: Cfg, target: Target) -> bool:
292302
# running on the host.
293303

294304
if cfg.baseline_crate_dir is None:
295-
eprint("Non-host target: --baseline-crate-dir must be specified to \
296-
run semver-checks")
305+
eprint(
306+
"Non-host target: --baseline-crate-dir must be specified to \
307+
run semver-checks"
308+
)
297309
sys.exit(1)
298310

299311
# Since semver-checks doesn't work with `--target`, we build the json ourself and
@@ -358,10 +370,12 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
358370
"""Run tests for a single target."""
359371
start = time.time()
360372
env = os.environ.copy()
361-
env.setdefault("RUSTFLAGS", "")
373+
rustflags = env.get("RUSTFLAGS") or ""
362374

363375
tname = target.name
364-
target_cfg = check_output(["rustc", "--print=cfg", "--target", tname])
376+
target_cfg = check_output(
377+
["rustc", f"+{cfg.toolchain_name}", "--print=cfg", "--target", tname]
378+
)
365379
target_env = re.findall(r'target_env="(.*)"', target_cfg)
366380
target_os = re.findall(r'target_os="(.*)"', target_cfg)
367381
target_bits = re.findall(r'target_pointer_width="(.*)"', target_cfg)[0]
@@ -383,40 +397,60 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
383397
cmd += ["-Zbuild-std=core"]
384398
# FIXME: With `the build-std` feature, `compiler_builtins` emits a lot of
385399
# lint warnings.
386-
env["RUSTFLAGS"] += " -Aimproper_ctypes_definitions"
400+
rustflags += " -Aimproper_ctypes_definitions"
387401
else:
388402
run(["rustup", "target", "add", tname, "--toolchain", cfg.toolchain_name])
389403

390404
# Test with expected combinations of features
391-
run(cmd, env=env)
392-
run([*cmd, "--features=extra_traits"], env=env)
405+
run(cmd, env=env, rustflags=rustflags)
406+
run([*cmd, "--features=extra_traits"], env=env, rustflags=rustflags)
393407

394408
if "gnu" in target_env and target_bits == "32":
395409
# Equivalent of _FILE_OFFSET_BITS=64
396-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS": "64"})
410+
run(
411+
cmd,
412+
env=env | {"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS": "64"},
413+
rustflags=rustflags,
414+
)
397415
# Equivalent of _TIME_BITS=64
398-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_TIME_BITS": "64"})
416+
run(
417+
cmd,
418+
env=env | {"RUST_LIBC_UNSTABLE_GNU_TIME_BITS": "64"},
419+
rustflags=rustflags,
420+
)
399421

400422
if "musl" in target_env:
401423
# Check with breaking changes from musl, including 64-bit time_t on 32-bit
402-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_MUSL_V1_2_3": "1"})
424+
run(
425+
cmd,
426+
env=env | {"RUST_LIBC_UNSTABLE_MUSL_V1_2_3": "1"},
427+
rustflags=rustflags,
428+
)
403429

404430
# Test again without default features, i.e. without `std`
405-
run([*cmd, "--no-default-features"])
406-
run([*cmd, "--no-default-features", "--features=extra_traits"])
431+
run([*cmd, "--no-default-features"], rustflags=rustflags)
432+
run([*cmd, "--no-default-features", "--features=extra_traits"], rustflags=rustflags)
407433

408434
# Ensure the crate will build when used as a dependency of `std`
409435
if cfg.nightly():
410-
run([*cmd, "--no-default-features", "--features=rustc-dep-of-std"])
436+
run(
437+
[*cmd, "--no-default-features", "--features=rustc-dep-of-std"],
438+
rustflags=rustflags,
439+
)
411440

412441
# For freebsd targets, check with the different versions we support
413442
# if on nightly or stable
414443
if "freebsd" in tname and cfg.toolchain >= Toolchain.STABLE:
415444
for version in FREEBSD_VERSIONS:
416-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)})
445+
run(
446+
cmd,
447+
env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)},
448+
rustflags=rustflags,
449+
)
417450
run(
418451
[*cmd, "--no-default-features"],
419452
env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)},
453+
rustflags=rustflags,
420454
)
421455

422456
if cfg.skip_semver:

0 commit comments

Comments
 (0)