mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
cmd/gogio: use GOOS=ios to target iOS with Go 1.16 and newer
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+31
-2
@@ -416,6 +416,17 @@ func archiveIOS(tmpDir, target, frameworkRoot string, bi *buildInfo) error {
|
|||||||
exe := filepath.Join(frameworkDir, framework)
|
exe := filepath.Join(frameworkDir, framework)
|
||||||
lipo := exec.Command("xcrun", "lipo", "-o", exe, "-create")
|
lipo := exec.Command("xcrun", "lipo", "-o", exe, "-create")
|
||||||
var builds errgroup.Group
|
var builds errgroup.Group
|
||||||
|
tags := bi.tags
|
||||||
|
goos := "ios"
|
||||||
|
supportsIOS, err := supportsGOOS("ios")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !supportsIOS {
|
||||||
|
// Go 1.15 and earlier target iOS with GOOS=darwin, tags=ios.
|
||||||
|
goos = "darwin"
|
||||||
|
tags = "ios " + tags
|
||||||
|
}
|
||||||
for _, a := range bi.archs {
|
for _, a := range bi.archs {
|
||||||
clang, cflags, err := iosCompilerFor(target, a)
|
clang, cflags, err := iosCompilerFor(target, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -428,14 +439,14 @@ func archiveIOS(tmpDir, target, frameworkRoot string, bi *buildInfo) error {
|
|||||||
"-ldflags=-s -w "+bi.ldflags,
|
"-ldflags=-s -w "+bi.ldflags,
|
||||||
"-buildmode=c-archive",
|
"-buildmode=c-archive",
|
||||||
"-o", lib,
|
"-o", lib,
|
||||||
"-tags", "ios "+bi.tags,
|
"-tags", tags,
|
||||||
bi.pkg,
|
bi.pkg,
|
||||||
)
|
)
|
||||||
lipo.Args = append(lipo.Args, lib)
|
lipo.Args = append(lipo.Args, lib)
|
||||||
cflagsLine := strings.Join(cflags, " ")
|
cflagsLine := strings.Join(cflags, " ")
|
||||||
cmd.Env = append(
|
cmd.Env = append(
|
||||||
os.Environ(),
|
os.Environ(),
|
||||||
"GOOS=darwin",
|
"GOOS="+goos,
|
||||||
"GOARCH="+a,
|
"GOARCH="+a,
|
||||||
"CGO_ENABLED=1",
|
"CGO_ENABLED=1",
|
||||||
"CC="+clang,
|
"CC="+clang,
|
||||||
@@ -471,6 +482,24 @@ func archiveIOS(tmpDir, target, frameworkRoot string, bi *buildInfo) error {
|
|||||||
return ioutil.WriteFile(moduleFile, []byte(module), 0644)
|
return ioutil.WriteFile(moduleFile, []byte(module), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func supportsGOOS(wantGoos string) (bool, error) {
|
||||||
|
geese, err := runCmd(exec.Command("go", "tool", "dist", "list"))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
for _, pair := range strings.Split(geese, "\n") {
|
||||||
|
s := strings.SplitN(pair, "/", 2)
|
||||||
|
if len(s) != 2 {
|
||||||
|
return false, fmt.Errorf("go tool dist list: invalid GOOS/GOARCH pair: %s", pair)
|
||||||
|
}
|
||||||
|
goos := s[0]
|
||||||
|
if goos == wantGoos {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func iosCompilerFor(target, arch string) (string, []string, error) {
|
func iosCompilerFor(target, arch string) (string, []string, error) {
|
||||||
var platformSDK string
|
var platformSDK string
|
||||||
var platformOS string
|
var platformOS string
|
||||||
|
|||||||
Reference in New Issue
Block a user