golang / go

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

x/mobile: building for iOS Simulator, but linking in object file built for iOS, for architecture arm64. #45805

Open mycroftcanner opened 3 years ago

mycroftcanner 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?

yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/Users/x/go/bin"
GOCACHE="/Users/x/Library/Caches/go-build"
GOENV="/Users/x/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/x/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/x/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="/Users/x/gcloud/src/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/z7/33jzmkp96sqdpll82cb2ddph0000gn/T/go-build452940234=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

gomobile bind -target=ios golang.org/x/mobile/example/bind/hello

What did you expect to see?

Framework binaries with multiple platforms are not supported anymore.

gomobile bind should generate a universal xcframework

What did you see instead?

In /Users/x/gcloud/src/example/bind/ios/Hello.framework/Hello(000005.o), building for iOS Simulator, but linking in object file (/Users/x/gcloud/src/example/bind/ios/Hello.framework/Hello(000005.o)) built for iOS, for architecture arm64.

We are supposed to use an xcframework instead

file Hello.framework/Versions/A/Hello
Hello.framework/Versions/A/Hello: Mach-O universal binary with 2 architectures: [x86_64:current ar archive random library] [arm64]
Hello.framework/Versions/A/Hello (for architecture x86_64): current ar archive random library
Hello.framework/Versions/A/Hello (for architecture arm64):  current ar archive random library
mycroftcanner commented 3 years ago

Here is a workaround:

mkdir -p iphoneos iphonesimulator
cp -rp Hello.framework iphoneos
mv Hello.framework iphonesimulator

lipo -remove x86_64 ./iphoneos/Hello.framework/Hello -o ./iphoneos/Hello.framework/Hello
lipo -remove arm64 ./iphonesimulator/Hello.framework/Hello -o ./iphonesimulator/Hello.framework/Hello

xcodebuild -create-xcframework -framework iphoneos/Hello.framework -framework iphonesimulator/Hello.framework -output Hello.xcframework
mycroftcanner commented 3 years ago

It seems Xcode 12.5 requires both x86_64-apple-ios-simulator and arm64-apple-ios-simulator

cherrymui commented 3 years ago

cc @hyangah @eliasnaur

ibigbug commented 3 years ago

Having same issue.

gadireddi226 commented 3 years ago

Having same issue too. This will be relevant for all projects that want to be on xcode 12+. There is neccessary to have xcframeworks with iOS and iOS simulator architecture or it will be very problematic for unit tests, building project etc..