Skip to content

Commit adfca8d

Browse files
committed
Replace RUST_LIBC_UNSTABLE env with libc_unstable* cfg
Make it easier to set these flags only for host or target, not both. This was discussed on Zulip.
1 parent 4a60423 commit adfca8d

File tree

6 files changed

+61
-41
lines changed

6 files changed

+61
-41
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,30 @@ jobs:
186186
- target: aarch64-linux-android
187187
- target: aarch64-unknown-linux-musl
188188
- target: aarch64-unknown-linux-musl
189-
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
189+
env: { TEST_MUSL_V1_2_3: 1 }
190190
artifact-tag: new-musl
191191
- target: arm-linux-androideabi
192192
- target: arm-unknown-linux-gnueabihf
193193
- target: arm-unknown-linux-musleabihf
194194
- target: arm-unknown-linux-musleabihf
195-
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
195+
env: { TEST_MUSL_V1_2_3: 1 }
196196
artifact-tag: new-musl
197197
# FIXME(#4297): Disabled due to spurious failue
198198
# - target: i686-linux-android
199199
- target: i686-unknown-linux-musl
200200
- target: i686-unknown-linux-musl
201-
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
201+
env: { TEST_MUSL_V1_2_3: 1 }
202202
artifact-tag: new-musl
203203
- target: loongarch64-unknown-linux-gnu
204204
- target: loongarch64-unknown-linux-musl
205205
- target: loongarch64-unknown-linux-musl
206-
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
206+
env: { TEST_MUSL_V1_2_3: 1 }
207207
artifact-tag: new-musl
208208
- target: powerpc64-unknown-linux-gnu
209209
- target: powerpc64le-unknown-linux-gnu
210210
- target: powerpc64le-unknown-linux-musl
211211
- target: powerpc64le-unknown-linux-musl
212-
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
212+
env: { TEST_MUSL_V1_2_3: 1 }
213213
artifact-tag: new-musl
214214
- target: riscv64gc-unknown-linux-gnu
215215
- target: s390x-unknown-linux-gnu
@@ -223,7 +223,7 @@ jobs:
223223
# - target: x86_64-unknown-linux-gnux32
224224
- target: x86_64-unknown-linux-musl
225225
- target: x86_64-unknown-linux-musl
226-
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
226+
env: { TEST_MUSL_V1_2_3: 1 }
227227
artifact-tag: new-musl
228228
# FIXME: It seems some items in `src/unix/mod.rs` aren't defined on redox actually.
229229
# - target: x86_64-unknown-redox

build.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ fn main() {
7070
//
7171
// On CI, we detect the actual FreeBSD version and match its ABI exactly,
7272
// running tests to ensure that the ABI is correct.
73-
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_FREEBSD_VERSION");
7473
// Allow overriding the default version for testing
75-
let which_freebsd = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") {
74+
let which_freebsd = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") {
7675
let vers = version.parse().unwrap();
7776
println!("cargo:warning=setting FreeBSD version to {vers}");
7877
vers
@@ -104,8 +103,7 @@ fn main() {
104103
_ => (),
105104
}
106105

107-
let mut musl_v1_2_3 = env_flag("RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
108-
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_MUSL_V1_2_3");
106+
let mut musl_v1_2_3 = env_flag("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3");
109107

110108
// OpenHarmony uses a fork of the musl libc
111109
let musl = target_env == "musl" || target_env == "ohos";
@@ -123,8 +121,6 @@ fn main() {
123121
}
124122
}
125123

126-
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
127-
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");
128124
if target_env == "gnu"
129125
&& target_os == "linux"
130126
&& target_ptr_width == "32"
@@ -133,25 +129,33 @@ fn main() {
133129
{
134130
let defaultbits = "32".to_string();
135131
let (timebits, filebits) = match (
136-
env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS"),
137-
env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
132+
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"),
133+
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
138134
) {
139-
(Ok(_), Ok(_)) => panic!("Do not set both RUST_LIBC_UNSTABLE_GNU_TIME_BITS and RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
135+
(Ok(_), Ok(_)) => panic!(
136+
"Do not set both `libc_unstable_gnu_time_bits` and \
137+
`libc_unstable_gnu_file_offset_bits`"
138+
),
140139
(Err(_), Err(_)) => (defaultbits.clone(), defaultbits.clone()),
141140
(Ok(tb), Err(_)) if tb == "64" => (tb.clone(), tb.clone()),
142141
(Ok(tb), Err(_)) if tb == "32" => (tb, defaultbits.clone()),
143-
(Ok(_), Err(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS, must be 32 or 64"),
142+
(Ok(_), Err(_)) => {
143+
panic!("Invalid value for libc_unstable_gnu_time_bits, must be 32 or 64")
144+
}
144145
(Err(_), Ok(fb)) if fb == "32" || fb == "64" => (defaultbits.clone(), fb),
145-
(Err(_), Ok(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32 or 64"),
146+
(Err(_), Ok(_)) => {
147+
panic!("Invalid value for `libc_unstable_gnu_file_offset_bits`, must be 32 or 64")
148+
}
146149
};
147150
let valid_bits = ["32", "64"];
148151
assert!(
149152
valid_bits.contains(&filebits.as_str()) && valid_bits.contains(&timebits.as_str()),
150-
"Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS or RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32, 64 or unset"
153+
"Invalid value for `libc_unstable_gnu_time_bits` or `libc_unstable_gnu_file_offset_bits`, \
154+
must be 32, 64 or unset"
151155
);
152156
assert!(
153157
!(filebits == "32" && timebits == "64"),
154-
"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS must be 64 or unset if RUST_LIBC_UNSTABLE_GNU_TIME_BITS is 64"
158+
"`libc_unstable_gnu_file_offset_bits` must be 64 or unset if `libc_unstable_gnu_time_bits` is 64"
155159
);
156160
if timebits == "64" {
157161
set_cfg("linux_time_bits64");

ci/run-docker.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ run() {
3737
)
3838

3939
if [[ "$run_target" = *"musl"* ]]; then
40-
if [ -n "${RUST_LIBC_UNSTABLE_MUSL_V1_2_3:-}" ]; then
40+
if [ -n "${TEST_MUSL_V1_2_3:-}" ]; then
41+
export RUSTFLAGS="$RUSTFLAGS libc_unstable_musl_v1_2_3"
4142
build_args+=("--build-arg=MUSL_VERSION=new")
4243
else
4344
build_args+=("--build-arg=MUSL_VERSION=old")
@@ -62,9 +63,6 @@ run() {
6263
--env RUSTFLAGS \
6364
--env RUSTDOCFLAGS \
6465
--env RUST_BACKTRACE \
65-
--env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \
66-
--env RUST_LIBC_UNSTABLE_GNU_TIME_BITS \
67-
--env RUST_LIBC_UNSTABLE_MUSL_V1_2_3 \
6866
--env CARGO_TERM_COLOR \
6967
--env CARGO_TERM_VERBOSE \
7068
--env CARGO_HOME=/cargo \

ci/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $cmd --features extra_traits -- $test_flags
5151

5252
if [ "$env" = "gnu" ] && [ "$bits" = "32" ]; then
5353
# shellcheck disable=SC2086
54-
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd -- $test_flags
54+
RUSTFLAGS="$RUSTFLAGS + libc_unstable_gnu_file_offset_bits='64'" $cmd -- $test_flags
5555
# shellcheck disable=SC2086
56-
RUST_LIBC_UNSTABLE_GNU_TIME_BITS=64 $cmd -- $test_flags
56+
RUSTFLAGS="$RUSTFLAGS + libc_unstable_gnu_time_bits='64'" $cmd -- $test_flags
5757
fi

ci/verify-build.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,12 @@ def run(
242242
args: Sequence[str | Path],
243243
*,
244244
env: Optional[dict[str, str]] = None,
245+
extra_rustflags: Optional[str] = None,
245246
check: bool = True,
246247
) -> sp.CompletedProcess:
248+
if extra_rustflags is not None:
249+
env = env or {}
250+
env["RUSTFLAGS"] = env.get("RUSTFLAGS", "") + " " + extra_rustflags
247251
xtrace(args, env=env)
248252
return sp.run(args, env=env, check=check)
249253

@@ -358,7 +362,7 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
358362
"""Run tests for a single target."""
359363
start = time.time()
360364
env = os.environ.copy()
361-
env.setdefault("RUSTFLAGS", "")
365+
rustflags = env.get("RUSTFLAGS", "")
362366

363367
tname = target.name
364368
target_cfg = check_output(["rustc", "--print=cfg", "--target", tname])
@@ -383,7 +387,7 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
383387
cmd += ["-Zbuild-std=core"]
384388
# FIXME: With `the build-std` feature, `compiler_builtins` emits a lot of
385389
# lint warnings.
386-
env["RUSTFLAGS"] += " -Aimproper_ctypes_definitions"
390+
rustflags += " -Aimproper_ctypes_definitions"
387391
else:
388392
run(["rustup", "target", "add", tname, "--toolchain", cfg.toolchain_name])
389393

@@ -393,13 +397,13 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
393397

394398
if "gnu" in target_env and target_bits == "32":
395399
# Equivalent of _FILE_OFFSET_BITS=64
396-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS": "64"})
400+
run(cmd, extra_rustflags=rustflags + " libc_unstable_gnu_file_offset_bits='64'")
397401
# Equivalent of _TIME_BITS=64
398-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_TIME_BITS": "64"})
402+
run(cmd, extra_rustflags=rustflags + " libc_unstable_gnu_time_bits='64'")
399403

400404
if "musl" in target_env:
401405
# 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"})
406+
run(cmd, extra_rustflags=rustflags + " libc_unstable_musl_v1_2_3")
403407

404408
# Test again without default features, i.e. without `std`
405409
run([*cmd, "--no-default-features"])
@@ -413,10 +417,16 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
413417
# if on nightly or stable
414418
if "freebsd" in tname and cfg.toolchain >= Toolchain.STABLE:
415419
for version in FREEBSD_VERSIONS:
416-
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)})
420+
421+
run(
422+
cmd,
423+
extra_rustflags=rustflags
424+
+ f" libc_unstable_freebsd_version = '{str(version)}'",
425+
)
417426
run(
418427
[*cmd, "--no-default-features"],
419-
env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)},
428+
extra_rustflags=rustflags
429+
+ f" libc_unstable_freebsd_version = '{str(version)}'",
420430
)
421431

422432
if cfg.skip_semver:

libc-test/build.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,7 @@ fn test_freebsd(target: &str) {
22752275
assert!(target.contains("freebsd"));
22762276
let mut cfg = ctest_cfg();
22772277

2278-
let freebsd_ver = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") {
2278+
let freebsd_ver = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") {
22792279
let vers = version.parse().unwrap();
22802280
println!("cargo:warning=setting FreeBSD version to {vers}");
22812281
Some(vers)
@@ -3607,25 +3607,33 @@ fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
36073607
{
36083608
let defaultbits = "32".to_string();
36093609
let (timebits, filebits) = match (
3610-
env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS"),
3611-
env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
3610+
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"),
3611+
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
36123612
) {
3613-
(Ok(_), Ok(_)) => panic!("Do not set both RUST_LIBC_UNSTABLE_GNU_TIME_BITS and RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
3613+
(Ok(_), Ok(_)) => panic!(
3614+
"Do not set both `libc_unstable_gnu_time_bits` and \
3615+
`libc_unstable_gnu_file_offset_bits`"
3616+
),
36143617
(Err(_), Err(_)) => (defaultbits.clone(), defaultbits.clone()),
36153618
(Ok(tb), Err(_)) if tb == "64" => (tb.clone(), tb.clone()),
36163619
(Ok(tb), Err(_)) if tb == "32" => (tb, defaultbits.clone()),
3617-
(Ok(_), Err(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS, must be 32 or 64"),
3620+
(Ok(_), Err(_)) => {
3621+
panic!("Invalid value for libc_unstable_gnu_time_bits, must be 32 or 64")
3622+
}
36183623
(Err(_), Ok(fb)) if fb == "32" || fb == "64" => (defaultbits.clone(), fb),
3619-
(Err(_), Ok(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32 or 64"),
3624+
(Err(_), Ok(_)) => {
3625+
panic!("Invalid value for `libc_unstable_gnu_file_offset_bits`, must be 32 or 64")
3626+
}
36203627
};
36213628
let valid_bits = ["32", "64"];
36223629
assert!(
36233630
valid_bits.contains(&filebits.as_str()) && valid_bits.contains(&timebits.as_str()),
3624-
"Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS or RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32, 64 or unset"
3631+
"Invalid value for `libc_unstable_gnu_time_bits` or `libc_unstable_gnu_file_offset_bits`, \
3632+
must be 32, 64 or unset"
36253633
);
36263634
assert!(
36273635
!(filebits == "32" && timebits == "64"),
3628-
"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS must be 64 or unset if RUST_LIBC_UNSTABLE_GNU_TIME_BITS is 64"
3636+
"`libc_unstable_gnu_file_offset_bits` must be 64 or unset if `libc_unstable_gnu_time_bits` is 64"
36293637
);
36303638
if timebits == "64" {
36313639
cfg.define("_TIME_BITS", Some("64"));
@@ -3692,7 +3700,7 @@ fn test_linux(target: &str) {
36923700
let mips64 = target.contains("mips64");
36933701
let mips32 = mips && !mips64;
36943702

3695-
let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
3703+
let musl_v1_2_3 = env::var("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
36963704
if musl_v1_2_3 {
36973705
assert!(musl);
36983706
}

0 commit comments

Comments
 (0)