From 37fea4226d4c107ac70f4b3a0fe8ae14dd0f82ad Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 17 Oct 2024 17:56:10 +1100 Subject: [PATCH 1/4] multiarch: fix build failures on 32-bit word arches The move to rustix fixed most of these issues, but the translations to MetadataExt still needed to be adjusted. Signed-off-by: Aleksa Sarai --- src/utils/fd.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/fd.rs b/src/utils/fd.rs index 7c6db60..a3e7c1c 100644 --- a/src/utils/fd.rs +++ b/src/utils/fd.rs @@ -43,13 +43,14 @@ impl Metadata { } } +#[allow(clippy::useless_conversion)] // 32-bit arches impl MetadataExt for Metadata { fn dev(&self) -> u64 { - self.0.st_dev + self.0.st_dev.into() } fn ino(&self) -> u64 { - self.0.st_ino + self.0.st_ino.into() } fn mode(&self) -> u32 { @@ -57,7 +58,7 @@ impl MetadataExt for Metadata { } fn nlink(&self) -> u64 { - self.0.st_nlink + self.0.st_nlink.into() } fn uid(&self) -> u32 { @@ -69,7 +70,7 @@ impl MetadataExt for Metadata { } fn rdev(&self) -> u64 { - self.0.st_rdev + self.0.st_rdev.into() } fn size(&self) -> u64 { @@ -174,9 +175,9 @@ fn proc_subpath(fd: Fd) -> Result { /// [kcommit-a481f4d91783]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a481f4d917835cad86701fc0d1e620c74bb5cd5f // TODO: Remove the explicit size once generic_arg_infer is stable. // -const DANGEROUS_FILESYSTEMS: [i64; 2] = [ - libc::PROC_SUPER_MAGIC, // procfs - 0x5a3c_69f0, // apparmorfs +const DANGEROUS_FILESYSTEMS: [rustix_fs::FsWord; 2] = [ + rustix_fs::PROC_SUPER_MAGIC, // procfs + 0x5a3c_69f0, // apparmorfs ]; impl FdExt for Fd { From 487c093b1abd4415bd48f5f86d12f026282e5dd8 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 17 Oct 2024 18:46:56 +1100 Subject: [PATCH 2/4] *: fix musl builds Almost everything works, thanks to the rustix migration. The only outstanding problem is that O_FSYNC is not provided by musl. We don't really care about these flags (they're only used for debug output in practice) so just skip defining it on musl. Signed-off-by: Aleksa Sarai --- src/flags.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flags.rs b/src/flags.rs index 3aff522..5d4ed7e 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -106,6 +106,7 @@ bitflags! { const O_SYNC = libc::O_SYNC; const O_ASYNC = libc::O_ASYNC; const O_DSYNC = libc::O_DSYNC; + #[cfg(not(target_env = "musl"))] // musl doesn't provide FSYNC const O_FSYNC = libc::O_FSYNC; const O_RSYNC = libc::O_RSYNC; const O_DIRECT = libc::O_DIRECT; From eb2fbcdee8f9f753e9bbfb4b06c292052fbe397f Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 17 Oct 2024 19:10:21 +1100 Subject: [PATCH 3/4] makefile: move CARGO_FLAGS placement Signed-off-by: Aleksa Sarai --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4b06c7c..a501884 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,8 @@ target/debug: $(SRC_FILES) # For some reason, --crate-types needs separate invocations. We can't use # #![crate_type] unfortunately, as using it with #![cfg_attr] has been # deprecated. - $(CARGO) $(CARGO_FLAGS) rustc --crate-type=cdylib $(RUSTC_FLAGS) - $(CARGO) $(CARGO_FLAGS) rustc --crate-type=staticlib $(RUSTC_FLAGS) + $(CARGO) rustc $(CARGO_FLAGS) --crate-type=cdylib $(RUSTC_FLAGS) + $(CARGO) rustc $(CARGO_FLAGS) --crate-type=staticlib $(RUSTC_FLAGS) .PHONY: release release: target/release @@ -40,8 +40,8 @@ target/release: $(SRC_FILES) # For some reason, --crate-types needs separate invocations. We can't use # #![crate_type] unfortunately, as using it with #![cfg_attr] has been # deprecated. - $(CARGO) $(CARGO_FLAGS) rustc --release --crate-type=cdylib $(RUSTC_FLAGS) - $(CARGO) $(CARGO_FLAGS) rustc --release --crate-type=staticlib $(RUSTC_FLAGS) + $(CARGO) rustc $(CARGO_FLAGS) --release --crate-type=cdylib $(RUSTC_FLAGS) + $(CARGO) rustc $(CARGO_FLAGS) --release --crate-type=staticlib $(RUSTC_FLAGS) .PHONY: smoke-test smoke-test: @@ -58,7 +58,7 @@ lint: lint-rust lint-rust: $(CARGO_NIGHTLY) fmt --all -- --check $(CARGO) clippy --all-features --all-targets - $(CARGO) check --all-features --all-targets + $(CARGO) check $(CARGO_FLAGS) --all-features --all-targets .PHONY: test-rust-doctest test-rust-doctest: From 8421d663c4deaa43e5f616332303a944fcafd3dc Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 17 Oct 2024 10:14:15 +1100 Subject: [PATCH 4/4] gha: test cross-compilation to other arches Signed-off-by: Aleksa Sarai --- .github/workflows/rust.yml | 36 ++++++++++++++++++++++++++++++++++++ CHANGELOG.md | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a190d64..39d059f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -57,6 +57,40 @@ jobs: toolchain: ${{ env.RUST_MSRV }} - run: cargo check --workspace --all-features --all-targets + check-cross: + strategy: + fail-fast: false + matrix: + target: + - x86_64-unknown-linux-musl + - aarch64-unknown-linux-musl + - arm-unknown-linux-gnueabi + - arm-unknown-linux-gnueabihf + - armv7-unknown-linux-gnueabihf + - i686-unknown-linux-gnu + - loongarch64-unknown-linux-gnu + - loongarch64-unknown-linux-musl + - powerpc-unknown-linux-gnu + - powerpc64-unknown-linux-gnu + - powerpc64le-unknown-linux-gnu + - riscv64gc-unknown-linux-gnu + - sparc64-unknown-linux-gnu + - s390x-unknown-linux-gnu + name: cargo check (${{ matrix.target }}) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + # TODO: Should we use MSRV for this? + targets: ${{ matrix.target }} + - name: cargo check --target=${{ matrix.target }} + run: >- + cargo check --target=${{ matrix.target }} --workspace --all-features --all-targets + - name: cargo build --target=${{ matrix.target }} + run: >- + cargo build --target=${{ matrix.target }} --release --all-features + rustdoc: name: cargo doc runs-on: ubuntu-latest @@ -132,6 +166,7 @@ jobs: needs: - check - check-msrv + - check-cross - rustdoc - test - examples @@ -155,6 +190,7 @@ jobs: needs: - check - check-msrv + - check-cross - rustdoc - test - examples diff --git a/CHANGELOG.md b/CHANGELOG.md index 5274979..b83d6bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - python bindings: add `Root.creat_raw` to create a new file and wrap it in a raw `WrappedFd` (os opposed to `Root.creat` which returns an `os.fdopen`). +### Fixes ### +- multiarch: we now build correctly on 32-bit architectures as well as + architectures that have unsigned char. We also have CI jobs that verify that + builds work on a fairly large number of architectures (all relevant tier-1 + and tier-2-with-host-tools architectures). If there is an architecture you + would like us to add to the build matrix and it is well-supported by `rustc`, + feel free to open an issue or PR! + ### Changed ### - syscalls: switch to rustix for most of our syscall wrappers to simplify how much code we have for wrapper raw syscalls. This also lets us build on