Skip to content

Commit

Permalink
Misc iOS build script fixes, related to MetalANGLE and xcframework bu…
Browse files Browse the repository at this point in the history
…ilds.
  • Loading branch information
mtehver committed Jul 12, 2021
1 parent 979c264 commit e8b214a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions scripts/build-android.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def buildAndroidSO(args, abi):
"-DSDK_CPP_DEFINES=%s" % " ".join(defines),
"-DSDK_VERSION='%s'" % version,
"-DSDK_PLATFORM='Android'",
"-DSDK_ANDROID_ABI='%s'" % abi,
'%s/scripts/build' % baseDir
]):
return False
Expand Down
36 changes: 21 additions & 15 deletions scripts/build-ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

IOS_ARCHS = ['i386', 'x86_64', 'armv7', 'arm64']

def getPlatformArch(arch):
if arch.endswith('-simulator'):
return 'SIMULATOR', arch[:-10]
return ('OS' if arch.startswith('arm') else 'SIMULATOR'), arch

def updateUmbrellaHeader(filename, defines):
with open(filename, 'r') as f:
lines = f.readlines()
Expand Down Expand Up @@ -91,7 +96,7 @@ def copyHeaders(args, baseDir, outputDir):
return True

def buildIOSLib(args, arch, outputDir=None):
platform = 'OS' if arch.startswith('arm') else 'SIMULATOR'
platform, arch = getPlatformArch(arch)
version = getVersion(args.buildnumber) if args.configuration == 'Release' else 'Devel'
baseDir = getBaseDir()
buildDir = outputDir or getBuildDir('ios', '%s-%s' % (platform, arch))
Expand All @@ -114,6 +119,7 @@ def buildIOSLib(args, arch, outputDir=None):
"-DSDK_DEV_TEAM='%s'" % (args.devteam if args.devteam else ""),
"-DSDK_VERSION='%s'" % version,
"-DSDK_PLATFORM='iOS'",
"-DSDK_IOS_ARCH='%s'" % arch,
'%s/scripts/build' % baseDir
]):
return False
Expand All @@ -124,7 +130,6 @@ def buildIOSLib(args, arch, outputDir=None):
])

def buildIOSFramework(args, archs, outputDir=None):
platformArchs = [('OS' if arch.startswith('arm') else 'SIMULATOR', arch) for arch in archs]
baseDir = getBaseDir()
distDir = outputDir or getDistDir('ios')
if args.sharedlib:
Expand All @@ -135,13 +140,13 @@ def buildIOSFramework(args, archs, outputDir=None):
makedirs(frameworkDir)

libFilePaths = []
for platform, arch in platformArchs:
libFilePath = "%s/%s-%s/libcarto_mobile_sdk.%s" % (getBuildDir('ios', '%s-%s' % (platform, arch)), args.configuration, 'iphoneos' if arch.startswith("arm") else 'iphonesimulator', 'dylib' if args.sharedlib else 'a')
if args.metalangle:
for platform, arch in map(getPlatformArch, archs):
libFilePath = "%s/%s-%s/libcarto_mobile_sdk.%s" % (getBuildDir('ios', '%s-%s' % (platform, arch)), args.configuration, ('iphone%s' % platform.lower()), 'dylib' if args.sharedlib else 'a')
if args.metalangle and not args.sharedlib:
mergedLibFilePath = '%s_merged.%s' % tuple(libFilePath.rsplit('.', 1))
angleLibFilePath = "%s/libs-external/angle-metal/%s/libangle.a" % (baseDir, arch)
angleLibFilePath = "%s/libs-external/angle-metal/%s/libangle.a" % (baseDir, arch if not (arch == 'arm64' and platform == 'simulator') else 'arm64-simulator')
if not execute('libtool', baseDir,
'-o', mergedLibFilePath, libFilePath, angleLibFilePath
'-static', '-o', mergedLibFilePath, libFilePath, angleLibFilePath
):
return False
libFilePath = mergedLibFilePath
Expand Down Expand Up @@ -180,9 +185,8 @@ def buildIOSFramework(args, archs, outputDir=None):
return True

def buildIOSXCFramework(args, archs, outputDir=None):
platformArchs = [('OS' if arch.startswith('arm') else 'SIMULATOR', arch) for arch in archs]
groupedPlatformArchs = {}
for platform, arch in platformArchs:
for platform, arch in map(getPlatformArch, archs):
groupedPlatformArchs[platform] = groupedPlatformArchs.get(platform, []) + [arch]
baseDir = getBaseDir()
distDir = outputDir or getDistDir('ios')
Expand Down Expand Up @@ -212,23 +216,23 @@ def buildIOSCocoapod(args, buildpackage):
version = args.buildversion
distName = 'sdk4-ios-%s%s.zip' % (("metal-" if args.metalangle else ""), version)
frameworkName = 'CartoMobileSDK%s' % ("-Metal" if args.metalangle else "")
frameworkDir = 'CartoMobileSDK.%s' % ("xcframework" if args.buildxcframework else "framework")
iosversion = '9.0'
frameworks = (["Metal", "MetalKit"] if args.metalangle else ["OpenGLES", "GLKit"]) + ["UIKit", "CoreGraphics", "CoreText", "CFNetwork", "Foundation"]
xcframeworks = []
if args.buildxcframework:
xcframeworks += [frameworkName]
frameworks = (["QuartzCore"] if args.metalangle else ["OpenGLES", "GLKit"]) + ["UIKit", "CoreGraphics", "CoreText", "CFNetwork", "Foundation"]
weakFrameworks = (["Metal"] if args.metalangle else [])

with open('%s/scripts/ios-cocoapod/CartoMobileSDK.podspec.template' % baseDir, 'r') as f:
cocoapodFile = string.Template(f.read()).safe_substitute({
'baseDir': baseDir,
'distDir': distDir,
'distName': distName,
'frameworkName': frameworkName,
'frameworkDir': frameworkDir,
'version': version,
'license': readLicense(),
'iosversion': iosversion,
'frameworks': ', '.join('"%s"' % framework for framework in frameworks),
'vendoredFrameworks': ', '.join('"%s.xcframework"' % framework for framework in xcframeworks) if xcframeworks else 'nil'
'frameworks': ', '.join('"%s"' % framework for framework in frameworks) if frameworks else 'nil',
'weakFrameworks': ', '.join('"%s"' % framework for framework in weakFrameworks) if weakFrameworks else 'nil'
})
with open('%s/%s.podspec' % (distDir, frameworkName), 'w') as f:
f.write(cocoapodFile)
Expand Down Expand Up @@ -263,6 +267,8 @@ def buildIOSCocoapod(args, buildpackage):
args = parser.parse_args()
if 'all' in args.iosarch or args.iosarch == []:
args.iosarch = IOS_ARCHS
if args.buildxcframework:
args.iosarch += ["arm64-simulator"]
args.defines += ';' + getProfile(args.profile).get('defines', '')
if args.metalangle:
args.defines += ';' + '_CARTO_USE_METALANGLE'
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-winphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def buildWinPhoneNativeDLL(args, arch):
'-DCMAKE_BUILD_TYPE=%s' % args.nativeconfiguration,
'-DWRAPPER_DIR=%s' % ('%s/generated/winphone-csharp/wrappers' % baseDir),
'-DSINGLE_LIBRARY:BOOL=ON',
"-DWINPHONE_ARCH=%s" % arch,
"-DSDK_CPP_DEFINES=%s" % " ".join(defines),
"-DSDK_VERSION='%s'" % version,
"-DSDK_PLATFORM='Windows Phone 10'",
"-DSDK_WINPHONE_ARCH='%s'" % arch,
'%s/scripts/build' % baseDir
]):
return False
Expand Down
10 changes: 6 additions & 4 deletions scripts/build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ elseif(IOS)
include_directories("${SDK_BASE_DIR}/ios/objc")
endif(INCLUDE_OBJC)
elseif(WIN32)
link_directories("${SDK_EXTERNAL_LIBS_DIR}/angle-uwp/${WINPHONE_ARCH}")
include_directories("${SDK_BASE_DIR}/winphone/native")
endif()

Expand All @@ -259,11 +258,14 @@ add_library(carto_mobile_sdk ${SDK_LIBRARY_TYPE} ${SDK_SRC_FILES} ${SDK_OBJECTS}
if(ANDROID)
target_link_libraries(carto_mobile_sdk EGL GLESv2 z log android jnigraphics)
elseif(IOS)
target_link_libraries(carto_mobile_sdk "-framework Foundation" "-framework CoreGraphics" "-framework CoreText" "-framework CFNetwork" "-framework UIKit")
if(SDK_CPP_DEFINES MATCHES ".*_CARTO_USE_METALANGLE.*")
target_link_libraries(carto_mobile_sdk "-framework Foundation" "-framework CoreGraphics" "-framework CoreText" "-framework Metal" "-framework MetalKit" "-framework UIKit" "-framework CFNetwork")
target_link_libraries(carto_mobile_sdk "${SDK_EXTERNAL_LIBS_DIR}/angle-metal/${SDK_IOS_ARCH}/libangle.a")
target_link_libraries(carto_mobile_sdk "-weak_framework OpenGLES" "-weak_framework Metal" "-framework QuartzCore")
else()
target_link_libraries(carto_mobile_sdk "-framework Foundation" "-framework CoreGraphics" "-framework CoreText" "-framework OpenGLES" "-framework GLKit" "-framework UIKit" "-framework CFNetwork")
target_link_libraries(carto_mobile_sdk "-framework OpenGLES" "-framework GLKit")
endif()
elseif(WIN32)
target_link_libraries(carto_mobile_sdk msxml6.lib d3d11.lib dwrite.lib d2d1.lib libEGL.dll.lib libGLESv2.dll.lib)
target_link_libraries(carto_mobile_sdk "${SDK_EXTERNAL_LIBS_DIR}/angle-uwp/${SDK_WINPHONE_ARCH}/libEGL.dll.lib" "${SDK_EXTERNAL_LIBS_DIR}/angle-uwp/${SDK_WINPHONE_ARCH}/libGLESv2.dll.lib")
target_link_libraries(carto_mobile_sdk "msxml6.lib" "d3d11.lib" "dwrite.lib" "d2d1.lib")
endif()
13 changes: 6 additions & 7 deletions scripts/ios-cocoapod/CartoMobileSDK.podspec.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,22 @@ Pod::Spec.new do |s|

s.source = { :http => "https://nutifront.s3.amazonaws.com/sdk_snapshots/$distName" }

s.source_files = "CartoMobileSDK.framework/**/*.{h,m}"
# s.exclude_files = "Classes/Exclude"
s.source_files = "$frameworkDir/**/*.{h,m,mm}"

s.public_header_files = "CartoMobileSDK.framework/**/*.{h,m}"
s.public_header_files = "$frameworkDir/**/*.{h}"

s.preserve_paths = "CartoMobileSDK.framework"
s.preserve_paths = "$frameworkDir"

s.frameworks = $frameworks

s.vendored_frameworks = $vendoredFrameworks
s.weak_frameworks = $weakFrameworks

s.vendored_frameworks = "$frameworkDir"

s.libraries = "z", "c++"

s.requires_arc = true

s.xcconfig = { "FRAMEWORK_SEARCH_PATHS" => "\"$(PODS_ROOT)/$frameworkName/\"" }

s.cocoapods_version = ">= 1.10.1"

end

0 comments on commit e8b214a

Please sign in to comment.