Skip to content

Commit c9405ec

Browse files
committed
(macOS) fix: build script for WireGuard
1 parent 5fbd776 commit c9405ec

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

daemon/References/macOS/scripts/build-wireguard.sh

+61-10
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,81 @@ BASE_DIR="$(pwd)" #set base folder of script location
1515
BUILD_DIR=${BASE_DIR}/../_deps/wg_build # work directory
1616
INSTALL_DIR=${BUILD_DIR}/../wg_inst
1717

18+
# Function to set up temporary Go environment
19+
# It downloads the specified Go version and sets up the environment variables
20+
# Arguments:
21+
# $1: Go version to download
22+
setup_go_env() {
23+
local GO_VERSION=$1
24+
local TEMP_GOROOT="${BUILD_DIR}/go-${GO_VERSION}"
25+
local TEMP_GOPATH="${BUILD_DIR}/gopath"
26+
27+
# Get system architecture
28+
local ARCH="$(uname -m)"
29+
if [ "${ARCH}" != "x86_64" ] && [ "${ARCH}" != "arm64" ]; then
30+
echo "ERROR: Unsupported architecture: ${ARCH}"
31+
exit 1
32+
fi
33+
34+
# Create GOPATH directory if it doesn't exist
35+
mkdir -p "${TEMP_GOPATH}"
36+
37+
# Check if Go is already installed in the expected location
38+
local NEED_DOWNLOAD=true
39+
if [ -d "${TEMP_GOROOT}" ] && [ -f "${TEMP_GOROOT}/bin/go" ]; then
40+
NEED_DOWNLOAD=false
41+
fi
42+
43+
if [ "$NEED_DOWNLOAD" = true ]; then
44+
echo "Downloading Go ${GO_VERSION} for architecture ${ARCH}..."
45+
mkdir -p "${TEMP_GOROOT}"
46+
curl -sSL "https://go.dev/dl/go${GO_VERSION}.darwin-${ARCH}.tar.gz" | tar -xz -C "${TEMP_GOROOT}" --strip-components=1
47+
fi
48+
49+
# Use the temporary Go installation
50+
export PATH="${TEMP_GOROOT}/bin:$PATH"
51+
export GOROOT="${TEMP_GOROOT}"
52+
export GOPATH="${TEMP_GOPATH}"
53+
54+
# Verify Go installation
55+
echo "Verifying Go installation..."
56+
go version
57+
if [ $? -ne 0 ]; then
58+
echo "Failed to set up Go environment"
59+
exit 1
60+
fi
61+
}
62+
1863
echo "******** Creating work-folder (${BUILD_DIR})..."
64+
65+
if [ -d "${BUILD_DIR}" ]; then
66+
# Ensure the build directory is writable, as Go makes files in the module cache read-only
67+
chmod -R +w "${BUILD_DIR}"
68+
fi
1969
rm -rf ${BUILD_DIR}
2070
rm -rf ${INSTALL_DIR}
2171
mkdir -pv ${BUILD_DIR}
2272
mkdir -pv ${INSTALL_DIR}
2373

74+
echo "******** Setting up Go environment version ${GO_VERSION}..."
75+
# Use the temporary Go v1.22.12 environment because 'wireguard-go' fails when using Go >= 1.23
76+
setup_go_env "1.22.12" # TODO: Remove this when wireguard-go supports latest Go versions
2477

25-
echo "******** Cloning WireGuard-go sources..."
78+
echo "******** Cloning WireGuard-go sources (version ${WG_GO_VER})..."
2679
cd ${BUILD_DIR}
27-
git clone https://git.zx2c4.com/wireguard-go/
80+
git clone --branch "${WG_GO_VER}" --depth 1 https://git.zx2c4.com/wireguard-go/
2881
cd wireguard-go
29-
echo "******** Checkout wireguard-go version (${WG_GO_VER})..."
30-
git checkout ${WG_GO_VER}
82+
3183
echo "******** Compiling 'wireguard-go'..."
32-
CGO_CFLAGS=-mmacosx-version-min=10.10 CGO_LDFLAGS=-mmacosx-version-min=10.10 make
84+
CGO_ENABLED=1 CGO_CFLAGS=-mmacosx-version-min=10.14 CGO_LDFLAGS=-mmacosx-version-min=10.14 make
3385

34-
echo "******** Cloning wireguard-tools sources..."
86+
echo "******** Cloning wireguard-tools sources (version ${WG_TOOLS_VER})..."
3587
cd ${BUILD_DIR}
36-
git clone https://git.zx2c4.com/wireguard-tools/
88+
git clone --branch "${WG_TOOLS_VER}" --depth 1 https://git.zx2c4.com/wireguard-tools/
3789
cd wireguard-tools/src
38-
echo "******** Checkout wireguard-tools version (${WG_TOOLS_VER})..."
39-
git checkout ${WG_TOOLS_VER}
90+
4091
echo "******** Compiling 'wireguard-tools'..."
41-
CFLAGS=-mmacosx-version-min=10.10 LDFLAGS=-mmacosx-version-min=10.10 make
92+
CFLAGS=-mmacosx-version-min=10.14 LDFLAGS=-mmacosx-version-min=10.14 make
4293

4394
echo "********************************"
4495
echo "******** BUILD COMPLETE ********"

0 commit comments

Comments
 (0)