From ed26ff6e137500cafe7ac71ebf110c867bdee6b6 Mon Sep 17 00:00:00 2001 From: Bruno Verachten Date: Wed, 8 Apr 2026 10:10:43 +0200 Subject: [PATCH] ci: fix riscv64 LLVM cross-compilation (tblgen native build) Setting CC/CXX as Docker ENV vars caused LLVM's native tblgen sub-build to also use the riscv64 cross-compiler, producing an riscv64 binary that fails to run on the x86_64 host: Exec format error: llvm-min-tblgen Fix: pass the cross-compiler via CMAKE_C/CXX_COMPILER cmake flags instead (cmake cache vars are not inherited by subprocess cmake invocations, so LLVM's native build finds the host compiler). Also pass CMAKE_SYSTEM_NAME=Linux/CMAKE_SYSTEM_PROCESSOR=riscv64 to LLVM via WASI_SDK_CI_TOOLCHAIN_LLVM_CMAKE_ARGS so LLVM sets CMAKE_CROSSCOMPILING=TRUE and triggers the native/target build split, matching the pattern used by the macOS matrix entries. Signed-off-by: Bruno Verachten --- .github/workflows/main.yml | 5 +++++ ci/docker/Dockerfile.riscv64-linux | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 78f7114..0262f5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,9 +34,14 @@ jobs: cross_cmake_args: >- -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 + -DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc + -DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++ -DWASI_SDK_LLDB=OFF env: WASI_SDK_CI_SKIP_SYSROOT: 1 + WASI_SDK_CI_TOOLCHAIN_LLVM_CMAKE_ARGS: >- + -DCMAKE_SYSTEM_NAME=Linux + -DCMAKE_SYSTEM_PROCESSOR=riscv64 - artifact: arm64-macos os: macos-14 diff --git a/ci/docker/Dockerfile.riscv64-linux b/ci/docker/Dockerfile.riscv64-linux index 6012568..f4456ec 100644 --- a/ci/docker/Dockerfile.riscv64-linux +++ b/ci/docker/Dockerfile.riscv64-linux @@ -16,13 +16,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ccache \ && rm -rf /var/lib/apt/lists/* -# Set the cross-compiler as the default so that cmake picks it up via CC/CXX -# and sets CMAKE_CROSSCOMPILING=TRUE, which causes LLVM to build a native -# tablegen before cross-compiling the rest of the toolchain. -ENV CC=riscv64-linux-gnu-gcc -ENV CXX=riscv64-linux-gnu-g++ - # Cargo needs an explicit linker when cross-compiling for riscv64. +# The C/C++ cross-compiler is passed via CMAKE_C/CXX_COMPILER cmake flags +# rather than CC/CXX env vars so that LLVM's native tblgen sub-build can +# still find the host compiler (cmake cache vars are not inherited by +# subprocess cmake invocations, but env vars are). ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-linux-gnu-gcc # Tell programs to cache in a location that both isn't a `--volume` mounted root