1#!/usr/bin/env bash
 2
 3# Install wild-linker official binaries from GitHub Releases.
 4
 5set -euo pipefail
 6
 7WILD_VERSION="${WILD_VERSION:-${1:-0.6.0}}"
 8if [ "$(uname -s)" != "Linux" ]; then
 9    echo "Error: This script is intended for Linux systems only."
10    exit 1
11elif [ -z "$WILD_VERSION" ]; then
12    echo "Usage: $0 [version]"
13    exit 1
14elif which -s wild && wild --version | grep -Fq "$WILD_VERSION" ; then
15    echo "Warning: existing wild $WILD_VERSION found at $(which wild). Skipping installation."
16    exit 0
17fi
18
19if [ "$(whoami)" = root ]; then SUDO=; else SUDO="$(command -v sudo || command -v doas || true)"; fi
20
21ARCH="$(uname -m)"
22WILD_REPO="${WILD_REPO:-https://github.com/davidlattimore/wild}"
23WILD_PACKAGE="wild-linker-${WILD_VERSION}-${ARCH}-unknown-linux-gnu"
24WILD_URL="${WILD_URL:-$WILD_REPO}/releases/download/$WILD_VERSION/${WILD_PACKAGE}.tar.gz"
25DEST_DIR=/usr/local/bin
26
27echo "Downloading from $WILD_URL"
28curl -fsSL --output - "$WILD_URL" \
29    | $SUDO tar -C ${DEST_DIR} --strip-components=1 --no-overwrite-dir -xzf - \
30    "${WILD_PACKAGE}/wild"
31
32cat <<EOF
33Wild is installed to ${DEST_DIR}/wild
34
35To make it your default, add or merge these lines into your ~/.cargo/config.toml:
36
37[target.x86_64-unknown-linux-gnu]
38linker = "clang"
39rustflags = ["-C", "link-arg=--ld-path=wild"]
40
41[target.aarch64-unknown-linux-gnu]
42linker = "clang"
43rustflags = ["-C", "link-arg=--ld-path=wild"]
44EOF