oscall 0.1.0

Low-level cross-platform interface to operating system services: files, memory mapping, networking and more, with no libc on Linux
Documentation
name: CI

on:
  push:
    # wip/** branches are work in progress pushed to be tested on the
    # platforms that cannot be tested locally (macOS, Windows, wasmtime)
    # before it lands; the jobs scripts/check.sh covers are skipped there.
    branches: [master, "wip/**"]
  pull_request:

# A newer push to the same branch (or PR) supersedes this run: cancel the
# older one instead of queueing every intermediate commit.
concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
  # Not on master: with frequent pushes no full run would ever finish.
  cancel-in-progress: ${{ github.ref_name != 'master' }}

permissions:
  contents: read

# Every job skips release-plz's pull request: it only changes the version and
# the changelog, of commits that were tested when they reached master, and
# its runs would compete for the macOS runners.

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # Every operating system on the runners' own architecture.
    name: Test & lint (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest # Linux x86_64
          - ubuntu-24.04-arm # Linux aarch64
          - macos-latest # macOS aarch64
          - macos-15-intel # macOS x86_64
          - windows-latest # Windows x86_64
          - windows-11-arm # Windows aarch64
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Cache
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.os }}

      - name: Format
        if: matrix.os == 'ubuntu-latest' # formatting is platform-independent
        run: cargo fmt --all --check

      - name: Clippy (all features, warnings denied)
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Clippy (no_std, warnings denied)
        run: cargo clippy --all-targets --no-default-features -- -D warnings

      - name: Test (all features)
        run: cargo test --all-features

      - name: Test (no_std)
        run: cargo test --no-default-features

  cross:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    # The architectures the runners don't have natively. Linux tests are
    # static musl binaries linked with rust-lld (no cross toolchain needed);
    # foreign ones run under qemu-user through binfmt_misc.
    name: Test (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
          # 32-bit x86 runs natively on x86_64.
          - { os: ubuntu-latest, target: i686-unknown-linux-musl }
          - { os: ubuntu-24.04-arm, target: aarch64-unknown-linux-musl }
          # The arm64 runners can't execute 32-bit ARM code: emulate it.
          - { os: ubuntu-latest, target: armv7-unknown-linux-musleabihf, qemu: arm }
          - { os: ubuntu-latest, target: riscv64gc-unknown-linux-musl, qemu: riscv64 }
    steps:
      - uses: actions/checkout@v7

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

      - name: Cache
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: Set up qemu-user
        if: matrix.qemu
        uses: docker/setup-qemu-action@v3
        with:
          platforms: ${{ matrix.qemu }}

      - name: Link static musl binaries with rust-lld
        if: runner.os == 'Linux'
        run: |
          target_env=$(tr 'a-z-' 'A-Z_' <<<"${{ matrix.target }}")
          echo "CARGO_TARGET_${target_env}_LINKER=rust-lld" >> "$GITHUB_ENV"
          # Not every musl target is static and self-contained by default.
          echo "CARGO_TARGET_${target_env}_RUSTFLAGS=-C target-feature=+crt-static -C link-self-contained=yes" >> "$GITHUB_ENV"

      # Doc-tests are skipped: the static linking flags do not reach rustdoc,
      # and the native jobs run them.
      - name: Test (all features)
        run: cargo test --lib --tests --all-features --target ${{ matrix.target }}

      - name: Test (no_std)
        run: cargo test --lib --tests --no-default-features --target ${{ matrix.target }}

  fullrust:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    # Libc-free static binaries built with fullrust
    # (https://github.com/KarpelesLab/fullrust), where target_os = "fullrust"
    # and cfg(unix) is false. aarch64 and armv7 run under the image's qemu-user.
    name: fullrust (${{ matrix.target }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-fullrust
          - aarch64-unknown-linux-fullrust
          - i686-unknown-linux-fullrust
          - armv7-unknown-linux-fullrusteabihf
    steps:
      - uses: actions/checkout@v7

      # Doc-tests are skipped: the fullrust toolchain ships no rustdoc.
      - name: Test (all features)
        uses: KarpelesLab/fullrust@master
        with:
          command: test
          target: ${{ matrix.target }}
          no-ecosystem: true
          args: --lib --tests --all-features

      - name: Test (no_std)
        uses: KarpelesLab/fullrust@master
        with:
          command: test
          target: ${{ matrix.target }}
          no-ecosystem: true
          args: --lib --tests --no-default-features

  windows-x86:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # 32-bit x86 runs natively on the x86_64 Windows runner.
    name: Test (i686-pc-windows-msvc)
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: i686-pc-windows-msvc

      - name: Cache
        uses: Swatinem/rust-cache@v2

      - name: Test (all features)
        run: cargo test --all-features --target i686-pc-windows-msvc

      - name: Test (no_std)
        run: cargo test --no-default-features --target i686-pc-windows-msvc

  wasm:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # WASI preview 1 runs under wasmtime, with the crate directory preopened.
    # The other WebAssembly targets are type-checked and linted only:
    # wasm32-unknown-unknown has no system interface to test.
    name: WebAssembly
    runs-on: ubuntu-latest
    env:
      CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime run --dir=.
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
          targets: wasm32-wasip1, wasm32-wasip2, wasm32-unknown-unknown

      - name: Install wasmtime
        uses: bytecodealliance/actions/wasmtime/setup@v1

      - name: Cache
        uses: Swatinem/rust-cache@v2

      - name: Test on WASI (all features)
        run: cargo test --all-features --target wasm32-wasip1

      - name: Test on WASI (no_std)
        run: cargo test --no-default-features --target wasm32-wasip1

      - name: Clippy (wasm32-wasip2)
        run: cargo clippy --all-targets --all-features --target wasm32-wasip2 -- -D warnings

      - name: Clippy (wasm32-unknown-unknown, all features)
        run: cargo clippy --lib --all-features --target wasm32-unknown-unknown -- -D warnings

      - name: Clippy (wasm32-unknown-unknown, no_std)
        run: cargo clippy --lib --no-default-features --target wasm32-unknown-unknown -- -D warnings

  check:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    # Targets with no runner and no emulator here: type-check and lint only.
    name: Check (${{ matrix.target }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target:
          - riscv64gc-unknown-linux-gnu
          - armv7-unknown-linux-gnueabihf
          - arm-unknown-linux-gnueabihf
          - i686-unknown-linux-gnu
          - x86_64-pc-windows-gnu
          - aarch64-pc-windows-gnullvm
    steps:
      - uses: actions/checkout@v7

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

      - name: Clippy (all features, warnings denied)
        run: cargo clippy --all-targets --all-features --target ${{ matrix.target }} -- -D warnings

  riscv32:
    if: ${{ !startsWith(github.head_ref, 'release-plz-') }}
    # 32-bit RISC-V Linux is tier 3: Rust ships no standard library for it,
    # so everything here builds one with a nightly toolchain (-Zbuild-std).
    # Nightly lints and nightly `std` change under it: the job reports, and
    # does not block.
    name: riscv32 Linux (nightly, qemu)
    runs-on: ubuntu-latest
    continue-on-error: true
    env:
      FREESTANDING_FLAGS: -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=static
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust nightly
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: clippy, rust-src

      # Not the runner's own qemu-user (8.2), which does not emulate the
      # socket timeouts of 64-bit time on a 32-bit target, and
      # docker/setup-qemu-action has no riscv32: Debian's static build of
      # qemu 10.
      - name: Install qemu-riscv32
        run: |
          docker run --rm -v "$RUNNER_TEMP":/out debian:trixie-slim sh -ec '
            apt-get update -qq
            apt-get install -y -qq --no-install-recommends qemu-user-static
            cp /usr/bin/qemu-riscv32-static /out/qemu-riscv32'
          sudo install "$RUNNER_TEMP/qemu-riscv32" /usr/local/bin/qemu-riscv32
          qemu-riscv32 --version

      - name: Clippy (all features, warnings denied)
        run: cargo clippy -Zbuild-std --all-targets --all-features --target riscv32gc-unknown-linux-gnu -- -D warnings

      - name: Clippy (no_std, warnings denied)
        run: cargo clippy -Zbuild-std --all-targets --no-default-features --target riscv32gc-unknown-linux-gnu -- -D warnings

      # No libc and no `std`: the Linux backend alone, natively first.
      - name: Freestanding program (x86_64)
        working-directory: tests/freestanding
        env:
          RUSTFLAGS: ${{ env.FREESTANDING_FLAGS }}
        run: cargo run --target x86_64-unknown-linux-gnu -- "$RUNNER_TEMP"

      - name: Freestanding program (riscv32)
        working-directory: tests/freestanding
        env:
          RUSTFLAGS: ${{ env.FREESTANDING_FLAGS }}
          CARGO_TARGET_RISCV32GC_UNKNOWN_LINUX_GNU_RUNNER: qemu-riscv32
        run: cargo run -Zbuild-std=core --target riscv32gc-unknown-linux-gnu -- "$RUNNER_TEMP"

      # The whole test-suite, as static musl binaries; the script builds musl.
      - name: Test (both feature sets)
        env:
          OSCALL_NIGHTLY: nightly
        run: scripts/riscv32.sh

  msrv:
    # Not on wip/** branches: scripts/check.sh covers this locally.
    if: ${{ !startsWith(github.ref_name, 'wip/') && !startsWith(github.head_ref, 'release-plz-') }}
    name: MSRV (1.95)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - name: Install Rust 1.95
        uses: dtolnay/rust-toolchain@1.95

      - name: Check
        run: cargo check --all-targets --all-features