1pkg / gopium

Gopium 🌺: Smart Go Structures Optimizer and Manager
MIT License
209 stars 7 forks source link

VS code extension error trying to write to C:\WINDOWS #30

Closed xiegeo closed 1 year ago

xiegeo commented 1 year ago

Using the vs code extension on window produced the following error. Looks like it's trying to build code in the windows system directory, which it obviously should not.

log output

gopium 🌺: C:\Users\...\go\bin\gopium.exe -p c:\Users\...\seed\dictionary -r ^Dictionary$ -c gc -a amd64 -l 64 -l 64 -l 64 -d -b -i 0 -w 8 -t 0 ast_go dictionary memory_pack
Error: visiting error happened err: exit status 1: stderr: go: creating work dir: mkdir C:\WINDOWS\go-build1514569921: Access is denied.
$ gopium -v
gopium version 1.6.2

$ go version
go version go1.19.3 windows/amd64

vs-code version:
Version: 1.73.1 (user setup)
Commit: 6261075646f055b99068d3688932416f2346dd3b
Date: 2022-11-09T04:27:29.066Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: No

$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xiege\AppData\Local\go-build
set GOENV=C:\Users\xiege\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\xiege\go\pkg\mod
set GONOPROXY=...
set GONOSUMDB=...
set GOOS=windows
set GOPATH=C:\Users\xiege\go
set GOPRIVATE=...
set GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\...\seed\go.mod
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\xiege\AppData\Local\Temp\go-build3538426132=/tmp/go-build -gno-record-gcc-switches
1pkg commented 1 year ago

@xiegeo it actually is expected behavior, that it tries implicitly to build the package. Here underneath https://github.com/1pkg/gopium/blob/406af8b07987b489d7138e86a2820bde34bd8b6e/typepkg/parser.go#L61 it uses this package https://pkg.go.dev/golang.org/x/tools/go/packages to infer the types sizes. AFAIK it's one of the most straightforward ways to calculate the actual sizes. The real question is why it uses C:\WINDOWS\go-build* as its build folder.

1pkg commented 1 year ago

@xiegeo please try to add -e "GOCACHE=C:\Users\xiege\AppData\Local\go-build" to the cli parameters. So your full command will look like

C:\Users\...\go\bin\gopium.exe -p c:\Users\...\seed\dictionary -r ^Dictionary$ -c gc -a amd64 -l 64 -l 64 -l 64 -d -b -i 0 -w 8 -t 0 ast_go dictionary memory_pack -e "GOCACHE=C:\Users\xiege\AppData\Local\go-build"
xiegeo commented 1 year ago

I got it to work with this: -e "GOCACHE=C:\Users\xiege\AppData\Local\go-build,GOPATH=C:\Users\xiege\go,GOTMPDIR=C:\tmp"

1pkg commented 1 year ago

@xiegeo, In the past I added this workaround https://github.com/1pkg/gopium/commit/970858171367fbf5dbd8ef4e1b6c201b5b06689a which clearly is not universal enough. This time I made a better fix in https://github.com/1pkg/gopium/pull/32 to propagate env defaults directly from go env command. This should resolve this issue in general case, I believe. I merged it, and published as https://github.com/1pkg/gopium/releases/tag/v1.7.0. Please try it out.

xiegeo commented 1 year ago

Thanks, that fixed it.