From cb1c240c1882ba965c265484eaf57809e4cd7090 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:00:28 +0100 Subject: [PATCH 1/8] Fix compilation on Android --- src/sys/unix.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 417641e5..418638ab 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -89,6 +89,7 @@ pub(crate) use libc::{ #[cfg(all( feature = "all", any( + target_os = "android", target_os = "freebsd", target_os = "fuchsia", target_os = "linux", From b2736907daabdb29c7d788efade8bd308dbbb0f4 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:03:03 +0100 Subject: [PATCH 2/8] Enable some more functions on Android Such as * Domain::PACKET constant * Socket::(set_)mark * Socket::(bind_)device * Socket::(set_)freebind --- src/sys/unix.rs | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 418638ab..d2e3526b 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -7,7 +7,10 @@ // except according to those terms. use std::cmp::min; -#[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] +#[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") +))] use std::ffi::{CStr, CString}; #[cfg(not(target_os = "redox"))] use std::io::IoSlice; @@ -163,7 +166,10 @@ impl Domain { /// # Notes /// /// This function is only available on Fuchsia and Linux. - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub const PACKET: Domain = Domain(libc::AF_PACKET); } @@ -172,7 +178,7 @@ impl_debug!( libc::AF_INET, libc::AF_INET6, libc::AF_UNIX, - #[cfg(any(target_os = "fuchsia", target_os = "linux"))] + #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] libc::AF_PACKET, libc::AF_UNSPEC, // = 0. ); @@ -888,7 +894,10 @@ impl crate::Socket { /// /// This function is only available on Fuchsia and Linux. On Linux it /// requires the `CAP_NET_ADMIN` capability. - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub fn mark(&self) -> io::Result { unsafe { getsockopt::(self.inner, libc::SOL_SOCKET, libc::SO_MARK).map(|mark| mark as u32) @@ -903,7 +912,10 @@ impl crate::Socket { /// /// This function is only available on Fuchsia and Linux. On Linux it /// requires the `CAP_NET_ADMIN` capability. - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub fn set_mark(&self, mark: u32) -> io::Result<()> { unsafe { setsockopt::(self.inner, libc::SOL_SOCKET, libc::SO_MARK, mark as c_int) } } @@ -913,7 +925,10 @@ impl crate::Socket { /// This value gets the socket binded device's interface name. /// /// This function is only available on Fuchsia and Linux. - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub fn device(&self) -> io::Result> { // TODO: replace with `MaybeUninit::uninit_array` once stable. let mut buf: [MaybeUninit; libc::IFNAMSIZ] = @@ -958,7 +973,10 @@ impl crate::Socket { /// If `interface` is `None` or an empty string it removes the binding. /// /// This function is only available on Fuchsia and Linux. - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub fn bind_device(&self, interface: Option<&CStr>) -> io::Result<()> { let (value, len) = if let Some(interface) = interface { (interface.as_ptr(), interface.to_bytes_with_nul().len()) @@ -1022,7 +1040,10 @@ impl crate::Socket { /// This function is only available on Fuchsia and Linux. /// /// [`set_freebind`]: Socket::set_freebind - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub fn freebind(&self) -> io::Result { unsafe { getsockopt::(self.inner, libc::SOL_SOCKET, libc::IP_FREEBIND) @@ -1039,7 +1060,10 @@ impl crate::Socket { /// to bind to it. /// /// This function is only available on Fuchsia and Linux. - #[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))] + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))] pub fn set_freebind(&self, reuse: bool) -> io::Result<()> { unsafe { setsockopt( From 879075172ed1971ab7592af1e192c38d6cd9530c Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:17:42 +0100 Subject: [PATCH 3/8] Don't borrow from packed struct on NetBSD --- src/sys/unix.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sys/unix.rs b/src/sys/unix.rs index d2e3526b..1254a8e2 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -1113,12 +1113,15 @@ from!(crate::Socket, UnixDatagram); fn in_addr_convertion() { let ip = Ipv4Addr::new(127, 0, 0, 1); let raw = to_in_addr(&ip); - assert_eq!(raw.s_addr, 127 << 0 | 1 << 24); + // NOTE: `in_addr` is packed on NetBSD and it's unsafe to borrow. + let a = raw.s_addr; + assert_eq!(a, 127 << 0 | 1 << 24); assert_eq!(from_in_addr(raw), ip); let ip = Ipv4Addr::new(127, 34, 4, 12); let raw = to_in_addr(&ip); - assert_eq!(raw.s_addr, 127 << 0 | 34 << 8 | 4 << 16 | 12 << 24); + let a = raw.s_addr; + assert_eq!(a, 127 << 0 | 34 << 8 | 4 << 16 | 12 << 24); assert_eq!(from_in_addr(raw), ip); } From 0d283408d8a35df04ee3d6c26d6aeb70af2dabe2 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:18:07 +0100 Subject: [PATCH 4/8] Add Makefile This has some common scripts such as checking all currently supported targets. --- Makefile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b38c7e23 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +# Targets available via Rustup that are supported. +TARGETS ?= "aarch64-apple-ios" "aarch64-linux-android" "x86_64-apple-darwin" "x86_64-fuchsia" "x86_64-pc-windows-msvc" "x86_64-sun-solaris" "x86_64-unknown-freebsd" "x86_64-unknown-linux-gnu" "x86_64-unknown-netbsd" "x86_64-unknown-redox" + +test: + cargo test --all-features + +# Test everything for the current OS/architecture and check all targets in +# $TARGETS. +test_all: check_all_targets + cargo hack test --feature-powerset + cargo hack test --feature-powerset --release + +# Check all targets using all features. +check_all_targets: $(TARGETS) +$(TARGETS): + cargo hack check --feature-powerset --all-targets --examples --bins --tests --target $@ + +# Installs all required targets for `check_all_targets`. +install_targets: + rustup target add $(TARGETS) + +# NOTE: when using this command you might want to change the `test` target to +# only run a subset of the tests you're actively working on. +dev: + find src/ tests/ Makefile Cargo.toml | entr -d -c $(MAKE) test + +clean: + cargo clean + +.PHONY: test test_all check_all_targets $(TARGETS) install_targets dev clean From ad74d7825f1203ccce85ad5bb8e075f5a36a4eed Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:22:49 +0100 Subject: [PATCH 5/8] Check all code in rustfmt on CI --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42888f3d..5d372adb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,7 +42,8 @@ jobs: - uses: actions/checkout@master - name: Install Rust run: rustup update stable && rustup default stable && rustup component add rustfmt - - run: cargo fmt -- --check + - name: Check formatting + run: cargo fmt --all -- --check check: name: Check From 3bafc4887aba2d37a5b376ef5787736f6e09e530 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:26:42 +0100 Subject: [PATCH 6/8] Add more target to check on CI --- .github/workflows/main.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5d372adb..19e2eaf4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,15 +50,17 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - target: [x86_64-unknown-redox, x86_64-fuchsia] + target: ["aarch64-apple-ios" "aarch64-linux-android" "x86_64-apple-darwin" "x86_64-fuchsia" "x86_64-pc-windows-msvc" "x86_64-sun-solaris" "x86_64-unknown-freebsd" "x86_64-unknown-linux-gnu" "x86_64-unknown-netbsd" "x86_64-unknown-redox"] steps: - uses: actions/checkout@master - name: Install Rust - run: rustup update nightly && rustup default nightly - - run: rustup target add ${{ matrix.target }} - - run: cargo check --target ${{ matrix.target }} --all-targets --examples --bins --tests --no-default-features - - run: cargo check --target ${{ matrix.target }} --all-targets --examples --bins --tests --all-features - continue-on-error: true + run: rustup update stable && rustup default stable + - name: Install cargo-hack + run: cargo install cargo-hack + - name: Install Target + run: rustup target add ${{ matrix.target }} + - name: Run check: + run: cargo hack check --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }} publish_docs: name: Publish Documentation From 5ee6f5d3457119ccf272f1009fe21c80bafa47cb Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:31:14 +0100 Subject: [PATCH 7/8] Run CI on current and v0.3.x branches --- .github/workflows/main.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 19e2eaf4..e58a1a32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,11 +1,15 @@ name: CI -on: [push, pull_request] +on: + push: + branches: [ master, v0.3.x ] + pull_request: + branches: [ master, v0.3.x ] env: CARGO_TERM_COLOR: always RUST_BACKTRACE: full jobs: - test: + Test: name: Test runs-on: ${{ matrix.os }} strategy: @@ -35,7 +39,7 @@ jobs: - run: cargo test - run: cargo test --features all - rustfmt: + Rustfmt: name: Rustfmt runs-on: ubuntu-latest steps: @@ -45,7 +49,7 @@ jobs: - name: Check formatting run: cargo fmt --all -- --check - check: + Check: name: Check runs-on: ubuntu-latest strategy: @@ -62,7 +66,7 @@ jobs: - name: Run check: run: cargo hack check --feature-powerset --all-targets --examples --bins --tests --target ${{ matrix.target }} - publish_docs: + Publish_docs: name: Publish Documentation runs-on: ubuntu-latest steps: From a717456323df8e0bb74f91b2c2f637e609c8e810 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 26 Dec 2020 15:32:03 +0100 Subject: [PATCH 8/8] Test will all combinations of features on CI --- .github/workflows/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e58a1a32..879c8802 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,8 +36,10 @@ jobs: - name: Install Rust (rustup) run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} shell: bash - - run: cargo test - - run: cargo test --features all + - name: Install cargo-hack + run: cargo install cargo-hack + - name: Run tests + run: cargo hack test --feature-powerset && cargo hack test --feature-powerset --release Rustfmt: name: Rustfmt