Skip to content

Commit

Permalink
Merge branch 'main' into github-features
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden authored Aug 20, 2024
2 parents 361247c + a003e10 commit 355c2bc
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/rust-android-run-tests-on-emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

adb wait-for-device
while [[ -z "$(adb shell getprop sys.boot_completed | tr -d '\r')" ]]; do sleep 1; done

any_failures=0
for test in $(find target/${{ matrix.target }}/debug/deps/ -type f -executable ! -name "*.so" -name "*-*"); do
adb push "$test" /data/local/tmp/
adb shell chmod +x /data/local/tmp/$(basename "$test")
adb shell /data/local/tmp/$(basename "$test") || any_failures=1
done

exit $any_failures
58 changes: 58 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,61 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- run: cargo hack check --feature-powerset --optional-deps --no-dev-deps --ignore-unknown-features --ignore-private --group-features runtime-async-std,async-io,async-std --group-features runtime-smol,async-io,smol

test-android:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- target: x86_64-linux-android
emulator-arch: x86_64
# Note that x86_64 image is only available for API 21+. See
# https://github.com/ReactiveCircus/android-emulator-runner?tab=readme-ov-file#configurations.
api-level: 21
- target: i686-linux-android
emulator-arch: x86
api-level: 19

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- name: Install Android SDK
uses: android-actions/setup-android@v3

- name: Install Android NDK
run: sdkmanager --install "ndk;25.2.9519653"

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.target }}

- uses: Swatinem/rust-cache@v2

- name: Install cargo-ndk
run: cargo install cargo-ndk

- name: Build unit tests for Android
run: cargo ndk -t ${{ matrix.target }} test --no-run

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Set up Android Emulator and run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: ${{ matrix.emulator-arch }}
script: .github/workflows/rust-android-run-tests-on-emulator.sh
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rustls-pemfile = "2"
rustls-platform-verifier = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
slab = "0.4"
slab = "0.4.6"
smol = "2"
socket2 = "0.5"
thiserror = "1.0.21"
Expand Down
2 changes: 1 addition & 1 deletion quinn-udp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log = ["tracing/log"]
direct-log = ["dep:log"]

[dependencies]
libc = "0.2.113"
libc = "0.2.158"
log = { workspace = true, optional = true }
socket2 = { workspace = true }
tracing = { workspace = true, optional = true }
Expand Down
46 changes: 37 additions & 9 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
use std::ptr;
use std::{
io::{self, IoSliceMut},
Expand Down Expand Up @@ -62,6 +67,7 @@ impl UdpSocketState {
|| cfg!(target_os = "macos")
|| cfg!(target_os = "ios")
|| cfg!(target_os = "android")
|| cfg!(target_os = "solaris")
{
cmsg_platform_space +=
unsafe { libc::CMSG_SPACE(mem::size_of::<libc::in6_pktinfo>() as _) as usize };
Expand All @@ -84,7 +90,7 @@ impl UdpSocketState {

// mac and ios do not support IP_RECVTOS on dual-stack sockets :(
// older macos versions also don't have the flag and will error out if we don't ignore it
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
if is_ipv4 || !io.only_v6()? {
if let Err(_err) =
set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON)
Expand Down Expand Up @@ -138,10 +144,11 @@ impl UdpSocketState {
target_os = "openbsd",
target_os = "netbsd",
target_os = "macos",
target_os = "ios"
target_os = "ios",
target_os = "solaris",
))]
// IP_RECVDSTADDR == IP_SENDSRCADDR on FreeBSD
// macOS uses only IP_RECVDSTADDR, no IP_SENDSRCADDR on macOS
// macOS uses only IP_RECVDSTADDR, no IP_SENDSRCADDR on macOS (the same on Solaris)
// macOS also supports IP_PKTINFO
{
if is_ipv4 {
Expand Down Expand Up @@ -367,7 +374,12 @@ fn send(state: &UdpSocketState, io: SockRef<'_>, transmit: &Transmit<'_>) -> io:
Ok(())
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> io::Result<usize> {
let mut names = [MaybeUninit::<libc::sockaddr_storage>::uninit(); BATCH_SIZE];
let mut ctrls = [cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit()); BATCH_SIZE];
Expand Down Expand Up @@ -404,7 +416,12 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
Ok(msg_count as usize)
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
))]
fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> io::Result<usize> {
let mut name = MaybeUninit::<libc::sockaddr_storage>::uninit();
let mut ctrl = cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit());
Expand Down Expand Up @@ -433,7 +450,12 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
///
/// It uses [`libc::syscall`] instead of [`libc::recvmmsg`]
/// to avoid linking error on systems where libc does not contain `recvmmsg`.
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
unsafe fn recvmmsg_with_fallback(
sockfd: libc::c_int,
msgvec: *mut libc::mmsghdr,
Expand Down Expand Up @@ -476,7 +498,12 @@ unsafe fn recvmmsg_with_fallback(
/// Fallback implementation of `recvmmsg` using `recvmsg`
/// for systems which do not support `recvmmsg`
/// such as Linux <2.6.33.
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
unsafe fn recvmmsg_fallback(
sockfd: libc::c_int,
msgvec: *mut libc::mmsghdr,
Expand Down Expand Up @@ -567,6 +594,7 @@ fn prepare_msg(
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "solaris",
))]
{
if encode_src_ip {
Expand Down Expand Up @@ -625,7 +653,7 @@ fn decode_recv(
ecn_bits = cmsg::decode::<u8, libc::cmsghdr>(cmsg);
},
// FreeBSD uses IP_RECVTOS here, and we can be liberal because cmsgs are opt-in.
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
(libc::IPPROTO_IP, libc::IP_RECVTOS) => unsafe {
ecn_bits = cmsg::decode::<u8, libc::cmsghdr>(cmsg);
},
Expand Down
8 changes: 4 additions & 4 deletions quinn-udp/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
use std::{
io::IoSliceMut,
Expand Down Expand Up @@ -51,7 +51,7 @@ fn ecn_v6() {
}

#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
fn ecn_v4() {
let send = Socket::from(UdpSocket::bind("127.0.0.1:0").unwrap());
let recv = Socket::from(UdpSocket::bind("127.0.0.1:0").unwrap());
Expand All @@ -71,7 +71,7 @@ fn ecn_v4() {
}

#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
fn ecn_v6_dualstack() {
let recv = socket2::Socket::new(
socket2::Domain::IPV6,
Expand Down Expand Up @@ -114,7 +114,7 @@ fn ecn_v6_dualstack() {
}

#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
fn ecn_v4_mapped_v6() {
let send = socket2::Socket::new(
socket2::Domain::IPV6,
Expand Down
1 change: 1 addition & 0 deletions quinn/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ fn run_echo(args: EchoArgs) {
// requires modifying this test - please update the list of supported
// platforms in the doc comment of `quinn_udp::RecvMeta::dst_ip`.
if cfg!(target_os = "linux")
|| cfg!(target_os = "android")
|| cfg!(target_os = "freebsd")
|| cfg!(target_os = "openbsd")
|| cfg!(target_os = "netbsd")
Expand Down

0 comments on commit 355c2bc

Please sign in to comment.