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 <gounthar@gmail.com>
pull/621/head
Bruno Verachten 3 months ago
parent 92ae26da05
commit ed26ff6e13
No known key found for this signature in database
GPG Key ID: E7EAD7209D3ECCD3

@ -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

@ -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

Loading…
Cancel
Save