如何在JetBrains Goland中构建IPFS(kubo)?

huangapple go评论81阅读模式
英文:

How to build IPFS (kubo) within JetBrains Goland?

问题

我是你的中文翻译助手,以下是翻译好的内容:

我对golang还不熟悉。首先要说的是,我可以使用标准的Go构建kubo(go-ipfs),但在Goland中没有这样做。使用标准的Go.exe构建时,我需要进入带有main模块和主函数的文件夹,然后运行go install

在Goland中重现的步骤:

  1. 安装Goland 2022.2.3
  2. 新建项目 -> 从SCV Git导入:https://github.com/ipfs/kubo
  3. 在C:\Users\Med\GolandProjects\中使用建议的Goland路径存储kubo项目
  4. 在设置中,在GOROOT字段中指定我的Go安装位置。
  5. 在上下文菜单中选择项目(kubo),我按下Run,它要求配置。
  6. 在我按下项目的运行按钮后,它创建了配置:

然后显示以下错误消息:

Error running 'go build github.com/ipfs/kubo': Cannot run program
"C:\Users\Med\AppData\Local\Temp\GoLand___go_build_github_com_ipfs_kubo.exe"
(in directory "C:\Users\Med\Go\kubo"): CreateProcess error=216, This
version of %1 is not compatible with the version of Windows you're
running. Check your computer's system information and then contact the
software publisher

在Web上搜索说错误216意味着操作系统和架构不匹配

它创建了一个小的exe文件,Windows 10无法运行。

我可以构建和运行kubo中的一些小测试程序,但无法构建整个项目。

Go环境:
C:\Users\Med\AppData\Local\Temp\GoLand>go env

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Med\AppData\Local\go-build
set GOENV=C:\Users\Med\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Med\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Med\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\programs\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\programs\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0
-fdebug-prefix-map=C:\Users\Med\AppData\Local\Temp\go-build1544731977=/tmp/go-build
-gno-record-gcc-switches

英文:

I am new to golang. First to say I
can build kubo(go-ipfs) with standard Go but didn't in Goland.
With standard Go.exe build I need to cd to the folder with the main module and main func and only then run: go install

Steps to reproduce in Golnad:

  1. Installed Goland 2022.2.3
  2. New Project - > from SCV Git: https://github.com/ipfs/kubo
  3. Used suggested Goland path within C:\Users\Med\GolandProjects\ to store kubo project
  4. In Settings In the GOROOT field I specified the location of my Go installation.
  5. Selecting project (kubo) in context meny I pressed Run - it asked for configuration.
  6. After I press Run on project it creates configuration:

如何在JetBrains Goland中构建IPFS(kubo)?

Then following error message is shown:

> Error running 'go build github.com/ipfs/kubo': Cannot run program
> "C:\Users\Med\AppData\Local\Temp\GoLand___go_build_github_com_ipfs_kubo.exe"
> (in directory "C:\Users\Med\Go\kubo"): CreateProcess error=216, This
> version of %1 is not compatible with the version of Windows you're
> running. Check your computer's system information and then contact the
> software publisher

Search in Web says error 216 means
mismatch in OS, ARCH.

It creates small exe file that windows 10 cann't run.

I can build and run some small test programs withing kubo - but not thr whole project.

Go env:
C:\Users\Med\AppData\Local\Temp\GoLand>go env

> set GO111MODULE=
> set GOARCH=amd64
> set GOBIN=
> set GOCACHE=C:\Users\Med\AppData\Local\go-build
> set GOENV=C:\Users\Med\AppData\Roaming\go\env
> set GOEXE=.exe
> set GOEXPERIMENT=
> set GOFLAGS=
> set GOHOSTARCH=amd64
> set GOHOSTOS=windows
> set GOINSECURE=
> set GOMODCACHE=C:\Users\Med\go\pkg\mod
> set GONOPROXY=
> set GONOSUMDB=
> set GOOS=windows
> set GOPATH=C:\Users\Med\go
> set GOPRIVATE=
> set GOPROXY=https://proxy.golang.org,direct
> set GOROOT=D:\programs\Go
> set GOSUMDB=sum.golang.org
> set GOTMPDIR=
> set GOTOOLDIR=D:\programs\Go\pkg\tool\windows_amd64
> set GOVCS=
> set GOVERSION=go1.19.1
> set GCCGO=gccgo
> set GOAMD64=v1
> set AR=ar
> set CC=gcc
> set CXX=g++
> set CGO_ENABLED=1
> set GOMOD=NUL
> set GOWORK=
> set CGO_CFLAGS=-g -O2
> set CGO_CPPFLAGS=
> set CGO_CXXFLAGS=-g -O2
> set CGO_FFLAGS=-g -O2
> set CGO_LDFLAGS=-g -O2
> set PKG_CONFIG=pkg-config
> set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0
> -fdebug-prefix-map=C:\Users\Med\AppData\Local\Temp\go-build1544731977=/tmp/go-build
> -gno-record-gcc-switches

答案1

得分: 1

我不明白为什么它能工作,但它确实能工作:
在右侧窗格的项目树中,我选择了"kubo/cmd/ipfs"项目,并从上下文菜单中选择了"Run"。然后,Goland构建了(我认为是)主包,创建了正确大小(60Mb)的可执行文件,并像守护进程一样提供服务:我可以通过WebUI连接,并能够观察之前上传的文件。但这不是守护进程 - 在调试过程中,我看到它不将这样的启动视为守护进程,并作为批处理进程退出。
这是自动创建的配置:

如何在JetBrains Goland中构建IPFS(kubo)?

编译器的输出:

GOROOT=C:\Users\Med\Go\go1.19.1 #gosetup
GOPATH=C:\Users\Med\Go #gosetup
C:\Users\Med\Go\go1.19.1\bin\go.exe build -o C:\Users\Med\AppData\Local\Temp\GoLand\___1go_build_github_com_ipfs_kubo_cmd_ipfs.exe -gcflags "all=-N -l" github.com/ipfs/kubo/cmd/ipfs #gosetup

但我仍然有兴趣了解Go/Goland构建的原理,并鼓励其他人根据这个kubo示例给出解释。

英文:

I didn't understand why it works but it works:
I selected kubo/cmd/ipfs item in the project tree on the right pane and pressed Run from context menu. And Goland built (I think) main package, created executable of correct size (60Mb) and serves like daemon serves: I can connect via WebUI and I'm able to observe my previously uploaded files. But this is not daemon - during debug I see that it do not consider such launch as daemon and exits as batch process.
This is configuration that was automatically created:

如何在JetBrains Goland中构建IPFS(kubo)?

Output of compilator:

GOROOT=C:\Users\Med\Go\go1.19.1 #gosetup
GOPATH=C:\Users\Med\Go #gosetup
C:\Users\Med\Go\go1.19.1\bin\go.exe build -o C:\Users\Med\AppData\Local\Temp\GoLand\___1go_build_github_com_ipfs_kubo_cmd_ipfs.exe -gcflags "all=-N -l" github.com/ipfs/kubo/cmd/ipfs #gosetup

But I'm still interested to understand the principles of Go/Goland build and I encourage others to give explanation based on this kubo example.

huangapple
  • 本文由 发表于 2022年10月4日 04:50:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/73940698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定