wireguard官方swift代码编译错误的解决办法

流水账:

[ -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

 

Windows

打开你的 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的即可。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

langeldep

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值