cmd/gogio: add -minsdk to iOS

Before that patch the minimum iOS version was hardcoded. That patch makes possible
to change the minimum iOS version using `-minsdk`.

Signed-off-by: Inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
Inkeliz
2022-01-01 19:51:27 +00:00
committed by Elias Naur
parent 6d9db2b13c
commit ac3bbc72ac
2 changed files with 24 additions and 12 deletions
+4 -1
View File
@@ -53,7 +53,10 @@ For Android builds the -minsdk flag specify the minimum SDK level. For example,
use -minsdk 22 to target Android 5.1 (Lollipop) and later. use -minsdk 22 to target Android 5.1 (Lollipop) and later.
For Windows builds the -minsdk flag specify the minimum OS version. For example, For Windows builds the -minsdk flag specify the minimum OS version. For example,
use -mindk 10 to target Windows 10 only, -minsdk 6 for Windows Vista and later. use -mindk 10 to target Windows 10 and later, -minsdk 6 for Windows Vista and later.
For iOS builds the -minsdk flag specify the minimum iOS version. For example,
use -mindk 15 to target iOS 15.0 and later.
The -work flag prints the path to the working directory and suppress The -work flag prints the path to the working directory and suppress
its deletion. its deletion.
+20 -11
View File
@@ -13,6 +13,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"time" "time"
@@ -20,10 +21,10 @@ import (
) )
const ( const (
minIOSVersion = "10.0" minIOSVersion = 10
// Metal is available from iOS 8 on devices, yet from version 13 on the // Metal is available from iOS 8 on devices, yet from version 13 on the
// simulator. // simulator.
minSimulatorVersion = "13.0" minSimulatorVersion = 13
) )
func buildIOS(tmpDir, target string, bi *buildInfo) error { func buildIOS(tmpDir, target string, bi *buildInfo) error {
@@ -193,7 +194,7 @@ int main(int argc, char * argv[]) {
lipo := exec.Command("xcrun", "lipo", "-o", exe, "-create") lipo := exec.Command("xcrun", "lipo", "-o", exe, "-create")
var builds errgroup.Group var builds errgroup.Group
for _, a := range bi.archs { for _, a := range bi.archs {
clang, cflags, err := iosCompilerFor(target, a) clang, cflags, err := iosCompilerFor(target, a, bi.minsdk)
if err != nil { if err != nil {
return err return err
} }
@@ -291,11 +292,16 @@ func iosIcons(bi *buildInfo, tmpDir, appDir, icon string) (string, error) {
return "", err return "", err
} }
assetPlist := filepath.Join(tmpDir, "assets.plist") assetPlist := filepath.Join(tmpDir, "assets.plist")
minsdk := bi.minsdk
if minsdk == 0 {
minsdk = minIOSVersion
}
compile := exec.Command( compile := exec.Command(
"actool", "actool",
"--compile", appDir, "--compile", appDir,
"--platform", iosPlatformFor(bi.target), "--platform", iosPlatformFor(bi.target),
"--minimum-deployment-target", minIOSVersion, "--minimum-deployment-target", strconv.Itoa(minsdk),
"--app-icon", "AppIcon", "--app-icon", "AppIcon",
"--output-partial-info-plist", assetPlist, "--output-partial-info-plist", assetPlist,
assets) assets)
@@ -342,7 +348,7 @@ func buildInfoPlist(bi *buildInfo) string {
<key>DTPlatformVersion</key> <key>DTPlatformVersion</key>
<string>12.4</string> <string>12.4</string>
<key>MinimumOSVersion</key> <key>MinimumOSVersion</key>
<string>%s</string> <string>%d</string>
<key>UIDeviceFamily</key> <key>UIDeviceFamily</key>
<array> <array>
<integer>1</integer> <integer>1</integer>
@@ -428,7 +434,7 @@ func archiveIOS(tmpDir, target, frameworkRoot string, bi *buildInfo) error {
tags = "ios " + tags 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, bi.minsdk)
if err != nil { if err != nil {
return err return err
} }
@@ -500,11 +506,10 @@ func supportsGOOS(wantGoos string) (bool, error) {
return false, nil return false, nil
} }
func iosCompilerFor(target, arch string) (string, []string, error) { func iosCompilerFor(target, arch string, minsdk int) (string, []string, error) {
var ( var (
platformSDK string platformSDK string
platformOS string platformOS string
minVer = minIOSVersion
) )
switch target { switch target {
case "ios": case "ios":
@@ -513,15 +518,19 @@ func iosCompilerFor(target, arch string) (string, []string, error) {
case "tvos": case "tvos":
platformOS = "tvos" platformOS = "tvos"
platformSDK = "appletv" platformSDK = "appletv"
} }
switch arch { switch arch {
case "arm", "arm64": case "arm", "arm64":
platformSDK += "os" platformSDK += "os"
if minsdk == 0 {
minsdk = minIOSVersion
}
case "386", "amd64": case "386", "amd64":
platformOS += "-simulator" platformOS += "-simulator"
platformSDK += "simulator" platformSDK += "simulator"
minVer = minSimulatorVersion if minsdk == 0 {
minsdk = minSimulatorVersion
}
default: default:
return "", nil, fmt.Errorf("unsupported -arch: %s", arch) return "", nil, fmt.Errorf("unsupported -arch: %s", arch)
} }
@@ -537,7 +546,7 @@ func iosCompilerFor(target, arch string) (string, []string, error) {
"-fembed-bitcode", "-fembed-bitcode",
"-arch", allArchs[arch].iosArch, "-arch", allArchs[arch].iosArch,
"-isysroot", sdkPath, "-isysroot", sdkPath,
"-m" + platformOS + "-version-min=" + minVer, "-m" + platformOS + "-version-min=" + strconv.Itoa(minsdk),
} }
return clang, cflags, nil return clang, cflags, nil
} }