diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42888f3d..879c8802 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: @@ -32,34 +36,39 @@ 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: + Rustfmt: name: Rustfmt runs-on: ubuntu-latest steps: - 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: + Check: name: Check 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: + Publish_docs: name: Publish Documentation runs-on: ubuntu-latest steps: 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 diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 417641e5..1254a8e2 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; @@ -89,6 +92,7 @@ pub(crate) use libc::{ #[cfg(all( feature = "all", any( + target_os = "android", target_os = "freebsd", target_os = "fuchsia", target_os = "linux", @@ -162,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); } @@ -171,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. ); @@ -887,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) @@ -902,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) } } @@ -912,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] = @@ -957,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()) @@ -1021,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) @@ -1038,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( @@ -1088,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); }