1# Copyright (c) Meta Platforms, Inc. and affiliates. 2# 3# This source code is licensed under the MIT license found in the 4# LICENSE file in the root directory of this source tree. 5 6require "json" 7require_relative "./hermes-utils.rb" 8 9react_native_path = File.join(__dir__, "..", "..") 10 11# Whether Hermes is built for Release or Debug is determined by the PRODUCTION envvar. 12build_type = ENV['PRODUCTION'] == "1" ? :release : :debug 13 14# package.json 15package = JSON.parse(File.read(File.join(react_native_path, "package.json"))) 16version = package['version'] 17 18# sdks/.hermesversion 19hermestag_file = File.join(react_native_path, "sdks", ".hermesversion") 20build_from_source = ENV['BUILD_FROM_SOURCE'] === 'true' 21 22git = "https://github.com/facebook/hermes.git" 23 24abort_if_invalid_tarball_provided! 25 26source = compute_hermes_source(build_from_source, hermestag_file, git, version, build_type, react_native_path) 27 28Pod::Spec.new do |spec| 29 spec.name = "ABI49_0_0hermes-engine" 30 spec.version = version 31 spec.summary = "Hermes is a small and lightweight JavaScript engine optimized for running React Native." 32 spec.description = "Hermes is a JavaScript engine optimized for fast start-up of React Native apps. It features ahead-of-time static optimization and compact bytecode." 33 spec.homepage = "https://hermesengine.dev" 34 spec.license = package['license'] 35 spec.author = "Facebook" 36 spec.source = source 37 spec.platforms = { :osx => "10.13", :ios => "12.4" } 38 39 spec.preserve_paths = '**/*.*' 40 spec.source_files = '' 41 42 spec.pod_target_xcconfig = { 43 "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", 44 "CLANG_CXX_LIBRARY" => "compiler-default" 45 }.merge!(build_type == :debug ? { "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" } : {}) 46 47 spec.ios.vendored_frameworks = "destroot/Library/Frameworks/ios/hermes.framework" 48 spec.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework" 49 50 if source[:http] then 51 52 spec.subspec 'Pre-built' do |ss| 53 ss.preserve_paths = ["destroot/bin/*"].concat(build_type == :debug ? ["**/*.{h,c,cpp}"] : []) 54 ss.source_files = "destroot/include/**/*.h" 55 ss.exclude_files = ["destroot/include/jsi/jsi/JSIDynamic.{h,cpp}", "destroot/include/jsi/jsi/jsilib-*.{h,cpp}"] 56 ss.header_mappings_dir = "destroot/include" 57 ss.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/ABI49_0_0hermes.xcframework" 58 ss.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework" 59 end 60 61 elsif source[:git] then 62 63 spec.subspec 'Hermes' do |ss| 64 ss.source_files = '' 65 ss.public_header_files = 'API/hermes/*.h' 66 ss.header_dir = 'ABI49_0_0hermes' 67 end 68 69 spec.subspec 'JSI' do |ss| 70 ss.source_files = '' 71 ss.public_header_files = 'API/jsi/jsi/*.h' 72 ss.header_dir = 'ABI49_0_0jsi' 73 end 74 75 spec.subspec 'Public' do |ss| 76 ss.source_files = '' 77 ss.public_header_files = 'public/hermes/Public/*.h' 78 ss.header_dir = 'ABI49_0_0hermes/Public' 79 end 80 81 hermesc_path = "${PODS_ROOT}/hermes-engine/build_host_hermesc" 82 83 if ENV.has_key?('HERMES_OVERRIDE_HERMESC_PATH') && File.exist?(ENV['HERMES_OVERRIDE_HERMESC_PATH']) then 84 hermesc_path = ENV['HERMES_OVERRIDE_HERMESC_PATH'] 85 end 86 87 spec.user_target_xcconfig = { 88 'HERMES_CLI_PATH' => "#{hermesc_path}/bin/hermesc" 89 } 90 91 spec.prepare_command = ". #{react_native_path}/sdks/hermes-engine/utils/create-dummy-hermes-xcframework.sh" 92 93 CMAKE_BINARY = %x(command -v cmake | tr -d '\n') 94 # NOTE: Script phases are sorted alphabetically inside Xcode project 95 spec.script_phases = [ 96 { 97 :name => '[RN] [1] Build Hermesc', 98 :script => <<-EOS 99 . ${PODS_ROOT}/../.xcode.env 100 export CMAKE_BINARY=${CMAKE_BINARY:-#{CMAKE_BINARY}} 101 . ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path} 102 EOS 103 }, 104 { 105 :name => '[RN] [2] Build Hermes', 106 :script => <<-EOS 107 . ${PODS_ROOT}/../.xcode.env 108 export CMAKE_BINARY=${CMAKE_BINARY:-#{CMAKE_BINARY}} 109 . ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermes-xcode.sh #{version} #{hermesc_path}/ImportHermesc.cmake 110 EOS 111 } 112 ] 113 end 114end 115