Skip to content

Commit

Permalink
Add cross compilation support
Browse files Browse the repository at this point in the history
  • Loading branch information
lemaitre-aneo committed Mar 24, 2024
1 parent 7b48e84 commit 571d252
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 25 deletions.
99 changes: 86 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,106 @@ jobs:
strategy:
fail-fast: false
matrix:
job:
- { target: x86_64-unknown-linux-musl, os: linux, arch: amd64, runner: ubuntu-latest, cross: false }
- { target: x86_64-apple-darwin, os: darwin, arch: amd64, runner: macos-latest, cross: false }
- { target: x86_64-pc-windows-msvc, os: windows, arch: amd64, runner: windows-latest, cross: false }
runs-on: ${{ matrix.job.runner }}
target:
# BSDs
#- { platform: aarch64-unknown-freebsd, os: linux, runner: ubuntu-latest, run: true } # No rust core
- { platform: i686-unknown-freebsd, os: linux, runner: ubuntu-latest, run: false }
- { platform: x86_64-unknown-freebsd, os: linux, runner: ubuntu-latest, run: false }
#- { platform: aarch64-unknown-netbsd, os: linux, runner: ubuntu-latest, run: true } # No rust core
- { platform: x86_64-unknown-netbsd, os: linux, runner: ubuntu-latest, run: false }

# WASM
#- { platform: wasm32-wasi, os: linux, runner: ubuntu-latest, run: true } # Incompatible Tokio

# Android (redundant with Linux Musl)
- { platform: aarch64-linux-android, os: linux, runner: ubuntu-latest, run: true }
- { platform: arm-linux-androideabi, os: linux, runner: ubuntu-latest, run: true }
- { platform: i686-linux-android, os: linux, runner: ubuntu-latest, run: true }
- { platform: x86_64-linux-android, os: linux, runner: ubuntu-latest, run: true }

# Linux Musl
- { platform: aarch64-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true }
- { platform: arm-unknown-linux-musleabi, os: linux, runner: ubuntu-latest, run: true }
- { platform: i586-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true }
- { platform: i686-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true }
- { platform: x86_64-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true }

# Linux GNU
- { platform: aarch64-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
- { platform: arm-unknown-linux-gnueabi, os: linux, runner: ubuntu-latest, run: true }
- { platform: i586-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
- { platform: i686-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
- { platform: x86_64-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }

#- { platform: mips-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true } # No rust core
#- { platform: mips64-unknown-linux-gnuabi64, os: linux, runner: ubuntu-latest, run: true } # No rust core
- { platform: powerpc-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
- { platform: powerpc64-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
#- { platform: riscv32gc-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true } # No rust core
- { platform: riscv64gc-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
- { platform: s390x-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }
#- { platform: sparc-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true } # No rust core
- { platform: sparc64-unknown-linux-gnu, os: linux, runner: ubuntu-latest, run: true }

# MacOS
- { platform: aarch64-apple-darwin, os: darwin, runner: macos-latest, run: false }
- { platform: x86_64-apple-darwin, os: darwin, runner: macos-latest, run: true }

# Windows
- { platform: aarch64-pc-windows-msvc, os: windows, runner: windows-latest, run: false }
- { platform: i586-pc-windows-msvc, os: windows, runner: windows-latest, run: false }
- { platform: i686-pc-windows-msvc, os: windows, runner: windows-latest, run: true }
- { platform: x86_64-pc-windows-msvc, os: windows, runner: windows-latest, run: true }
toolchain:
- stable
- nightly
runs-on: ${{ matrix.target.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: taiki-e/install-action@v2
with:
tool: protoc,sccache
- name: Install toolchain
if: ${{ !contains(matrix.toolchain, 'nightly') }}
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target.platform }}
toolchain: ${{ matrix.toolchain }}
components: rust-src,rust-docs,rustfmt,clippy
- name: Install toolchain (with miri)
if: contains(matrix.toolchain, 'nightly')
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
toolchain: 1.76.0
components: rust-src,rustfmt,clippy
targets: ${{ matrix.target.platform }}
toolchain: ${{ matrix.toolchain }}
components: rust-src,rust-docs,rustfmt,clippy,miri
- name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target.platform }}
- name: Setup Cache
uses: Swatinem/[email protected]
with:
shared-key: "build-${{ matrix.job.target }}"
shared-key: "build-${{ matrix.toolchain }}-${{ matrix.target.platform }}"
- name: Build
run: |
cargo build --locked --release --target ${{ matrix.job.target }}
cargo build --all --locked
- name: Test
if: matrix.target.run
run: |
cargo test --all --locked
- name: Test Release
if: matrix.target.run
run: |
cargo test --all --locked --release
- name: Test Miri
if: contains(matrix.toolchain, 'nightly')
run: |
cargo test --locked --release --target ${{ matrix.job.target }}
cargo miri test --all --locked
- name: Format
run: |
cargo fmt --check
cargo fmt --all --check
- name: Clippy
run: |
cargo clippy --no-deps -- -Dwarnings -Dunused_extern_crates
cargo clippy --all --no-deps -- -Dwarnings -Dunused-crate-dependencies
24 changes: 12 additions & 12 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ macro_rules! serialize {
type Ok = ();
type Error = Error;

fn $serialize<T: ?Sized>(&mut self, $($key: &'static str,)? value: &T) -> Result<(), Self::Error>
fn $serialize<T>(&mut self, $($key: &'static str,)? value: &T) -> Result<(), Self::Error>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
$(self.current_field = $key;)?
value.serialize(&mut **self)
Expand Down Expand Up @@ -125,9 +125,9 @@ impl<'a> ser::Serializer for &'a mut SftpEncoder {
Ok(())
}

fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
value.serialize(self)
}
Expand All @@ -149,27 +149,27 @@ impl<'a> ser::Serializer for &'a mut SftpEncoder {
self.serialize_u32(variant_index)
}

fn serialize_newtype_struct<T: ?Sized>(
fn serialize_newtype_struct<T>(
self,
name: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
self.current_field = name;
value.serialize(self)
}

fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_name: &'static str,
variant_index: u32,
variant: &'static str,
value: &T,
) -> Result<Self::Ok, Self::Error>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
self.current_field = variant;
self.serialize_u32(variant_index)?;
Expand Down Expand Up @@ -265,16 +265,16 @@ impl<'a> ser::SerializeMap for &'a mut SftpEncoder {
type Ok = ();
type Error = Error;

fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error>
fn serialize_key<T>(&mut self, key: &T) -> Result<(), Self::Error>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
key.serialize(&mut **self)
}

fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error>
fn serialize_value<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: serde::Serialize,
T: serde::Serialize + ?Sized,
{
value.serialize(&mut **self)
}
Expand Down

0 comments on commit 571d252

Please sign in to comment.