流水账:
[ -n "/usr/local/Cellar/go/1.16.3/libexec" ]
mkdir -p "/Users/zhh/Desktop/Build/Intermediates.noindex/WireGuard.build/Debug/wireguard-go-bridge/goroot"
rsync -a --delete --exclude=pkg/obj/go-build "/usr/local/Cellar/go/1.16.3/libexec/" "/Users/zhh/Desktop/Build/Intermediates.noindex/WireGuard.build/Debug/wireguard-go-bridge/goroot/"
cat goruntime-*.diff | patch -p1 -f -N -r- -d "/Users/zhh/Desktop/Build/Intermediates.noindex/WireGuard.build/Debug/wireguard-go-bridge/goroot"
patching file src/runtime/sys_darwin.go
Hunk #1 FAILED at 469.
1 out of 1 hunk FAILED -- saving rejects to file -
patching file src/runtime/sys_darwin_amd64.s
Hunk #1 succeeded at 114 (offset 5 lines).
patching file src/runtime/sys_darwin_arm64.s
Hunk #1 succeeded at 143 (offset 8 lines).
make: *** [/Users/zhh/Desktop/Build/Intermediates.noindex/WireGuard.build/Debug/wireguard-go-bridge/goroot/.prepared] Error 1
Command ExternalBuildToolExecution failed with a nonzero exit code
这个问题的原因是 go的环境配置不对造成的。
修改makefile文件,强制设置REAL_GOROOT,BUILD_GOROOT
REAL_GOROOT := /usr/local/Cellar/go/1.16.3/libexec
BUILD_GOROOT := $(BUILDDIR)/goroot
GOBIN := $(REAL_GOROOT)/bin/go
$(warning $(REAL_GOROOT))
$(warning $(BUILD_GOROOT))
export GOROOT := $(BUILDDIR)/goroot
$(BUILD_GOROOT)/.prepared:
[ -n "$(REAL_GOROOT)" ]
mkdir -p "$(BUILD_GOROOT)"
rsync -a --delete --exclude=pkg/obj/go-build "$(REAL_GOROOT)/" "$(BUILD_GOROOT)/"
touch "$@"
define libwg-go-a
$(BUILDDIR)/libwg-go-$(1).a: export CGO_ENABLED := 1
$(BUILDDIR)/libwg-go-$(1).a: export CGO_CFLAGS := $(CFLAGS_PREFIX) $(ARCH)
$(BUILDDIR)/libwg-go-$(1).a: export CGO_LDFLAGS := $(CFLAGS_PREFIX) $(ARCH)
$(BUILDDIR)/libwg-go-$(1).a: export GOOS := darwin
$(BUILDDIR)/libwg-go-$(1).a: export GOARCH := $(GOARCH_$(1))
$(BUILDDIR)/libwg-go-$(1).a: $(BUILD_GOROOT)/.prepared go.mod
$(GOBIN) build -tags ios -ldflags=-w -trimpath -v -o "$(BUILDDIR)/libwg-go-$(1).a" -buildmode c-archive
rm -f "$(BUILDDIR)/libwg-go-$(1).h"
endef
$(foreach ARCH,$(ARCHS),$(eval $(call libwg-go-a,$(ARCH))))
$(DESTDIR)/wireguard-go-version.h: $(BUILD_GOROOT)/.prepared go.mod
$(GOBIN) list -m golang.zx2c4.com/wireguard | sed -n 's/.*v\([0-9.]*\).*/#define WIREGUARD_GO_VERSION "\1"/p' > "$@"
$(DESTDIR)/libwg-go.a: $(foreach ARCH,$(ARCHS),$(BUILDDIR)/libwg-go-$(ARCH).a)
@mkdir -vp "$(DESTDIR)"
$(LIPO) -create -output "$@" $^
在终端是设置环境变量
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct
或者
$ export GO111MODULE=on
$ export GOPROXY=https://goproxy.cn
或者
$ echo "export GO111MODULE=on" >> ~/.profile
$ echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
$ source ~/.profile
打开你的 PowerShell 并执行
C:\> $env:GO111MODULE = "on"
C:\> $env:GOPROXY = "https://goproxy.cn"
或者
1. 打开“开始”并搜索“env”
2. 选择“编辑系统环境变量”
3. 点击“环境变量…”按钮
4. 在“<你的用户名> 的用户变量”章节下(上半部分)
5. 点击“新建…”按钮
6. 选择“变量名”输入框并输入“GO111MODULE”
7. 选择“变量值”输入框并输入“on”
8. 点击“确定”按钮
9. 点击“新建…”按钮
10. 选择“变量名”输入框并输入“GOPROXY”
11. 选择“变量值”输入框并输入“https://goproxy.cn”
12. 点击“确定”按钮
如果下面的报错
2021-04-12 18:15:29.129793-0700 WireGuard[2426:22357] Unable to add config to keychain: -60005
2021-04-12 18:15:29.134784-0700 WireGuard[2426:22357] Add: Saving configuration failed: Error Domain=NEVPNErrorDomain Code=1 "Missing protocol or protocol has invalid type" UserInfo={NSLocalizedDescription=Missing protocol or protocol has invalid type}
这个问题的原因是你run的target是iOS的, 在macOS上是无法运行iOS的app的, 把启动的target改为for macOS的即可。