Skip to content

Commit

Permalink
arm64 simulators & catalyst support (was #543 and #475) (#546)
Browse files Browse the repository at this point in the history
Summary:
This PR is #475 with adjustments
to folder names. It also fixes caches and CI issues.

Pull Request resolved: #546

Test Plan: CircleCI

Reviewed By: mhorowitz

Differential Revision: D29597379

Pulled By: Huxpro

fbshipit-source-id: f278f9c5503965cb998872993a1ce38cfcdaadcc
  • Loading branch information
Titozzz authored and facebook-github-bot committed Jul 9, 2021
1 parent 53235a8 commit 62e5abe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ if(APPLE AND HERMES_BUILD_APPLE_FRAMEWORK)
add_custom_command(TARGET libhermes POST_BUILD
COMMAND /usr/libexec/PlistBuddy -c "Add :MinimumOSVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:libhermes>/Info.plist
)
elseif(HERMES_APPLE_TARGET_PLATFORM MATCHES "catalyst")
add_custom_command(TARGET libhermes POST_BUILD
COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:libhermes>/Resources/Info.plist
)
elseif(HERMES_APPLE_TARGET_PLATFORM MATCHES "macos")
add_custom_command(TARGET libhermes POST_BUILD
COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:libhermes>/Resources/Info.plist
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ endif()
# https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_SYSROOT.html
set(CMAKE_OSX_SYSROOT ${HERMES_APPLE_TARGET_PLATFORM})

if(HERMES_APPLE_TARGET_PLATFORM MATCHES "catalyst")
set(CMAKE_OSX_SYSROOT "macosx")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-target x86_64-arm64-apple-ios14.0-macabi -isystem ${CMAKE_OSX_SYSROOT}/System/iOSSupport/usr/include")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-target x86_64-arm64-apple-ios14.0-macabi -isystem ${CMAKE_OSX_SYSROOT}/System/iOSSupport/usr/include")
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()

# This must be consistent with the release_version in:
# - android/build.gradle
# - npm/package.json
Expand Down
2 changes: 1 addition & 1 deletion hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Pod::Spec.new do |spec|
spec.source_files = "destroot/include/**/*.h"
spec.header_mappings_dir = "destroot/include"

spec.ios.vendored_frameworks = "destroot/Library/Frameworks/iphoneos/hermes.framework"
spec.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"
spec.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework"

spec.xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++14", "CLANG_CXX_LIBRARY" => "compiler-default", "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" }
Expand Down
18 changes: 9 additions & 9 deletions utils/build-apple-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function build_host_hermesc {
# Utility function to configure an Apple framework
function configure_apple_framework {
local build_cli_tools enable_bitcode
if [[ $1 == iphoneos ]]; then

if [[ $1 == iphoneos || $1 == catalyst ]]; then
enable_bitcode="true"
else
enable_bitcode="false"
Expand Down Expand Up @@ -93,27 +94,26 @@ function build_apple_framework {
}

# Accepts an array of frameworks and will place all of
# the architectures into the first one in the list
# the architectures into an universal folder and then remove
# the merged frameworks from destroot
function create_universal_framework {
cd ./destroot/Library/Frameworks || exit 1

local platforms=("$@")
local args=""

echo "Creating universal framework for platforms: ${platforms[*]}"

for i in "${!platforms[@]}"; do
platforms[$i]="${platforms[$i]}/hermes.framework/hermes"
args+="-framework ${platforms[$i]}/hermes.framework "
done

lipo -create -output "${platforms[0]}" "${platforms[@]}"
mkdir universal
xcodebuild -create-xcframework "$args" -output "universal/hermes.xcframework"

# Once all was linked into a single framework, clean destroot
# from unused frameworks
for platform in "${@:2}"; do
for platform in "$@"; do
rm -r "$platform"
done

lipo -info "${platforms[0]}"

cd - || exit 1
}
7 changes: 4 additions & 3 deletions utils/build-ios-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

. ./utils/build-apple-framework.sh

if [ ! -d destroot/Library/Frameworks/iphoneos/hermes.framework ]; then
if [ ! -d destroot/Library/Frameworks/universal/hermes.xcframework ]; then
ios_deployment_target=$(get_ios_deployment_target)

build_apple_framework "iphoneos" "armv7;armv7s;arm64" "$ios_deployment_target"
build_apple_framework "iphonesimulator" "x86_64;i386" "$ios_deployment_target"
build_apple_framework "iphonesimulator" "x86_64;arm64" "$ios_deployment_target"
build_apple_framework "catalyst" "x86_64;arm64" "$ios_deployment_target"

create_universal_framework "iphoneos" "iphonesimulator"
create_universal_framework "iphoneos" "iphonesimulator" "catalyst"
else
echo "Skipping; Clean \"destroot\" to rebuild".
fi

0 comments on commit 62e5abe

Please sign in to comment.