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

cmd/build: 'GOOS=ios go build' will also include darwin code #59789

Closed
awsong opened this issue Apr 24, 2023 · 2 comments
Closed

cmd/build: 'GOOS=ios go build' will also include darwin code #59789

awsong opened this issue Apr 24, 2023 · 2 comments

Comments

@awsong
Copy link

awsong commented Apr 24, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.3 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/wsong/Library/Caches/go-build"
GOENV="/Users/wsong/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/wsong/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/wsong/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/opt/homebrew/Cellar/go/1.20.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.3/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/tmp/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lr/s8_5072s6cs602ksv8tv5myh0000gn/T/go-build3771226631=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I intend to compile some code that include only ios implementation, and excluding darwin implementation.
But I found when I give GOOS=ios my darwin code is also compiled in.

I created a minimal demo folder like this

$ ls
test.go         test_darwin.go  test_ios.go

If I run go list with GOOS=dardwin, I get

$GOOS=darwin go list -f '{{.GoFiles}}' 
[test.go test_darwin.go]

If I run go list with GOOS=ios, I get

$ GOOS=ios go list -f '{{.GoFiles}}' 
[test.go test_darwin.go test_ios.go]

What did you expect to see?

$ GOOS=ios go list -f '{{.GoFiles}}' 
[test.go test_ios.go]

What did you see instead?

$ GOOS=ios go list -f '{{.GoFiles}}' 
[test.go test_darwin.go test_ios.go]
@rittneje
Copy link

This is mentioned in the docs. https://pkg.go.dev/cmd/go

Using GOOS=ios matches build tags and files as for GOOS=darwin in addition to ios tags and files.

You'll need to add a //go:build !ios directive at the top of these files if you want to exclude them.

@awsong
Copy link
Author

awsong commented Apr 24, 2023

I see. I thought all OS types are mutually exclusive.

Thanks for the info.

@awsong awsong closed this as completed Apr 24, 2023
@golang golang locked and limited conversation to collaborators Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants
@awsong @gopherbot @rittneje and others