From d14a9f0c6fedb4ff399d915c576fc2b707a927ad Mon Sep 17 00:00:00 2001 From: Taner Sener Date: Sat, 27 Feb 2021 12:33:12 +0000 Subject: [PATCH] support arm64-simulator on tvos --- scripts/function-apple.sh | 58 ++++++++++++++++++++++++++++++++++++--- scripts/function-ios.sh | 6 ++-- scripts/function-macos.sh | 4 +-- scripts/function-tvos.sh | 24 ++++++++++------ scripts/function.sh | 17 ++++++++++-- tvos.sh | 3 ++ 6 files changed, 92 insertions(+), 20 deletions(-) diff --git a/scripts/function-apple.sh b/scripts/function-apple.sh index b58ebfd..07308f5 100755 --- a/scripts/function-apple.sh +++ b/scripts/function-apple.sh @@ -91,6 +91,36 @@ disable_ios_architecture_not_supported_on_detected_sdk_version() { fi } +# +# 1. architecture index +# 2. detected sdk version +# +disable_tvos_architecture_not_supported_on_detected_sdk_version() { + local ARCH_NAME=$(get_arch_name $1) + + case ${ARCH_NAME} in + arm64-simulator) + + # INTRODUCED IN TVOS SDK 14 + if [[ $2 == 14* ]]; then + local SUPPORTED=1 + else + local SUPPORTED=0 + fi + ;; + *) + local SUPPORTED=1 + ;; + esac + + if [[ ${SUPPORTED} -ne 1 ]]; then + if [[ -z ${BUILD_FORCE} ]]; then + echo -e "INFO: Disabled ${ARCH_NAME} architecture which is not supported on SDK $2\n" 1>>"${BASEDIR}"/build.log 2>&1 + disable_arch "${ARCH_NAME}" + fi + fi +} + # # 1. architecture index # 2. detected sdk version @@ -925,7 +955,7 @@ get_apple_architectures_for_variant() { done ;; "${ARCH_VAR_TVOS}") - for index in ${ARCH_ARM64} ${ARCH_X86_64}; do + for index in ${ARCH_ARM64} ${ARCH_X86_64} ${ARCH_ARM64_SIMULATOR}; do ARCHITECTURES+=" $(get_full_arch_name "${index}") " done ;; @@ -935,7 +965,7 @@ get_apple_architectures_for_variant() { done ;; "${ARCH_VAR_APPLETVSIMULATOR}") - for index in ${ARCH_X86_64}; do + for index in ${ARCH_X86_64} ${ARCH_ARM64_SIMULATOR}; do ARCHITECTURES+=" $(get_full_arch_name "${index}") " done ;; @@ -1140,9 +1170,19 @@ get_sdk_name() { ;; esac ;; - i386 | arm64-simulator) + i386) echo "iphonesimulator" ;; + arm64-simulator) + case ${FFMPEG_KIT_BUILD_TYPE} in + ios) + echo "iphonesimulator" + ;; + tvos) + echo "appletvsimulator" + ;; + esac + ;; *-mac-catalyst) echo "macosx" ;; @@ -1180,9 +1220,19 @@ get_min_version_cflags() { ;; esac ;; - i386 | arm64-simulator) + i386) echo "-mios-simulator-version-min=$(get_min_sdk_version)" ;; + arm64-simulator) + case ${FFMPEG_KIT_BUILD_TYPE} in + ios) + echo "-mios-simulator-version-min=$(get_min_sdk_version)" + ;; + tvos) + echo "-mappletvsimulator-version-min=$(get_min_sdk_version)" + ;; + esac + ;; *-mac-catalyst) echo "-miphoneos-version-min=$(get_min_sdk_version)" ;; diff --git a/scripts/function-ios.sh b/scripts/function-ios.sh index 2fa6fb0..0139d8f 100755 --- a/scripts/function-ios.sh +++ b/scripts/function-ios.sh @@ -18,8 +18,8 @@ display_help() { COMMAND=$(echo "$0" | sed -e 's/\.\///g') echo -e "\n'$COMMAND' builds FFmpegKit for iOS platform. By default nine architectures (armv7, armv7s, arm64, \ -arm64-simulator, arm64-mac-catalyst, arm64e, i386, x86-64 and x86-64-mac-catalyst) are built without any external \ -libraries enabled. Options can be used to disable architectures and/or enable external libraries. Please note that GPL \ +arm64-mac-catalyst, arm64-simulator, arm64e, i386, x86-64 and x86-64-mac-catalyst) are enabled without any external \ +libraries. Options can be used to disable architectures and/or enable external libraries. Please note that GPL \ libraries (external libraries with GPL license) need --enable-gpl flag to be set explicitly. When compilation ends, \ libraries are created under the prebuilt folder.\n" echo -e "Usage: ./$COMMAND [OPTION]...\n" @@ -32,8 +32,8 @@ libraries are created under the prebuilt folder.\n" echo -e " --disable-armv7\t\tdo not build armv7 architecture [yes]" echo -e " --disable-armv7s\t\tdo not build armv7s architecture [yes]" echo -e " --disable-arm64\t\tdo not build arm64 architecture [yes]" - echo -e " --disable-arm64-simulator\tdo not build arm64-simulator architecture [yes]" echo -e " --disable-arm64-mac-catalyst\tdo not build arm64-mac-catalyst architecture [yes]" + echo -e " --disable-arm64-simulator\tdo not build arm64-simulator architecture [yes]" echo -e " --disable-arm64e\t\tdo not build arm64e architecture [yes]" echo -e " --disable-i386\t\tdo not build i386 architecture [yes]" echo -e " --disable-x86-64\t\tdo not build x86-64 architecture [yes]" diff --git a/scripts/function-macos.sh b/scripts/function-macos.sh index d8b791b..b63d2b4 100755 --- a/scripts/function-macos.sh +++ b/scripts/function-macos.sh @@ -10,8 +10,8 @@ enable_default_macos_architectures() { display_help() { COMMAND=$(echo "$0" | sed -e 's/\.\///g') - echo -e "\n'$COMMAND' builds FFmpegKit for macOS platform. By default two architectures (arm64 and x86-64) are built \ -without any external libraries enabled. Options can be used to disable architectures and/or enable external libraries. \ + echo -e "\n'$COMMAND' builds FFmpegKit for macOS platform. By default two architectures (arm64 and x86-64) are \ +enabled without any external libraries. Options can be used to disable architectures and/or enable external libraries. \ Please note that GPL libraries (external libraries with GPL license) need --enable-gpl flag to be set explicitly. \ When compilation ends, libraries are created under the prebuilt folder.\n" echo -e "Usage: ./$COMMAND [OPTION]...\n" diff --git a/scripts/function-tvos.sh b/scripts/function-tvos.sh index 092e91d..b2b30db 100755 --- a/scripts/function-tvos.sh +++ b/scripts/function-tvos.sh @@ -5,15 +5,16 @@ source "${BASEDIR}/scripts/function-apple.sh" enable_default_tvos_architectures() { ENABLED_ARCHITECTURES[ARCH_ARM64]=1 ENABLED_ARCHITECTURES[ARCH_X86_64]=1 + ENABLED_ARCHITECTURES[ARCH_ARM64_SIMULATOR]=1 } display_help() { COMMAND=$(echo "$0" | sed -e 's/\.\///g') - echo -e "\n'$COMMAND' builds FFmpegKit for tvOS platform. By default two architectures (arm64 and x86-64) are built \ -without any external libraries enabled. Options can be used to disable architectures and/or enable external libraries. \ -Please note that GPL libraries (external libraries with GPL license) need --enable-gpl flag to be set explicitly. \ -When compilation ends, libraries are created under the prebuilt folder.\n" + echo -e "\n'$COMMAND' builds FFmpegKit for tvOS platform. By default three architectures (arm64, arm64-simulator \ +and x86-64) are enabled without any external libraries. Options can be used to disable architectures and/or enable \ +external libraries. Please note that GPL libraries (external libraries with GPL license) need --enable-gpl flag to be \ +set explicitly. When compilation ends, libraries are created under the prebuilt folder.\n" echo -e "Usage: ./$COMMAND [OPTION]...\n" echo -e "Specify environment variables as VARIABLE=VALUE to override default build options.\n" @@ -23,6 +24,7 @@ When compilation ends, libraries are created under the prebuilt folder.\n" echo -e "Architectures:" echo -e " --disable-arm64\t\tdo not build arm64 architecture [yes]" + echo -e " --disable-arm64-simulator\tdo not build arm64-simulator architecture [yes]" echo -e " --disable-x86-64\t\tdo not build x86-64 architecture [yes]\n" echo -e "Libraries:" @@ -73,7 +75,7 @@ get_common_cflags() { arm64) echo "-fstrict-aliasing -fembed-bitcode -DTVOS ${LTS_BUILD_FLAG}${BUILD_DATE} -isysroot ${SDK_PATH}" ;; - x86-64) + x86-64 | arm64-simulator) echo "-fstrict-aliasing -DTVOS ${LTS_BUILD_FLAG}${BUILD_DATE} -isysroot ${SDK_PATH}" ;; esac @@ -84,6 +86,9 @@ get_arch_specific_cflags() { arm64) echo "-arch arm64 -target $(get_target) -march=armv8-a+crc+crypto -mcpu=generic -DFFMPEG_KIT_ARM64" ;; + arm64-simulator) + echo "-arch arm64 -target $(get_target) -march=armv8-a+crc+crypto -mcpu=generic -DFFMPEG_KIT_ARM64_SIMULATOR" + ;; x86-64) echo "-arch x86_64 -target $(get_target) -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -DFFMPEG_KIT_X86_64" ;; @@ -107,7 +112,7 @@ get_size_optimization_cflags() { ;; esac ;; - x86-64) + x86-64 | arm64-simulator) case $1 in x264 | ffmpeg) ARCH_OPTIMIZATION="-O2 -Wno-ignored-optimization-argument" @@ -134,7 +139,7 @@ get_size_optimization_asm_cflags() { arm64) ARCH_OPTIMIZATION="-Oz" ;; - x86-64) + x86-64 | arm64-simulator) ARCH_OPTIMIZATION="-O2" ;; esac @@ -307,6 +312,9 @@ get_arch_specific_ldflags() { arm64) echo "-arch arm64 -march=armv8-a+crc+crypto -fembed-bitcode" ;; + arm64-simulator) + echo "-arch arm64 -march=armv8-a+crc+crypto" + ;; x86-64) echo "-arch x86_64 -march=x86-64" ;; @@ -367,7 +375,7 @@ set_toolchain_paths() { LOCAL_ASMFLAGS="$(get_asmflags "$1")" case ${ARCH} in - arm64) + arm64*) if [ "$1" == "x265" ]; then export AS="${LOCAL_GAS_PREPROCESSOR}" export AS_ARGUMENTS="-arch aarch64" diff --git a/scripts/function.sh b/scripts/function.sh index 4d64900..c1e8803 100755 --- a/scripts/function.sh +++ b/scripts/function.sh @@ -16,7 +16,7 @@ get_arch_name() { 9) echo "x86-64" ;; # android, ios, macos, tvos 10) echo "x86-64-mac-catalyst" ;; # ios 11) echo "arm64-mac-catalyst" ;; # ios - 12) echo "arm64-simulator" ;; # ios + 12) echo "arm64-simulator" ;; # ios, tvos esac } @@ -427,7 +427,11 @@ get_target() { fi ;; arm64-simulator) - echo "$(get_target_cpu)-apple-ios$(get_min_sdk_version)-simulator" + if [[ ${FFMPEG_KIT_BUILD_TYPE} == "ios" ]]; then + echo "$(get_target_cpu)-apple-ios$(get_min_sdk_version)-simulator" + elif [[ ${FFMPEG_KIT_BUILD_TYPE} == "tvos" ]]; then + echo "$(get_target_cpu)-apple-tvos$(get_min_sdk_version)-simulator" + fi ;; x86-64) if [[ ${FFMPEG_KIT_BUILD_TYPE} == "android" ]]; then @@ -451,9 +455,16 @@ get_host() { arm-v7a | arm-v7a-neon) echo "arm-linux-androideabi" ;; - armv7 | armv7s | arm64e | i386 | *-mac-catalyst | arm64-simulator) + armv7 | armv7s | arm64e | i386 | *-mac-catalyst) echo "$(get_target_cpu)-ios-darwin" ;; + arm64-simulator) + if [[ ${FFMPEG_KIT_BUILD_TYPE} == "ios" ]]; then + echo "$(get_target_cpu)-ios-darwin" + elif [[ ${FFMPEG_KIT_BUILD_TYPE} == "tvos" ]]; then + echo "$(get_target_cpu)-tvos-darwin" + fi + ;; arm64-v8a) echo "aarch64-linux-android" ;; diff --git a/tvos.sh b/tvos.sh index f30d792..e9f6701 100755 --- a/tvos.sh +++ b/tvos.sh @@ -157,6 +157,9 @@ if [[ -n ${DISPLAY_HELP} ]]; then exit 0 fi +# DISABLE NOT SUPPORTED ARCHITECTURES +disable_tvos_architecture_not_supported_on_detected_sdk_version "${ARCH_ARM64_SIMULATOR}" "${DETECTED_TVOS_SDK_VERSION}" + # CHECK SOME RULES FOR .xcframework BUNDLES # 1. DO NOT ALLOW --lts AND --xcframework OPTIONS TOGETHER