#!/bin/sh # SPDX-License-Identifier: AGPL-3.0-or-later # # Installs the wild linker (https://github.com/wild-linker/wild) into an Alpine # builder image. Run as root from the Dockerfile, before it drops to `builder`. # # Why wild: linking beavershell is the single longest step of a rebuild, and it # runs every time any crate changes. wild is much faster than both GNU ld (what # the native images got by default) and lld (what the cross image used). # # Why the project's own release rather than `cargo install wild-linker`: # - The musl releases are built with the `mimalloc` feature. wild's # PACKAGING.md singles this out: musl's allocator is *much* worse than # glibc's for wild's allocation pattern, so a plain `cargo install` on # Alpine would give up a large part of the speedup we came for. # - They are built `--profile dist`, and static-pie, so the binary needs # nothing from the image and works in any of the three builders. # - No compile step, so the image stays cheap to rebuild. # # Alpine has no wild package, so this is out-of-band like rustup (see the note # in packaging/alpine/APKBUILD.in about why neither is in makedepends). # # To bump: change VERSION and replace BOTH checksums. `uname -m` values match # wild's asset names exactly, so no arch translation is needed. set -e VERSION=0.10.0 ARCH="$(uname -m)" case "$ARCH" in x86_64) SHA256=2d920a6c21372026c1c2a7711c547b2da33708f93bcaae1da196151bdab69453 ;; aarch64) SHA256=49cfca01b10a4cd15ef4932687bef1708a052828875bc30f5124bb5085c23d40 ;; *) echo "install-wild.sh: no wild musl release for $ARCH" >&2 exit 1 ;; esac NAME="wild-linker-${VERSION}-${ARCH}-unknown-linux-musl" URL="https://github.com/wild-linker/wild/releases/download/${VERSION}/${NAME}.tar.gz" cd /tmp curl --proto '=https' --tlsv1.2 -sSfLO "$URL" echo "${SHA256} ${NAME}.tar.gz" | sha256sum -c - tar -xzf "${NAME}.tar.gz" install -Dm755 "${NAME}/wild" /usr/local/bin/wild # `ld.wild` is what makes clang's -fuse-ld=wild work; wild's PACKAGING.md asks # packagers to ship it. ln -sf /usr/local/bin/wild /usr/local/bin/ld.wild # A directory whose only entry is an `ld` symlink, for gcc. gcc grew # -fuse-ld=wild only in 16.1 (Alpine 3.20 ships 13), so gcc callers pass # -B/usr/local/lib/wild instead: gcc's linker search hits our `ld` first and # finds crt objects, libgcc and everything else in its normal path, since that # is the only file here. install -d /usr/local/lib/wild ln -sf /usr/local/bin/wild /usr/local/lib/wild/ld rm -rf "${NAME}" "${NAME}.tar.gz" # Fail the image build now rather than mid-link if the download was for the # wrong arch or is otherwise unusable. wild --version