Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gha: test cross-compilation to other arches #91

Merged
merged 4 commits into from
Oct 17, 2024
Merged
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
36 changes: 36 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,6 +166,7 @@ jobs:
needs:
- check
- check-msrv
- check-cross
- rustdoc
- test
- examples
Expand All @@ -155,6 +190,7 @@ jobs:
needs:
- check
- check-msrv
- check-cross
- rustdoc
- test
- examples
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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. <https://github.com/rust-lang/rust/issues/91632>
$(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
Expand All @@ -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. <https://github.com/rust-lang/rust/issues/91632>
$(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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/utils/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ 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 {
self.0.st_mode
}

fn nlink(&self) -> u64 {
self.0.st_nlink
self.0.st_nlink.into()
}

fn uid(&self) -> u32 {
Expand All @@ -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 {
Expand Down Expand Up @@ -174,9 +175,9 @@ fn proc_subpath<Fd: AsRawFd>(fd: Fd) -> Result<String, Error> {
/// [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.
// <https://github.com/rust-lang/rust/issues/85077>
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<Fd: AsFd> FdExt for Fd {
Expand Down
Loading