| 1 | #!/bin/sh |
| 2 | # rustc's linker for the Mac OS X 10.6 targets: links against the 10.6 SDK (see |
| 3 | # `remote.sh sdk`), so an import 10.6 lacks fails here, plus the shims in rt/. |
| 4 | # rustc clamps the deployment target to 10.12; this pins it back to 10.6. |
| 5 | set -eu |
| 6 | here=$(cd "$(dirname "$0")" && pwd) |
| 7 | sdk=${SNOW_LEOPARD_SDK:-$here/../../target/snow-leopard/MacOSX10.6.sdk} |
| 8 | [ -d "$sdk" ] || { echo "link.sh: no 10.6 SDK at $sdk; run remote.sh sdk" >&2; exit 1; } |
| 9 | arch=x86_64 |
| 10 | prev= |
| 11 | for arg; do |
| 12 | shift |
| 13 | case "$arg" in |
| 14 | -mmacosx-version-min=*) arg=-mmacosx-version-min=10.6 ;; |
| 15 | esac |
| 16 | # 10.6 keeps these inside ApplicationServices, which re-exports them to its clients. |
| 17 | if [ "$prev" = -framework ]; then |
| 18 | case "$arg" in |
| 19 | CoreGraphics | CoreText | ImageIO | ColorSync) arg=ApplicationServices ;; |
| 20 | # Test binaries whose dev-dependencies take draw's wgpu backend (ui, canvas) |
| 21 | # name Metal, which 10.6 lacks; nothing they run on 10.6 calls into it. |
| 22 | Metal) arg=Foundation ;; |
| 23 | # 10.7's; rt/avfoundation.c stands in for what the app imports from them. |
| 24 | AVFoundation | CoreMedia) arg=Foundation ;; |
| 25 | esac |
| 26 | fi |
| 27 | [ "$prev" = -arch ] && arch=$arg |
| 28 | prev=$arg |
| 29 | set -- "$@" "$arg" |
| 30 | done |
| 31 | work=$(mktemp -d "${TMPDIR:-/tmp}/snow-leopard-link.XXXXXX") |
| 32 | trap 'rm -rf "$work"' EXIT |
| 33 | for source in "$here"/rt/*.c; do |
| 34 | clang -arch "$arch" -isysroot "$sdk" -mmacosx-version-min=10.6 -O2 -Wall \ |
| 35 | -c "$source" -o "$work/$(basename "$source" .c).o" |
| 36 | done |
| 37 | # shims.o overrides libSystem, so it links as an object; the rest fill in functions later |
| 38 | # systems added, from an archive, so only binaries calling them pull in their frameworks. |
| 39 | ar rcs "$work/libsnow_leopard.a" $(ls "$work"/*.o | grep -v /shims.o) |
| 40 | status=0 |
| 41 | clang -isysroot "$sdk" "$@" "$work/shims.o" "$work/libsnow_leopard.a" 2>"$work/log" || status=$? |
| 42 | # rustc's objects claim 10.12; ld-prime's stub deprecation is noise for a frozen SDK. |
| 43 | grep -v -e "was built for newer 'macOS' version (10.12)" -e "dylib stub (MH_DYLIB_STUB)" \ |
| 44 | -e "no platform load command found in .*crt1" "$work/log" >&2 || true |
| 45 | exit $status |