Skip to content

Commit

Permalink
Merge pull request #46 from n0-computer/ci-win-android-cross
Browse files Browse the repository at this point in the history
chore/fix: add CI for more platforms and targets, fix build error on 32bit systems
  • Loading branch information
sgwilym authored Aug 19, 2024
2 parents b0a5eeb + 274b2f1 commit e30304e
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 27 deletions.
251 changes: 246 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,256 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: -Dwarnings
RUSTDOCFLAGS: -Dwarnings
MSRV: "1.76"

jobs:
build:
build_and_test_nix:
timeout-minutes: 30
name: "Build and test"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
rust: [stable]
# once feature flags are used more, enable testing with all combinations
# features: [all, none, default]
features: [none, default]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install ${{ matrix.rust }} rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest

- name: Select features
run: |
case "${{ matrix.features }}" in
all)
echo "FEATURES=--all-features" >> "$GITHUB_ENV"
;;
none)
echo "FEATURES=--no-default-features" >> "$GITHUB_ENV"
;;
default)
echo "FEATURES=" >> "$GITHUB_ENV"
;;
*)
exit 1
esac
- name: build tests
run: |
cargo nextest run --workspace --exclude willow-fuzz ${{ env.FEATURES }} --lib --bins --tests --no-run
- name: run tests
run: |
cargo nextest run --workspace --exclude willow-fuzz ${{ env.FEATURES }} --lib --bins --tests --no-fail-fast
env:
RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}}

- name: run doctests
if: ${{ matrix.features == 'all' }}
env:
RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}}
run: |
cargo test --workspace --exclude willow-fuzz --all-features --doc
build_and_test_windows:
timeout-minutes: 30
name: "Build and test (Windows)"
strategy:
fail-fast: false
matrix:
os: [windows-latest]
rust: [stable]
# once feature flags are used more, enable testing with all combinations
# features: [all, none, default]
features: [default, none]
target:
- x86_64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.git-ref }}

- name: Install ${{ matrix.rust }}
run: |
rustup toolchain install ${{ matrix.rust }}
rustup toolchain default ${{ matrix.rust }}
rustup target add ${{ matrix.target }}
rustup set default-host ${{ matrix.target }}
- name: Install cargo-nextest
shell: powershell
run: |
$tmp = New-TemporaryFile | Rename-Item -NewName { $_ -replace 'tmp$', 'zip' } -PassThru
Invoke-WebRequest -OutFile $tmp https://get.nexte.st/latest/windows
$outputDir = if ($Env:CARGO_HOME) { Join-Path $Env:CARGO_HOME "bin" } else { "~/.cargo/bin" }
$tmp | Expand-Archive -DestinationPath $outputDir -Force
$tmp | Remove-Item
- name: Select features
run: |
switch ("${{ matrix.features }}") {
"all" {
echo "FEATURES=--all-features" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
"none" {
echo "FEATURES=--no-default-features" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
"default" {
echo "FEATURES=" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
default {
Exit 1
}
}
- uses: msys2/setup-msys2@v2

- name: build tests
run: |
cargo nextest run --workspace --exclude willow-fuzz ${{ env.FEATURES }} --lib --bins --tests --target ${{ matrix.target }} --no-run
- name: run tests
run: |
cargo nextest run --workspace --exclude willow-fuzz ${{ env.FEATURES }} --lib --bins --tests --target ${{ matrix.target }} --no-fail-fast
env:
RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}}

- name: run doctests
if: ${{ matrix.features == 'all' }}
env:
RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}}
run: |
cargo test --workspace --exclude willow-fuzz --all-features --doc
cross_build_and_test:
name: Build and test (cross)
timeout-minutes: 30
runs-on: ubuntu-latest
strategy:
matrix:
target:
- i686-unknown-linux-gnu
- aarch64-unknown-linux-gnu
# note that there are known bugs in arm cross-compile qemu runners
# if issues appear we might have to disable these
# - see https://github.com/cross-rs/cross/issues/1311
- armv7-linux-androideabi@23
- aarch64-linux-android@23
include:
- target: i686-unknown-linux-gnu
name: Linux 32bit
- target: aarch64-unknown-linux-gnu
name: Linux aarch64
- target: armv7-linux-androideabi@23
name: Android armv7
- target: aarch64-linux-android@23
name: Android aarch64

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- name: Cleanup Docker
continue-on-error: true
run: |
docker kill $(docker ps -q)
# setup-cross-toolchain-action sets the `CARGO_BUILD_TARGET` environment variable,
# so there is no need for an explicit `--target` flag.
- name: Build tests
run: cargo build --workspace --exclude willow-fuzz
- name: Run tests
run: cargo test --verbose --workspace --exclude willow-fuzz

fuzz_tests:
timeout-minutes: 30
name: "Run fuzz tests"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
rust: [nightly]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install ${{ matrix.rust }} rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: build and run fuzz tests
run: |
cargo test -p willow-fuzz
check_fmt:
timeout-minutes: 30
name: Chec fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: fmt
run: cargo fmt --all -- --check

check_docs:
timeout-minutes: 30
name: Check docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-05-02
- name: Install sccache
uses: mozilla-actions/[email protected]

- name: Docs
run: cargo doc --workspace --all-features --no-deps --document-private-items
env:
RUSTDOCFLAGS: --cfg docsrs

clippy_check:
name: Check clippy
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Install sccache
uses: mozilla-actions/[email protected]

- name: clippy check (all features)
run: cargo clippy --workspace --all-features --all-targets --bins --tests --benches

- name: clippy check (no features)
run: cargo clippy --workspace --no-default-features --lib --bins --tests

- name: clippy check (default features)
run: cargo clippy --workspace --all-targets
5 changes: 3 additions & 2 deletions data-model/src/relative_encodings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use syncify::syncify;
use syncify::syncify_replace;

#[syncify(encoding_sync)]
pub(super) mod encoding {
use super::*;
// TODO: Unclear why this is marked unused.
#[allow(unused_imports)]
use syncify::syncify_replace;

#[syncify_replace(use ufotofu::sync::{BulkConsumer, BulkProducer};)]
use ufotofu::local_nb::{BulkConsumer, BulkProducer};
Expand Down
2 changes: 0 additions & 2 deletions earthstar/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(new_uninit)]

pub mod cinn25519;
pub mod identity_id;
pub mod namespace_id;
7 changes: 4 additions & 3 deletions encoding/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use syncify::syncify;

#[syncify(encoding_sync)]
pub mod encoding {

use crate::error::DecodeError;

use either::Either;
// TODO: Somehow this is marked as unused. But if I remove it, the syncify_replace is not
// working. Weird!
#[allow(unused_imports)]
use syncify::syncify_replace;

#[syncify_replace(use ufotofu::sync::{ BulkProducer};)]
#[syncify_replace(use ufotofu::sync::BulkProducer;)]
use ufotofu::local_nb::BulkProducer;

/// Have `Producer` produce a single byte, or return an error if the final value was produced or the producer experienced an error.
Expand Down
20 changes: 10 additions & 10 deletions encoding/src/max_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use syncify::syncify_replace;
/// Return the least natural number such that 256^`n` is greater than or equal to `n`.
///
/// Used for determining the minimal number of bytes needed to represent a given unsigned integer, and more specifically [`path_length_power`](https://willowprotocol.org/specs/encodings/index.html#path_length_power) and [`path_count_power`](https://willowprotocol.org/specs/encodings/index.html#path_count_power).
pub const fn max_power(max_size: usize) -> u8 {
pub const fn max_power(max_size: u64) -> u8 {
if max_size < 256 {
1
} else if max_size < 65536 {
} else if max_size < 256u64.pow(2) {
2
} else if max_size < 16777216 {
} else if max_size < 256u64.pow(3) {
3
} else if max_size < 4294967296 {
} else if max_size < 256u64.pow(4) {
4
} else if max_size < (256_usize).pow(5) {
} else if max_size < 256u64.pow(5) {
5
} else if max_size < (256_usize).pow(6) {
} else if max_size < 256u64.pow(6) {
6
} else if max_size < (256_usize).pow(7) {
} else if max_size < 256u64.pow(7) {
7
} else {
8
Expand Down Expand Up @@ -48,8 +48,8 @@ pub(super) mod encoding {
panic!("Can't encode a value larger than its maximum possible value!")
}

let power = max_power(max_size);
let value_encoded_raw: [u8; size_of::<u64>()] = value.to_be_bytes();
let power = max_power(max_size as u64);
let value_encoded_raw: [u8; size_of::<u64>()] = (value as u64).to_be_bytes();

consumer
.bulk_consume_full_slice(&value_encoded_raw[size_of::<u64>() - (power as usize)..])
Expand All @@ -67,7 +67,7 @@ pub(super) mod encoding {
where
P: BulkProducer<Item = u8>,
{
let power = max_power(max_size);
let power = max_power(max_size as u64);
let mut slice = [0u8; size_of::<u64>()];

producer
Expand Down
4 changes: 2 additions & 2 deletions meadowcap/src/mc_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ pub(super) mod encoding {
}
}

let delegations_count = self.delegations_len();
let delegations_count = self.delegations_len() as u64;

if delegations_count >= 4294967296 {
header |= 0b0011_1111;
Expand All @@ -394,7 +394,7 @@ pub(super) mod encoding {
};

if delegations_count >= 60 {
encode_compact_width_be(delegations_count as u64, consumer).await?;
encode_compact_width_be(delegations_count, consumer).await?;
}

let mut prev_area = out.clone();
Expand Down
4 changes: 2 additions & 2 deletions meadowcap/src/mc_subspace_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub(super) mod encoding {
{
let mut header = 0;

let delegations_count = self.delegations.len();
let delegations_count = self.delegations.len() as u64;

if delegations_count >= 4294967296 {
header |= 0b1111_1111;
Expand All @@ -288,7 +288,7 @@ pub(super) mod encoding {
Encodable::encode(&self.initial_authorisation, consumer).await?;

if delegations_count >= 60 {
encode_compact_width_be(delegations_count as u64, consumer).await?;
encode_compact_width_be(delegations_count, consumer).await?;
}

for delegation in self.delegations.iter() {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "stable"

0 comments on commit e30304e

Please sign in to comment.