Skip to content

Commit

Permalink
feat: add tvOS support (#1529)
Browse files Browse the repository at this point in the history
Summary:
Add Apple TV support for Hermes.

*Note:* This support requires a few source file changes to work around code that will not compile for tvOS. Comments containing the compiler errors have been added.

Pull Request resolved: #1529

Test Plan:
- tvOS is added to the Apple test app and to Circle CI
- Patch will be added to a test build of React Native TV to verify against RNTester

Reviewed By: tmikov

Differential Revision: D64030986

Pulled By: neildhar

fbshipit-source-id: 3338a4b97f3e750d1a116916f051d23c15d51976
  • Loading branch information
douglowder authored and facebook-github-bot committed Oct 10, 2024
1 parent 2e2483e commit 924f1d1
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 126 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ jobs:
-destination 'platform=visionOS Simulator,name=Apple Vision Pro' \
-scheme ApplePlatformsIntegrationVisionOSTests
working_directory: test/ApplePlatformsIntegrationTestApp
- run:
name: Test Apple TV application
command: |
xcodebuild test \
-workspace ApplePlatformsIntegrationTests.xcworkspace \
-configuration Debug \
-destination 'platform=tvOS Simulator,name=Apple TV' \
-scheme ApplePlatformsIntegrationTVOSTests
working_directory: test/ApplePlatformsIntegrationTestApp

build-apple-runtime:
<<: *apple_defaults
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
build_macosx
destroot
- name: Install dependencies
run: brew install cmake ninja
run: brew install cmake ninja && xcodebuild -downloadPlatform visionOS && xcodebuild -downloadPlatform tvOS
- name: Build the test application
run: pod install
working-directory: test/ApplePlatformsIntegrationTestApp
Expand All @@ -201,6 +201,22 @@ jobs:
-destination 'platform=iOS Simulator,name=iPhone 14' \
-scheme ApplePlatformsIntegrationMobileTests
working-directory: test/ApplePlatformsIntegrationTestApp
- name: Test Apple Vision application
run: |-
xcodebuild test \
-workspace ApplePlatformsIntegrationTests.xcworkspace \
-configuration Debug \
-destination 'platform=visionOS Simulator,name=Apple Vision Pro' \
-scheme ApplePlatformsIntegrationVisionOSTests
working-directory: test/ApplePlatformsIntegrationTestApp
- name: Test Apple TV application
run: |-
xcodebuild test \
-workspace ApplePlatformsIntegrationTests.xcworkspace \
-configuration Debug \
-destination 'platform=tvOS Simulator,name=Apple TV' \
-scheme ApplePlatformsIntegrationTVOSTests
working-directory: test/ApplePlatformsIntegrationTestApp
package-apple-runtime:
runs-on: macos-latest
needs:
Expand Down
4 changes: 4 additions & 0 deletions API/hermes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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 "appletv")
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
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ if(HERMES_APPLE_TARGET_PLATFORM MATCHES "catalyst")
set(THREADS_PREFER_PTHREAD_FLAG ON)
endif()

if(HERMES_APPLE_TARGET_PLATFORM MATCHES "appletv")
add_definitions(-DTARGET_OS_IPHONE=1)
add_definitions(-DTARGET_OS_TV=1)
endif()

# This must be consistent with the release_version in:
# - android/build.gradle
# - npm/package.json
Expand Down
2 changes: 2 additions & 0 deletions external/icu_decls/unicode/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@
# include <TargetConditionals.h>
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */
# define U_PLATFORM U_PF_IPHONE
# elif defined(TARGET_OS_TV) && TARGET_OS_TV /* variant of TARGET_OS_MAC */
# define U_PLATFORM U_PF_IPHONE
# else
# define U_PLATFORM U_PF_DARWIN
# endif
Expand Down
3 changes: 2 additions & 1 deletion external/llvh/lib/Support/Unix/Process.inc
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ void Process::PreventCoreFiles() {
setrlimit(RLIMIT_CORE, &rlim);
#endif

#if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
#if defined(HAVE_MACH_MACH_H) && !defined(__GNU__) && !(defined(TARGET_OS_TV) && TARGET_OS_TV)
// Disable crash reporting on Mac OS X 10.0-10.4
// Disable crash reporting on tvOS: 'task_get_exception_ports' is unavailable: not available on tvOS

// get information about the original set of exception ports for the task
mach_msg_type_number_t Count = 0;
Expand Down
4 changes: 4 additions & 0 deletions external/llvh/lib/Support/Unix/Program.inc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
}
#endif

// error: 'fork' is unavailable: not available on tvOS
// error: 'execve' is unavailable: not available on tvOS
#if !(defined(TARGET_OS_TV) && TARGET_OS_TV)
// Create a child process.
int child = fork();
switch (child) {
Expand Down Expand Up @@ -325,6 +328,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
PI.Process = child;

return true;
#endif // TARGET_OS_TV
}

namespace llvh {
Expand Down
3 changes: 2 additions & 1 deletion hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ Pod::Spec.new do |spec|
# The podspec would be serialized to JSON and people will download prebuilt binaries instead of the source.
# TODO(use the hash field as a validation mechanism when the process is stable)
spec.source = ENV['hermes-artifact-url'] ? { http: ENV['hermes-artifact-url'] } : { git: "https://github.com/facebook/hermes.git", tag: "v#{spec.version}" }
spec.platforms = { :osx => "10.13", :ios => "12.0", :visionos => "1.0" }
spec.platforms = { :osx => "10.13", :ios => "12.0", :visionos => "1.0", :tvos => "12.0" }

spec.preserve_paths = ["destroot/bin/*"].concat(HermesHelper::BUILD_TYPE == :debug ? ["**/*.{h,c,cpp}"] : [])
spec.source_files = "destroot/include/**/*.h"
spec.header_mappings_dir = "destroot/include"

spec.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"
spec.visionos.vendored_frameworks = "destroot/Library/Frameworks/universal/hermes.xcframework"
spec.tvos.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++17", "CLANG_CXX_LIBRARY" => "compiler-default", "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" }
Expand Down
3 changes: 3 additions & 0 deletions lib/Support/OSCompatPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,13 @@ bool unset_env(const char *name) {
void *SigAltStackLeakSuppressor::stackRoot_{nullptr};

SigAltStackLeakSuppressor::~SigAltStackLeakSuppressor() {
// error: 'sigaltstack' is unavailable: not available on tvOS
#if !(defined(TARGET_OS_TV) && TARGET_OS_TV)
stack_t oldAltStack;
if (sigaltstack(nullptr, &oldAltStack) == 0) {
stackRoot_ = oldAltStack.ss_sp;
}
#endif
}

} // namespace oscompat
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Loading

0 comments on commit 924f1d1

Please sign in to comment.