From f3cb6b321fa1e16dc14b9bcdc37f001375a8c85c Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 22 Aug 2021 09:17:05 -0600 Subject: [PATCH 1/2] Fix building the tests for Redox and Illumos Also, split the overbroad test_mknod_family into two tests --- test/test_fcntl.rs | 2 -- test/test_stat.rs | 71 +++++++++++++++++++++++++-------------------- test/test_time.rs | 6 ++-- test/test_unistd.rs | 1 + 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index ae6756ece2..e74a85984a 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -28,8 +28,6 @@ use std::io::prelude::*; #[cfg(not(target_os = "redox"))] use std::os::unix::fs; -use crate::*; - #[test] #[cfg(not(target_os = "redox"))] fn test_openat() { diff --git a/test/test_stat.rs b/test/test_stat.rs index 42c536a872..922c25fd7d 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -11,7 +11,6 @@ use std::path::Path; #[cfg(not(any(target_os = "netbsd", target_os = "redox")))] use libc::{S_IFMT, S_IFLNK}; -#[cfg(not(target_os = "redox"))] use libc::mode_t; #[cfg(not(target_os = "redox"))] @@ -312,39 +311,47 @@ fn test_mkdirat_fail() { target_os = "ios", target_os = "macos", target_os = "redox")))] -fn test_mknod_family() { +fn test_mknod() { + use stat::{lstat, mknod, SFlag}; + + let file_name = "test_file"; + let tempdir = tempfile::tempdir().unwrap(); + let target = tempdir.path().join(file_name); + mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap(); + let mode = lstat(&target).unwrap().st_mode as mode_t; + assert!(mode & libc::S_IFREG == libc::S_IFREG); + assert!(mode & libc::S_IRWXU == libc::S_IRWXU); +} + +#[test] +#[cfg(not(any(target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "macos", + target_os = "redox")))] +fn test_mknodat() { use fcntl::{AtFlags, OFlag}; use nix::dir::Dir; - use stat::{fstatat, lstat, mknod, mknodat, SFlag}; + use stat::{fstatat, mknodat, SFlag}; let file_name = "test_file"; - { - let tempdir = tempfile::tempdir().unwrap(); - let target = tempdir.path().join(file_name); - mknod(&target, SFlag::S_IFREG, Mode::S_IRWXU, 0).unwrap(); - let mode = lstat(&target).unwrap().st_mode as mode_t; - assert!(mode & libc::S_IFREG == libc::S_IFREG); - assert!(mode & libc::S_IRWXU == libc::S_IRWXU); - } - { - let tempdir = tempfile::tempdir().unwrap(); - let target_dir = Dir::open(tempdir.path(), OFlag::O_DIRECTORY, Mode::S_IRWXU).unwrap(); - mknodat( - target_dir.as_raw_fd(), - file_name, - SFlag::S_IFREG, - Mode::S_IRWXU, - 0, - ) - .unwrap(); - let mode = fstatat( - target_dir.as_raw_fd(), - file_name, - AtFlags::AT_SYMLINK_NOFOLLOW, - ) - .unwrap() - .st_mode as mode_t; - assert!(mode & libc::S_IFREG == libc::S_IFREG); - assert!(mode & libc::S_IRWXU == libc::S_IRWXU); - } + let tempdir = tempfile::tempdir().unwrap(); + let target_dir = Dir::open(tempdir.path(), OFlag::O_DIRECTORY, Mode::S_IRWXU).unwrap(); + mknodat( + target_dir.as_raw_fd(), + file_name, + SFlag::S_IFREG, + Mode::S_IRWXU, + 0, + ) + .unwrap(); + let mode = fstatat( + target_dir.as_raw_fd(), + file_name, + AtFlags::AT_SYMLINK_NOFOLLOW, + ) + .unwrap() + .st_mode as mode_t; + assert!(mode & libc::S_IFREG == libc::S_IFREG); + assert!(mode & libc::S_IRWXU == libc::S_IRWXU); } diff --git a/test/test_time.rs b/test/test_time.rs index c321352d79..dc307e57b3 100644 --- a/test/test_time.rs +++ b/test/test_time.rs @@ -6,11 +6,12 @@ target_os = "emscripten", ))] use nix::time::clock_getcpuclockid; -use nix::time::{clock_getres, clock_gettime, ClockId}; +use nix::time::{clock_gettime, ClockId}; +#[cfg(not(target_os = "redox"))] #[test] pub fn test_clock_getres() { - assert!(clock_getres(ClockId::CLOCK_REALTIME).is_ok()); + assert!(nix::time::clock_getres(ClockId::CLOCK_REALTIME).is_ok()); } #[test] @@ -31,6 +32,7 @@ pub fn test_clock_getcpuclockid() { assert!(clock_gettime(clock_id).is_ok()); } +#[cfg(not(target_os = "redox"))] #[test] pub fn test_clock_id_res() { assert!(ClockId::CLOCK_REALTIME.res().is_ok()); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 984dd2c995..37e7a9b37b 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1025,6 +1025,7 @@ fn test_access_file_exists() { assert!(access(&path, AccessFlags::R_OK | AccessFlags::W_OK).is_ok()); } +#[cfg(not(target_os = "redox"))] #[test] fn test_user_into_passwd() { // get the UID of the "nobody" user From d20fe20af79cc6fa4528a8a170ad50a1319a1fbf Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 22 Aug 2021 09:19:51 -0600 Subject: [PATCH 2/2] Multiple CI improvements: * Install cross the easy way, via cargo * Don't test in release mode. Nix contains no release-dependent paths, and release mode testing has to my knowledge never revealed a bug in Nix. * Add Linux powerpc back to CI, fixed by the latest cross. * Check the tests even on platforms that can't run them. * DRY for the Illumos and Redox sections * Cross-check iOS from a Linux VM instead of OSX * Revert the workaround for rust-lang/rustup issue 2774 --- .cirrus.yml | 109 +++++++++++++++++++++++--------------------------- bors.toml | 1 + ci/install.sh | 49 ----------------------- ci/script.sh | 31 -------------- 4 files changed, 52 insertions(+), 138 deletions(-) delete mode 100644 ci/install.sh delete mode 100644 ci/script.sh diff --git a/.cirrus.yml b/.cirrus.yml index cb360947cd..3a74a4a42b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -8,9 +8,6 @@ cargo_cache: # the system's binaries, so the environment shouldn't matter. task: name: FreeBSD amd64 & i686 - env: - # Temporary workaround for https://github.com/rust-lang/rustup/issues/2774 - RUSTUP_IO_THREADS: 1 freebsd_instance: image: freebsd-11-4-release-amd64 setup_script: @@ -31,24 +28,17 @@ task: - name: OSX x86_64 env: TARGET: x86_64-apple-darwin - - name: iOS aarch64 - env: - TARGET: aarch64-apple-ios - DISABLE_TESTS: 1 - - name: iOS x86_64 - env: - TARGET: x86_64-apple-ios - DISABLE_TESTS: 1 osx_instance: image: catalina-xcode setup_script: - curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs - sh rustup.sh -y --profile=minimal --default-toolchain 1.46.0 - . $HOME/.cargo/env - - bash ci/install.sh + - cargo install cross script: - . $HOME/.cargo/env - - bash ci/script.sh + - cross build --target $TARGET + - cross test --target $TARGET before_cache_script: rm -rf $CARGO_HOME/registry/index # Use cross for QEMU-based testing @@ -100,10 +90,11 @@ task: - curl --proto '=https' --tlsv1.2 -sSf -o rustup.sh https://sh.rustup.rs - sh rustup.sh -y --profile=minimal --default-toolchain 1.46.0 - . $HOME/.cargo/env - - bash ci/install.sh + - cargo install cross script: - . $HOME/.cargo/env || true - - bash ci/script.sh + - cross build --target $TARGET + - cross test --target $TARGET before_cache_script: rm -rf $CARGO_HOME/registry/index # Tasks for Linux amd64 builds @@ -128,14 +119,18 @@ task: - rustup target add --toolchain $TOOLCHAIN $TARGET script: - cargo +$TOOLCHAIN build --target $TARGET --all-targets - - cargo +$TOOLCHAIN build --target $TARGET --all-targets --release - cargo +$TOOLCHAIN test --target $TARGET - - cargo +$TOOLCHAIN test --target $TARGET --release before_cache_script: rm -rf $CARGO_HOME/registry/index # Tasks for cross-compiling, but no testing task: + container: + image: rust:1.46 + env: + TOOLCHAIN: 1.46.0 matrix: + # Cross claims to support Android, but when it tries to run Nix's tests it + # reports undefined symbol references. - name: Android aarch64 env: TARGET: aarch64-linux-android @@ -154,9 +149,40 @@ task: - name: Linux arm-musleabi env: TARGET: arm-unknown-linux-musleabi + - name: Fuchsia x86_64 + env: + TARGET: x86_64-fuchsia + - name: Illumos + env: + TARGET: x86_64-unknown-illumos + # illumos toolchain isn't available via rustup until 1.50 + TOOLCHAIN: 1.50.0 + container: + image: rust:1.50 + # Cross claims to support running tests on iOS, but it actually doesn't. + # https://github.com/rust-embedded/cross/issues/535 + - name: iOS aarch64 + env: + TARGET: aarch64-apple-ios + # Rustup only supports cross-building from arbitrary hosts for iOS at + # 1.49.0 and above. Below that it's possible to cross-build from an OSX + # host, but OSX VMs + # are more expensive than Linux VMs. + TOOLCHAIN: 1.49.0 + - name: iOS x86_64 + env: + TARGET: x86_64-apple-ios + TOOLCHAIN: 1.49.0 + # Cross testing on powerpc fails with "undefined reference to renameat2". + # Perhaps cross is using too-old a version? - name: Linux powerpc env: TARGET: powerpc-unknown-linux-gnu + # Cross claims to support Linux powerpc64, but it really doesn't. + # https://github.com/rust-embedded/cross/issues/441 + - name: Linux powerpc64 + env: + TARGET: powerpc64-unknown-linux-gnu - name: Linux s390x env: TARGET: s390x-unknown-linux-gnu @@ -166,57 +192,24 @@ task: - name: NetBSD x86_64 env: TARGET: x86_64-unknown-netbsd - - name: Fuchsia x86_64 + - name: Redox x86_64 env: - TARGET: x86_64-fuchsia - container: - image: rust:1.46 - setup_script: - - rustup target add $TARGET - script: - - cargo +$TOOLCHAIN check --target $TARGET - - cargo +$TOOLCHAIN check --target $TARGET --release - - cargo +$TOOLCHAIN check --all-targets --target $TARGET - before_cache_script: rm -rf $CARGO_HOME/registry/index - -# illumos toolchain isn't available via rustup until 1.50 -task: - name: illumos - env: - TARGET: x86_64-unknown-illumos - container: - image: rust:1.50 + TARGET: x86_64-unknown-redox + # Redox requires a nightly compiler. + # If stuff breaks, change nightly to the date in the toolchain_* + # directory at https://static.redox-os.org + TOOLCHAIN: nightly-2020-08-04 setup_script: - rustup target add $TARGET - script: - - cargo +$TOOLCHAIN check --target $TARGET - - cargo +$TOOLCHAIN check --target $TARGET --release - before_cache_script: rm -rf $CARGO_HOME/registry/index - -# Redoxer is too unreliable, so we'll do a cross-build only -# See also: -# https://github.com/nix-rust/nix/issues/1258 -# https://github.com/rust-embedded/cross/issues/427 -task: - name: Redox x86_64 - env: - TARGET: x86_64-unknown-redox - # Redox requires a nightly compiler. - # If stuff breaks, change nightly to the date in the toolchain_* - # directory at https://static.redox-os.org - TOOLCHAIN: nightly-2020-08-04 - container: - image: rustlang/rust:nightly - setup_script: - rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET script: - cargo +$TOOLCHAIN check --target $TARGET - - cargo +$TOOLCHAIN check --target $TARGET --release + - cargo +$TOOLCHAIN check --all-targets --target $TARGET before_cache_script: rm -rf $CARGO_HOME/registry/index # Test that we can build with the lowest version of all dependencies. # "cargo test" doesn't work because some of our dev-dependencies, like -# rand, can't build with thier own minimal dependencies. +# rand, can't build with their own minimal dependencies. task: name: Minver container: diff --git a/bors.toml b/bors.toml index a02fd6918a..1e2ad980c1 100644 --- a/bors.toml +++ b/bors.toml @@ -17,6 +17,7 @@ status = [ "Linux i686", "Linux mipsel", "Linux powerpc", + "Linux powerpc64", "Linux powerpc64le", "Linux s390x", "Linux x32", diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100644 index bcb7c110d4..0000000000 --- a/ci/install.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -set -ex - -main() { - local target= - if [ $CIRRUS_OS = linux ]; then - target=x86_64-unknown-linux-musl - else - target=x86_64-apple-darwin - fi - - # Builds for iOS are done on OSX, but require the specific target to be - # installed. - IFS=';' read -ra TARGET_ARRAY <<< "$TARGET" - for t in "${TARGET_ARRAY[@]}"; do - case $t in - aarch64-apple-ios) - rustup target install aarch64-apple-ios - ;; - armv7-apple-ios) - rustup target install armv7-apple-ios - ;; - armv7s-apple-ios) - rustup target install armv7s-apple-ios - ;; - i386-apple-ios) - rustup target install i386-apple-ios - ;; - x86_64-apple-ios) - rustup target install x86_64-apple-ios - ;; - esac - done - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/japaric/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git japaric/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index f998039a2e..0000000000 --- a/ci/script.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# This script takes care of testing your crate - -set -ex - -main() { - # Add a cfg spec to allow disabling specific tests under CI. - if [ "$CIRRUS_CI" = true ]; then - export RUSTFLAGS=--cfg=cirrus - fi - - IFS=';' read -ra TARGET_ARRAY <<< "$TARGET" - for t in "${TARGET_ARRAY[@]}"; do - # Build debug and release targets - cross build --target $t - cross build --target $t --release - - if [ ! -z $DISABLE_TESTS ]; then - continue - fi - - # Run tests on debug and release targets. - cross test --target $t - cross test --target $t --release - done -} - -# we don't run the "test phase" when doing deploys -if [ -z $CIRRUS_TAG ]; then - main -fi