xmake
xmake copied to clipboard
Failed to compile golang example project
Xmake 版本
xmake v2.7.7+20230224
操作系统版本和架构
macOS Monterey 12.6.3 / Apple M2
描述问题
在编译使用 xmake create -l go -t console test
命令创建的测试项目时,出现了以下问题:
首先出现以下提示:
note: we need build go for darwin_amd64 only once first! (pass -y or --confirm=y/n/d to skip confirm)?
please input: y (y/n)
如果选择y,会出现以下报错:
error: go: no such tool "compile"
go: no such tool "compile"
go: no such tool "compile"
go: no such tool "compile"
go tool dist: FAILED: /opt/homebrew/Cellar/go/1.20.2/libexec/bin/go install -tags=math_big_pure_go compiler_bootstrap purego bootstrap/cmd/...: exit status 2
且之后无法使用go编译任何程序,必须重装。
如果选择n,会出现以下报错:
error: src/main.go:3:8: could not import fmt (file not found)
期待的结果
正常编译
工程配置
add_rules("mode.debug", "mode.release")
target("test")
set_kind("binary")
add_packages("go")
add_files("src/*.go")
附加信息和错误日志
xmake和go均使用homebrew安装,GO111MODULE开启。
go 目前支持不完善,而且 go 编译工具最近更新变动比较大,也许已经 break 了很多东西。。建议直接使用 go 去构建项目。。
等回头有空我再看看怎么改进下。
看了下,似乎最近版本的 go ,在构建 pkg 时候,它的 make.bash 运行失败了。。具体我也不清楚,它们做了什么调整给 break 了。。得要 go 那边看看了。。https://github.com/golang/go/issues/59515
另外,你这的 go 安装也不完整,go/pkg/darwin_amd64
下没东西,所以会导致 xmake 自动去 build go pkg。。否则 go 的所有基础 pkg 都用不了。。然后这个 build pkg 失败了。。
如果安装完整的话,按理 pkg/darwin_amd64
应该带着的,也就不会去 build 它。
另外,你这的 go 安装也不完整,
go/pkg/darwin_amd64
下没东西,所以会导致 xmake 自动去 build go pkg。。否则 go 的所有基础 pkg 都用不了。。然后这个 build pkg 失败了。。如果安装完整的话,按理
pkg/darwin_amd64
应该带着的,也就不会去 build 它。
看了一下 $GOPATH/go/pkg
下面只有 mod
和 sumdb
两个文件夹……
另外我是 arm64 架构,也需要有 darwin_amd64
吗?
看了下。似乎 go 1.20 以上大改过了。。
之前的低版本:
usr/local/Cellar/go/1.19.x/libexec/pkg/darwin_amd64/
下有 std fmt.a 等标准库,不管是 arm64 还是 amd64,如果是 arm64 那就是在 darwin_arm64 目录下 。。必须要有一份 std fmt 等库文件的,否则编译引用到相关库会失败,但是通常 brew 帮你自动编译安装好了。。所以低版本的 xmake 基本上可以直接用,不需要额外对 std 编译,除非是走交叉编译才需要。。
现在的新版本
usr/local/Cellar/go/1.20.3/libexec/pkg/darwin_amd64/
没有这个目录了,似乎整体结构和构件流程变了。go build 会自动取临时编译 std 等库来用,具体怎么编译 std 我还不太清楚,得花时间分析。所以暂时 1.20 以上 go 暂时支持不了。。
packagefile flag=/Users/ruki/Library/Caches/go-build/22/2247f9978d3d4006f55e9b4f9656a0f9b7eccee3296c9f02d88d1097b7928715-d
packagefile fmt=/Users/ruki/Library/Caches/go-build/dd/dd642792b2010d210bbeae67dbc0c6d52b0359a4423190a71f940f8ad557ccac-d
packagefile os=/Users/ruki/Library/Caches/go-build/4c/4c50c7d932f181691143a39e9e7adcd443280f3d9be2bc20c8ea465fb28c744d-d
以我的最新的观察 使用xmake编译go语言的时候 go如果安装在D盘 xmake会导致D:\Program Files\Go\pkg\tool\windows_amd64 目录下文件被清空
而直接使用go build不会出现此问题
Bot detected the issue body's language is not English, translate it automatically.
With my latest observation When using xmake to compile go language If go is installed on the D drive xmake will result in D:\Program Files\Go\pkg\tool\windows_amd64 The files in the directory are cleared
This problem will not occur if you use go build directly.
go 后来更新后,很多被 break 了。。最近也没时间改进,等回头有空再看看吧
Bot detected the issue body's language is not English, translate it automatically.
After go was later updated, many of them were broken. . I haven’t had time to improve it recently, so I’ll take a look at it later when I have time.