| 1 | #!/bin/sh |
| 2 | # cargo for Linux from macOS or Linux: `cargo.sh ARCH COMMAND ARGS...`, ARCH x86_64 or aarch64. |
| 3 | # zig compiles C and links against glibc 2.17, Rust's own floor, which reaches back to RHEL 7, |
| 4 | # Debian 8 and Ubuntu 14.04. |
| 5 | set -eu |
| 6 | here=$(cd "$(dirname "$0")" && pwd) |
| 7 | case ${1:-} in |
| 8 | x86_64 | aarch64) ;; |
| 9 | *) |
| 10 | echo "usage: $0 x86_64|aarch64 COMMAND ARGS..." >&2 |
| 11 | exit 2 |
| 12 | ;; |
| 13 | esac |
| 14 | arch=$1 command=$2 |
| 15 | shift 2 |
| 16 | command -v zig >/dev/null || { echo "zig is required as the cross linker" >&2; exit 1; } |
| 17 | triple=$arch-unknown-linux-gnu |
| 18 | rustup target add "$triple" >/dev/null |
| 19 | variable=$(echo "$triple" | tr - _) |
| 20 | # The build id ties an executable to its published .debug file. |
| 21 | env "CARGO_TARGET_$(echo "$triple" | tr 'a-z-' 'A-Z_')_LINKER=$here/cc.sh" \ |
| 22 | "CC_$variable=$here/cc.sh" "AR_$variable=$here/ar.sh" \ |
| 23 | ZIG_TARGET="$arch-linux-gnu.2.17" \ |
| 24 | cargo "$command" --target "$triple" \ |
| 25 | --config "target.$triple.rustflags=['-C','link-arg=-Wl,--build-id']" "$@" |