Skip to content

Commit

Permalink
ci: Check various FreeBSD versions
Browse files Browse the repository at this point in the history
Since we suport multiple versions and this is tier 2, we should make
sure that we can build with a couple versions. This does not run tests.

Additionally, introduce an environment variable for an easy way to
override the version for testing.

This includes an unrelated cleanup adjustment in `verify-build.sh`
  • Loading branch information
tgross35 committed Nov 27, 2024
1 parent 57dfd5b commit 9c2f78e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
9 changes: 8 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,20 @@ fn main() {
//
// On CI, we detect the actual FreeBSD version and match its ABI exactly,
// running tests to ensure that the ABI is correct.
let which_freebsd = if libc_ci {
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 vers = version.parse().unwrap();
println!("cargo:warning=setting FreeBSD version to {vers}");
vers
} else if libc_ci {
which_freebsd().unwrap_or(12)
} else if rustc_dep_of_std {
12
} else {
12
};

match which_freebsd {
x if x < 10 => panic!("FreeBSD older than 10 is not supported"),
10 => set_cfg("freebsd10"),
Expand Down
50 changes: 35 additions & 15 deletions ci/verify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if [ "$TOOLCHAIN" = "nightly" ] ; then
rustup component add rust-src
fi

# Run the tests for a specific target
test_target() {
target="${1}"
no_dist="${2:-0}"
Expand Down Expand Up @@ -67,8 +68,31 @@ test_target() {
# Test again without default features, i.e. without "std"
$cmd --no-default-features
$cmd --no-default-features --features extra_traits

# For tier 2 freebsd targets, check with the different versions we support
# if on nightly or stable
case "$rust-$target" in
stable-x86_64-*freebsd*) do_freebsd_checks=1 ;;
nightly-i686*freebsd*) do_freebsd_checks=1 ;;
esac

if [ -n "${do_freebsd_checks:-}" ]; then
for version in $freebsd_versions; do
export RUST_LIBC_UNSTABLE_FREEBSD_VERSION="$version"
$cmd
$cmd --no-default-features
done
fi
}

freebsd_versions="\
11 \
12 \
13 \
14 \
15 \
"

rust_linux_targets="\
aarch64-linux-android \
aarch64-unknown-linux-gnu \
Expand Down Expand Up @@ -240,21 +264,19 @@ for target in $targets; do
if echo "$target" | grep -q "$filter"; then
if [ "$os" = "windows" ]; then
TARGET="$target" ./ci/install-rust.sh
test_target "$target"
else
# `wasm32-wasip1` was renamed from `wasm32-wasi`
if [ "$target" = "wasm32-wasip1" ] && [ "$supports_wasi_pn" = "0" ]; then
target="wasm32-wasi"
fi
fi

# `wasm32-wasip2` only exists in recent versions of Rust
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
continue
fi

test_target "$target"
# `wasm32-wasip1` was renamed from `wasm32-wasi`
if [ "$target" = "wasm32-wasip1" ] && [ "$supports_wasi_pn" = "0" ]; then
target="wasm32-wasi"
fi

# `wasm32-wasip2` only exists in recent versions of Rust
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
continue
fi

test_target "$target"
test_run=1
fi
done
Expand All @@ -263,11 +285,9 @@ for target in ${no_dist_targets:-}; do
if echo "$target" | grep -q "$filter"; then
if [ "$os" = "windows" ]; then
TARGET="$target" ./ci/install-rust.sh
test_target "$target" 1
else
test_target "$target" 1
fi

test_target "$target" 1
test_run=1
fi
done
Expand Down
7 changes: 7 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4663,9 +4663,16 @@ fn test_linux_like_apis(target: &str) {
}

fn which_freebsd() -> Option<i32> {
if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_FREEBSD_VERSION") {
let vers = version.parse().unwrap();
println!("cargo:warning=setting FreeBSD version to {vers}");
return Some(vers);
}

let output = std::process::Command::new("freebsd-version")
.output()
.ok()?;

if !output.status.success() {
return None;
}
Expand Down

0 comments on commit 9c2f78e

Please sign in to comment.