golang / go

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

x/mobile/cmd/gobind: gobind fails when binding ObjC imports to Go #47113

Open ydnar opened 3 years ago

ydnar commented 3 years ago

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

$ go version
go version go1.16.5 darwin/amd64

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="amd64"
GOBIN=""
GOCACHE="/Users/ydnar/Library/Caches/go-build"
GOENV="/Users/ydnar/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ydnar/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ydnar/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.5/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ydnar/development/ydnar/gomobile/go.mod"
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/6g/1gng3zts0t39s_qbtt7p0wsc0000gn/T/go-build3263680334=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

On current master branch of https://github.com/golang/mobile, I ran go test ./bind.

What did you expect to see?

Tests pass.

What did you see instead?

Tests fail, in particular TestGenGoObjcWrappers, when clang (run by gobind under xcrun) couldn’t find certain system headers like sys/types.h.

Output of go test ./bind:

--- FAIL: TestGenGoObjcWrappers (0.16s)
    bind_test.go:450: Foundation: clang failed to parse module: exit status 1: In file included from /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
        /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16:10: fatal error: 'sys/types.h' file not found
        #include <sys/types.h>
                 ^~~~~~~~~~~~~
        TranslationUnitDecl 0x7f9981029208 <<invalid sloc>> <invalid sloc>
        |-TypedefDecl 0x7f9981029ac0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
        | `-BuiltinType 0x7f99810297a0 '__int128'
        |-TypedefDecl 0x7f9981029b30 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
        | `-BuiltinType 0x7f99810297c0 'unsigned __int128'
        |-TypedefDecl 0x7f9981029bd8 <<invalid sloc>> <invalid sloc> implicit referenced SEL 'SEL *'
        | `-PointerType 0x7f9981029b90 'SEL *'
        |   `-BuiltinType 0x7f9981029a00 'SEL'
        |-TypedefDecl 0x7f9981029cb8 <<invalid sloc>> <invalid sloc> implicit referenced id 'id'
        | `-ObjCObjectPointerType 0x7f9981029c60 'id'
        |   `-ObjCObjectType 0x7f9981029c30 'id'
        |-TypedefDecl 0x7f9981029d98 <<invalid sloc>> <invalid sloc> implicit referenced Class 'Class'
        | `-ObjCObjectPointerType 0x7f9981029d40 'Class'
        |   `-ObjCObjectType 0x7f9981029d10 'Class'
        |-ObjCInterfaceDecl 0x7f9981029df0 <<invalid sloc>> <invalid sloc> implicit Protocol

[+25,000 lines]

cc @hyangah

mknyszek commented 3 years ago

CC @hyangah via https://dev.golang.org/owners

Also maybe @hajimehoshi?

muyuballs commented 2 years ago

me too.