Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopls: spawns cc1 processes on file save when using imports that use cgo #268

Closed
elegos opened this issue Jun 30, 2020 · 10 comments
Closed
Labels
FrozenDueToAge upstream-tools Issues that are caused by problems in the tools that the extension depends on. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@elegos
Copy link

elegos commented Jun 30, 2020

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.14.3 linux/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.46.1
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.15.0
  • Run go env to get the go development environment details
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/elegos/.cache/go-build"
GOENV="/home/elegos/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/elegos/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build151379296=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

{
    "editor.codeActionsOnSave": {
        "source.fixAll": true
    },
    "go.formatTool": "goimports",
    "go.useLanguageServer": true,
    "git.confirmSync": false
}

Describe the bug

Whenever I try to save my go sources that import a dependency which makes use of cgo, the file save is blocked until all the cc1 instances that have been spawned (using 100% of a thread each) end, which usually takes ~10 seconds

Steps to reproduce the behavior:

  1. write a source which imports "github.com/therecipe/qt/widgets", like this:
package whatever

import (
	"github.com/therecipe/qt/widgets"
)

// InstagoMainWindow the main window
type InstagoMainWindow struct {
	widgets.QMainWindow
}

// BuildInstagoMainWindow generate a new main window
func BuildInstagoMainWindow() InstagoMainWindow {
	mw := InstagoMainWindow{}

	return mw
}
  1. Save (CTRL+S)
  2. Multiple cc1 processes will spawn, temporarely preventing you to save the file (follows a filtered ps aux command):
elegos      9494  100  0.3  78688 55912 ?        R    09:09   0:25 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1 -quiet -I /tmp/go-build871050079/b035/ -I . /tmp/cgo-gcc-input-836666895.c -quiet -dumpbase cgo-gcc-input-836666895.c -m64 -mtune=generic -march=x86-64 -auxbase-strip /tmp/go-build871050079/b035//_cgo_.o -gdwarf-2 -O0 -Wno-error -w -o /tmp/ccud6fE1.s
elegos      9496  101  0.3  80732 56324 ?        R    09:09   0:25 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1 -quiet -I /tmp/go-build186212497/b035/ -I . /tmp/cgo-gcc-input-162233745.c -quiet -dumpbase cgo-gcc-input-162233745.c -m64 -mtune=generic -march=x86-64 -auxbase-strip /tmp/go-build186212497/b035//_cgo_.o -gdwarf-2 -O0 -Wno-error -w -o /tmp/cc5ImAsa.s
elegos      9882  101  0.3  76604 53680 ?        R    09:09   0:22 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1 -quiet -I /tmp/go-build192614965/b035/ -I . /tmp/cgo-gcc-input-928280638.c -quiet -dumpbase cgo-gcc-input-928280638.c -m64 -mtune=generic -march=x86-64 -auxbase-strip /tmp/go-build192614965/b035//_cgo_.o -gdwarf-2 -O0 -Wno-error -w -o /tmp/ccVYw7oo.s
elegos     10079  100  0.2  71908 48400 ?        R    09:09   0:17 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1 -quiet -I /tmp/go-build052863757/b035/ -I . /tmp/cgo-gcc-input-787651463.c -quiet -dumpbase cgo-gcc-input-787651463.c -m64 -mtune=generic -march=x86-64 -auxbase-strip /tmp/go-build052863757/b035//_cgo_.o -gdwarf-2 -O0 -Wno-error -w -o /tmp/ccv0Umob.s
elegos     10087  102  0.2  69748 45692 ?        R    09:10   0:14 /usr/libexec/gcc/x86_64-redhat-linux/10/cc1 -quiet -I /tmp/go-build611592304/b035/ -I . /tmp/cgo-gcc-input-696381330.c -quiet -dumpbase cgo-gcc-input-696381330.c -m64 -mtune=generic -march=x86-64 -auxbase-strip /tmp/go-build611592304/b035//_cgo_.o -gdwarf-2 -O0 -Wno-error -w -o /tmp/ccoOkvBS.s

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

@hyangah
Copy link
Contributor

hyangah commented Jun 30, 2020

@stamblerre @heschik What is the current status of cgo support in the language server?

My understanding is completely avoiding invocation of cgo tool and c compilation isn't
possible because it's necessary to extract the type info, but I see various progress and improvement
has made for golang/go#35720 and golang/go#35721,
and some will require go1.15.

@hyangah hyangah added the upstream-tools Issues that are caused by problems in the tools that the extension depends on. label Jun 30, 2020
@hyangah hyangah changed the title vscode spawns cc1 processes on file save when using imports that use cgo gopls: spawns cc1 processes on file save when using imports that use cgo Jun 30, 2020
@stamblerre
Copy link
Contributor

Heschi can probably speak to this a bit more than I can, but significant progress has been made for users of Go 1.15. gopls now has a command to re-run the cgo tool on-demand.

@heschi
Copy link
Contributor

heschi commented Jun 30, 2020

For a program that doesn't directly use cgo, cgo compilation should only happen once, but it has to completely finish. Until it does, each save will probably kick off a new compilation process. Note that each of those are running the same compilation step with different working directories.

By now I would expect this to be resolved. If not, please run go build, wait for it to finish, and then run it again. The second invocation should be instant, and gopls should no longer trigger cgo. If not, we can try to investigate further.

@elegos
Copy link
Author

elegos commented Jun 30, 2020

@heschik it's actually happening for each file which references a file which includes that dependency (i.e. a main.go file that references that InstagoMainWindow.go file). So every time I create a new file it will keep my CPU busy for ~a minute. Though yes, after it finishes it will not spawn cc1 processes anymore. Can't this process, which is highly expensive CPU-wise, be queued and executed asynchronously, so that you can keep on saving and working?

@heschi
Copy link
Contributor

heschi commented Jun 30, 2020

Then the most likely explanation is that compilation is failing each time. Have you run go build? Can you upload a repro case somewhere?

@elegos
Copy link
Author

elegos commented Jun 30, 2020

@heschik you can find a repro case here:

git clone [email protected]:elegos/instago.git
cd instago
git checkout feature/gui
pushd source/gui
make setup
popd
code .

Then open source/gui/main.go and save. Now open source/gui/ui/MainWindow.go and save.

@heschi
Copy link
Contributor

heschi commented Jul 1, 2020

I have successfully built qt projects before, but this one fails with a missing symbol:
vendor/github.com/therecipe/qt/core/core-minimal.go:15:42: undefined: NewQByteArrayFromPointer

I noticed that the source/gui folder is a nested module. That is likely to cause problems. Opening the nested module as the workspace directory in VSCode, or using Add Folder to add it to the workspace as a top-level directory, may work better.

You still haven't answered my question. Does go build succeed?

@elegos
Copy link
Author

elegos commented Jul 2, 2020

Hello @heschik

Yes, go build succedes.

As for the submodule, it was not my intention, but apparently the chain tool used to build the solution including the library (provided by the library itself) is cumbersome to say the least and didn't allow me to specify the main package rather than the root of the project. I'll try to make one unique go module (in the root of the project) and, if successful, see if there are differences in VSCode.

@stamblerre
Copy link
Contributor

@elegos: Were you able to resolve this issue? Is it OK to close this?

@stamblerre stamblerre added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 10, 2020
@gopherbot
Copy link
Collaborator

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Dec 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge upstream-tools Issues that are caused by problems in the tools that the extension depends on. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants