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

fix iOS build #816

Merged
merged 1 commit into from
Dec 5, 2023
Merged

fix iOS build #816

merged 1 commit into from
Dec 5, 2023

Conversation

Mrs4s
Copy link
Contributor

@Mrs4s Mrs4s commented Dec 4, 2023

I came across a build error when trying to compile for iOS. To rectify this, I've introduced a check for GOOS=iOS. This addition resolved the issues in my use case.

I simply tested it and it was fine, but I don’t know if there are other effects.

@lu4p
Copy link
Member

lu4p commented Dec 4, 2023

Can you send us a minimal example so we can reproduce the build failure for ios? (Probably just import crypto/x509)

Can you add that code as a test case to crossbuild.txtar, to verify that iOS programs can be built on other systems?

Read CONTRIBUTING.md, to understand how our testing works.

If you get stuck anywhere, don't hesitate to ask for help.

Usually this would require a test to verify that the resulting binary can run on iOS, however this is a single line change so I think that's a little overkill.

@Mrs4s
Copy link
Contributor Author

Mrs4s commented Dec 4, 2023

test code:

// main.go
package main

import "C"
import (
	"runtime"
)

func main() {}

//export getString
func getString() *C.char {
	return C.CString("hello world from go! runtime: " + runtime.Version())
}

build script:

#!/bin/sh
export GOOS=ios
export GOARCH=arm64
export CGO_ENABLED=1
export SDK=iphonesimulator
#export SDK=iphoneos
export CGO_CFLAGS="-fembed-bitcode"
export MIN_VERSION=15

SDK_PATH=$(xcrun --sdk "$SDK" --show-sdk-path)
export SDK_PATH

if [ "$GOARCH" = "amd64" ]; then
    CARCH="x86_64"
elif [ "$GOARCH" = "arm64" ]; then
    CARCH="arm64"
fi

if [ "$SDK" = "iphoneos" ]; then
  export TARGET="$CARCH-apple-ios$MIN_VERSION"
elif [ "$SDK" = "iphonesimulator" ]; then
  export TARGET="$CARCH-apple-ios$MIN_VERSION-simulator"
fi

export CGO_LDFLAGS="-target ${TARGET} -syslibroot \"${SDK_PATH}\""
CC="$(pwd)/clangwrap.sh"
export CC

garble build -buildmode=c-archive -o TestGoiOS.a 

clangwrap.sh:

#!/bin/sh

CLANG=$(xcrun --sdk "$SDK" --find clang)

exec "$CLANG" -target "$TARGET" -isysroot "$SDK_PATH" "$@"

error message:

# runtime
panic: package "crypto/x509/internal/macos" still missing after go list call

goroutine 1 [running]:
main.listPackage(0x14000178900, {0x14000c29dd2, 0x1a})
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/shared.go:380 +0x5ac
main.(*transformer).transformLinkname(0x14000130840, {0x14000c29dbe?, 0x3?}, {0x14000c29dd2, 0x22})
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/main.go:1154 +0x2d0
main.(*transformer).transformDirectives(0x16b712b4a?, {0x14000a41c00, 0x46, 0x16b712b14?})
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/main.go:1094 +0x124
main.(*transformer).transformCompile(0x14000130840, {0x1400013a030?, 0x1400002a094?, 0x7?})
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/main.go:1041 +0x944
main.mainErr({0x1400013a010, 0xa7, 0x104cda100?})
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/main.go:457 +0x740
main.main1()
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/main.go:254 +0x21c
main.main()
        /tmp/global/pkg/mod/mvdan.cc/[email protected]/main.go:146 +0x1c
exit status 1

NOTE: Building for target iOS can only be done on macOS with xcode tools installed

@lu4p
Copy link
Member

lu4p commented Dec 5, 2023

We will properly test iOS support once #810 is done, merging this for now. Thanks @Mrs4s.

@lu4p lu4p merged commit 0752f9e into burrowers:master Dec 5, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants