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

x/mobile: does -ldflags -X work for gomobile bind? #65871

Closed
arhtur007 opened this issue Feb 22, 2024 · 0 comments
Closed

x/mobile: does -ldflags -X work for gomobile bind? #65871

arhtur007 opened this issue Feb 22, 2024 · 0 comments
Labels
mobile Android, iOS, and x/mobile
Milestone

Comments

@arhtur007
Copy link

arhtur007 commented Feb 22, 2024

Go version

go 1.21

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/arthurwang/Library/Caches/go-build'
GOENV='/Users/arthurwang/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/arthurwang/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/arthurwang/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -ffile-prefix-map=/var/folders/fd/79_ybcj55_1__0nhtlyrrvc40000gn/T/go-build590198146=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I was trying setting variables with ldflags in gomobile

here's my file structure and code
└── sdk
├── go.mod
└── sdk.go

go.mod

module github.com/MyRepo/sdk

go 1.21.1

sdk.go

package sdk

var (
	SDKVersion string
)

func Print() {
	fmt.Println("######")
	fmt.Println(SDKVersion)
	fmt.Println("######")
}

and here's my command
I've tried both

gomobile bind -v -target=ios -ldflags "-s -w -X sdk.SDKVersion=testVersion"

and
gomobile bind -v -target=ios -ldflags "-s -w -X github.com/MyRepo/sdk/sdk.SDKVersion=testVersion"

What did you see happen?

Here's my output

######

######

What did you expect to see?

######
testVersion
######
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 22, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

2 participants