golang / go

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

x/mobile: comments in the generated objective-C header depend on which file the function is in #46581

Open necro351 opened 3 years ago

necro351 commented 3 years ago

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

$ go version
go version go1.16.2 darwin/amd64

Does this issue reproduce with the latest release?

I am using golang.org/x/mobile v0.0.0-20210220033013-bdb1ca9a1e08 I believe its the latest release.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rick/Library/Caches/go-build"
GOENV="/Users/rick/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/rick/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rick/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4g/tb10nky94cxcyrgk2_7bzcch0000gn/T/go-build1988548916=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

When I make an iOS framework to link into my mobile app using this command:

   go build
   gomobile bind -target=iOS

I get a framework that links and works as expected. However, the comments in the generated objective-C header are only included if I make sure all the public functions for the package are in the same file. If I put some public functions in a different file but the same golang package, the functions will be included in the generated header but not the associated comments.

Note that go doc, etc..., all work fine and show the public functions with their comments.

What did you expect to see?

It should not matter which file the public golang function is in or how many files in the package contain public functions. The comments for each function should always be included in the generated header if the function is public and has comments that go doc can see and associate with the function.

What did you see instead?

Some comments are missing if functions are in two or more files.

cherrymui commented 3 years ago

cc @eliasnaur @hyangah