Merge pull request #668 from kiwix/667-xcf

CoreKiwix for iOS Simulator
This commit is contained in:
Matthieu Gautier 2023-12-05 11:09:09 +01:00 committed by GitHub
commit 6695af6014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 30 deletions

View File

@ -26,7 +26,8 @@ BUILD_DEF = """
| macos | native_static | | | BP | BP | | macos-x86_64 | | macos | native_static | | | BP | BP | | macos-x86_64 |
| macos | native_mixed | BP | BP | | | | macos-x86_64 | | macos | native_mixed | BP | BP | | | | macos-x86_64 |
| macos | iOS_arm64 | dB | dB | | | | | | macos | iOS_arm64 | dB | dB | | | | |
| macos | iOS_x86_64 | dB | dB | | | | | | macos | iOSSimulator_x86_64| dB | dB | | | | |
| macos | iOSSimulator_arm64 | dB | dB | | | | |
| macos | macOS_arm64_static | | | BP | BP | | macos-arm64 | | macos | macOS_arm64_static | | | BP | BP | | macos-arm64 |
| macos | macOS_arm64_mixed | BP | BP | | | | macos-arm64 | | macos | macOS_arm64_mixed | BP | BP | | | | macos-arm64 |
| macos | macOS_x86_64 | B | B | | | | | | macos | macOS_x86_64 | B | B | | | | |

View File

@ -147,7 +147,8 @@ jobs:
- native_static - native_static
- native_mixed - native_mixed
- iOS_arm64 - iOS_arm64
- iOS_x86_64 - iOSSimulator_x86_64
- iOSSimulator_arm64
- macOS_arm64_static - macOS_arm64_static
- macOS_arm64_mixed - macOS_arm64_mixed
- macOS_x86_64 - macOS_x86_64

View File

@ -9,7 +9,13 @@ from .base import Dependency, NoopSource, Builder as BaseBuilder
class AppleXCFramework(Dependency): class AppleXCFramework(Dependency):
name = "apple_xcframework" name = "apple_xcframework"
subPlatformNames = ["macOS_x86_64", "macOS_arm64_static", "iOS_x86_64", "iOS_arm64"] subPlatformNames = [
"macOS_x86_64",
"macOS_arm64_static",
"iOS_arm64",
"iOSSimulator_x86_64",
"iOSSimulator_arm64",
]
Source = NoopSource Source = NoopSource
class Builder(BaseBuilder): class Builder(BaseBuilder):
@ -23,10 +29,18 @@ class AppleXCFramework(Dependency):
target for target in self.all_subplatforms if target.startswith("macOS") target for target in self.all_subplatforms if target.startswith("macOS")
] ]
@property
def iossimulator_subplatforms(self):
return [
target
for target in self.all_subplatforms
if target.startswith("iOSSimulator")
]
@property @property
def ios_subplatforms(self): def ios_subplatforms(self):
return [ return [
target for target in self.all_subplatforms if target.startswith("iOS") target for target in self.all_subplatforms if target.startswith("iOS_")
] ]
@classmethod @classmethod
@ -56,13 +70,7 @@ class AppleXCFramework(Dependency):
static_ars = [str(f) for f in Path(lib_dir).glob("*.a")] static_ars = [str(f) for f in Path(lib_dir).glob("*.a")]
# create merged.a from all *.a in install_dir/lib # create merged.a from all *.a in install_dir/lib
command = [ command = ["libtool", "-static", "-o", "merged.a", *static_ars]
"libtool",
"-static",
"-o",
"merged.a",
*static_ars
]
run_command(command, lib_dir, context) run_command(command, lib_dir, context)
# will be included in xcframework # will be included in xcframework
@ -71,24 +79,18 @@ class AppleXCFramework(Dependency):
return xcf_libs return xcf_libs
def _make_macos_fat(self, context): def make_fat_with(self, platforms, folder_name, context):
"""create fat merged.a in fake macOS_fat install/lib with macOS archs""" """create fat merged.a in {folder_name} install/lib with {platforms} archs"""
macos_libs = [] libs = []
for target in self.macos_subplatforms: for target in platforms:
plt = PlatformInfo.get_platform(target) plt = PlatformInfo.get_platform(target)
macos_libs.append(pj(plt.buildEnv.install_dir, "lib", "merged.a")) libs.append(pj(plt.buildEnv.install_dir, "lib", "merged.a"))
fat_dir = pj(self.buildEnv.build_dir, "macOS_fat") fat_dir = pj(self.buildEnv.build_dir, folder_name)
os.makedirs(fat_dir, exist_ok=True) os.makedirs(fat_dir, exist_ok=True)
output_merged = pj(fat_dir, "merged.a") output_merged = pj(fat_dir, "merged.a")
command = [ command = ["lipo", "-create", "-output", output_merged, *libs]
"lipo",
"-create",
"-output",
output_merged,
*macos_libs
]
run_command(command, self.buildEnv.build_dir, context) run_command(command, self.buildEnv.build_dir, context)
return [output_merged] return [output_merged]
@ -99,8 +101,10 @@ class AppleXCFramework(Dependency):
command = ["xcodebuild", "-create-xcframework"] command = ["xcodebuild", "-create-xcframework"]
for lib in xcf_libs: for lib in xcf_libs:
command += [ command += [
"-library", lib, "-library",
"-headers", pj(ref_plat.buildEnv.install_dir, "include") lib,
"-headers",
pj(ref_plat.buildEnv.install_dir, "include"),
] ]
command += ["-output", self.final_path] command += ["-output", self.final_path]
run_command(command, self.buildEnv.build_dir, context) run_command(command, self.buildEnv.build_dir, context)
@ -109,5 +113,16 @@ class AppleXCFramework(Dependency):
xcf_libs = [] xcf_libs = []
self.command("remove_if_exists", self._remove_if_exists) self.command("remove_if_exists", self._remove_if_exists)
xcf_libs += self.command("merge_libs", self._merge_libs) xcf_libs += self.command("merge_libs", self._merge_libs)
xcf_libs += self.command("make_macos_fat", self._make_macos_fat) xcf_libs += self.command(
"make_macos_fat",
self.make_fat_with,
self.macos_subplatforms,
"macOS_fat",
)
xcf_libs += self.command(
"make_simulator_fat",
self.make_fat_with,
self.iossimulator_subplatforms,
"iOS-simulator_fat",
)
self.command("build_xcframework", self._build_xcframework, xcf_libs) self.command("build_xcframework", self._build_xcframework, xcf_libs)

View File

@ -131,11 +131,20 @@ class iOSArm64(ApplePlatformInfo):
min_iphoneos_version = '15.0' min_iphoneos_version = '15.0'
class iOSx64(ApplePlatformInfo): class iOSx64Simulator(ApplePlatformInfo):
name = 'iOS_x86_64' name = 'iOSSimulator_x86_64'
arch = cpu = 'x86_64' arch = cpu = 'x86_64'
host = 'x86_64-apple-darwin' host = 'x86_64-apple-darwin'
target = 'x86_64-apple-ios' target = 'x86-apple-ios-simulator'
sdk_name = 'iphonesimulator'
min_iphoneos_version = '15.0'
class iOSArm64Simulator(ApplePlatformInfo):
name = 'iOSSimulator_arm64'
arch = cpu = 'arm64'
host = 'arm-apple-darwin'
target = 'aarch64-apple-ios-simulator'
sdk_name = 'iphonesimulator' sdk_name = 'iphonesimulator'
min_iphoneos_version = '15.0' min_iphoneos_version = '15.0'