From 4d0a9ed2d6af81c151b350ba43b69e67753eb366 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 2 Dec 2026 20:13:22 +0100 Subject: [PATCH] ci: build and test the Docker and Podman drivers Build the Docker and Podman drivers as OpenShell builds its release binaries, in the flake's dev shell with its cross toolchains: natively for x86_64 and aarch64 Linux and for aarch64 macOS. Run OpenShell's conformance suite on its tmachine with the drivers built here swapped into the packaged deb (Docker) and rpm (Podman), on Ubuntu and on rootful and rootless Fedora. The gateway packages, runtime images and the conformance program come from OpenShell's published test-inputs bundle at 9972314fa, which the Cargo pins now also use. Signed-off-by: Evan Lezar --- .github/actions/build-rust-binary/action.yml | 92 +++++++++ .github/actions/pull-test-inputs/action.yml | 43 ++++ .github/actions/setup-nix/action.yml | 51 +++++ .github/actions/setup-rust/action.yml | 38 ++++ .github/workflows/build-binaries-linux.yml | 67 ++++++ .github/workflows/build-binaries-macos.yml | 56 +++++ .github/workflows/driver-build-test.yml | 204 +++++++++++++++++++ .github/workflows/e2e-suites.yml | 181 ++++++++++++++++ Cargo.lock | 30 +-- Cargo.toml | 22 +- README.md | 18 ++ flake.lock | 82 ++++++++ flake.nix | 102 ++++++++++ nix/pkgs/aws-lc.nix | 39 ++++ nix/strings.nix | 11 + nix/toolchain/darwin.nix | 25 +++ nix/toolchain/default.nix | 37 ++++ nix/toolchain/glibc-2.28/libc.nix | 44 ++++ nix/toolchain/glibc-2.28/stdenv.nix | 34 ++++ nix/toolchain/glibc-2.28/sysroot.nix | 42 ++++ nix/toolchain/linux.nix | 52 +++++ 21 files changed, 1245 insertions(+), 25 deletions(-) create mode 100644 .github/actions/build-rust-binary/action.yml create mode 100644 .github/actions/pull-test-inputs/action.yml create mode 100644 .github/actions/setup-nix/action.yml create mode 100644 .github/actions/setup-rust/action.yml create mode 100644 .github/workflows/build-binaries-linux.yml create mode 100644 .github/workflows/build-binaries-macos.yml create mode 100644 .github/workflows/driver-build-test.yml create mode 100644 .github/workflows/e2e-suites.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/pkgs/aws-lc.nix create mode 100644 nix/strings.nix create mode 100644 nix/toolchain/darwin.nix create mode 100644 nix/toolchain/default.nix create mode 100644 nix/toolchain/glibc-2.28/libc.nix create mode 100644 nix/toolchain/glibc-2.28/stdenv.nix create mode 100644 nix/toolchain/glibc-2.28/sysroot.nix create mode 100644 nix/toolchain/linux.nix diff --git a/.github/actions/build-rust-binary/action.yml b/.github/actions/build-rust-binary/action.yml new file mode 100644 index 0000000..f0a255f --- /dev/null +++ b/.github/actions/build-rust-binary/action.yml @@ -0,0 +1,92 @@ +# SPDX-License-Identifier: Apache-2.0 + +name: Build Rust Binary +description: Build, verify, package, and upload an auditable Rust binary + +inputs: + package: + description: Cargo package that owns the binary + required: true + binary: + description: Cargo binary name + required: true + triple: + description: Rust target triple + required: true + cargo-version: + description: Cargo package version embedded in the binary + required: true + run-check: + description: Run the binary to check its name; false for a binary cross-built for another architecture + required: false + default: "true" + artifact-name: + description: GitHub artifact name + required: false + default: "" + extra-cargo-flags: + description: Additional flags passed to cargo build + required: false + default: "" + entitlements-file: + description: Path to an entitlements plist for macOS ad-hoc codesigning (skipped when empty or not on macOS) + required: false + default: "" +runs: + using: composite + steps: + # Per-binary caches are large and other branches can restore main's, so + # saving them elsewhere mostly evicts main's from the shared quota. + - uses: ./.github/actions/setup-rust + with: + cache-key: binaries-v2-${{ inputs.binary }}-${{ inputs.triple }} + save-cache: ${{ github.ref == 'refs/heads/main' }} + + - name: Set version + shell: nix develop -c bash -euo pipefail {0} + env: + INPUTS_CARGO_VERSION: ${{ inputs.cargo-version }} + run: sed -i "s/^version = \"0\\.0\\.0\"$/version = \"${INPUTS_CARGO_VERSION}\"/" Cargo.toml + + - name: Build ${{ inputs.binary }} + shell: nix develop -c bash -euo pipefail {0} + env: + GIT_DIR: /nonexistent + INPUTS_PACKAGE: ${{ inputs.package }} + INPUTS_BINARY: ${{ inputs.binary }} + INPUTS_TRIPLE: ${{ inputs.triple }} + INPUTS_EXTRA_CARGO_FLAGS: ${{ inputs.extra-cargo-flags }} + run: cargo auditable build --release --target "${INPUTS_TRIPLE}" --package "${INPUTS_PACKAGE}" --bin "${INPUTS_BINARY}" ${INPUTS_EXTRA_CARGO_FLAGS} + + - name: Verify ${{ inputs.binary }} + shell: nix develop -c bash -euo pipefail {0} + env: + INPUTS_BINARY: ${{ inputs.binary }} + INPUTS_TRIPLE: ${{ inputs.triple }} + INPUTS_RUN_CHECK: ${{ inputs.run-check }} + run: | + binary="target/${INPUTS_TRIPLE}/release/${INPUTS_BINARY}" + # Confirm the binary runs and reports the expected name. + if [ "${INPUTS_RUN_CHECK}" = "true" ]; then + "$binary" --version | grep -q "^${INPUTS_BINARY} " + fi + # Confirm Syft can decode the embedded cargo-auditable metadata. + SYFT_CHECK_FOR_APP_UPDATE=false syft "file:${binary}" -o cyclonedx-json | grep 'pkg:cargo/' > /dev/null + + - name: Codesign with entitlements + if: inputs.entitlements-file != '' && runner.os == 'macOS' + shell: bash + env: + INPUTS_ENTITLEMENTS: ${{ inputs.entitlements-file }} + INPUTS_TRIPLE: ${{ inputs.triple }} + INPUTS_BINARY: ${{ inputs.binary }} + run: /usr/bin/codesign --entitlements "${INPUTS_ENTITLEMENTS}" --force -s - "target/${INPUTS_TRIPLE}/release/${INPUTS_BINARY}" + + - name: Upload ${{ inputs.binary }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: ${{ inputs.artifact-name || format('{0}-{1}', inputs.binary, inputs.triple) }} + path: target/${{ inputs.triple }}/release/${{ inputs.binary }} + compression-level: 0 + retention-days: 5 + if-no-files-found: error diff --git a/.github/actions/pull-test-inputs/action.yml b/.github/actions/pull-test-inputs/action.yml new file mode 100644 index 0000000..0e24df4 --- /dev/null +++ b/.github/actions/pull-test-inputs/action.yml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: Apache-2.0 + +name: Pull OpenShell test inputs +description: >- + Pull OpenShell's published test-inputs bundle (ghcr.io/ai-openshell/openshell/test-inputs:) + with ORAS and verify its SHA256SUMS. Nothing from OpenShell is built here. The bundle is a + package of ai-openshell/openshell: the token needs read:packages, or the package must grant this + repository access. + +inputs: + test-inputs: + description: ai-openshell/openshell commit whose published bundle to pull + required: true + token: + description: Token that can read the package + required: true + directory: + description: Directory to pull the bundle into (recreated) + required: true + +runs: + using: composite + steps: + - name: Install ORAS + uses: oras-project/setup-oras@1d808f7d7f6995cc68b7bf507bfe5c5446e1dc9d # v2.0.0 + + - name: Pull and verify the bundle + shell: bash + env: + GH_TOKEN: ${{ inputs.token }} + TEST_INPUTS: ${{ inputs.test-inputs }} + BUNDLE: ${{ inputs.directory }} + run: | + set -euo pipefail + ref="ghcr.io/ai-openshell/openshell/test-inputs:${TEST_INPUTS}" + echo "${GH_TOKEN}" | oras login ghcr.io -u "${GITHUB_ACTOR}" --password-stdin + rm -rf "$BUNDLE" + mkdir -p "$BUNDLE" + oras pull "$ref" --output "$BUNDLE" || { + echo "::error::Could not pull ${ref}. Is there a Release Dev or Branch E2E run of that commit, and can the token read the package?" + exit 1 + } + (cd "$BUNDLE" && sha256sum --quiet -c SHA256SUMS) diff --git a/.github/actions/setup-nix/action.yml b/.github/actions/setup-nix/action.yml new file mode 100644 index 0000000..1d17f16 --- /dev/null +++ b/.github/actions/setup-nix/action.yml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: Apache-2.0 + +name: Setup Nix +description: Install Determinate Nix, configure Cachix, and optionally prepare the development shell + +inputs: + cachix-auth-token: + description: Token used to write build outputs to Cachix + required: false + default: "" + + prepare-shell: + description: Prepare the development shell, retrying once on failure + required: false + default: "false" + shell-installable: + description: Development shell to prepare + required: false + default: "." + +runs: + using: composite + steps: + - uses: DeterminateSystems/determinate-nix-action@e847f25223456b3058e12f7fc9d777b6a6f25060 # v3.23.2 + with: + github-token: ${{ github.token }} + summarize: false + # One failed HTTP/2 connection fails every NAR multiplexed on it, and + # Nix fails completed NARs it then resumes at EOF with HTTP 416 + # (NixOS/nix#16722). Separate HTTP/1.1 connections limit the damage. + extra-conf: | + http2 = false + + - uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17 + with: + name: openshell + authToken: ${{ inputs.cachix-auth-token }} + skipPush: ${{ inputs.cachix-auth-token == '' }} + + - name: Prepare Nix development shell + if: inputs.prepare-shell == 'true' + shell: bash + env: + NIX_SHELL_INSTALLABLE: ${{ inputs.shell-installable }} + run: | + # HTTP 416 is not retried by Nix; a fresh invocation restarts downloads. + if nix develop "$NIX_SHELL_INSTALLABLE" -c true; then + exit 0 + fi + echo "::warning::Nix shell preparation failed; retrying once." + nix develop "$NIX_SHELL_INSTALLABLE" -c true diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.yml new file mode 100644 index 0000000..a9df7c1 --- /dev/null +++ b/.github/actions/setup-rust/action.yml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: Apache-2.0 + +name: Setup Rust +description: Configure Rust caches after setup-nix has prepared the development shell + +inputs: + cache-key: + description: Rust target cache namespace + required: true + save-cache: + description: Whether this job writes the Rust target cache + required: false + default: "false" + +outputs: + cache-hit: + description: "true when the cache key matched exactly" + value: ${{ steps.cache.outputs.cache-hit }} + +runs: + using: composite + steps: + - name: Hash Nix development shell + id: dev-shell + shell: bash + run: | + shell_drv=$(nix eval --raw --impure .#devShells --apply 'shells: shells.${builtins.currentSystem}.default.drvPath') + echo "hash=$(nix hash file --type sha256 --base16 "$shell_drv")" >> "$GITHUB_OUTPUT" + + - name: Cache Rust target and registry + id: cache + uses: Swatinem/rust-cache@6a7bc3ebce750e0a16a430dd57485acfdb38b05f + with: + shared-key: ${{ inputs.cache-key }}-${{ steps.dev-shell.outputs.hash }} + save-if: ${{ inputs.save-cache }} + cache-on-failure: ${{ inputs.save-cache }} + cache-bin: "false" + cmd-format: nix develop -c {0} diff --git a/.github/workflows/build-binaries-linux.yml b/.github/workflows/build-binaries-linux.yml new file mode 100644 index 0000000..98b62cd --- /dev/null +++ b/.github/workflows/build-binaries-linux.yml @@ -0,0 +1,67 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Builds the Linux binaries of this repository the way OpenShell's build-binaries-linux.yml builds +# its release binaries: release profile, cargo-auditable, in the flake's development shell with the +# cross toolchains. The drivers are built natively for x86_64 and aarch64. + +name: Build Linux Binaries + +on: + workflow_call: + inputs: + cargo-version: + required: false + type: string + default: "0.0.0" + checkout-ref: + required: false + type: string + default: "" + secrets: + CACHIX_AUTH_TOKEN: + required: false + +permissions: + contents: read + +jobs: + # The external drivers, linked for the guest like OpenShell's other external drivers (gnu). + drivers: + name: ${{ matrix.binary }} (${{ matrix.triple }}) + strategy: + fail-fast: false + matrix: + include: + - package: openshell-driver-docker + binary: openshell-driver-docker + triple: x86_64-unknown-linux-gnu + runner: ubuntu-24.04 + - package: openshell-driver-docker + binary: openshell-driver-docker + triple: aarch64-unknown-linux-gnu + runner: ubuntu-24.04-arm + - package: openshell-driver-podman + binary: openshell-driver-podman + triple: x86_64-unknown-linux-gnu + runner: ubuntu-24.04 + - package: openshell-driver-podman + binary: openshell-driver-podman + triple: aarch64-unknown-linux-gnu + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + timeout-minutes: 60 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ inputs.checkout-ref || github.sha }} + - uses: ./.github/actions/setup-nix + with: + prepare-shell: "true" + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + - uses: ./.github/actions/build-rust-binary + with: + package: ${{ matrix.package }} + binary: ${{ matrix.binary }} + triple: ${{ matrix.triple }} + cargo-version: ${{ inputs.cargo-version }} diff --git a/.github/workflows/build-binaries-macos.yml b/.github/workflows/build-binaries-macos.yml new file mode 100644 index 0000000..c10d052 --- /dev/null +++ b/.github/workflows/build-binaries-macos.yml @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Builds the macOS binaries of this repository the way OpenShell's build-binaries-macos.yml builds +# its release binaries: release profile, cargo-auditable, in the flake's development shell. Only the +# drivers that run on a macOS host are built; the VM driver has its own workflow. + +name: Build macOS Binaries + +on: + workflow_call: + inputs: + cargo-version: + required: false + type: string + default: "0.0.0" + checkout-ref: + required: false + type: string + default: "" + secrets: + CACHIX_AUTH_TOKEN: + required: false + +permissions: + contents: read + +jobs: + build: + name: ${{ matrix.binary }} (${{ matrix.triple }}) + strategy: + fail-fast: false + matrix: + include: + - package: openshell-driver-docker + binary: openshell-driver-docker + triple: aarch64-apple-darwin + - package: openshell-driver-podman + binary: openshell-driver-podman + triple: aarch64-apple-darwin + runs-on: macos-15 + timeout-minutes: 60 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ inputs.checkout-ref || github.sha }} + - uses: ./.github/actions/setup-nix + with: + prepare-shell: "true" + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + - uses: ./.github/actions/build-rust-binary + with: + package: ${{ matrix.package }} + binary: ${{ matrix.binary }} + triple: ${{ matrix.triple }} + cargo-version: ${{ inputs.cargo-version }} diff --git a/.github/workflows/driver-build-test.yml b/.github/workflows/driver-build-test.yml new file mode 100644 index 0000000..0e4626c --- /dev/null +++ b/.github/workflows/driver-build-test.yml @@ -0,0 +1,204 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Builds the drivers as OpenShell builds its release binaries and runs OpenShell's conformance +# suite against them on its tmachine: the Docker and Podman drivers built here replace the ones +# in OpenShell's packaged gateway. Format, lint, tests and the license headers are in ci.yml. + +name: Driver Build and Test + +on: + pull_request: + push: + branches: [main] + workflow_dispatch: + inputs: + openshell-rev: + description: ai-openshell/openshell commit that provides tmachine, the gateway and the conformance suite + required: false + type: string + openshell-test-inputs: + description: ai-openshell/openshell commit whose published test-inputs bundle (ghcr) to reuse + required: false + type: string + +permissions: + contents: read + +concurrency: + group: driver-build-test-${{ github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + # The OpenShell commit the conformance lane tests against: a commit with the driver launch + # protocol, which packages the drivers next to the gateway. Move it with the openshell-* git rev in Cargo.toml. + OPENSHELL_REV: ${{ inputs.openshell-rev || '9972314fa89320860e734f533e08d6994407d5fe' }} + # The commit whose test-inputs bundle (ghcr.io/ai-openshell/openshell/test-inputs:) the + # lane reuses: tmachine inputs, the gateway packages and the prebuilt openshell-conformance. It is + # published for OpenShell's Release Dev runs on main and for Branch E2E runs, and does not expire. + # Keep it at OPENSHELL_REV, which must be a commit with a published bundle. + OPENSHELL_TEST_INPUTS: ${{ inputs.openshell-test-inputs || '9972314fa89320860e734f533e08d6994407d5fe' }} + +jobs: + # The binaries of this repository, built as OpenShell builds its release binaries + # (build-binaries-linux.yml): the Docker and Podman drivers for the guest. + build-binaries-linux: + name: Build Linux binaries + permissions: + contents: read + uses: ./.github/workflows/build-binaries-linux.yml + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + + # The drivers that run on a macOS host. + build-binaries-macos: + name: Build macOS binaries + permissions: + contents: read + uses: ./.github/workflows/build-binaries-macos.yml + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + + # Stages the inputs the way OpenShell's prepare-integration job does: its packaged gateway and + # CLI, runtime images and test workload image, its prebuilt openshell-conformance, with the + # drivers built here put into its deb and rpm, uploaded as one artifact. Nothing from OpenShell is + # built here; the inputs come from its published test-inputs bundle. + prepare-inputs: + name: Prepare integration inputs + needs: build-binaries-linux + runs-on: ubuntu-24.04 + timeout-minutes: 30 + permissions: + contents: read + packages: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # The bundle is a package of ai-openshell/openshell; a token that can read it is needed + # (OPENSHELL_ARTIFACTS_TOKEN needs read:packages, or the package grants this repository access). + - name: Download OpenShell's test inputs + uses: ./.github/actions/pull-test-inputs + with: + test-inputs: ${{ env.OPENSHELL_TEST_INPUTS }} + token: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN || github.token }} + directory: ${{ runner.temp }}/openshell-test-inputs + + - name: Stage the integration inputs + run: | + set -euo pipefail + bundle="${RUNNER_TEMP}/openshell-test-inputs" + mkdir -p artifacts/prebuilt-conformance + cp -a "$bundle/tmachine-inputs/." artifacts/ + cp "$bundle"/conformance/openshell-conformance-x86_64-unknown-linux-musl/* artifacts/prebuilt-conformance/ + + # The packaged gateway launches the drivers from /usr/libexec/openshell, so the drivers + # under test replace the ones in OpenShell's deb, and the suites run on the plain `deb` + # installer. The artifacts hold the bare binaries built by build-binaries-linux. + - name: Download the drivers + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: openshell-driver-@(docker|podman)-x86_64-unknown-linux-gnu + merge-multiple: true + path: ${{ runner.temp }}/drivers + + - name: Replace the drivers in the OpenShell deb + env: + DRIVERS: ${{ runner.temp }}/drivers + run: | + set -euo pipefail + deb=artifacts/packages/openshell.deb + root="${RUNNER_TEMP}/deb-root" + rm -rf "$root" + dpkg-deb -R "$deb" "$root" + for driver in docker podman; do + target="$root/usr/libexec/openshell/openshell-driver-${driver}" + [ -f "$target" ] || { echo "::error::The OpenShell deb has no ${target#"$root"}; it predates the driver launch protocol." >&2; exit 1; } + install -m 0755 "${DRIVERS}/openshell-driver-${driver}" "$target" + done + # The package's checksums describe the replaced files. + rm -f "$root/DEBIAN/md5sums" + dpkg-deb --root-owner-group -b "$root" "${RUNNER_TEMP}/openshell.deb" + mv "${RUNNER_TEMP}/openshell.deb" "$deb" + dpkg-deb -c "$deb" | grep openshell-driver- + + # The same for the gateway rpm, which the Fedora Podman environments install. rpmrebuild + # rebuilds the package with the drivers replaced and everything else (metadata, scriptlets, + # file attributes) kept; it runs in a Fedora container, as the runner has no rpm tooling. + - name: Replace the drivers in the OpenShell rpm + env: + DRIVERS: ${{ runner.temp }}/drivers + run: | + set -euo pipefail + rpm_dir="${GITHUB_WORKSPACE}/artifacts/packages/rpm" + out="${RUNNER_TEMP}/rpm-out" + rm -rf "$out" + mkdir -p "$out" + cat > "${RUNNER_TEMP}/change-files.sh" <<'SCRIPT' + #!/bin/sh + # rpmrebuild runs this with the package's files under $RPM_BUILD_ROOT. + set -eu + for driver in docker podman; do + target="${RPM_BUILD_ROOT}/usr/libexec/openshell/openshell-driver-${driver}" + [ -f "$target" ] || { echo "the rpm has no ${target#"$RPM_BUILD_ROOT"}; it predates the driver launch protocol" >&2; exit 1; } + install -m 0755 "/drivers/openshell-driver-${driver}" "$target" + done + SCRIPT + chmod +x "${RUNNER_TEMP}/change-files.sh" + docker run --rm \ + --volume "${rpm_dir}:/in:ro" \ + --volume "${out}:/out" \ + --volume "${DRIVERS}:/drivers:ro" \ + --volume "${RUNNER_TEMP}/change-files.sh:/change-files.sh:ro" \ + --env "HOST_UID=$(id -u)" --env "HOST_GID=$(id -g)" \ + quay.io/fedora/fedora:42 bash -euo pipefail -c ' + dnf -y -q install rpmrebuild rpm-build + rpmrebuild --package --notest-install --directory /out \ + --change-files=/change-files.sh /in/openshell-gateway.rpm + rebuilt=$(find /out -name "*.rpm") + [ "$(echo "$rebuilt" | wc -l)" -eq 1 ] + for driver in docker podman; do + rpm2cpio "$rebuilt" | cpio --extract --to-stdout "./usr/libexec/openshell/openshell-driver-${driver}" 2>/dev/null \ + | cmp - "/drivers/openshell-driver-${driver}" + done + chown -R "${HOST_UID}:${HOST_GID}" /out + ' + rebuilt=$(find "$out" -name '*.rpm') + mv "$rebuilt" "${rpm_dir}/openshell-gateway.rpm" + + - name: Upload the integration inputs + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: tmachine-inputs + path: artifacts + compression-level: 0 + retention-days: 2 + if-no-files-found: error + + # The suites, by family, as in OpenShell's branch-e2e.yml. Adding a family is a row in + # e2e-suites.yml and a call here. The env context is not available in `with`, so the + # revision default is repeated from OPENSHELL_REV above; keep them together. + conformance-integration: + name: Conformance + needs: prepare-inputs + permissions: + contents: read + uses: ./.github/workflows/e2e-suites.yml + with: + family: conformance + openshell-rev: ${{ inputs.openshell-rev || '9972314fa89320860e734f533e08d6994407d5fe' }} + + required: + name: Required checks + if: always() + needs: [build-binaries-linux, build-binaries-macos, conformance-integration] + runs-on: ubuntu-24.04 + steps: + - name: Fail unless every job succeeded + env: + RESULTS: ${{ join(needs.*.result, ' ') }} + run: | + for r in $RESULTS; do + [ "$r" = success ] || { echo "a required job finished with: $r" >&2; exit 1; } + done diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml new file mode 100644 index 0000000..6a85682 --- /dev/null +++ b/.github/workflows/e2e-suites.yml @@ -0,0 +1,181 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Runs OpenShell's testkit suites in tmachine environments against the drivers built here, as +# OpenShell's e2e-suites.yml does for its own. Each row of `rows` below names a tmachine +# environment and installer, the family (conformance, features or drivers/) and the +# gateway name the installer registers. The `family` input selects the rows of one family. +# The caller prepares the inputs once (see prepare-inputs in driver-build-test.yml) and uploads +# them as the tmachine-inputs artifact; nothing from OpenShell is built here except the +# tmachine runner. + +name: E2E Suites + +on: + workflow_call: + inputs: + family: + description: Run only the rows of this family and the workspaces under it (for example conformance); empty runs every row + required: false + type: string + default: "" + openshell-rev: + description: ai-openshell/openshell commit that provides tmachine; it must be the commit the inputs were built at + required: true + type: string + +permissions: + contents: read + +# github.workflow is the caller's name here, so scope the group to this workflow to avoid +# colliding with (and cancelling) the caller's other jobs. +concurrency: + group: ${{ github.workflow }}-e2e-suites-${{ inputs.family }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + # The rows live here, in one place. Add a driver or a suite by adding a row; the runner needs + # no list of its own. + select: + name: Select E2E suites + runs-on: ubuntu-24.04 + timeout-minutes: 5 + outputs: + matrix: ${{ steps.rows.outputs.matrix }} + steps: + - name: Select the rows to run + id: rows + env: + FAMILY: ${{ inputs.family }} + run: | + set -euo pipefail + # Only amd64 for now: CI has no arm64 runner with KVM for tmachine, and the inputs + # are amd64. `driver` is the driver under test; the prepared deb and rpm carry the + # build of it from this repository, which the packaged gateway launches. The gateway + # is the name the installer registers with the CLI (`openshell` for the packaged + # installers). Docker runs on Ubuntu with the deb, Podman on Fedora with the rpm. + rows='[ + {"driver":"docker","environment":"ubuntu-docker-rootful","installer":"deb","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04"}, + {"driver":"podman","environment":"fedora-podman-rootful","installer":"rpm","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04"}, + {"driver":"podman","environment":"fedora-podman-rootless","installer":"rpm","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04"} + ]' + matrix=$(jq -c --arg family "${FAMILY}" '{include: map( + select($family == "" or .family == $family or (.family | startswith($family + "/"))) + | .package //= "" + | .suite = (if .package == "" then .family else "\(.family)/\(.package)" end) + | .artifact = ([.driver, .suite, .environment, .installer] | join("-") | gsub("/"; "-")) + )}' <<< "$rows") + if [ "$(jq '.include | length' <<< "$matrix")" -eq 0 ]; then + echo "::error::No E2E suites match family '${FAMILY}'" + exit 1 + fi + echo "$matrix" + echo "matrix=${matrix}" >> "$GITHUB_OUTPUT" + + suites: + name: E2E suites (${{ matrix.driver }}, ${{ matrix.suite }}, ${{ matrix.environment }}, ${{ matrix.installer }}) + needs: select + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.select.outputs.matrix) }} + runs-on: ${{ matrix.runner }} + timeout-minutes: 60 + steps: + # tmachine, from the commit the inputs were built at. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ai-openshell/openshell + ref: ${{ inputs.openshell-rev }} + persist-credentials: false + + # The runner starts with about 11 GB free of 72 GB, and tmachine's guest disks, the Nix + # store and the inputs together fill it; QEMU then stalls on a full host disk, which + # shows up as a hang in the guest's first large write (`docker load`). Remove what the + # runner image preinstalls and this job doesn't use. + - name: Free disk space + run: | + df -h / + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/share/boost \ + /usr/local/julia* /opt/microsoft /usr/share/swift /usr/local/.ghcup + sudo docker system prune -af >/dev/null 2>&1 || true + df -h / + + - name: Check KVM is available + run: | + if [[ ! -c /dev/kvm ]]; then + echo "::error::The runner did not expose /dev/kvm" + exit 1 + fi + sudo chmod 0666 /dev/kvm + + - uses: ./.github/actions/setup-nix + + - name: Cache tmachine disks + uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0 + with: + path: ~/.cache/tmachine + # tmachine keys its disk layers on a hash of the Ansible tree and the setup inputs, so + # each environment and installer needs its own key, as in OpenShell's e2e-suites.yml. + key: tmachine-${{ runner.os }}-${{ runner.arch }}-${{ matrix.environment }}-${{ matrix.installer }}-${{ hashFiles('tests/tmachine/ansible/**', 'tests/tmachine/config.nix', 'tests/tmachine/images.nix', 'tests/tmachine/src/qemu/setup.rs', 'tests/tmachine/src/qemu/install.rs', 'scripts/keycloak-realm.json') }} + + - name: Download integration inputs + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: tmachine-inputs + path: artifacts + + - name: Host diagnostics + run: | + df -h / /home/runner "$HOME/.cache" 2>/dev/null || df -h + free -m + nproc + ls -l /dev/kvm + du -sh artifacts/* 2>/dev/null || true + + - name: Run the suites in this environment + env: + ENVIRONMENT: ${{ matrix.environment }} + INSTALLER: ${{ matrix.installer }} + FAMILY: ${{ matrix.family }} + GATEWAY: ${{ matrix.gateway }} + run: | + # Sample the host while the suite runs, so a slow or stuck step can be explained + # afterwards: disk, memory, load, and how QEMU was started (accelerator, memory). + mkdir -p diagnostics + ( + while true; do + { + date -u +%FT%TZ + df -h / | tail -1 + free -m | sed -n 2p + du -sh "$HOME/.cache/tmachine" /nix 2>/dev/null + cat /proc/loadavg + pgrep -af qemu | cut -c1-400 | head -3 || true + echo + } >> diagnostics/host.log 2>&1 + sleep 15 + done + ) & + sampler=$! + trap 'kill "$sampler" 2>/dev/null || true' EXIT + # Retry dependency preparation, then run the suites once. + nix build --no-link .#openshell-test-runner || nix build --no-link .#openshell-test-runner + program=artifacts/prebuilt-conformance/openshell-conformance + chmod +x "$program" + "$program" list > /dev/null + nix run .#openshell-test-runner -- run \ + --environment "${ENVIRONMENT}" \ + --installer "${INSTALLER}" \ + --family "${FAMILY}" \ + --program "$program" \ + --gateway "${GATEWAY}" \ + --results artifacts/test-results + + - name: Upload results + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: e2e-results-${{ matrix.artifact }} + path: | + artifacts/test-results + diagnostics + if-no-files-found: ignore diff --git a/Cargo.lock b/Cargo.lock index c00ca07..e9288fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2562,7 +2562,7 @@ dependencies = [ [[package]] name = "openshell-core" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "async-trait", "base64 0.22.1", @@ -2608,7 +2608,7 @@ dependencies = [ [[package]] name = "openshell-crypto" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "aws-lc-rs", "jsonwebtoken", @@ -2667,7 +2667,7 @@ dependencies = [ [[package]] name = "openshell-driver-launch" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "http", "prost", @@ -2727,7 +2727,7 @@ dependencies = [ [[package]] name = "openshell-driver-sdk" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "http", "libc", @@ -2799,8 +2799,10 @@ dependencies = [ [[package]] name = "openshell-extension-core" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ + "h2", + "hyper", "hyper-util", "serde", "thiserror", @@ -2812,7 +2814,7 @@ dependencies = [ [[package]] name = "openshell-isolation-interface" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "openshell-core", "serde", @@ -2824,7 +2826,7 @@ dependencies = [ [[package]] name = "openshell-ocsf" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "jiff 1.0.3", "serde", @@ -2838,7 +2840,7 @@ dependencies = [ [[package]] name = "openshell-otel" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "async-trait", "bytes", @@ -2870,7 +2872,7 @@ dependencies = [ [[package]] name = "openshell-otel-test-support" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "bytes", "http", @@ -2894,7 +2896,7 @@ dependencies = [ [[package]] name = "openshell-policy" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "hickory-proto", "miette", @@ -2909,7 +2911,7 @@ dependencies = [ [[package]] name = "openshell-policy-schema" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "miette", "noyalib", @@ -2922,7 +2924,7 @@ dependencies = [ [[package]] name = "openshell-sandbox-backend" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "async-trait", "bytes", @@ -2954,7 +2956,7 @@ dependencies = [ [[package]] name = "openshell-spiffe" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "async-trait", "base64 0.22.1", @@ -2966,7 +2968,7 @@ dependencies = [ [[package]] name = "openshell-vfio" version = "0.0.0" -source = "git+https://github.com/ai-openshell/openshell?rev=2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2#2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" +source = "git+https://github.com/ai-openshell/openshell?rev=9972314fa89320860e734f533e08d6994407d5fe#9972314fa89320860e734f533e08d6994407d5fe" dependencies = [ "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 7c3f641..057ab6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,19 +13,19 @@ license = "Apache-2.0" repository = "https://github.com/NVIDIA/OpenShell" [workspace.dependencies] -# OpenShell platform crates, pinned to one commit of ai-openshell/openshell: the v0.1.11 release. +# OpenShell platform crates, pinned to one commit of ai-openshell/openshell: a main commit (v0.1.11 plus later changes). # It has the driver launch protocol and SDK (PR 5914), which the drivers here build on, and the # openshell-container-runtime crate (PR 6023). -openshell-core = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2", default-features = false } -openshell-isolation-interface = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-sandbox-backend = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-otel = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-driver-sdk = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-driver-launch = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-otel-test-support = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-policy = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-vfio = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2" } -openshell-crypto = { git = "https://github.com/ai-openshell/openshell", rev = "2b03ec2d43c574ebe8df85426ddb7ceb98fc50c2", default-features = false, features = ["aws-lc"] } +openshell-core = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe", default-features = false } +openshell-isolation-interface = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-sandbox-backend = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-otel = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-driver-sdk = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-driver-launch = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-otel-test-support = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-policy = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-vfio = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe" } +openshell-crypto = { git = "https://github.com/ai-openshell/openshell", rev = "9972314fa89320860e734f533e08d6994407d5fe", default-features = false, features = ["aws-lc"] } openshell-container-runtime = { path = "crates/openshell-container-runtime" } tokio = { version = "1.53.3", features = ["full"] } diff --git a/README.md b/README.md index b14f984..f892f20 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,21 @@ cargo test --workspace ``` The VM driver's tests build ext4 images and need `mke2fs` (e2fsprogs 1.43 or newer). + +## CI + +`ci.yml` checks the license headers, runs `cargo fmt`, `cargo clippy` and `cargo test`, and lints the +workflows. `driver-build-test.yml` builds the Docker and Podman drivers as OpenShell builds its release +binaries (in the flake's dev shell, with its cross toolchains) for x86_64 and aarch64 Linux and for +aarch64 macOS. It then runs OpenShell's conformance suite on OpenShell's tmachine, with the drivers +built here replacing the ones in OpenShell's packaged gateway: the Docker driver on +`ubuntu-docker-rootful` with the deb, and the Podman driver on `fedora-podman-rootful` and +`fedora-podman-rootless` with the rpm. The packaged gateway launches the replaced driver from +`/usr/libexec/openshell`. + +Nothing from OpenShell is built here. The gateway packages, the runtime images and +`openshell-conformance` come from OpenShell's published test-inputs bundle +(`ghcr.io/ai-openshell/openshell/test-inputs:`, which does not expire), selected by +`OPENSHELL_TEST_INPUTS` in `driver-build-test.yml`; tmachine is checked out at `OPENSHELL_REV`. Keep the pins +together: the `rev` of the OpenShell git dependencies in `Cargo.toml`, `OPENSHELL_REV` and +`OPENSHELL_TEST_INPUTS`. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a572224 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1787135253, + "narHash": "sha256-RD2kNWCG+Bjo6h+JVjWVNntZs2GtRoeY2xHjts/FNkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ffb3c9b700e759be2ef13237c9d8f953b32a1e46", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1787281715, + "narHash": "sha256-5yIL5XL31hCZBPWDdUOvUy4cYAl27XZrke7JELhHlnI=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "89abdfd661ea493cde2f73d7b1332cb34150aa43", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6676649 --- /dev/null +++ b/flake.nix @@ -0,0 +1,102 @@ +# SPDX-License-Identifier: Apache-2.0 + +# The build environment for the desktop drivers, taken from ai-openshell/openshell's flake: the +# development shell with its cross toolchains (gnu and musl for x86_64 and aarch64, native on +# macOS). The CI builds the drivers in this shell, as OpenShell +# builds its release binaries. Keep nixpkgs and rust-overlay in step with OpenShell's flake.lock +# so its Cachix cache applies. +{ + description = "OpenShell desktop drivers build environment"; + + nixConfig = { + extra-substituters = [ "https://openshell.cachix.org" ]; + extra-trusted-public-keys = [ + "openshell.cachix.org-1:OAr5MunsfH5PZvUsfD08OtGx5RtcwdNZGJdU5FqLm5w=" + ]; + }; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + flake-utils, + nixpkgs, + rust-overlay, + ... + }: + flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + devShellPackages = with pkgs; [ + cargo-auditable + # Build and inspect ext4 images in VM driver tests. + e2fsprogs + gh + git + # Required to find packages. + pkg-config + cmakeMinimal + zlib + openssl_3_5 + xz + syft + zstd + ]; + rustToolchain = + ((pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { + targets = map (toolchain: toolchain.target) (builtins.attrValues toolchains); + }).overrideAttrs + { + propagatedBuildInputs = [ ]; + depsHostHostPropagated = [ ]; + depsTargetTargetPropagated = [ ]; + }; + # The drivers only need AWS-LC (through openshell-crypto); OpenShell's z3 is for its prover. + buildInputs = { pkgs, stdenv }: [ + (pkgs.callPackage ./nix/pkgs/aws-lc.nix { inherit stdenv; }) + ]; + inherit (import ./nix/toolchain) mkToolchain; + toolchains = { + x86_64-gnu = mkToolchain { + pkgs = pkgs.pkgsCross.gnu64; + inherit buildInputs; + }; + x86_64-musl = mkToolchain { + pkgs = pkgs.pkgsCross.musl64; + inherit buildInputs; + }; + aarch64-gnu = mkToolchain { + pkgs = pkgs.pkgsCross.aarch64-multiplatform; + inherit buildInputs; + }; + aarch64-musl = mkToolchain { + pkgs = pkgs.pkgsCross.aarch64-multiplatform-musl; + inherit buildInputs; + }; + } + // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isDarwin { + aarch64-darwin = mkToolchain { + inherit pkgs buildInputs; + }; + }; + in + { + + devShells.default = pkgs.mkShellNoCC { + packages = [ rustToolchain ] ++ devShellPackages; + env = pkgs.lib.foldl' (env: toolchain: env // toolchain.env) { } (builtins.attrValues toolchains); + }; + } + ); +} diff --git a/nix/pkgs/aws-lc.nix b/nix/pkgs/aws-lc.nix new file mode 100644 index 0000000..e7209f2 --- /dev/null +++ b/nix/pkgs/aws-lc.nix @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + lib, + stdenv, + aws-lc, + buildEnv, + callPackage, +}: + +let + strings = callPackage ../strings.nix { }; + target = stdenv.hostPlatform.rust.cargoShortTarget; + package = + (aws-lc.override { + inherit stdenv; + useSharedLibraries = false; + withRustBindings = true; + }).overrideAttrs + (old: { + BINDGEN_EXTRA_CLANG_ARGS = "--target=${target}"; + passthru = old.passthru // { + env.${strings.targetEnvVar target "AWS_LC_SYS_SYSTEM_DIR"} = "${libraries}"; + }; + }); + libraries = buildEnv { + name = "${target}-aws-lc-libraries"; + paths = [ + (lib.getLib package) + (lib.getDev package) + ]; + pathsToLink = [ + "/include" + "/lib" + "/share/rust" + ]; + }; +in +package diff --git a/nix/strings.nix b/nix/strings.nix new file mode 100644 index 0000000..50ae074 --- /dev/null +++ b/nix/strings.nix @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ lib }: + +let + targetSuffix = builtins.replaceStrings [ "-" ] [ "_" ]; +in +{ + targetEnvVar = target: name: "${name}_${targetSuffix target}"; + cargoTargetEnvVar = target: name: "CARGO_TARGET_${lib.toUpper (targetSuffix target)}_${name}"; +} diff --git a/nix/toolchain/darwin.nix b/nix/toolchain/darwin.nix new file mode 100644 index 0000000..9bf2a9c --- /dev/null +++ b/nix/toolchain/darwin.nix @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + pkgs, + packages, +}: + +let + inherit (pkgs) stdenv; + target = stdenv.hostPlatform.rust.cargoShortTarget; + # The processed Nix SDK removes system stubs such as libiconv and libc++. + sysroot = pkgs.apple-sdk.src; +in +{ + inherit stdenv sysroot; + driver = pkgs.buildPackages.writeShellScriptBin "${target}-cc" '' + exec ${stdenv.cc.cc}/bin/clang \ + "$@" \ + --target=${target} \ + -isysroot ${sysroot} \ + -mmacosx-version-min=${stdenv.hostPlatform.darwinMinVersion} \ + -fuse-ld=${stdenv.cc.bintools.bintools}/bin/ld \ + ${pkgs.lib.escapeShellArgs (map (package: "-L${pkgs.lib.getLib package}/lib") packages)} + ''; +} diff --git a/nix/toolchain/default.nix b/nix/toolchain/default.nix new file mode 100644 index 0000000..a882ffc --- /dev/null +++ b/nix/toolchain/default.nix @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + mkToolchain = + { + pkgs, + buildInputs, + }: + + let + strings = pkgs.callPackage ../strings.nix { }; + platform = + pkgs.callPackage (if pkgs.stdenv.hostPlatform.isDarwin then ./darwin.nix else ./linux.nix) + { + inherit packages; + }; + inherit (platform) stdenv sysroot; + target = stdenv.hostPlatform.rust.cargoShortTarget; + packages = buildInputs { inherit pkgs stdenv; }; + toolchain = platform.driver; + binPrefix = + "${stdenv.cc.bintools}/bin/" + + pkgs.lib.optionalString (!stdenv.hostPlatform.isDarwin) stdenv.cc.targetPrefix; + in + toolchain.overrideAttrs (old: { + passthru = (old.passthru or { }) // { + inherit target stdenv sysroot; + buildInputs = packages; + env = pkgs.lib.foldl' (env: package: env // (package.passthru.env or { })) { } packages // { + ${strings.cargoTargetEnvVar target "LINKER"} = "${toolchain}/bin/${target}-cc"; + ${strings.targetEnvVar target "CC"} = "${toolchain}/bin/${target}-cc"; + ${strings.targetEnvVar target "AS"} = "${binPrefix}as"; + ${strings.targetEnvVar target "AR"} = "${binPrefix}ar"; + }; + }; + }); +} diff --git a/nix/toolchain/glibc-2.28/libc.nix b/nix/toolchain/glibc-2.28/libc.nix new file mode 100644 index 0000000..1519080 --- /dev/null +++ b/nix/toolchain/glibc-2.28/libc.nix @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + lib, + stdenv, + callPackage, + fetchurl, +}: + +let + nixpkgs = builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/f6519103bf8c8217c4007baaeb8bcaa1fcf95f1f.tar.gz"; + sha256 = "sha256-391FrgZ+VwYYg7poRQBmWwUMkK7dan66m6QhomEWkPE="; + }; + glibc = callPackage "${nixpkgs}/pkgs/development/libraries/glibc" { + # Provide the stdenv attributes used by the historical recipe. + stdenv = stdenv // { + inherit lib; + inherit (stdenv.hostPlatform) is64bit isx86_64; + }; + }; +in +glibc.overrideAttrs (old: { + pname = "glibc"; + name = "glibc-2.28"; + version = "2.28"; + src = fetchurl { + url = "https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz"; + hash = "sha256-8xjW4/H07Qt00oMqxPSR0PuSjkUcntpZTL8cO+569Hw="; + }; + hardeningDisable = old.hardeningDisable ++ [ "pic" ]; + configureFlags = lib.remove "--enable-obsolete-rpc" old.configureFlags ++ [ "--disable-werror" ]; + postPatch = old.postPatch + '' + # Fixes a bug in Make that triggers infinte recursion on expansion. + substituteInPlace sysdeps/gnu/Makefile \ + --replace-fail \ + '$(object-suffixes) $(object-suffixes:=.d)' \ + '$(object-suffixes)' + + # Keep the cross tools selected by Nix instead of GCC's bare tool names. + sed -i -e '/^AR=/d' -e '/^AS=/d' -e '/^LD=/d' \ + -e '/^OBJCOPY=/d' -e '/^OBJDUMP=/d' configure + ''; +}) diff --git a/nix/toolchain/glibc-2.28/stdenv.nix b/nix/toolchain/glibc-2.28/stdenv.nix new file mode 100644 index 0000000..d431cc8 --- /dev/null +++ b/nix/toolchain/glibc-2.28/stdenv.nix @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ pkgs }: + +let + glibc = pkgs.callPackage ./libc.nix { }; + baseGcc = pkgs.gcc15Stdenv.cc.cc; + bintools = pkgs.buildPackages.wrapBintoolsWith { + bintools = pkgs.buildPackages.binutils-unwrapped; + libc = glibc; + }; + bootstrap = pkgs.overrideCC pkgs.stdenv ( + pkgs.buildPackages.wrapCCWith { + cc = baseGcc; + inherit bintools; + } + ); + gcc = baseGcc.override ( + if pkgs.stdenv.buildPlatform.config == pkgs.stdenv.hostPlatform.config then + { stdenv = bootstrap; } + else + { libcCross = glibc; } + ); + stdenv = pkgs.overrideCC pkgs.stdenv ( + pkgs.buildPackages.wrapCCWith { + cc = gcc; + inherit bintools; + libcxx = gcc.lib; + } + ); +in +{ + inherit glibc gcc stdenv; +} diff --git a/nix/toolchain/glibc-2.28/sysroot.nix b/nix/toolchain/glibc-2.28/sysroot.nix new file mode 100644 index 0000000..656118e --- /dev/null +++ b/nix/toolchain/glibc-2.28/sysroot.nix @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + pkgs, + glibc, + buildInputs ? [ ], +}: + +let + target = pkgs.stdenv.targetPlatform.config; + +in +pkgs.buildEnv { + name = "${target}-sysroot"; + paths = [ + glibc.out + glibc.dev + glibc.static + ] + ++ pkgs.lib.concatMap (package: [ + (pkgs.lib.getDev package) + (pkgs.lib.getLib package) + ]) buildInputs; + pathsToLink = [ + "/include" + "/lib" + ]; + extraPrefix = "/usr"; + + postBuild = '' + # Rust explicitly links -lgcc_s, even with -static-libgcc. + echo 'GROUP ( libgcc.a libgcc_eh.a )' > "$out/usr/lib/libgcc_s.a" + + # Linker scripts must resolve libraries through the sysroot, not the store. + rm "$out/usr/lib/libc.so" "$out/usr/lib/libm.so" + sed 's|${glibc.out}/lib/||g' ${glibc.out}/lib/libc.so > "$out/usr/lib/libc.so" + sed 's|${glibc.out}/lib/||g' ${glibc.out}/lib/libm.so > "$out/usr/lib/libm.so" + + ln -s usr/lib "$out/lib" + ln -s usr/lib "$out/lib64" + ''; +} diff --git a/nix/toolchain/linux.nix b/nix/toolchain/linux.nix new file mode 100644 index 0000000..b5ac907 --- /dev/null +++ b/nix/toolchain/linux.nix @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + pkgs, + packages, +}: + +let + target = pkgs.stdenv.hostPlatform.rust.cargoShortTarget; + isMusl = pkgs.stdenv.hostPlatform.isMusl; + gnu = pkgs.callPackage ./glibc-2.28/stdenv.nix { }; + stdenv = if isMusl then pkgs.stdenv else gnu.stdenv; + sysroot = + if isMusl then + null + else + pkgs.callPackage ./glibc-2.28/sysroot.nix { + buildInputs = packages; + inherit (gnu) glibc; + }; + cc = if isMusl then stdenv.cc else gnu.gcc; + searchFlags = + pkgs.lib.optionals (!isMusl) [ + "--sysroot=${sysroot}" + "-isystem${sysroot}/usr/include" + "-B${sysroot}/usr/lib" + "-L${sysroot}/usr/lib" + ] + ++ pkgs.lib.optionals isMusl (map (package: "-L${pkgs.lib.getLib package}/lib") packages); + runtimeFlags = pkgs.lib.optionals (!isMusl) [ + "-Wl,--dynamic-linker=${ + { + x86_64-unknown-linux-gnu = "/lib64/ld-linux-x86-64.so.2"; + aarch64-unknown-linux-gnu = "/lib/ld-linux-aarch64.so.1"; + } + .${target} + }" + "-static-libgcc" + "-lssp" + ]; +in +{ + inherit stdenv sysroot; + driver = pkgs.buildPackages.writeShellScriptBin "${target}-cc" '' + exec ${cc}/bin/${stdenv.cc.targetPrefix}gcc \ + -B${pkgs.buildPackages.mold-unwrapped}/bin \ + -B${pkgs.buildPackages.binutils-unwrapped}/${target}/bin \ + ${pkgs.lib.escapeShellArgs searchFlags} \ + "$@" \ + -fuse-ld=mold ${pkgs.lib.escapeShellArgs runtimeFlags} + ''; +}