Repository: go
Issue: x/mobile/cmd/gobind: gobind fails when binding ObjC imports to Go
Labels: NeedsInvestigation,mobile

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.16.5 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?

Yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ 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"
</pre></details>

### 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