Closed Gregory-Ledray closed 4 years ago
CC @jayconrod @matloob @neelance @cherrymui
Looking at your go env
output, you appear to be running the go build
command on a Windows host? That's probably a relevant detail.
$ GOOS=js GOARCH=wasm go build -o ./cmd ./...
You're trying to write output files cmd/wasm1
, cmd/wasm2
, etc., but these paths already exist and are directories, so it cannot overwrite it, as the error message clearly stated.
Writing to any other directories where there aren't such paths should work.
Why does it work with GOOS=windows GOARCH=amd64 but not GOOS=js GOARCH=wasm?
Because cmd/wasm1
, etc. are build-tagged for wasm. It doesn't build on windows.
Closing as this works as intended.
Oh! The outputs for the default GOOS=windows
have a .exe
suffix.
That's what avoids the collision with the existing directories for non-build-tagged binaries.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I was checking out the changes in #14295 and they work great most of the time, but I might have found an edge case where they fail.
The changes in #14295 work great with regular GOOS and GOARCH on non-empty directories (nice work!):
``` gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ go list ./... gitlab.com/polyapp-open-source/poly/testdata/cmd gitlab.com/polyapp-open-source/poly/testdata/cmd/hello gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ ls ./cmd hello main.go wasm1 wasm2 wasm3 gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ go build -o ./cmd ./... gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ ls ./cmd cmd.exe hello hello.exe main.go wasm1 wasm2 wasm3 ```But doesn't work with GOOS=js GOARCH=wasm
It works great with GOOS=js GOARCH=wasm if I make a new directory:
``` gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ ls ./cmd hello main.go wasm1 wasm2 wasm3 gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ ls ./bin ls: cannot access './bin': No such file or directory gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ GOOS=js GOARCH=wasm go list ./... gitlab.com/polyapp-open-source/poly/testdata/cmd gitlab.com/polyapp-open-source/poly/testdata/cmd/hello gitlab.com/polyapp-open-source/poly/testdata/cmd/wasm1 gitlab.com/polyapp-open-source/poly/testdata/cmd/wasm2 gitlab.com/polyapp-open-source/poly/testdata/cmd/wasm3 gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ mkdir ./bin gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ GOOS=js GOARCH=wasm go build -o ./bin ./... gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ ls ./bin cmd hello wasm1 wasm2 wasm3 ```And it works great if I rebuild into the bin directory:
``` gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ GOOS=js GOARCH=wasm go build -o ./bin ./... gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ rm ./bin/cmd ./bin/hello ./bin/wasm2 gledr@LAPTOP-AH6IAHBO MINGW64 ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata (CI-expansion) $ GOOS=js GOARCH=wasm go build -o ./bin ./... ```Is this intended to work with non-empty parent directories of the binaries? Why does it work with GOOS=windows GOARCH=amd64 but not GOOS=js GOARCH=wasm?
My directory structure lives inside $GOPATH at ~/Polyapp_Apps/gocode/src/gitlab.com/polyapp-open-source/poly/testdata because, setting the exact issue aside, I'm writing some tools to make linting, testing, building, and running my multi-arch. programs a bit easier.
``` testdata/ cmd/ hello/ main.go main_test.go wasm1/ main_js_wasm.go wasm2/ main_js_wasm.go wasm3/ main.go main.go ```Here are my test files in order of the directory structure. Some files have perhaps changed a bit since I ran the commands above - I don't recall if the test file existed before
testdata/cmd/hello/main.go ``` package main import ( "fmt" "os" ) func main() { fmt.Println("Hello from poly/testdata/cmd/hello/main.go") osCheck() } // osCheck returns true for success using syscalls and false otherwise func osCheck() bool { _, err := os.Stat(".") if err != nil { fmt.Println("os.Stat failed: " + err.Error()) return false } return true } ``` testdata/cmd/hello/main_test.go ``` package main import "testing" func TestOsCheck(t *testing.T) { chk := osCheck() if chk == false { t.Fatal("couldn't stat") } } ``` testdata/cmd/wasm1/main_js_wasm.go ``` // +build js package main import "fmt" func main() { fmt.Println("hello from testdata/cmd/wasm1/main_js_wasm.go") } ``` testdata/cmd/wasm2/main_js_wasm.go ``` // +build js package main import "fmt" func main() { fmt.Println("hello from testdata/cmd/wasm2/main_js_wasm.go") } ``` testdata/cmd/wasm3/main.go ``` // +build js package main import "fmt" func main() { fmt.Println("Hello from testdata/cmd/wasm3/main.go") } ``` testdata/cmd/main.go ``` package main import "fmt" func main() { fmt.Println("Hello from poly/testdata/cmd/main.go") } ```