Search code examples
gobuildipfsgoland

How to build IPFS (kubo) within JetBrains Goland?


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:

enter image description here

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


Solution

  • 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:

    enter image description here

    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.