@@ -15,30 +15,81 @@ BASE_DIR="$(pwd)" #set base folder of script location
15
15
BUILD_DIR=${BASE_DIR} /../_deps/wg_build # work directory
16
16
INSTALL_DIR=${BUILD_DIR} /../wg_inst
17
17
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
+
18
63
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
19
69
rm -rf ${BUILD_DIR}
20
70
rm -rf ${INSTALL_DIR}
21
71
mkdir -pv ${BUILD_DIR}
22
72
mkdir -pv ${INSTALL_DIR}
23
73
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
24
77
25
- echo " ******** Cloning WireGuard-go sources..."
78
+ echo " ******** Cloning WireGuard-go sources (version ${WG_GO_VER} ) ..."
26
79
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/
28
81
cd wireguard-go
29
- echo " ******** Checkout wireguard-go version (${WG_GO_VER} )..."
30
- git checkout ${WG_GO_VER}
82
+
31
83
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
33
85
34
- echo " ******** Cloning wireguard-tools sources..."
86
+ echo " ******** Cloning wireguard-tools sources (version ${WG_TOOLS_VER} ) ..."
35
87
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/
37
89
cd wireguard-tools/src
38
- echo " ******** Checkout wireguard-tools version (${WG_TOOLS_VER} )..."
39
- git checkout ${WG_TOOLS_VER}
90
+
40
91
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
42
93
43
94
echo " ********************************"
44
95
echo " ******** BUILD COMPLETE ********"
0 commit comments