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

Add Makefile #170

Closed
wants to merge 8 commits into from
Closed
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
37 changes: 23 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
50 changes: 39 additions & 11 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}

Expand All @@ -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.
);
Expand Down Expand Up @@ -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<u32> {
unsafe {
getsockopt::<c_int>(self.inner, libc::SOL_SOCKET, libc::SO_MARK).map(|mark| mark as u32)
Expand All @@ -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::<c_int>(self.inner, libc::SOL_SOCKET, libc::SO_MARK, mark as c_int) }
}
Expand All @@ -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<Option<CString>> {
// TODO: replace with `MaybeUninit::uninit_array` once stable.
let mut buf: [MaybeUninit<u8>; libc::IFNAMSIZ] =
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<bool> {
unsafe {
getsockopt::<c_int>(self.inner, libc::SOL_SOCKET, libc::IP_FREEBIND)
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}

Expand Down