fix: use pure MIPS asm for __atomic_is_lock_free, remove unsupported --defsym
Some checks are pending
Build MIPS Binary / build (push) Waiting to run

This commit is contained in:
spinline
2026-02-07 00:40:39 +03:00
parent f4d0351c5b
commit f99fc4a134
2 changed files with 7 additions and 23 deletions

View File

@@ -34,8 +34,7 @@ jobs:
env: env:
# Ensure we are building a fully static binary # Ensure we are building a fully static binary
# -C link-self-contained=no: Let Zig (the linker) handle CRT objects (crt1.o, etc.) # -C link-self-contained=no: Let Zig (the linker) handle CRT objects (crt1.o, etc.)
# --defsym=__atomic_is_lock_free=... Maps the missing symbol to our shim RUSTFLAGS: "-C target-feature=+crt-static -C link-self-contained=no -C link-arg=-msoft-float"
RUSTFLAGS: "-C target-feature=+crt-static -C link-self-contained=no -C link-arg=-msoft-float -C link-arg=-Wl,--defsym=__atomic_is_lock_free=__atomic_is_lock_free_shim"
CFLAGS_mips_unknown_linux_musl: "-msoft-float" CFLAGS_mips_unknown_linux_musl: "-msoft-float"
run: | run: |
cd backend cd backend

View File

@@ -46,20 +46,18 @@ RUN ARCH=$(dpkg --print-architecture) && \
mv "zig-linux-$ZIG_ARCH-$ZIG_VER" /root/zig && \ mv "zig-linux-$ZIG_ARCH-$ZIG_VER" /root/zig && \
rm zig.tar.xz rm zig.tar.xz
# 5. Fix: Create libatomic.a shim for MIPS # 5. Fix: Create libatomic.a with __atomic_is_lock_free for MIPS
# MIPS musl static build often misses __atomic_is_lock_free. # MIPS musl static build misses __atomic_is_lock_free.
# We create a minimal implementation to satisfy the linker. # We provide it via pure assembly to avoid Clang builtin conflicts.
# We rename the function to avoid builtin conflict and alias it via linker flags later.
RUN . "$HOME/.cargo/env" && \ RUN . "$HOME/.cargo/env" && \
echo '#include <stdbool.h>' > atomic.c && \ printf '.text\n.globl __atomic_is_lock_free\n.type __atomic_is_lock_free, @function\n__atomic_is_lock_free:\n sltiu $v0, $a0, 5\n jr $ra\n nop\n.size __atomic_is_lock_free, .-__atomic_is_lock_free\n' > atomic.s && \
echo 'bool __atomic_is_lock_free_shim(unsigned int size, const volatile void *ptr) { return size <= 4; }' >> atomic.c && \ /root/zig/zig cc -target mips-linux-musl -msoft-float -c -o atomic.o atomic.s && \
/root/zig/zig cc -target mips-linux-musl -msoft-float -c -o atomic.o atomic.c && \
/root/zig/zig ar rcs libatomic.a atomic.o && \ /root/zig/zig ar rcs libatomic.a atomic.o && \
RUST_SYSROOT=$(rustc --print sysroot) && \ RUST_SYSROOT=$(rustc --print sysroot) && \
TARGET_LIB_DIR="$RUST_SYSROOT/lib/rustlib/mips-unknown-linux-musl/lib" && \ TARGET_LIB_DIR="$RUST_SYSROOT/lib/rustlib/mips-unknown-linux-musl/lib" && \
mkdir -p "$TARGET_LIB_DIR" && \ mkdir -p "$TARGET_LIB_DIR" && \
cp libatomic.a "$TARGET_LIB_DIR/" && \ cp libatomic.a "$TARGET_LIB_DIR/" && \
rm atomic.c atomic.o libatomic.a rm atomic.s atomic.o libatomic.a
# 6. Install Tools (Trunk, cargo-zigbuild, wasm-bindgen protocol aligned) # 6. Install Tools (Trunk, cargo-zigbuild, wasm-bindgen protocol aligned)
# We install trunk binary to save time, others via cargo # We install trunk binary to save time, others via cargo
@@ -75,19 +73,6 @@ RUN . "$HOME/.cargo/env" && \
# Install wasm-bindgen-cli (Compiling from source to avoid glibc issues, doing it ONCE here) # Install wasm-bindgen-cli (Compiling from source to avoid glibc issues, doing it ONCE here)
cargo install wasm-bindgen-cli --version 0.2.108 cargo install wasm-bindgen-cli --version 0.2.108
# 6. Fix: Create dummy libatomic.a for MIPS
# openssl-sys demands -latomic, but Zig provides the symbols in compiler-rt.
# We create an empty archive to satisfy the linker.
RUN . "$HOME/.cargo/env" && \
echo '' > atomic.c && \
/root/zig/zig cc -target mips-linux-musl -c -o atomic.o atomic.c && \
/root/zig/zig ar rcs libatomic.a atomic.o && \
RUST_SYSROOT=$(rustc --print sysroot) && \
TARGET_LIB_DIR="$RUST_SYSROOT/lib/rustlib/mips-unknown-linux-musl/lib" && \
mkdir -p "$TARGET_LIB_DIR" && \
cp libatomic.a "$TARGET_LIB_DIR/" && \
rm atomic.c atomic.o libatomic.a
# 7. Install Gitea Act Runner Binary # 7. Install Gitea Act Runner Binary
# We fetch the binary directly to run as the entrypoint # We fetch the binary directly to run as the entrypoint
RUN ARCH=$(dpkg --print-architecture) && \ RUN ARCH=$(dpkg --print-architecture) && \