From 0dbbc9dfdba3662a24b8b5b354049d98348e1701 Mon Sep 17 00:00:00 2001 From: richarddd Date: Mon, 14 Sep 2026 14:18:05 +0200 Subject: [PATCH 1/2] Rebase the cargo-zigbuild CI refactor onto master and extend it to riscv64gc-unknown-linux-gnu --- .github/workflows/bindings.yml | 135 +++++++++ .github/workflows/ci.yml | 497 +++++++++------------------------ 2 files changed, 264 insertions(+), 368 deletions(-) create mode 100644 .github/workflows/bindings.yml diff --git a/.github/workflows/bindings.yml b/.github/workflows/bindings.yml new file mode 100644 index 00000000..4105d0cf --- /dev/null +++ b/.github/workflows/bindings.yml @@ -0,0 +1,135 @@ +name: Update bindings + +on: + workflow_dispatch: + inputs: + base: + description: Branch to open the pull request against + required: false + default: master + push: + branches: + - master + paths: + - 'sys/quickjs' + - 'sys/wrapper.h' + - 'sys/build.rs' + - 'sys/Cargo.toml' + - '.github/workflows/bindings.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + bindings: + name: ${{ matrix.target }} + strategy: + fail-fast: false + matrix: + include: + # Cross-compiled Linux targets handled by cargo-zigbuild. + - { os: ubuntu-latest, target: i686-unknown-linux-gnu, rust: stable, builder: zigbuild } + - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, rust: stable, builder: zigbuild } + - { os: ubuntu-latest, target: x86_64-unknown-linux-musl, rust: stable, builder: zigbuild } + - { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, rust: stable, builder: zigbuild } + - { os: ubuntu-latest, target: aarch64-unknown-linux-musl, rust: stable, builder: zigbuild } + - { os: ubuntu-latest, target: armv7-unknown-linux-gnueabihf, rust: stable, builder: zigbuild } + - { os: ubuntu-latest, target: powerpc64-unknown-linux-gnu, rust: stable, builder: zigbuild } + - { os: ubuntu-24.04, target: riscv64gc-unknown-linux-gnu, rust: stable, builder: zigbuild } + - { os: ubuntu-24.04, target: loongarch64-unknown-linux-gnu, rust: nightly, builder: zigbuild } + - { os: ubuntu-24.04, target: loongarch64-unknown-linux-musl, rust: nightly, builder: zigbuild } + # Native builds. + - { os: macos-latest, target: x86_64-apple-darwin, rust: stable, builder: native } + - { os: macos-latest, target: aarch64-apple-darwin, rust: stable, builder: native } + - { os: windows-latest, target: x86_64-pc-windows-msvc, rust: stable, builder: native } + - { os: windows-latest, target: x86_64-pc-windows-gnu, rust: stable, builder: msys2 } + - { os: windows-11-arm, target: aarch64-pc-windows-msvc, rust: stable, builder: native } + - { os: ubuntu-latest, target: wasm32-wasip1, rust: stable, builder: native } + - { os: ubuntu-latest, target: wasm32-wasip2, rust: nightly, builder: native } + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v7 + with: + submodules: true + + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + components: rust-src + + - name: Set up zig + if: matrix.builder == 'zigbuild' + uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1 + with: + version: 0.16.0 + + - name: Install cargo-zigbuild + if: matrix.builder == 'zigbuild' + uses: taiki-e/install-action@7be9fd86bd1707236395105d6e9329dd1511a7e1 # v2.79.0 + with: + tool: cargo-zigbuild + + - name: Set up msys2 + if: matrix.builder == 'msys2' + uses: msys2/setup-msys2@e9898307ac31d1a803454791be09ab9973336e1c # v2.31.1 + with: + release: false + + - name: Prepare msys2 env + if: matrix.builder == 'msys2' + shell: pwsh + run: | + New-Item -Path "C:\Program Files\LLVM\x86_64-w64-mingw32" -ItemType SymbolicLink -Value "C:\msys64\mingw64\x86_64-w64-mingw32" + New-Item -Path "C:\Program Files\LLVM\i686-w64-mingw32" -ItemType SymbolicLink -Value "C:\msys64\mingw64\i686-w64-mingw32" + echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\msys64\mingw32\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "CC_x86_64_pc_windows_gnu=x86_64-w64-mingw32-gcc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + echo "CC_i686_pc_windows_gnu=i686-w64-mingw32-gcc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + + - name: Regenerate bindings + shell: bash + env: + BUILD_TARGET: ${{ matrix.target }} + RUST_LOG: bindgen=warn,bindgen::ir=error,bindgen::codegen=error + run: | + if [ "${{ matrix.builder }}" = "zigbuild" ]; then + cargo zigbuild --manifest-path sys/Cargo.toml --target ${{ matrix.target }} --features bindgen,update-bindings,logging + else + cargo build --manifest-path sys/Cargo.toml --target ${{ matrix.target }} --features bindgen,update-bindings,logging + fi + cat "sys/src/bindings/${{ matrix.target }}.rs" | head -n 20 + + - name: Upload bindings + uses: actions/upload-artifact@v7 + with: + name: bindings-${{ matrix.target }} + path: sys/src/bindings/${{ matrix.target }}.rs + overwrite: true + + open-pr: + needs: bindings + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v7 + - name: Download bindings artifacts + uses: actions/download-artifact@v8 + with: + pattern: bindings-* + path: sys/src/bindings + merge-multiple: true + - name: Create pull request + uses: peter-evans/create-pull-request@v8 + with: + base: ${{ github.event.inputs.base || github.ref_name }} + branch: update-bindings + delete-branch: true + commit-message: Update bindings + title: Update bindings + body: | + Regenerated `sys/src/bindings/*.rs` after a change to `sys/quickjs`, `sys/wrapper.h`, `sys/build.rs`, or `sys/Cargo.toml`. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13713048..a03f0363 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,6 @@ on: push: branches: - master - - update-bindings pull_request: # Only run on the latest ref @@ -49,6 +48,7 @@ jobs: target/doc/rquickjs target/doc/rquickjs-sys target/doc/rquickjs-macro + check: runs-on: ubuntu-latest permissions: @@ -65,10 +65,7 @@ jobs: run: cargo clippy --all --all-targets --features full-async,bindgen msrv: - # Check to see if rquickjs builds on minimal supported Rust version. runs-on: ubuntu-latest - # we use a matrix here just because env can't be used in job names - # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability strategy: matrix: msrv: [1.87.0] @@ -159,410 +156,174 @@ jobs: fail-fast: ${{ startsWith(github.ref, 'refs/tags/') }} matrix: include: - # Generate bindings - - task: bindings - os: ubuntu-latest - rust: stable - target: i686-unknown-linux-gnu - features: full-async - - task: bindings - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: full-async - - - task: bindings - os: macos-latest - rust: stable - target: x86_64-apple-darwin - features: full-async - - task: bindings - os: macos-latest - rust: stable - target: aarch64-apple-darwin - features: full-async - no-test: true - - - task: bindings - os: windows-latest - rust: stable - target: x86_64-pc-windows-gnu - features: full-async - - task: bindings - os: windows-latest - rust: stable - target: x86_64-pc-windows-msvc - features: full-async - - task: bindings - os: windows-11-arm - rust: stable - target: aarch64-pc-windows-msvc - features: full-async - - task: test - os: windows-latest - rust: stable - target: x86_64-pc-windows-msvc - features: full-async - optimization: true - - - task: bindings - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-musl - features: full-async - - task: bindings - os: ubuntu-latest - rust: stable - target: aarch64-unknown-linux-musl - features: full-async - - - task: bindings - os: ubuntu-latest - rust: stable - target: aarch64-unknown-linux-gnu - features: full-async - - - task: bindings - os: ubuntu-latest - rust: stable - target: armv7-unknown-linux-gnueabihf - features: full-async - - - task: bindings - os: ubuntu-latest - rust: stable - target: powerpc64-unknown-linux-gnu - features: full-async - - - task: bindings - os: ubuntu-24.04 - rust: nightly - target: loongarch64-unknown-linux-musl - features: full-async - - task: bindings - os: ubuntu-24.04 - rust: nightly - target: loongarch64-unknown-linux-gnu - features: full-async - - - task: bindings - os: ubuntu-24.04 - rust: stable - target: riscv64gc-unknown-linux-gnu - features: full-async - - - task: bindings - os: ubuntu-latest - rust: stable - target: wasm32-wasip1 - features: full-async-wasi - - task: bindings - os: ubuntu-latest - rust: nightly - target: wasm32-wasip2 - features: full-async-wasi - - # Test features - - task: features - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: rust-alloc - - task: features - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: loader - - task: features - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: futures - - task: features - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: parallel - - task: features - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: disable-assertions - - task: features - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: half - - # Test channels - - task: channels - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-gnu - features: full-async - - task: channels - os: ubuntu-latest - rust: beta - target: x86_64-unknown-linux-gnu - features: full-async - - task: channels - os: ubuntu-latest - rust: nightly - target: x86_64-unknown-linux-gnu - features: full-async + # Cross-compiled Linux targets via cargo-zigbuild + QEMU. + - { task: test, os: ubuntu-latest, rust: stable, target: i686-unknown-linux-gnu, features: full-async, builder: zigbuild } + - { task: test, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-musl, features: full-async, builder: zigbuild } + - { task: test, os: ubuntu-latest, rust: stable, target: aarch64-unknown-linux-gnu, features: full-async, builder: zigbuild, qemu: aarch64 } + - { task: test, os: ubuntu-latest, rust: stable, target: aarch64-unknown-linux-musl, features: full-async, builder: zigbuild, qemu: aarch64 } + - { task: test, os: ubuntu-latest, rust: stable, target: armv7-unknown-linux-gnueabihf, features: full-async, builder: zigbuild, qemu: arm } + - { task: test, os: ubuntu-24.04, rust: stable, target: riscv64gc-unknown-linux-gnu, features: full-async, builder: zigbuild, qemu: riscv64 } + # NOTE: powerpc64-unknown-linux-gnu is not tested in CI because zig's + # bundled lld does not support PPC64 ELFv1 (the ABI Rust's + # precompiled std for that target uses), so linking the test + # executables fails. Bindings are still regenerated for it via + # `.github/workflows/bindings.yml` (sys builds as a static rlib, + # which does not trigger lld). + - { task: test, os: ubuntu-24.04, rust: nightly, target: loongarch64-unknown-linux-gnu, features: full-async, builder: zigbuild, qemu: loongarch64 } + - { task: test, os: ubuntu-24.04, rust: nightly, target: loongarch64-unknown-linux-musl, features: full-async, builder: zigbuild, qemu: loongarch64 } + + # Native targets. + - { task: test, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: full-async, builder: native } + + - { task: test, os: macos-latest, rust: stable, target: x86_64-apple-darwin, features: full-async, builder: native } + - { task: test, os: macos-latest, rust: stable, target: aarch64-apple-darwin, features: full-async, builder: native, no-test: true } + + - { task: test, os: windows-latest, rust: stable, target: x86_64-pc-windows-gnu, features: full-async, builder: msys2 } + - { task: test, os: windows-latest, rust: stable, target: x86_64-pc-windows-msvc, features: full-async, builder: native, optimization: true } + - { task: test, os: windows-11-arm, rust: stable, target: aarch64-pc-windows-msvc, features: full-async, builder: native } + + # WebAssembly targets (wasmtime runner). + - { task: test, os: ubuntu-latest, rust: stable, target: wasm32-wasip1, features: full-async-wasi, builder: native, wasi: true } + - { task: test, os: ubuntu-latest, rust: nightly, target: wasm32-wasip2, features: full-async-wasi, builder: native, wasi: true } + + # Feature matrix (native x86_64 Linux). + - { task: features, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: rust-alloc, builder: native } + - { task: features, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: loader, builder: native } + - { task: features, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: futures, builder: native } + - { task: features, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: parallel, builder: native } + - { task: features, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: disable-assertions, builder: native } + - { task: features, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: half, builder: native } + + # Channel matrix (native x86_64 Linux). + - { task: channels, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: full-async, builder: native } + - { task: channels, os: ubuntu-latest, rust: beta, target: x86_64-unknown-linux-gnu, features: full-async, builder: native } + - { task: channels, os: ubuntu-latest, rust: nightly, target: x86_64-unknown-linux-gnu, features: full-async, builder: native } runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v7 with: submodules: true - - name: Setup cross linux toolchain - if: contains(matrix.target, '-linux-') && !startsWith(matrix.target, 'aarch64') && !startsWith(matrix.target, 'armv7') && !startsWith(matrix.target, 'loongarch64') && !startsWith(matrix.target, 'riscv64') && !startsWith(matrix.target, 'x86_64-') && !endsWith(matrix.target, '-musl') && !startsWith(matrix.target, 'powerpc64') - run: | - case "${{ matrix.target }}" in - i686-*) SYSTEM_ARCH=i386 ;; - esac - GCC_TARGET=$(printf "${{ matrix.target }}" | sed 's/-unknown-/-/' | sed 's/arm[^-]*/arm/g') - ENV_TARGET=$(printf "${{ matrix.target }}" | tr '[:lower:]' '[:upper:]' | tr '-' '_') - sudo dpkg --add-architecture ${SYSTEM_ARCH} - sudo apt-get update -y - sudo apt-get install -y libc6-dev:${SYSTEM_ARCH} gcc-${GCC_TARGET} libgcc-s1:${SYSTEM_ARCH} - echo "CARGO_TARGET_${ENV_TARGET}_LINKER=${GCC_TARGET}-gcc" >> $GITHUB_ENV - - name: Setup musl-tools - if: startsWith(matrix.target, 'x86_64-') && endsWith(matrix.target, '-musl') - run: sudo apt-get update -y && sudo apt-get install -y musl-tools - - - name: Setup armv7 toolchain - if: startsWith(matrix.target, 'armv7') && contains(matrix.target, '-linux-') - run: | - sudo apt-get update -y - sudo apt-get install -y \ - libc6-armhf-cross \ - libc6-dev-armhf-cross \ - gcc-arm-linux-gnueabihf \ - qemu-user - echo "CC_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV - echo "CXX_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++" >> $GITHUB_ENV - echo "AR_armv7_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar" >> $GITHUB_ENV - echo "CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV - echo "CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER=qemu-arm -L /usr/arm-linux-gnueabihf" >> $GITHUB_ENV - - - name: Setup powerpc64 toolchain - if: startsWith(matrix.target, 'powerpc64') && endsWith(matrix.target, '-gnu') - run: | - sudo apt-get update -y - sudo apt-get install -y \ - libc6-ppc64-cross \ - libc6-dev-ppc64-cross \ - gcc-powerpc64-linux-gnu \ - qemu-user - echo "CC_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-gcc" >> $GITHUB_ENV - echo "CXX_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-g++" >> $GITHUB_ENV - echo "AR_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-ar" >> $GITHUB_ENV - echo "CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_LINKER=powerpc64-linux-gnu-gcc" >> $GITHUB_ENV - echo "CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_RUNNER=qemu-ppc64 -L /usr/powerpc64-linux-gnu" >> $GITHUB_ENV - - - name: Setup gnu aarch64 - if: startsWith(matrix.target, 'aarch64') && endsWith(matrix.target, '-gnu') - run: | - sudo apt-get update -y - sudo apt-get install -y \ - curl \ - libc6-arm64-cross \ - libc6-dev-arm64-cross \ - crossbuild-essential-arm64 \ - clang \ - qemu-system-arm \ - qemu-efi-aarch64 \ - qemu-utils \ - qemu-user - - echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV - echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV - echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV - echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV - echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER=qemu-aarch64" >> $GITHUB_ENV - - echo "LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib" >> $GITHUB_ENV - - sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1 + - name: Set up zig + if: matrix.builder == 'zigbuild' + uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1 + with: + version: 0.16.0 - mkdir -p ~/.cargo/ - echo "[target.aarch64-unknown-linux-gnu]" >> ~/.cargo/config.toml - echo 'rustflags = ["-C", "linker=aarch64-linux-gnu-gcc"]' >> ~/.cargo/config.toml + - name: Install cargo-zigbuild + if: matrix.builder == 'zigbuild' + uses: taiki-e/install-action@7be9fd86bd1707236395105d6e9329dd1511a7e1 # v2.79.0 + with: + tool: cargo-zigbuild - - name: Setup musl aarch64 - if: startsWith(matrix.target, 'aarch64') && contains(matrix.target, '-musl') + - name: Install QEMU user emulation + if: matrix.qemu + shell: bash run: | - sudo apt-get update -y - sudo apt-get install -y \ - curl \ - libc6-arm64-cross \ - libc6-dev-arm64-cross \ - crossbuild-essential-arm64 \ - clang \ - qemu-system-arm \ - qemu-efi-aarch64 \ - qemu-utils \ - qemu-user - - curl -L --retry 5 https://github.com/musl-cross/musl-cross/releases/latest/download/aarch64-unknown-linux-musl.tar.xz | tar xJf - - sudo mv aarch64-unknown-linux-musl /musl - - echo "CC_aarch64_unknown_linux_musl=aarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV - echo "CXX_aarch64_unknown_linux_musl=aarch64-unknown-linux-musl-g++" >> $GITHUB_ENV - echo "AR_aarch64_unknown_linux_musl=aarch64-unknown-linux-musl-ar" >> $GITHUB_ENV - echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV - echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-aarch64" >> $GITHUB_ENV - - mkdir -p ~/.cargo/ - echo "[target.aarch64-unknown-linux-musl]" >> ~/.cargo/config.toml - echo 'rustflags = ["-C", "link-self-contained=yes","-C", "linker=rust-lld"]' >> ~/.cargo/config.toml - - echo "/musl/bin" >> $GITHUB_PATH + # Cross-compiled glibc binaries need both the dynamic linker and the + # matching sysroot at runtime. zigbuild produces dynamic binaries for + # *-linux-gnu targets, so install the cross libc and point qemu's + # -L prefix at it. *-linux-musl binaries are statically linked and + # need neither. + case "${{ matrix.target }}" in + aarch64-unknown-linux-gnu) + LIBC_PKG=libc6-arm64-cross + PREFIX=/usr/aarch64-linux-gnu + ;; + armv7-unknown-linux-gnueabihf) + LIBC_PKG=libc6-armhf-cross + PREFIX=/usr/arm-linux-gnueabihf + ;; + loongarch64-unknown-linux-gnu) + LIBC_PKG=libc6-dev-loong64-cross + PREFIX=/usr/loongarch64-linux-gnu + ;; + riscv64gc-unknown-linux-gnu) + LIBC_PKG=libc6-riscv64-cross + PREFIX=/usr/riscv64-linux-gnu + ;; + *) + LIBC_PKG='' + PREFIX='' + ;; + esac - - name: Setup cross loongarch64 - if: startsWith(matrix.target, 'loongarch64') && contains(matrix.target, '-linux-') - run: | sudo apt-get update -y - sudo apt-get install -y \ - curl \ - libc6-dev-loong64-cross \ - gcc-14-loongarch64-linux-gnu \ - g++-14-loongarch64-linux-gnu \ - clang \ - qemu-user \ - qemu-system-arm \ - qemu-efi-aarch64 \ - qemu-utils \ - qemu-user-static - - curl -L --retry 5 https://github.com/musl-cross/musl-cross/releases/latest/download/loongarch64-unknown-linux-musl.tar.xz | tar xJf - - sudo mv loongarch64-unknown-linux-musl /musl - - ls -al /usr/loongarch64-linux-gnu + sudo apt-get install -y qemu-user $LIBC_PKG - echo "CC_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV - echo "CXX_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-g++" >> $GITHUB_ENV - echo "AR_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-ar" >> $GITHUB_ENV - echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_LINKER=loongarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV - echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-loongarch64 -L /musl/loongarch64-unknown-linux-musl/sysroot" >> $GITHUB_ENV + QEMU_TARGET=$(printf "${{ matrix.target }}" | tr '[:lower:]' '[:upper:]' | tr '-' '_') + if [ -n "$PREFIX" ]; then + echo "CARGO_TARGET_${QEMU_TARGET}_RUNNER=qemu-${{ matrix.qemu }} -L $PREFIX" >> "$GITHUB_ENV" + else + echo "CARGO_TARGET_${QEMU_TARGET}_RUNNER=qemu-${{ matrix.qemu }}" >> "$GITHUB_ENV" + fi - echo "CC_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-gcc-14" >> $GITHUB_ENV - echo "CXX_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-g++-14" >> $GITHUB_ENV - echo "AR_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-ar" >> $GITHUB_ENV - echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER=loongarch64-linux-gnu-gcc-14" >> $GITHUB_ENV - echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_RUNNER=qemu-loongarch64 -L /usr/loongarch64-linux-gnu" >> $GITHUB_ENV - - mkdir -p ~/.cargo/ - echo "[target.loongarch64-unknown-linux-musl]" >> ~/.cargo/config.toml - echo 'rustflags = ["-C", "target-feature=+crt-static", "-C", "link-self-contained=yes", "-C", "linker=loongarch64-unknown-linux-musl-gcc"]' >> ~/.cargo/config.toml - echo "[target.loongarch64-unknown-linux-gnu]" >> ~/.cargo/config.toml - echo 'rustflags = ["-C", "linker=loongarch64-linux-gnu-gcc-14"]' >> ~/.cargo/config.toml - - echo "/musl/bin" >> $GITHUB_PATH + - name: Set up wasmtime + if: matrix.wasi + uses: bytecodealliance/actions/wasmtime/setup@v1 - - name: Setup cross riscv64 - if: startsWith(matrix.target, 'riscv64') && contains(matrix.target, '-linux-') + - name: Configure wasmtime runner + if: matrix.wasi + shell: bash run: | - sudo apt-get update -y - sudo apt-get install -y \ - clang \ - crossbuild-essential-riscv64 \ - qemu-user + WASI_TARGET=$(printf "${{ matrix.target }}" | tr '[:lower:]' '[:upper:]' | tr '-' '_') + echo "CARGO_TARGET_${WASI_TARGET}_RUNNER=wasmtime" >> "$GITHUB_ENV" - mkdir -p ~/.cargo/ - cat >> ~/.cargo/config.toml <> $GITHUB_ENV - sudo ln -s /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld-linux-riscv64-lp64d.so.1 - - name: Setup wasmtime for wasm32-wasip1 and wasm32-wasip2 - if: matrix.target == 'wasm32-wasip1' || matrix.target == 'wasm32-wasip2' - uses: bytecodealliance/actions/wasmtime/setup@v1 - - name: Setup msys2 toolchains - if: startsWith(matrix.os, 'windows') && endsWith(matrix.target, '-gnu') - uses: msys2/setup-msys2@v2 + - name: Set up msys2 + if: matrix.builder == 'msys2' + uses: msys2/setup-msys2@e9898307ac31d1a803454791be09ab9973336e1c # v2.31.1 with: release: false - - name: Prepare env for windows - if: startsWith(matrix.os, 'windows') && endsWith(matrix.target, '-gnu') + + - name: Prepare msys2 env + if: matrix.builder == 'msys2' + shell: pwsh run: | - # Add symlinks to the target-specific GNU sysroots for Clang New-Item -Path "C:\Program Files\LLVM\x86_64-w64-mingw32" -ItemType SymbolicLink -Value "C:\msys64\mingw64\x86_64-w64-mingw32" New-Item -Path "C:\Program Files\LLVM\i686-w64-mingw32" -ItemType SymbolicLink -Value "C:\msys64\mingw64\i686-w64-mingw32" - # Add paths to GCC executables to PATH echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append echo "C:\msys64\mingw32\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - # Configure CC_ environment variables echo "CC_x86_64_pc_windows_gnu=x86_64-w64-mingw32-gcc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append - echo "CC_i686_pc_windows_gnu=i686-w64-mingw32-gcc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append - # echo "HOST_CC=x86_64-w64-mingw32-gcc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + echo "CC_i686_pc_windows_gnu=i686-w64-mingw32-gcc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + - name: Setup Rust uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} components: rustfmt rust-src + - name: Update deps run: cargo update - - name: Build sys - env: - RUST_LOG: bindgen=warn,bindgen::ir=error,bindgen::codegen=error - BUILD_TARGET: ${{ matrix.target }} - run: | - cargo build ${{ matrix.optimization && '--release' || '' }} --manifest-path sys/Cargo.toml --target ${{ matrix.target }} --features bindgen,update-bindings,logging - cat sys/src/bindings/${{ matrix.target }}.rs - - name: Upload bindings - if: matrix.task == 'bindings' - uses: actions/upload-artifact@v7 - with: - name: bindings-${{ matrix.target }} - path: sys/src/bindings/${{ matrix.target }}.rs - overwrite: true + - name: Build - if: ${{ !matrix.no-build }} + shell: bash env: BUILD_TARGET: ${{ matrix.target }} TARGET: ${{ matrix.target }} run: | - cargo build ${{ matrix.optimization && '--release' || '' }} --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} + if [ "${{ matrix.builder }}" = "zigbuild" ]; then + cargo zigbuild ${{ matrix.optimization && '--release' || '' }} --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} + else + cargo build ${{ matrix.optimization && '--release' || '' }} --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} + fi + - name: Test - if: ${{ !matrix.no-build && !matrix.no-test }} + if: ${{ !matrix.no-test }} timeout-minutes: 12 + shell: bash env: RUST_BACKTRACE: full run: | - # Limit test threads to 1 for QEMU-emulated targets to work around an intermittent + # Limit test threads on QEMU-emulated targets to work around an intermittent # QEMU user-mode emulation bug: "QEMU internal SIGSEGV {code=MAPERR, addr=0x20}" - # This is a race condition in QEMU's thread emulation, not a bug in rquickjs. - ${{ (startsWith(matrix.target, 'loongarch64') || startsWith(matrix.target, 'riscv64') || startsWith(matrix.target, 'aarch64-unknown-linux') || startsWith(matrix.target, 'armv7') || startsWith(matrix.target, 'powerpc64')) && 'RUST_TEST_THREADS=1' || '' }} ${{ matrix.target == 'wasm32-wasip1' && 'CARGO_TARGET_WASM32_WASIP1_RUNNER=wasmtime' || '' }} ${{ matrix.target == 'wasm32-wasip2' && 'CARGO_TARGET_WASM32_WASIP2_RUNNER=wasmtime' || '' }} cargo test ${{ matrix.optimization && '--release' || '' }} --all ${{ (matrix.target == 'wasm32-wasip1' || matrix.target == 'wasm32-wasip2') && '--exclude module-loader' || '' }} --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} - - update-bindings: - if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/') }} - needs: - - test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - name: Download bindings - uses: actions/download-artifact@v8 - with: - pattern: bindings-* - path: sys/src/bindings - merge-multiple: true - - name: Create pull request - uses: peter-evans/create-pull-request@v8 - with: - base: ${{ github.head_ref }} - commit-message: Updated bindings - branch: update-bindings - delete-branch: true - title: Update bindings - body: | - Bindings should be updated to be consistent with latest changes + if [ -n "${{ matrix.qemu }}" ]; then + export RUST_TEST_THREADS=1 + fi + if [ "${{ matrix.builder }}" = "zigbuild" ]; then + cargo-zigbuild test ${{ matrix.optimization && '--release' || '' }} --all --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} + elif [ "${{ matrix.wasi }}" = "true" ]; then + cargo test ${{ matrix.optimization && '--release' || '' }} --all --exclude module-loader --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} + else + cargo test ${{ matrix.optimization && '--release' || '' }} --all --target ${{ matrix.target }} --no-default-features --features ${{ matrix.features }} + fi From 3903039304abdbf4492188a0e81e4d8f9519e51f Mon Sep 17 00:00:00 2001 From: richarddd Date: Mon, 14 Sep 2026 14:34:57 +0200 Subject: [PATCH 2/2] Pin cargo-zigbuild to 0.23.4 for the aarch64 cortex-a53 fix and build loongarch64 natively since zig cc rejects nightly's --no-rosegment flag --- .github/workflows/bindings.yml | 5 ++- .github/workflows/ci.yml | 65 ++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/.github/workflows/bindings.yml b/.github/workflows/bindings.yml index 4105d0cf..306b7371 100644 --- a/.github/workflows/bindings.yml +++ b/.github/workflows/bindings.yml @@ -70,7 +70,10 @@ jobs: if: matrix.builder == 'zigbuild' uses: taiki-e/install-action@7be9fd86bd1707236395105d6e9329dd1511a7e1 # v2.79.0 with: - tool: cargo-zigbuild + # 0.23.0+ fixes zig cc rejecting -Wl,--fix-cortex-a53-843419 on aarch64 + # (rust-cross/cargo-zigbuild#452); install-action's default resolves to + # an older cached version, so pin explicitly. + tool: cargo-zigbuild@0.23.4 - name: Set up msys2 if: matrix.builder == 'msys2' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a03f0363..7f25d148 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,8 +169,8 @@ jobs: # executables fails. Bindings are still regenerated for it via # `.github/workflows/bindings.yml` (sys builds as a static rlib, # which does not trigger lld). - - { task: test, os: ubuntu-24.04, rust: nightly, target: loongarch64-unknown-linux-gnu, features: full-async, builder: zigbuild, qemu: loongarch64 } - - { task: test, os: ubuntu-24.04, rust: nightly, target: loongarch64-unknown-linux-musl, features: full-async, builder: zigbuild, qemu: loongarch64 } + - { task: test, os: ubuntu-24.04, rust: nightly, target: loongarch64-unknown-linux-gnu, features: full-async, builder: native } + - { task: test, os: ubuntu-24.04, rust: nightly, target: loongarch64-unknown-linux-musl, features: full-async, builder: native } # Native targets. - { task: test, os: ubuntu-latest, rust: stable, target: x86_64-unknown-linux-gnu, features: full-async, builder: native } @@ -214,7 +214,10 @@ jobs: if: matrix.builder == 'zigbuild' uses: taiki-e/install-action@7be9fd86bd1707236395105d6e9329dd1511a7e1 # v2.79.0 with: - tool: cargo-zigbuild + # 0.23.0+ fixes zig cc rejecting -Wl,--fix-cortex-a53-843419 on aarch64 + # (rust-cross/cargo-zigbuild#452); install-action's default resolves to + # an older cached version, so pin explicitly. + tool: cargo-zigbuild@0.23.4 - name: Install QEMU user emulation if: matrix.qemu @@ -234,10 +237,6 @@ jobs: LIBC_PKG=libc6-armhf-cross PREFIX=/usr/arm-linux-gnueabihf ;; - loongarch64-unknown-linux-gnu) - LIBC_PKG=libc6-dev-loong64-cross - PREFIX=/usr/loongarch64-linux-gnu - ;; riscv64gc-unknown-linux-gnu) LIBC_PKG=libc6-riscv64-cross PREFIX=/usr/riscv64-linux-gnu @@ -258,6 +257,55 @@ jobs: echo "CARGO_TARGET_${QEMU_TARGET}_RUNNER=qemu-${{ matrix.qemu }}" >> "$GITHUB_ENV" fi + - name: Setup cross loongarch64 + # zig cc rejects nightly rustc's -Wl,--no-rosegment as an unsupported + # linker arg (unlike the aarch64 cortex-a53 case, this isn't fixed in + # any cargo-zigbuild release), so loongarch64 is built natively here + # instead of through zigbuild. + if: startsWith(matrix.target, 'loongarch64') && contains(matrix.target, '-linux-') + run: | + sudo apt-get update -y + sudo apt-get install -y \ + libc6-dev-loong64-cross \ + gcc-14-loongarch64-linux-gnu \ + g++-14-loongarch64-linux-gnu \ + lld \ + qemu-user \ + qemu-user-static + + curl -L --retry 5 https://github.com/musl-cross/musl-cross/releases/latest/download/loongarch64-unknown-linux-musl.tar.xz | tar xJf - + sudo mv loongarch64-unknown-linux-musl /musl + + echo "CC_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV + echo "CXX_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-g++" >> $GITHUB_ENV + echo "AR_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-ar" >> $GITHUB_ENV + echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_LINKER=loongarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV + echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_RUNNER=qemu-loongarch64 -L /musl/loongarch64-unknown-linux-musl/sysroot" >> $GITHUB_ENV + + echo "CC_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-gcc-14" >> $GITHUB_ENV + echo "CXX_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-g++-14" >> $GITHUB_ENV + echo "AR_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-ar" >> $GITHUB_ENV + + # Nightly's -Wl,--no-rosegment isn't supported by ubuntu-24.04's cross ld; + # force lld via a linker wrapper (a rustflags link-arg gets clobbered by the + # job-wide RUSTFLAGS from setup-rust-toolchain). + cat > /usr/local/bin/loongarch64-linux-gnu-gcc-lld <<'WRAP' + #!/bin/sh + exec loongarch64-linux-gnu-gcc-14 -fuse-ld=lld "$@" + WRAP + chmod +x /usr/local/bin/loongarch64-linux-gnu-gcc-lld + + echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER=loongarch64-linux-gnu-gcc-lld" >> $GITHUB_ENV + echo "CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_RUNNER=qemu-loongarch64 -L /usr/loongarch64-linux-gnu" >> $GITHUB_ENV + + mkdir -p ~/.cargo/ + echo "[target.loongarch64-unknown-linux-musl]" >> ~/.cargo/config.toml + echo 'rustflags = ["-C", "target-feature=+crt-static", "-C", "link-self-contained=yes", "-C", "linker=loongarch64-unknown-linux-musl-gcc"]' >> ~/.cargo/config.toml + echo "[target.loongarch64-unknown-linux-gnu]" >> ~/.cargo/config.toml + echo 'rustflags = ["-C", "linker=loongarch64-linux-gnu-gcc-lld"]' >> ~/.cargo/config.toml + + echo "/musl/bin" >> $GITHUB_PATH + - name: Set up wasmtime if: matrix.wasi uses: bytecodealliance/actions/wasmtime/setup@v1 @@ -317,6 +365,9 @@ jobs: run: | # Limit test threads on QEMU-emulated targets to work around an intermittent # QEMU user-mode emulation bug: "QEMU internal SIGSEGV {code=MAPERR, addr=0x20}" + case "${{ matrix.target }}" in + loongarch64-*) export RUST_TEST_THREADS=1 ;; + esac if [ -n "${{ matrix.qemu }}" ]; then export RUST_TEST_THREADS=1 fi