Skip to content

Commit

Permalink
Fix ios and android builds (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-mariappan-ramasamy authored Jul 23, 2024
1 parent 96fb69e commit ed0a23a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 9 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,52 @@ jobs:
if: ${{ failure() }}
run: echo "Some of jobs failed" && false

build_n_test_android:
strategy:
fail-fast: false
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install cargo ndk and rust compiler for android target
if: ${{ !cancelled() }}
run: |
cargo install --locked cargo-ndk
rustup target add x86_64-linux-android
- name: clippy
if: ${{ !cancelled() }}
run: cargo ndk -t x86_64 clippy --all-features --features="async tokio/rt-multi-thread" -- -D warnings
- name: Build
if: ${{ !cancelled() }}
run: |
cargo ndk -t x86_64 rustc --verbose --all-features --features="async tokio/rt-multi-thread" --lib --crate-type=cdylib
- name: Abort on error
if: ${{ failure() }}
run: echo "Android build job failed" && false

build_n_test_ios:
strategy:
fail-fast: false
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: Install cargo lipo and rust compiler for ios target
if: ${{ !cancelled() }}
run: |
cargo install --locked cargo-lipo
rustup target add x86_64-apple-ios aarch64-apple-ios
- name: clippy
if: ${{ !cancelled() }}
run: cargo clippy --target x86_64-apple-ios --all-features --features="async tokio/rt-multi-thread" -- -D warnings
- name: Build
if: ${{ !cancelled() }}
run: |
cargo lipo --verbose --all-features --features="async tokio/rt-multi-thread"
- name: Abort on error
if: ${{ failure() }}
run: echo "iOs build job failed" && false

semver:
name: Check semver
strategy:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tun2"
version = "2.0.3"
version = "2.0.4"
edition = "2021"
authors = ["meh. <meh@schizofreni.co>", "@ssrlive"]
license = "WTFPL"
Expand Down
4 changes: 2 additions & 2 deletions src/platform/android/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ impl Device {
}

/// Recv a packet from tun device
pub fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
pub fn recv(&self, buf: &mut [u8]) -> std::io::Result<usize> {
self.tun.recv(buf)
}

/// Send a packet to tun device
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
pub fn send(&self, buf: &[u8]) -> std::io::Result<usize> {
self.tun.send(buf)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ pub struct PlatformConfig;

/// Create a TUN device with the given name.
pub fn create(configuration: &Configuration) -> Result<Device> {
Device::new(&configuration)
Device::new(configuration)
}
4 changes: 2 additions & 2 deletions src/platform/ios/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ impl Device {
}

/// Recv a packet from tun device
pub fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
pub fn recv(&self, buf: &mut [u8]) -> std::io::Result<usize> {
self.tun.recv(buf)
}

/// Send a packet to tun device
pub fn send(&self, buf: &[u8]) -> io::Result<usize> {
pub fn send(&self, buf: &[u8]) -> std::io::Result<usize> {
self.tun.send(buf)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ impl PlatformConfig {

/// Create a TUN device with the given name.
pub fn create(configuration: &Configuration) -> Result<Device> {
Device::new(&configuration)
Device::new(configuration)
}
6 changes: 5 additions & 1 deletion src/platform/posix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
//! POSIX compliant support.

mod sockaddr;
pub(crate) use sockaddr::{ipaddr_to_sockaddr, sockaddr_union};
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
pub(crate) use sockaddr::sockaddr_union;

#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) use sockaddr::ipaddr_to_sockaddr;

mod fd;
pub(crate) use self::fd::Fd;
Expand Down
3 changes: 2 additions & 1 deletion src/platform/posix/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ fn rs_addr_to_sockaddr(addr: std::net::SocketAddr) -> sockaddr_union {

/// # Safety
/// Fill the `addr` with the `src_addr` and `src_port`, the `size` should be the size of overwriting
pub unsafe fn ipaddr_to_sockaddr<T>(
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(crate) unsafe fn ipaddr_to_sockaddr<T>(
src_addr: T,
src_port: u16,
addr: &mut libc::sockaddr,
Expand Down

0 comments on commit ed0a23a

Please sign in to comment.