diff --git a/.cargo/config b/.cargo/config index f7717e4..78f3a61 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,3 +1,2 @@ [target.x86_64-unknown-linux-musl] -linker = "/opt/cross/bin/x86_64-linux-musl-gcc" -rustflags = ["-C", "link-args=-static"] +linker = "./linker" diff --git a/Makefile b/Makefile index 04584ca..73ca252 100644 --- a/Makefile +++ b/Makefile @@ -11,4 +11,4 @@ rust: .PHONY: rust-musl rust-musl: - CXX=/opt/cross/bin/x86_64-linux-musl-g++ cargo run --target x86_64-unknown-linux-musl + CROSS_COMPILE=/opt/cross/bin/x86_64-linux-musl- cargo run --target x86_64-unknown-linux-musl diff --git a/linker b/linker new file mode 100755 index 0000000..1cd1874 --- /dev/null +++ b/linker @@ -0,0 +1,18 @@ +#!/bin/bash + +args=() + +for arg in "$@"; do + if [[ $arg = *"Bdynamic"* ]]; then + args+=() # we do not want this arg + elif [[ $arg = *"crti.o"* ]]; then + args+=("$arg" "/opt/cross/lib/gcc/x86_64-linux-musl/9.2.0/crtbeginS.o" "-Bstatic") + elif [[ $arg = *"crtn.o"* ]]; then + args+=("-lgcc" "-lgcc_eh" "-lc" "/opt/cross/lib/gcc/x86_64-linux-musl/9.2.0/crtendS.o" "$arg") + else + args+=("$arg") + fi +done + +echo "RUNNING WITH ARGS: ${args[@]}" +/opt/cross/bin/x86_64-linux-musl-g++ "${args[@]}"