Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,30 +186,30 @@ jobs:
- target: aarch64-linux-android
- target: aarch64-unknown-linux-musl
- target: aarch64-unknown-linux-musl
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
env: { TEST_MUSL_V1_2_3: 1 }
artifact-tag: new-musl
- target: arm-linux-androideabi
- target: arm-unknown-linux-gnueabihf
- target: arm-unknown-linux-musleabihf
- target: arm-unknown-linux-musleabihf
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
env: { TEST_MUSL_V1_2_3: 1 }
artifact-tag: new-musl
# FIXME(#4297): Disabled due to spurious failue
# - target: i686-linux-android
- target: i686-unknown-linux-musl
- target: i686-unknown-linux-musl
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
env: { TEST_MUSL_V1_2_3: 1 }
artifact-tag: new-musl
- target: loongarch64-unknown-linux-gnu
- target: loongarch64-unknown-linux-musl
- target: loongarch64-unknown-linux-musl
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
env: { TEST_MUSL_V1_2_3: 1 }
artifact-tag: new-musl
- target: powerpc64-unknown-linux-gnu
- target: powerpc64le-unknown-linux-gnu
- target: powerpc64le-unknown-linux-musl
- target: powerpc64le-unknown-linux-musl
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
env: { TEST_MUSL_V1_2_3: 1 }
artifact-tag: new-musl
- target: riscv64gc-unknown-linux-gnu
- target: s390x-unknown-linux-gnu
Expand All @@ -223,7 +223,7 @@ jobs:
# - target: x86_64-unknown-linux-gnux32
- target: x86_64-unknown-linux-musl
- target: x86_64-unknown-linux-musl
env: { RUST_LIBC_UNSTABLE_MUSL_V1_2_3: 1 }
env: { TEST_MUSL_V1_2_3: 1 }
artifact-tag: new-musl
# FIXME: It seems some items in `src/unix/mod.rs` aren't defined on redox actually.
# - target: x86_64-unknown-redox
Expand Down
35 changes: 17 additions & 18 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ fn main() {
//
// On CI, we detect the actual FreeBSD version and match its ABI exactly,
// running tests to ensure that the ABI is correct.
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_FREEBSD_VERSION");
// Allow overriding the default version for testing
let which_freebsd = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") {
let which_freebsd = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") {
let vers = version.parse().unwrap();
println!("cargo:warning=setting FreeBSD version to {vers}");
vers
Expand Down Expand Up @@ -104,8 +103,7 @@ fn main() {
_ => (),
}

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

// OpenHarmony uses a fork of the musl libc
let musl = target_env == "musl" || target_env == "ohos";
Expand All @@ -123,13 +121,6 @@ fn main() {
}
}

let linux_time_bits64 = env::var("RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64").is_ok();
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64");
if linux_time_bits64 {
set_cfg("linux_time_bits64");
}
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_TIME_BITS");
if target_env == "gnu"
&& target_os == "linux"
&& target_ptr_width == "32"
Expand All @@ -138,25 +129,33 @@ fn main() {
{
let defaultbits = "32".to_string();
let (timebits, filebits) = match (
env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS"),
env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"),
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
) {
(Ok(_), Ok(_)) => panic!("Do not set both RUST_LIBC_UNSTABLE_GNU_TIME_BITS and RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
(Ok(_), Ok(_)) => panic!(
"Do not set both `libc_unstable_gnu_time_bits` and \
`libc_unstable_gnu_file_offset_bits`"
),
(Err(_), Err(_)) => (defaultbits.clone(), defaultbits.clone()),
(Ok(tb), Err(_)) if tb == "64" => (tb.clone(), tb.clone()),
(Ok(tb), Err(_)) if tb == "32" => (tb, defaultbits.clone()),
(Ok(_), Err(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS, must be 32 or 64"),
(Ok(_), Err(_)) => {
panic!("Invalid value for libc_unstable_gnu_time_bits, must be 32 or 64")
}
(Err(_), Ok(fb)) if fb == "32" || fb == "64" => (defaultbits.clone(), fb),
(Err(_), Ok(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32 or 64"),
(Err(_), Ok(_)) => {
panic!("Invalid value for `libc_unstable_gnu_file_offset_bits`, must be 32 or 64")
}
};
let valid_bits = ["32", "64"];
assert!(
valid_bits.contains(&filebits.as_str()) && valid_bits.contains(&timebits.as_str()),
"Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS or RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32, 64 or unset"
"Invalid value for `libc_unstable_gnu_time_bits` or `libc_unstable_gnu_file_offset_bits`, \
must be 32, 64 or unset"
);
assert!(
!(filebits == "32" && timebits == "64"),
"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS must be 64 or unset if RUST_LIBC_UNSTABLE_GNU_TIME_BITS is 64"
"`libc_unstable_gnu_file_offset_bits` must be 64 or unset if `libc_unstable_gnu_time_bits` is 64"
);
if timebits == "64" {
set_cfg("linux_time_bits64");
Expand Down
6 changes: 2 additions & 4 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ run() {
)

if [[ "$run_target" = *"musl"* ]]; then
if [ -n "${RUST_LIBC_UNSTABLE_MUSL_V1_2_3:-}" ]; then
if [ -n "${TEST_MUSL_V1_2_3:-}" ]; then
export RUSTFLAGS="$RUSTFLAGS libc_unstable_musl_v1_2_3"
build_args+=("--build-arg=MUSL_VERSION=new")
else
build_args+=("--build-arg=MUSL_VERSION=old")
Expand All @@ -62,9 +63,6 @@ run() {
--env RUSTFLAGS \
--env RUSTDOCFLAGS \
--env RUST_BACKTRACE \
--env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \
--env RUST_LIBC_UNSTABLE_GNU_TIME_BITS \
--env RUST_LIBC_UNSTABLE_MUSL_V1_2_3 \
--env CARGO_TERM_COLOR \
--env CARGO_TERM_VERBOSE \
--env CARGO_HOME=/cargo \
Expand Down
4 changes: 2 additions & 2 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $cmd --features extra_traits -- $test_flags

if [ "$env" = "gnu" ] && [ "$bits" = "32" ]; then
# shellcheck disable=SC2086
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd -- $test_flags
RUSTFLAGS="$RUSTFLAGS libc_unstable_gnu_file_offset_bits='64'" $cmd -- $test_flags
# shellcheck disable=SC2086
RUST_LIBC_UNSTABLE_GNU_TIME_BITS=64 $cmd -- $test_flags
RUSTFLAGS="$RUSTFLAGS libc_unstable_gnu_time_bits='64'" $cmd -- $test_flags
fi
30 changes: 23 additions & 7 deletions ci/verify-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,15 @@ def run(
args: Sequence[str | Path],
*,
env: Optional[dict[str, str]] = None,
extra_rustflags: Optional[str] = None,
check: bool = True,
) -> sp.CompletedProcess:
if env is None:
env = os.environ.copy()

if extra_rustflags is not None:
env["RUSTFLAGS"] = env.get("RUSTFLAGS", "") + " " + extra_rustflags

xtrace(args, env=env)
return sp.run(args, env=env, check=check)

Expand Down Expand Up @@ -358,7 +365,7 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
"""Run tests for a single target."""
start = time.time()
env = os.environ.copy()
env.setdefault("RUSTFLAGS", "")
rustflags = ""

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

Expand All @@ -393,13 +400,16 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:

if "gnu" in target_env and target_bits == "32":
# Equivalent of _FILE_OFFSET_BITS=64
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS": "64"})
run(
cmd,
extra_rustflags=rustflags + " libc_unstable_gnu_file_offset_bits='64'",
)
# Equivalent of _TIME_BITS=64
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_GNU_TIME_BITS": "64"})
run(cmd, extra_rustflags=rustflags + " libc_unstable_gnu_time_bits='64'")

if "musl" in target_env:
# Check with breaking changes from musl, including 64-bit time_t on 32-bit
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_MUSL_V1_2_3": "1"})
run(cmd, extra_rustflags=rustflags + " libc_unstable_musl_v1_2_3")

# Test again without default features, i.e. without `std`
run([*cmd, "--no-default-features"])
Expand All @@ -413,10 +423,16 @@ def test_target(cfg: Cfg, target: Target) -> TargetResult:
# if on nightly or stable
if "freebsd" in tname and cfg.toolchain >= Toolchain.STABLE:
for version in FREEBSD_VERSIONS:
run(cmd, env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)})

run(
cmd,
extra_rustflags=rustflags
+ f" libc_unstable_freebsd_version = '{str(version)}'",
)
run(
[*cmd, "--no-default-features"],
env=env | {"RUST_LIBC_UNSTABLE_FREEBSD_VERSION": str(version)},
extra_rustflags=rustflags
+ f" libc_unstable_freebsd_version = '{str(version)}'",
)

if cfg.skip_semver:
Expand Down
26 changes: 17 additions & 9 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ fn test_freebsd(target: &str) {
assert!(target.contains("freebsd"));
let mut cfg = ctest_cfg();

let freebsd_ver = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") {
let freebsd_ver = if let Ok(version) = env::var("CARGO_CFG_LIBC_UNSTABLE_FREEBSD_VERSION") {
let vers = version.parse().unwrap();
println!("cargo:warning=setting FreeBSD version to {vers}");
Some(vers)
Expand Down Expand Up @@ -3607,25 +3607,33 @@ fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
{
let defaultbits = "32".to_string();
let (timebits, filebits) = match (
env::var("RUST_LIBC_UNSTABLE_GNU_TIME_BITS"),
env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_TIME_BITS"),
env::var("CARGO_CFG_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
) {
(Ok(_), Ok(_)) => panic!("Do not set both RUST_LIBC_UNSTABLE_GNU_TIME_BITS and RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS"),
(Ok(_), Ok(_)) => panic!(
"Do not set both `libc_unstable_gnu_time_bits` and \
`libc_unstable_gnu_file_offset_bits`"
),
(Err(_), Err(_)) => (defaultbits.clone(), defaultbits.clone()),
(Ok(tb), Err(_)) if tb == "64" => (tb.clone(), tb.clone()),
(Ok(tb), Err(_)) if tb == "32" => (tb, defaultbits.clone()),
(Ok(_), Err(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS, must be 32 or 64"),
(Ok(_), Err(_)) => {
panic!("Invalid value for libc_unstable_gnu_time_bits, must be 32 or 64")
}
(Err(_), Ok(fb)) if fb == "32" || fb == "64" => (defaultbits.clone(), fb),
(Err(_), Ok(_)) => panic!("Invalid value for RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32 or 64"),
(Err(_), Ok(_)) => {
panic!("Invalid value for `libc_unstable_gnu_file_offset_bits`, must be 32 or 64")
}
};
let valid_bits = ["32", "64"];
assert!(
valid_bits.contains(&filebits.as_str()) && valid_bits.contains(&timebits.as_str()),
"Invalid value for RUST_LIBC_UNSTABLE_GNU_TIME_BITS or RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS, must be 32, 64 or unset"
"Invalid value for `libc_unstable_gnu_time_bits` or `libc_unstable_gnu_file_offset_bits`, \
must be 32, 64 or unset"
);
assert!(
!(filebits == "32" && timebits == "64"),
"RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS must be 64 or unset if RUST_LIBC_UNSTABLE_GNU_TIME_BITS is 64"
"`libc_unstable_gnu_file_offset_bits` must be 64 or unset if `libc_unstable_gnu_time_bits` is 64"
);
if timebits == "64" {
cfg.define("_TIME_BITS", Some("64"));
Expand Down Expand Up @@ -3692,7 +3700,7 @@ fn test_linux(target: &str) {
let mips64 = target.contains("mips64");
let mips32 = mips && !mips64;

let musl_v1_2_3 = env::var("RUST_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
let musl_v1_2_3 = env::var("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok();
if musl_v1_2_3 {
assert!(musl);
}
Expand Down
Loading