golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.99k stars 17.54k forks source link

x/mobile: CGO_CXXFLAGS, CGO_LDFLAGS overwritten for ios #56137

Open happyalu opened 1 year ago

happyalu commented 1 year ago

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

$ go version
go version go1.18.2 darwin/amd64

Does this issue reproduce with the latest release?

This bug is in cmd/gomobile, and is reproducible with the latest commit on that.

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

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"

What did you do?

I was trying to build an ios framework with gomobile that also includes C dependencies. I need to set CGO_CXXFLAGS and CGO_LDFLAGS to get the build working.

CGO_ENABLED=1 CGO_LDFLAGS="<flags>" CGO_CXXFLAGS="<flags>" gomobile bind -target ios/arm64,iossimulator/amd64 -iosversion 9.3.0 ./cmd/app

What did you expect to see?

gomobile should forward the values of CGO_CXXFLAGS and CGO_LDFLAGS to rest of the build process (gobind, go build, etc.) This does happen when building for Android, but not when targeting ios.

What did you see instead?

The CGO_CXXFLAGS, CGO_LDFLAGS, etc. variables get overwritten by values that are required to introduce system dependencies for ios.

This was causing my build to break.

Ideally, these new values introduced by gomobile should be appended to values already in the environment. I tried out this change that resolves this issue.

joedian commented 1 year ago

Hi happyalu,

Can you please add more details to the bug and use the bug format. If this is not a bug, please see below.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

happyalu commented 1 year ago

Sorry, I was not aware of the bug template. Updated my post above with more details.

dr2chase commented 1 year ago

@hyangah can you give this a look?