@@ -183,19 +183,37 @@ detect_container_engine() {
183183 return 0
184184}
185185
186- # Check prerequisites
187- check_prerequisites () {
188- # Check for qemu (for cross-platform emulation)
189- if ! command_exists qemu-user-static && ! command_exists qemu-aarch64-static; then
186+ # Check QEMU/binfmt
187+ check_qemu_binfmt () {
188+ local cross_qemu=0
189+
190+ # Check if binfmt_misc is mounted and QEMU handlers are enabled
191+ if [[ -d " /proc/sys/fs/binfmt_misc" ]]; then
192+ if grep -qi ' enabled' " /proc/sys/fs/binfmt_misc/qemu-arm" 2> /dev/null || \
193+ grep -qi ' enabled' " /proc/sys/fs/binfmt_misc/qemu-aarch64" 2> /dev/null; then
194+ log_info " QEMU binfmt_misc handlers are registered and enabled"
195+ cross_qemu=1
196+ fi
197+ fi
198+
199+ # Fallback: check for qemu-user-static binaries in PATH
200+ if [[ " ${cross_qemu} " -eq 0 ]]; then
201+ if command_exists qemu-user-static & > /dev/null || \
202+ command_exists qemu-aarch64-static & > /dev/null; then
203+ log_info " QEMU user-static binaries found in PATH"
204+ cross_qemu=1
205+ fi
206+ fi
207+
208+ if [[ " ${cross_qemu} " -eq 0 ]]; then
190209 log_error " QEMU user emulation not found. Cross-platform builds may fail."
191210 log_error " Install with: sudo apt-get install qemu-user-static (Debian/Ubuntu)"
192211 log_error " sudo pacman -S qemu-user-static (Arch)"
193212 log_error " Github Actions: https://github.com/docker/setup-qemu-action"
194213 echo " "
195214 return 1
196- else
197- log_verbose " QEMU user emulation available"
198215 fi
216+ return 0
199217}
200218
201219# Get the default RUST TARGET
@@ -478,6 +496,12 @@ if [[ "\${CONTAINER_RUST_TARGET}" == *"riscv64"* ]]; then
478496 }
479497 fi
480498 fi
499+
500+ # Remove any occurrences of '-C link-self-contained=yes'
501+ if [[ -n "\$ {CONTAINER_RUSTFLAGS}" ]]; then
502+ CONTAINER_RUSTFLAGS_TMP="\$ (echo "\$ {CONTAINER_RUSTFLAGS}" | sed -E 's/-C[[:space:]]+link-self-contained[[:space:]]*=[[:space:]]*yes//g' | xargs)"
503+ export CONTAINER_RUSTFLAGS="\$ {CONTAINER_RUSTFLAGS_TMP}"
504+ fi
481505else
482506 echo "Standard toolchain setup for target: \$ {CONTAINER_RUST_TARGET}"
483507 export RUST_TARGET="\$ {CONTAINER_RUST_TARGET}"
@@ -506,8 +530,8 @@ if [[ "\${CONTAINER_RBUILD_STATIC}" == "1" ]]; then
506530 rust_flags+=("-C" "target-feature=+crt-static")
507531 rust_flags+=("-C" "default-linker-libraries=yes")
508532
509- # Only add link-self-contained for non-GNU targets
510- if [[ "\$ {RUST_TARGET}" != *"gnu"* ]]; then
533+ # Only add link-self-contained for non-GNU/custom targets
534+ if [[ "\$ {RUST_TARGET}" != *"gnu"* && " \$ {RUST_TARGET}" != *"alpine"* ]]; then
511535 rust_flags+=("-C" "link-self-contained=yes")
512536 fi
513537
@@ -683,9 +707,9 @@ main() {
683707 exit 1
684708 fi
685709
686- # Check prerequisites
687- check_prerequisites
688- # if ! check_prerequisites ; then
710+ # Check QEMU Binfmt
711+ check_qemu_binfmt
712+ # if ! check_qemu_binfmt ; then
689713 # exit 1
690714 # fi
691715
0 commit comments