diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..91df2b9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +.jj +.idea +**/target diff --git a/.github/workflows/docker-publish-manual.yml b/.github/workflows/docker-publish-manual.yml deleted file mode 100644 index 272adb8..0000000 --- a/.github/workflows/docker-publish-manual.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Docker (manual and monthly) - -on: - workflow_dispatch: - # Monthly rebuild so the image picks up new Rust releases from rust:latest. - schedule: - - cron: '17 4 1 * *' - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - id-token: write - - steps: - - name: Checkout repository - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 - - - name: Log into registry ${{ env.REGISTRY }} - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 - with: - platforms: linux/amd64,linux/arm64 - context: . - pull: true - push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Install cosign - uses: sigstore/cosign-installer@ba7bc0a3fef59531c69a25acd34668d6d3fe6f22 # v4.1.0 - - - name: Sign the published Docker image - env: - IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - DIGEST: ${{ steps.build-and-push.outputs.digest }} - run: cosign sign --yes "${IMAGE}@${DIGEST}" diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index e809953..2dae17e 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,86 +1,84 @@ name: Docker - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - on: push: - branches: [ "master" ] - -env: - # Use docker.io for Docker Hub if empty - REGISTRY: ghcr.io - # github.repository as / - IMAGE_NAME: ${{ github.repository }} - - + branches: [master] + pull_request: + workflow_dispatch: + schedule: + # Rebuild pinned inputs; updates are explicit reviewed changes. + - cron: '17 4 1 * *' +permissions: + contents: read jobs: - build: - runs-on: ubuntu-latest + test: + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-24.04 + arch: amd64 + - runner: ubuntu-24.04-arm + arch: arm64 + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f + - name: Build image on native host + run: | + mkdir -p "$RUNNER_TEMP/evidence" + docker build --progress plain -t rustxc:test . > "$RUNNER_TEMP/evidence/image.log" 2>&1 + docker image inspect rustxc:test > "$RUNNER_TEMP/evidence/image.json" + - name: Native C, C++, assembly, discovery and Rust smoke + run: | + docker run --rm -v "$PWD/tests:/tests:ro" -v "$RUNNER_TEMP/evidence:/evidence" \ + -v rustxc-ci-xwin:/opt/xwin -e RUSTXC_EVIDENCE_DIR=/evidence rustxc:test /opt/rustxc/smoke \ + aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu powerpc64le-unknown-linux-gnu \ + aarch64-apple-darwin x86_64-apple-darwin \ + x86_64-pc-windows-msvc aarch64-pc-windows-msvc \ + > "$RUNNER_TEMP/evidence/smoke.log" 2>&1 + - name: Alternate pinned Rust toolchain + run: | + docker run --rm -v "$PWD/tests:/tests:ro" -v "$RUNNER_TEMP/evidence:/evidence" \ + -e RUSTUP_TOOLCHAIN=1.96.0 -e RUSTXC_EVIDENCE_DIR=/evidence/rust196 \ + rustxc:test /opt/rustxc/smoke x86_64-unknown-linux-gnu \ + > "$RUNNER_TEMP/evidence/rust196.log" 2>&1 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + if: always() + with: + name: smoke-${{ matrix.arch }} + path: | + ${{ runner.temp }}/evidence/*.log + ${{ runner.temp }}/evidence/*.json + ${{ runner.temp }}/evidence/*.txt + publish: + needs: test + if: github.event_name != 'pull_request' + runs-on: ubuntu-24.04 permissions: contents: read packages: write - # This is used to complete the identity challenge - # with sigstore/fulcio when running outside of PRs. id-token: write - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Checkout repository - uses: actions/checkout@v4 - - # Install the cosign tool except on PR - # https://github.com/sigstore/cosign-installer - - name: Install cosign - if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 - with: - cosign-release: 'v2.2.4' - - # Set up BuildKit Docker container builder to be able to build - # multi-platform images and export cache - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 - - # Login against a Docker registry except on PR - # https://github.com/docker/login-action - - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' - uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 with: - registry: ${{ env.REGISTRY }} + registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - # Build and push Docker image with Buildx (don't push on PR) - # https://github.com/docker/build-push-action - - name: Build and push Docker image - id: build-and-push - uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + - uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 + id: image with: platforms: linux/amd64,linux/arm64 context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + push: true + tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ github.sha }} cache-from: type=gha cache-to: type=gha,mode=max - - # Sign the resulting Docker image digest except on PRs. - # This will only write to the public Rekor transparency log when the Docker - # repository is public to avoid leaking data. If you would like to publish - # transparency data even for private images, pass --force to cosign below. - # https://github.com/sigstore/cosign - - name: Sign the published Docker image - if: ${{ github.event_name != 'pull_request' }} + - uses: sigstore/cosign-installer@ba7bc0a3fef59531c69a25acd34668d6d3fe6f22 + - name: Sign image index env: - # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable - TAGS: ${{ steps.meta.outputs.tags }} - DIGEST: ${{ steps.build-and-push.outputs.digest }} - # This step uses the identity token to provision an ephemeral certificate - # against the sigstore community Fulcio instance. - run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} + IMAGE: ghcr.io/${{ github.repository }} + DIGEST: ${{ steps.image.outputs.digest }} + run: cosign sign --yes "${IMAGE}@${DIGEST}" diff --git a/Dockerfile b/Dockerfile index d3b0244..cbaa81b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,67 +1,50 @@ -# Build the Mac OS X toolchain -FROM rust:latest AS osxcross - -ARG MACOS_X_SDK_VERSION=26.1 -RUN < /.cargo/config.toml <<- CARGO -[target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" - -[target.x86_64-unknown-linux-gnu] -linker = "x86_64-linux-gnu-gcc" - -[target.powerpc64le-unknown-linux-gnu] -linker = "powerpc64le-linux-gnu-gcc" - -[target.x86_64-apple-darwin] -linker = "$(basename $(find /toolchain -name 'x86_64-apple-darwin*-clang'))" - -[target.aarch64-apple-darwin] -linker = "$(basename $(find /toolchain -name 'aarch64-apple-darwin*-clang'))" -CARGO -EOF - -ENV PATH="$PATH:/toolchain/macos/bin" +# syntax=docker/dockerfile:1.7@sha256:a57df69d0ea827fb7266491f2813635de6f17269be881f696fbfdf2d83dda33e +# Multi-architecture index, not an architecture-specific manifest. +ARG RUST_IMAGE=rust:1.97.1-bookworm@sha256:0e2bcaef56d041a486784e54104a81aebe0da44bd03019bd70bc0401e42e4a97 +FROM ${RUST_IMAGE} AS base +ARG DEBIAN_SNAPSHOT=20260811T000000Z +RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/* && \ + printf 'deb [check-valid-until=no] https://snapshot.debian.org/archive/debian/%s bookworm main\n' "$DEBIAN_SNAPSHOT" > /etc/apt/sources.list + +# Download foreign packages rather than executing foreign binaries. These stages +# run natively on either build host. Each dependency closure has its own root. +FROM base AS sysroots +RUN apt-get update && apt-get install -y --no-install-recommends python3 ca-certificates +COPY scripts/make-sysroots /usr/local/bin/ +RUN make-sysroots + +FROM base AS tools +RUN apt-get update && apt-get install -y --no-install-recommends \ + clang-19 lld-19 llvm-19 llvm-19-tools libclang-rt-19-dev \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \ + gcc-x86-64-linux-gnu g++-x86-64-linux-gnu \ + gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \ + cmake ninja-build make pkg-config nasm python3 file ca-certificates curl xz-utils \ + && rm -rf /var/lib/apt/lists/* +ARG CARGO_XWIN_VERSION=0.23.1 +RUN cargo install --locked cargo-xwin --version "$CARGO_XWIN_VERSION" && \ + rm -rf /usr/local/cargo/registry /usr/local/cargo/git +# LLVM's integrated assembler and ld64.lld support both Darwin architectures. +# SDK is checksum-verified. See README licensing requirements before distribution. +ARG MACOS_SDK_VERSION=14.5 +ARG MACOS_SDK_SHA256=6e146275d19f027faa2e8354da5e0267513abf013b8f16ad65a231653a2b1c5d +RUN curl -fL --retry 5 "https://github.com/joseluisq/macosx-sdks/releases/download/${MACOS_SDK_VERSION}/MacOSX${MACOS_SDK_VERSION}.sdk.tar.xz" -o /tmp/macos.tar.xz && \ + echo "$MACOS_SDK_SHA256 /tmp/macos.tar.xz" | sha256sum -c - && \ + mkdir -p /opt/sdk && tar -xJf /tmp/macos.tar.xz -C /opt/sdk && \ + mv "/opt/sdk/MacOSX${MACOS_SDK_VERSION}.sdk" /opt/sdk/macos && rm /tmp/macos.tar.xz +RUN rustup target add --toolchain 1.97.1 \ + aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu powerpc64le-unknown-linux-gnu \ + aarch64-apple-darwin x86_64-apple-darwin \ + x86_64-pc-windows-msvc aarch64-pc-windows-msvc && \ + rustup component add --toolchain 1.97.1 rustfmt clippy && \ + dpkg-query -W > /opt/rustxc-packages.txt +COPY --from=sysroots /opt/sysroots /opt/sysroots +COPY scripts/ /opt/rustxc/ +RUN /opt/rustxc/configure && mv /opt/rustxc-packages.txt /opt/rustxc/packages.txt +ENV PATH="/opt/rustxc/bin:/usr/lib/llvm-19/bin:${PATH}" \ + MACOSX_DEPLOYMENT_TARGET=11.0 \ + XWIN_CACHE_DIR=/opt/xwin XWIN_ARCH=x86_64,aarch64 \ + XWIN_VERSION=17 XWIN_SDK_VERSION=10.0.26100 XWIN_CRT_VERSION=14.44.17.14 WORKDIR /mnt +ENTRYPOINT ["/opt/rustxc/entrypoint"] +CMD ["bash"] diff --git a/README.md b/README.md index b593330..3b24e97 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,158 @@ -This is a [docker image](https://github.com/martint/rustxc/pkgs/container/rustxc) that contains an environment for cross-compiling Rust projects to the following platforms: -* aarch64-unknown-linux-gnu -* x86_64-unknown-linux-gnu -* powerpc64le-unknown-linux-gnu -* x86_64-apple-darwin -* aarch64-apple-darwin +# rustxc -To use it: +Cross-compile Rust applications and native dependencies from Linux ARM64 or +AMD64 containers. Targets: - docker run --mount type=bind,source="$(pwd)",target=/mnt ghcr.io/martint/rustxc:latest \ - cargo build \ - --target powerpc64le-unknown-linux-gnu \ - --target x86_64-unknown-linux-gnu \ - --target aarch64-unknown-linux-gnu \ - --target x86_64-apple-darwin \ - --target aarch64-apple-darwin +* `aarch64-unknown-linux-gnu` +* `x86_64-unknown-linux-gnu` +* `powerpc64le-unknown-linux-gnu` +* `aarch64-apple-darwin` +* `x86_64-apple-darwin` +* `x86_64-pc-windows-msvc` +* `aarch64-pc-windows-msvc` -To build the image locally: +Build locally with `docker build -t rustxc:local .`. The image contains GCC/G++, +binutils, LLVM 19/Clang/lld (including integrated assemblers, `llvm-lib`, `llvm-rc`, +and executable inspection tools), CMake, Ninja, NASM and target pkg-config wrappers. +`build-target` installs the target standard library for the **active** Rust +version, then uses Cargo, or cargo-xwin for MSVC. Rust 1.97.1, rustfmt, clippy and all seven target +standard libraries are preinstalled. Other `rust-toolchain.toml` versions and +`RUSTUP_TOOLCHAIN` overrides work through rustup; first use needs network access. +Use an image digest rather than `latest` for reproducible project builds. - docker build . -t rustxc +## Build a project -To rebuild and publish the image manually, open the repository's **Actions** tab, -select **Docker (manual and monthly)**, and click **Run workflow**. The workflow must first be -merged into the default branch. You can also trigger it with the GitHub CLI: +Mount your project at `/mnt`. Source can be mounted read-only when Cargo outputs +are stored separately. Do not mount a host `CARGO_HOME`, which could replace the +image's Cargo configuration/tools. - gh workflow run docker-publish-manual.yml --ref master +```sh +docker build -t rustxc:local . +mkdir -p /tmp/rustxc-build +# Run from your Rust project's directory: +docker run --rm -v "$PWD:/mnt:ro" -v /tmp/rustxc-build:/build \ + -e CARGO_TARGET_DIR=/build/target rustxc:local \ + build-target aarch64-unknown-linux-gnu --locked --release +``` -Each build pulls fresh base images to update the Rust toolchain, builds for -AMD64 and ARM64, and publishes to `ghcr.io/martint/rustxc:latest`. +Replace the target with any target listed above. Cargo package, binary and feature +selection flags can follow `--release`, for example `-p my-package --bin my-app`. +For either Windows target, persist the SDK/CRT download cache in a named volume: -The same workflow also runs on the first day of every month so the image picks up -new Rust releases without a manual run. +```sh +docker run --rm -v "$PWD:/mnt:ro" -v /tmp/rustxc-build:/build \ + -v rustxc-xwin:/opt/xwin -e CARGO_TARGET_DIR=/build/target rustxc:local \ + build-target aarch64-pc-windows-msvc --locked --release +``` +Executables are in `/tmp/rustxc-build/target//release/` (`.exe` on +Windows). `cargo xwin build --locked --release --target ...` is +also supported. Plain `cargo build` works for Linux/macOS after installing the +active toolchain's target with rustup. Windows requires cargo-xwin. -# Resources +## Native libraries and baselines -* https://github.com/tpoechtrager/osxcross -* https://dev.to/mbround18/rust-cross-compiling-from-linux-to-mac-on-github-actions-2mj8 -* https://github.com/mbround18/setup-osxcross/blob/main/action.yml -* https://burgers.io/cross-compile-rust-from-arm-to-x86-64 -* https://stackoverflow.com/questions/41761485/how-to-cross-compile-from-mac-to-linux -* https://github.com/messense/homebrew-macos-cross-toolchains +Linux baseline: **Debian 12, glibc 2.36**, Linux kernel 4.18 or newer +(the selected deployment baseline). Each target gets its own Debian dependency +closure under `/opt/sysroots/`. Compiler wrappers pass an explicit +sysroot and clear ambient header/library search variables. Target-qualified +pkg-config wrappers replace both `PKG_CONFIG_LIBDIR` and `PKG_CONFIG_PATH`, set +`PKG_CONFIG_SYSROOT_DIR`, and never search host `.pc` files. Clang/lld use GCC runtime and C++ support selected +explicitly from inside the target sysroot; GCC cross compilers and binutils are also available. +Do not pass host `-I`/`-L` paths or override the supplied target compilers. + +The sysroots include ALSA, udev, D-Bus, Wayland client/cursor/EGL, X11/XCB and +extensions, xkbcommon (including X11), EGL/OpenGL and Vulkan headers/import libraries. +These support common desktop audio, gamepad, windowing and clipboard dependencies. +Additional native dependencies must be built for the target and its deployment +baseline; host installations cannot substitute for target libraries. + +Linux system libraries remain **external at runtime**, including glibc, libgcc, +libstdc++ when used, ALSA, udev, Wayland, X11/XCB extensions, xkbcommon, and the +Vulkan/EGL/OpenGL loader and suitable GPU drivers. Some are loaded with dlopen +and do not appear in ELF `NEEDED`. A working desktop session, audio device/server, +udev device access, an XDG desktop portal with a file chooser backend, and +`libdbus-1.so.3` are runtime requirements for applications that use them. Portal-based file dialogs +need a desktop portal backend implementing the file chooser interface; applications +may also require tools such as Zenity for fallback dialogs. Libraries loaded with +`dlopen` must be checked separately from ELF `NEEDED`. Sysroot drivers are not +application redistribution assets. +`inspect` reports ELF machine, NEEDED and symbol versions and rejects glibc +requirements newer than 2.36. The baseline is for the binary's dependency ABI; +packaging newer replacement libraries can raise it. + +macOS baseline: **11.0 for both architectures**, SDK 14.5. Both Rust and native +compiler invocations use `MACOSX_DEPLOYMENT_TARGET=11.0`; Clang's integrated +assembler and ld64.lld produce Mach-O without a host Apple toolchain. Apple +frameworks, libSystem and libc++ remain OS dependencies. No third-party macOS +libraries are bundled. Target pkg-config intentionally has no host fallback. +Inspect `LC_BUILD_VERSION`/`LC_VERSION_MIN_MACOSX` and load commands before +shipping. SDK availability does not establish an application's minimum runtime OS; +GPU/backend checks on the baseline OS are still required. + +Windows uses cargo-xwin 0.23.1, LLVM 19, Windows SDK **10.0.26100**, CRT +**14.44.17.14**, desktop variant, both architectures. cargo-xwin sets clang-cl, +lld-link, llvm-lib and CMake toolchain paths for the target. SDK/CRT are downloaded +on first use into `/opt/xwin`; preserve that directory in a named volume. +They are not baked into the published image. The package manifest URL and actual +SHA-256 are pinned in `prepare-xwin`; a populated cache with other or unknown +inputs is rejected. Use a fresh named volume when updating pins. The SDK version is a build input, +not a promise that the application runs on every Windows version. Validate on +Windows 10/11 with appropriate graphics drivers; imported DLLs and the selected +CRT linkage determine deployment needs. Dynamic CRT builds need the matching +Microsoft Visual C++ Redistributable; inspect PE imports. + +## SDK licenses + +Downloading an SDK is not a grant to redistribute it. cargo-xwin use accepts the +[Microsoft SDK/Visual Studio terms](https://go.microsoft.com/fwlink/?LinkId=2086102). +Only components designated redistributable under the applicable terms may be +shipped with an application; keep SDK headers, import libraries and download +caches out of distributed application bundles and public images. Read the +[xwin licensing notes](https://github.com/Jake-Shadle/xwin#licenses). + +The macOS SDK remains subject to the +[Apple Xcode and Apple SDKs agreement](https://www.apple.com/legal/sla/docs/xcode.pdf). +The agreement restricts Apple Software use to Apple-branded products running +macOS and limits redistribution. A third-party archive or private storage does +not grant additional SDK rights. The default build retains rustxc's existing +SDK-in-image model; publishers must establish their right to use and redistribute +that SDK before publishing an image. rustxc grants no rights to these SDKs. + +## Validation and updates + +Run the native fixture on either host architecture: + +```sh +mkdir -p /tmp/rustxc-smoke +docker run --rm -v "$PWD/tests:/tests:ro" -v /tmp/rustxc-smoke:/evidence -e RUSTXC_EVIDENCE_DIR=/evidence rustxc:local /opt/rustxc/smoke aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu powerpc64le-unknown-linux-gnu aarch64-apple-darwin x86_64-apple-darwin x86_64-pc-windows-msvc aarch64-pc-windows-msvc > /tmp/rustxc-smoke/smoke.log 2>&1 +``` + +The locked fixture compiles and links Rust, C, C++, portable assembly, zstd and +Linux pkg-config-discovered libraries. It tests CMake root-path isolation and +rejects host include/library paths. Non-Windows ARM64 also compiles SHA assembly; +Windows ARM64 uses portable SHA plus a separate native assembly probe because +`sha2-asm` 0.6.4 does not support Windows. + +CI runs these smoke builds on native AMD64 and ARM64 runners before +multi-architecture publication. Downstream application integration tests belong +in the consuming project's CI, using a pinned rustxc image digest. Successful +compilation does not verify GUI, GPU, clipboard, file dialogs, audio or gamepads. +Those need platform runtime checks; no renderer windows are launched by the +smoke scripts. + +Updates are reviewed changes to Dockerfile pins: resolve the Rust **index** digest +(`docker buildx imagetools inspect rust:-bookworm`), advance the Debian +snapshot, verify the SDK archive checksum, update cargo-xwin and Microsoft SDK/CRT +versions together (including the immutable package manifest URL/checksum in +`prepare-xwin` and its channel descriptor), and regenerate the fixture lockfile when needed. Re-run both +host matrices and downstream integration builds, inspect ABI requirements, and record image +digests. `/opt/rustxc/packages.txt` and each sysroot's `packages.txt` record package +versions. Rustup and Microsoft's service metadata are online services; archive +approved toolchains/SDK caches for offline rebuilds. Monthly/manual builds reuse +pins rather than silently following `rust:latest` or moving SDK branches. + +The **Docker** workflow supports manual dispatch, monthly rebuilds and pushes to +master; it publishes AMD64+ARM64 `latest` and commit tags and signs the index digest. + +See [toolchain validation scope](docs/validation.md). diff --git a/docs/validation.md b/docs/validation.md new file mode 100644 index 0000000..dabd597 --- /dev/null +++ b/docs/validation.md @@ -0,0 +1,40 @@ +# Toolchain validation + +The repository's validation contract is the locked native fixture and CMake +probe, run for all seven targets on both container host architectures. Downstream +application builds and application-specific dependency failures belong in the +consuming project's integration tests. + +## Coverage + +The native fixture compiles and links Rust, C, C++, assembly and bundled zstd C +sources. Non-Windows ARM64 additionally compiles SHA assembly. Windows ARM64 uses +portable SHA and a separate native ARM64 assembly probe: sha2-asm 0.6.4 explicitly +rejects Windows, independently of the assembler's capabilities. + +Linux probes ALSA, udev, D-Bus, Wayland, X11/extensions, xkbcommon, EGL and Vulkan +through target pkg-config. Include/library paths must be inside the selected +sysroot. An injected host `.pc` file must remain invisible. CMake probes exercise +target compilers and root-path isolation. Native Linux smoke executables also +run; cross-target executables are inspected rather than executed. + +`inspect` reports ELF/Mach-O/PE headers, imported libraries and deployment +requirements, and rejects ELF glibc requirements above the declared baseline. +The smoke driver checks executable architecture and reports representative +zstd/SHA object headers. See the README for the complete invocation. + +CI runs the matrix on native AMD64 and ARM64 runners and retains image metadata +and build logs as artifacts. An alternate Rust version exercises installation of +the active toolchain's target standard library. Changes to compiler, SDK, +sysroot or Rust inputs require rerunning this matrix. + +## Runtime limits + +Compilation and header inspection do not verify GUI/GPU compatibility. Consumers +must test on each deployment OS and architecture, including the declared baseline, +with appropriate graphics drivers and desktop services. Check runtime-loaded +libraries, rendering, shader compilation, X11/Wayland sessions, portal file +dialogs, clipboard, audio and gamepad permissions as applicable. Windows CRT +redistribution and macOS application signing/notarization are separate packaging +requirements. No visible renderer windows or profiler recordings are part of +rustxc's smoke suite. diff --git a/scripts/build-target b/scripts/build-target new file mode 100755 index 0000000..dce47f5 --- /dev/null +++ b/scripts/build-target @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail +if (($# < 1)); then echo "usage: build-target TARGET [cargo build options...]" >&2; exit 2; fi +target=$1; shift +case "$target" in + aarch64-unknown-linux-gnu|x86_64-unknown-linux-gnu|powerpc64le-unknown-linux-gnu|aarch64-apple-darwin|x86_64-apple-darwin|x86_64-pc-windows-msvc|aarch64-pc-windows-msvc) ;; + *) echo "Unsupported target: $target" >&2; exit 2 ;; +esac +# rustup honors rust-toolchain.toml and RUSTUP_TOOLCHAIN. Install std for the +# ACTIVE version rather than assuming that the image's default is selected. +rustup target add "$target" +if [[ $target == *-windows-msvc ]]; then + unset CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH LIBRARY_PATH SDKROOT INCLUDE LIB + mkdir -p "${XWIN_CACHE_DIR:-/opt/xwin}" + exec 9>"${XWIN_CACHE_DIR:-/opt/xwin}/rustxc.lock" + flock 9 + /opt/rustxc/prepare-xwin + exec cargo xwin build --target "$target" "$@" +else + if [[ $target == *-apple-darwin ]]; then export SDKROOT=/opt/sdk/macos; fi + exec cargo build --target "$target" "$@" +fi diff --git a/scripts/configure b/scripts/configure new file mode 100755 index 0000000..d6b0266 --- /dev/null +++ b/scripts/configure @@ -0,0 +1,60 @@ +#!/bin/bash +set -euo pipefail +mkdir -p /opt/rustxc/bin /opt/rustxc/cmake /usr/local/cargo +for command in build-target inspect; do ln -sf /opt/rustxc/$command /opt/rustxc/bin/$command; done +config=/usr/local/cargo/config.toml +: > "$config" +: > /opt/rustxc/environment +for target in aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu powerpc64le-unknown-linux-gnu aarch64-apple-darwin x86_64-apple-darwin x86_64-pc-windows-msvc aarch64-pc-windows-msvc; do + for tool in cc cxx ar ranlib as pkg-config; do + ln -sf /opt/rustxc/tool "/opt/rustxc/bin/$target-$tool" + done + upper=${target^^}; upper=${upper//-/_} + key=${target//-/_} + cat >> "$config" < /opt/rustxc/cmake/$target.cmake <> /opt/rustxc/cmake/$target.cmake <> /opt/rustxc/environment + fi + # Target-qualified cc-rs/pkg-config variables leave build-script HOST tools + # untouched, including when the target and host architectures coincide. + cat >> /opt/rustxc/environment <&2; exit 1 + fi ;; + *Mach-O*) llvm-objdump --macho --private-headers --dylibs-used "$binary" ;; + *PE32*) llvm-readobj --file-headers --coff-imports "$binary" ;; + *) echo "Unrecognized executable" >&2; exit 1 ;; + esac +done diff --git a/scripts/make-sysroots b/scripts/make-sysroots new file mode 100755 index 0000000..c3fdf4e --- /dev/null +++ b/scripts/make-sysroots @@ -0,0 +1,47 @@ +#!/bin/bash +set -euo pipefail +# Resolve the complete package closure against an EMPTY dpkg database, so host +# packages never satisfy a target dependency. apt downloads, dpkg-deb extracts. +for spec in aarch64:arm64 x86_64:amd64 powerpc64le:ppc64el; do + cpu=${spec%:*}; arch=${spec#*:} + root=/opt/sysroots/$cpu-unknown-linux-gnu + state=$(mktemp -d) + mkdir -p "$state/lists/partial" "$state/archives/partial" "$root" + touch "$state/status" + opts=(-o "APT::Architecture=$arch" -o "APT::Architectures=$arch" + -o "Dir::State=$state" -o "Dir::State::status=$state/status" + -o "Dir::State::lists=$state/lists" -o "Dir::Cache::archives=$state/archives" + -o APT::Sandbox::User=root) + apt-get "${opts[@]}" update + apt-get "${opts[@]}" --download-only --no-install-recommends -y install \ + libc6-dev libstdc++-12-dev libasound2-dev libudev-dev libdbus-1-dev \ + libwayland-dev libxkbcommon-dev libxkbcommon-x11-dev \ + libx11-dev libx11-xcb-dev libxcursor-dev libxi-dev libxrandr-dev \ + libxinerama-dev libxfixes-dev libxrender-dev libxcb-shape0-dev \ + libxcb-xfixes0-dev libxcb-render0-dev libxcb-randr0-dev \ + libegl1-mesa-dev libgl1-mesa-dev libvulkan-dev + for deb in "$state"/archives/*.deb; do dpkg-deb -x "$deb" "$root"; done + # Absolute symlinks in Debian packages must resolve inside this sysroot. + python3 - "$root" <<'PY' +import os, sys +root = sys.argv[1] +for parent, dirs, files in os.walk(root): + for name in dirs + files: + path = os.path.join(parent, name) + if os.path.islink(path) and os.readlink(path).startswith('/'): + target = root + os.readlink(path) + os.unlink(path) + os.symlink(os.path.relpath(target, parent), path) +PY + # Architecture-independent protocol .pc files are required by x11.pc. + # Retain them even though the rest of /usr/share is not a build input. + if [[ -d $root/usr/share/pkgconfig ]]; then + mkdir -p "$root/usr/lib/pkgconfig" + cp -a "$root/usr/share/pkgconfig/." "$root/usr/lib/pkgconfig/" + fi + # Record exactly which target packages were selected. + for deb in "$state"/archives/*.deb; do + dpkg-deb -f "$deb" Package Version Architecture + done > "$root/packages.txt" + rm -rf "$state" "${root:?}/usr/share" "${root:?}/usr/bin" "${root:?}/usr/sbin" +done diff --git a/scripts/prepare-xwin b/scripts/prepare-xwin new file mode 100755 index 0000000..191fc11 --- /dev/null +++ b/scripts/prepare-xwin @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail +# Pin Microsoft's package catalogue, not only its moving component selectors. +# cargo-xwin 0.23.1/xwin 0.10 reads these cached names before using the network. +if [[ ${XWIN_VERSION:-17} != 17 ]]; then + echo "The pinned SDK catalogue is for Visual Studio 17; update the manifest pin first" >&2 + exit 2 +fi +cache=${XWIN_CACHE_DIR:-/opt/xwin}/xwin/dl +name=pkg_manifest_5bd3b0b2ae509af2e9559b852f78545df0bf2c081dd850caed76f1dc134c511e.vsman +checksum=87791000b1d6357e174f039ce9c2f03d150d4e90b45e8e52468d797dac62022c +identity="manifest=$checksum sdk=${XWIN_SDK_VERSION:?} crt=${XWIN_CRT_VERSION:?} arch=${XWIN_ARCH:?} variant=${XWIN_VARIANT:-desktop}" +stamp=${XWIN_CACHE_DIR:-/opt/xwin}/rustxc-inputs +if [[ -f ${cache%/dl}/DONE ]]; then + if [[ -f $stamp ]] && [[ $(cat "$stamp") == "$identity" ]]; then exit 0; fi + echo "SDK cache has different or unrecorded inputs; use a fresh XWIN_CACHE_DIR/volume" >&2 + exit 2 +fi +mkdir -p "$cache" +printf '%s\n' "$identity" > "$stamp" +cp /opt/rustxc/windows-channel.json "$cache/manifest_17.json" +if ! [[ -f $cache/$name ]]; then + curl -fL --retry 5 https://download.visualstudio.microsoft.com/download/pr/4bc08c27-bd31-470c-9a30-3b62707fbf0f/5bd3b0b2ae509af2e9559b852f78545df0bf2c081dd850caed76f1dc134c511e/VisualStudio.vsman -o "$cache/$name" +fi +echo "$checksum $cache/$name" | sha256sum -c - diff --git a/scripts/smoke b/scripts/smoke new file mode 100755 index 0000000..62efe6f --- /dev/null +++ b/scripts/smoke @@ -0,0 +1,60 @@ +#!/bin/bash +set -euo pipefail +# Run inside the image; output/build products belong outside the checkout. +# Generated by configure during the image build. +# shellcheck source=/dev/null +source /opt/rustxc/environment +out=${RUSTXC_EVIDENCE_DIR:-/tmp/rustxc-smoke} +mkdir -p "$out" /tmp/rustxc-host-pkgconfig +cat > /tmp/rustxc-host-pkgconfig/rustxc-host-only.pc <<'PC' +Name: rustxc-host-only +Description: host contamination sentinel +Version: 1 +Libs: -L/usr/lib -lhost +PC +export PKG_CONFIG_PATH=/tmp/rustxc-host-pkgconfig +export CARGO_TARGET_DIR=$out/target +for target in "$@"; do + echo "Host $(uname -m); target $target" + if [[ $target == *-linux-gnu ]]; then + /opt/rustxc/bin/"$target"-cc -v -E -x c /dev/null + /opt/rustxc/bin/"$target"-pkg-config --cflags --libs alsa libudev wayland-client xkbcommon x11 + elif [[ $target == *-apple-darwin ]]; then + /opt/rustxc/bin/"$target"-cc -v -E -x c /dev/null + fi + if [[ $target != *-windows-msvc ]]; then + cmake -S /tests/cmake -B "$out/cmake-$target" -G Ninja \ + "-DCMAKE_TOOLCHAIN_FILE=/opt/rustxc/cmake/$target.cmake" -DCMAKE_BUILD_TYPE=Release + cmake --build "$out/cmake-$target" + /opt/rustxc/inspect "$out/cmake-$target/probe" + fi + /opt/rustxc/build-target "$target" --manifest-path /tests/native/Cargo.toml --locked --release -vv + for native in zstd-sys sha2-asm; do + while IFS= read -r object; do + llvm-readobj --file-headers "$object" + break + done < <(find "$CARGO_TARGET_DIR/$target/release/build" -path "*/$native-*/out/*.o" -type f) + done + suffix=; [[ $target != *-windows-msvc ]] || suffix=.exe + /opt/rustxc/inspect "$CARGO_TARGET_DIR/$target/release/rustxc-native-smoke$suffix" + case "$target" in + aarch64-unknown-linux-gnu) expected='ELF 64-bit LSB.*ARM aarch64' ;; + x86_64-unknown-linux-gnu) expected='ELF 64-bit LSB.*x86-64' ;; + powerpc64le-unknown-linux-gnu) expected='ELF 64-bit LSB.*PowerPC' ;; + aarch64-apple-darwin) expected='Mach-O 64-bit arm64' ;; + x86_64-apple-darwin) expected='Mach-O 64-bit x86_64' ;; + x86_64-pc-windows-msvc) expected='PE32\+.*x86-64' ;; + aarch64-pc-windows-msvc) expected='PE32\+.*Aarch64' ;; + esac + file "$CARGO_TARGET_DIR/$target/release/rustxc-native-smoke$suffix" | grep -E "$expected" + case "$target:$(uname -m)" in + aarch64-unknown-linux-gnu:aarch64|x86_64-unknown-linux-gnu:x86_64) + cpu=${target%%-*} + LD_LIBRARY_PATH="/opt/sysroots/$target/usr/lib/$cpu-linux-gnu:/opt/sysroots/$target/lib/$cpu-linux-gnu" \ + "$CARGO_TARGET_DIR/$target/release/rustxc-native-smoke" ;; + esac + # Even an explicit host PKG_CONFIG_PATH must not contaminate target discovery. + if "/opt/rustxc/bin/$target-pkg-config" --exists rustxc-host-only; then + echo "pkg-config host contamination" >&2; exit 1 + fi +done diff --git a/scripts/tool b/scripts/tool new file mode 100755 index 0000000..1edd7e1 --- /dev/null +++ b/scripts/tool @@ -0,0 +1,58 @@ +#!/bin/bash +set -euo pipefail +name=${0##*/} +case "$name" in + *-pkg-config) tool=pkg-config; target=${name%-pkg-config} ;; + *) tool=${name##*-}; target=${name%-"$tool"} ;; +esac +# Environment include/library paths can otherwise bypass a compiler's sysroot. +unset CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH LIBRARY_PATH SDKROOT +if [[ $target == *-unknown-linux-gnu ]]; then + cpu=${target%%-*} + triple=$cpu-linux-gnu + [[ $cpu != powerpc64le ]] || triple=powerpc64le-linux-gnu + root=/opt/sysroots/$target + case $tool in + pkg-config) + export PKG_CONFIG_SYSROOT_DIR=$root + export PKG_CONFIG_LIBDIR=$root/usr/lib/$triple/pkgconfig:$root/usr/lib/pkgconfig:$root/usr/share/pkgconfig + export PKG_CONFIG_PATH='' PKG_CONFIG_DIR='' PKG_CONFIG_ALLOW_CROSS=1 + exec /usr/bin/pkg-config "$@" ;; + cc|cxx) + compiler=clang; [[ $tool != cxx ]] || compiler=clang++ + exec "$compiler" --target="$triple" --sysroot="$root" \ + --gcc-install-dir="$root/usr/lib/gcc/$triple/12" \ + -fuse-ld=lld "$@" ;; + *) exec "$triple-$tool" "$@" ;; + esac +elif [[ $target == *-apple-darwin ]]; then + case $tool in + pkg-config) + # No third-party Darwin libraries are bundled. Never fall back to + # host .pc files. Projects can populate this target-only directory. + export PKG_CONFIG_SYSROOT_DIR=/opt/sdk/macos + export PKG_CONFIG_LIBDIR=/opt/sysroots/$target/usr/lib/pkgconfig + export PKG_CONFIG_PATH='' PKG_CONFIG_DIR='' PKG_CONFIG_ALLOW_CROSS=1 + exec /usr/bin/pkg-config "$@" ;; + ar|ranlib) exec "llvm-$tool" "$@" ;; + cc) compiler=clang ;; + as) compiler=clang; set -- -c "$@" ;; + cxx) compiler=clang++ ;; + esac + exec "$compiler" --target="$target" -isysroot /opt/sdk/macos \ + -mmacosx-version-min="${MACOSX_DEPLOYMENT_TARGET:-11.0}" -fuse-ld=lld "$@" +else + case $tool in + as) exec clang --target="$target" -c "$@" ;; + ar) exec llvm-lib "$@" ;; + ranlib) exec llvm-ranlib "$@" ;; + esac + if [[ $tool == pkg-config ]]; then + export PKG_CONFIG_SYSROOT_DIR=/opt/xwin + export PKG_CONFIG_LIBDIR=/opt/sysroots/$target/usr/lib/pkgconfig + export PKG_CONFIG_PATH='' PKG_CONFIG_DIR='' PKG_CONFIG_ALLOW_CROSS=1 + exec /usr/bin/pkg-config "$@" + fi + echo 'Use cargo xwin build for MSVC (Microsoft SDK/CRT required)' >&2 + exit 1 +fi diff --git a/scripts/windows-channel.json b/scripts/windows-channel.json new file mode 100644 index 0000000..8236b34 --- /dev/null +++ b/scripts/windows-channel.json @@ -0,0 +1,17 @@ +{ + "channelItems": [ + { + "id": "Microsoft.VisualStudio.Manifests.VisualStudio", + "version": "17.14.37824.6", + "type": "Manifest", + "payloads": [ + { + "fileName": "VisualStudio.vsman", + "sha256": "5bd3b0b2ae509af2e9559b852f78545df0bf2c081dd850caed76f1dc134c511e", + "size": 30443792, + "url": "https://download.visualstudio.microsoft.com/download/pr/4bc08c27-bd31-470c-9a30-3b62707fbf0f/5bd3b0b2ae509af2e9559b852f78545df0bf2c081dd850caed76f1dc134c511e/VisualStudio.vsman" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/cmake/CMakeLists.txt b/tests/cmake/CMakeLists.txt new file mode 100644 index 0000000..8f4222f --- /dev/null +++ b/tests/cmake/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.25) +project(rustxc_cmake_probe LANGUAGES C CXX) +add_library(probe_c STATIC ../native/native/probe.c) +add_library(probe_cpp STATIC ../native/native/probe.cpp) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + find_package(PkgConfig REQUIRED) + pkg_check_modules(NATIVE REQUIRED IMPORTED_TARGET alsa libudev dbus-1 wayland-client x11 xkbcommon) + target_link_libraries(probe_c PUBLIC PkgConfig::NATIVE) +endif() +add_executable(probe main.cpp) +target_link_libraries(probe PRIVATE probe_c probe_cpp) diff --git a/tests/cmake/main.cpp b/tests/cmake/main.cpp new file mode 100644 index 0000000..e61eefc --- /dev/null +++ b/tests/cmake/main.cpp @@ -0,0 +1,3 @@ +extern "C" int rustxc_c(); +extern "C" int rustxc_cpp(const char *text); +int main() { return rustxc_c() == 8 && rustxc_cpp("rustxc") == 6 ? 0 : 1; } diff --git a/tests/native/Cargo.lock b/tests/native/Cargo.lock new file mode 100644 index 0000000..b28e821 --- /dev/null +++ b/tests/native/Cargo.lock @@ -0,0 +1,192 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cc" +version = "1.2.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom", + "libc", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rustxc-native-smoke" +version = "0.1.0" +dependencies = [ + "cc", + "pkg-config", + "sha2", + "zstd", + "zstd-sys", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", + "sha2-asm", +] + +[[package]] +name = "sha2-asm" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b845214d6175804686b2bd482bcffe96651bb2d1200742b712003504a2dac1ab" +dependencies = [ + "cc", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d80649ab6db9d9f6f9c80a40becd948eda4714a0a5ac8c4d157a32231c7882" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.16+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/tests/native/Cargo.toml b/tests/native/Cargo.toml new file mode 100644 index 0000000..b8391ec --- /dev/null +++ b/tests/native/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "rustxc-native-smoke" +version = "0.1.0" +edition = "2024" +publish = false + +[dependencies] +sha2 = "=0.10.9" +zstd = "=0.13.3" +# Pin the bundled C dependency for reproducible native smoke builds. +zstd-sys = { version = "=2.0.16", default-features = false } + +[target.'cfg(all(target_arch = "aarch64", not(target_os = "windows")))'.dependencies] +sha2 = { version = "=0.10.9", features = ["asm"] } + +[build-dependencies] +cc = "=1.2.41" +pkg-config = "=0.3.32" diff --git a/tests/native/build.rs b/tests/native/build.rs new file mode 100644 index 0000000..a8bd008 --- /dev/null +++ b/tests/native/build.rs @@ -0,0 +1,69 @@ +fn main() { + let mut c = cc::Build::new(); + if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "linux" { + let expected_root = + std::path::PathBuf::from("/opt/sysroots").join(std::env::var("TARGET").unwrap()); + for library in [ + "alsa", + "libudev", + "dbus-1", + "wayland-client", + "wayland-cursor", + "wayland-egl", + "x11", + "xcursor", + "xi", + "xrandr", + "xkbcommon", + "xkbcommon-x11", + "xcb", + "egl", + "vulkan", + ] { + let found = pkg_config::Config::new().probe(library).unwrap(); + c.includes(&found.include_paths); + for path in found.include_paths.iter().chain(found.link_paths.iter()) { + assert!( + path.starts_with(&expected_root), + "host path: {}", + path.display() + ); + } + } + } + c.file("native/probe.c").compile("probe_c"); + + if std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "msvc" { + // cc 1.2.41's clang-cl .S path writes an intermediate beside the source. + // Drive LLVM's integrated assembler explicitly, keeping source read-only. + let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); + let target = std::env::var("TARGET").unwrap(); + let assembler = std::env::var(format!("AS_{}", target.replace('-', "_"))).unwrap(); + let object = out.join("probe_asm.obj"); + assert!( + std::process::Command::new(assembler) + .args(["native/probe.S", "-o"]) + .arg(&object) + .status() + .unwrap() + .success() + ); + assert!( + std::process::Command::new("llvm-lib") + .arg(format!("/out:{}", out.join("probe_asm.lib").display())) + .arg(&object) + .status() + .unwrap() + .success() + ); + println!("cargo:rustc-link-search=native={}", out.display()); + println!("cargo:rustc-link-lib=static=probe_asm"); + } else { + cc::Build::new().file("native/probe.S").compile("probe_asm"); + } + cc::Build::new() + .cpp(true) + .file("native/probe.cpp") + .compile("probe_cpp"); + println!("cargo:rerun-if-changed=native"); +} diff --git a/tests/native/native/probe.S b/tests/native/native/probe.S new file mode 100644 index 0000000..30534c1 --- /dev/null +++ b/tests/native/native/probe.S @@ -0,0 +1,20 @@ +#ifdef __APPLE__ +#define NAME _rustxc_asm +#else +#define NAME rustxc_asm +#endif +.text +.globl NAME +NAME: +#if defined(__aarch64__) + mov w0, #42 + ret +#elif defined(__x86_64__) + mov $42, %eax + ret +#elif defined(__powerpc64__) + li 3, 42 + blr +#else +#error Unsupported smoke architecture +#endif diff --git a/tests/native/native/probe.c b/tests/native/native/probe.c new file mode 100644 index 0000000..91d7e61 --- /dev/null +++ b/tests/native/native/probe.c @@ -0,0 +1,23 @@ +#include +#include +#ifdef __linux__ +#include +#include +#include +#include +#include +#include +/* Strong references force the linker to consume target libraries. This function + * is linked but never called: smoke tests do not open desktop/audio devices. */ +void *rustxc_discovery(void) { + int major, minor, micro; + dbus_get_version(&major, &minor, µ); + const char *version = snd_asoundlib_version(); + struct udev *udev = udev_new(); + struct wl_display *display = wl_display_connect(NULL); + Display *x11 = XOpenDisplay(NULL); + struct xkb_context *xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + return version && udev && display && x11 ? xkb : NULL; +} +#endif +int rustxc_c(void) { return (int)sizeof(uint64_t); } diff --git a/tests/native/native/probe.cpp b/tests/native/native/probe.cpp new file mode 100644 index 0000000..38fe11d --- /dev/null +++ b/tests/native/native/probe.cpp @@ -0,0 +1,2 @@ +#include +extern "C" int rustxc_cpp(const char *text) { return std::string(text).size(); } diff --git a/tests/native/src/main.rs b/tests/native/src/main.rs new file mode 100644 index 0000000..f8cbb0a --- /dev/null +++ b/tests/native/src/main.rs @@ -0,0 +1,28 @@ +use sha2::{Digest, Sha256}; +unsafe extern "C" { + fn rustxc_asm() -> i32; + fn rustxc_c() -> i32; + fn rustxc_cpp(text: *const std::ffi::c_char) -> i32; +} +#[cfg(target_os = "linux")] +unsafe extern "C" { + fn rustxc_discovery() -> *mut std::ffi::c_void; +} +fn main() { + #[cfg(target_os = "linux")] + std::hint::black_box(rustxc_discovery as unsafe extern "C" fn() -> *mut std::ffi::c_void); + assert_eq!(unsafe { rustxc_asm() }, 42); + assert_eq!(unsafe { rustxc_c() }, 8); + assert_eq!(unsafe { rustxc_cpp(c"rustxc".as_ptr()) }, 6); + let input = b"native C, C++ and assembly smoke test"; + let compressed = zstd::encode_all(&input[..], 1).unwrap(); + assert_eq!(zstd::decode_all(&compressed[..]).unwrap(), input); + assert_eq!( + Sha256::digest(b"abc").as_slice(), + &[ + 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, + 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, + 0xf2, 0x00, 0x15, 0xad + ] + ); +}