| build: fix musl cross-compilation for aarch64/riscv64/loongarch64 Problem: - Cross-compiling to musl targets using glibc cross-compilers causes undefined references to fopen64, fseeko64, ftello64, mkstemp64, etc. - mlua-sys builds its own Lua library that references these *64 functions - musl libc doesn't provide these functions (it uses 64-bit file ops by default) - riscv64/loongarch64 builds were producing dynamically linked binaries instead of statically linked ones Solution: 1. Add missing shim functions (fseeko64, ftello64, mkstemp64) to musl_compat.c 2. Add stdlib.h include for mkstemp() declaration 3. Define off64_t type for musl compatibility 4. Fix ar command: use 'ar rs' to append instead of 'ar rcs' which replaces 5. Add add_musl_compat_to_mlua() function to inject shims into mlua-sys's liblua5.4.a after it's built 6. Implement two-pass build for cross-compilation: - First pass builds mlua-sys's Lua - Then add musl_compat.o to the library - Retry if linking failed due to *64 undefined references 7. Add -C target-feature=+crt-static to RUSTFLAGS for all architectures to ensure static CRT linkage Root Cause Analysis: - glibc cross-compiler headers cause *64 function calls even with -D_FILE_OFFSET_BITS=64 -U_LARGEFILE64_SOURCE flags - mlua-sys ignores LUA_LIB/LUA_LIB_NAME and builds its own Lua - Rust's musl targets for riscv64/loongarch64 don't enable crt-static by default Fixes: make release-aarch64 error: undefined reference to 'fopen64' undefined reference to 'fseeko64' undefined reference to 'ftello64' undefined reference to 'mkstemp64' Signed-off-by: Wu Fengguang <wfg@mail.ustc.edu.cn> | 4 个月前 |