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 "open3" 8 9# sdks/hermesc/osx-bin/ImportHermesc.cmake 10import_hermesc_file=File.join(__dir__, "..", "hermesc", "osx-bin", "ImportHermesc.cmake") 11 12# package.json 13package_file = File.join(__dir__, "..", "..", "package.json") 14package = JSON.parse(File.read(package_file)) 15version = package['version'] 16 17# We need to check the current git branch/remote to verify if 18# we're on a React Native release branch to actually build Hermes. 19currentbranch, err = Open3.capture3("git rev-parse --abbrev-ref HEAD") 20currentremote, err = Open3.capture3("git config --get remote.origin.url") 21 22source = {} 23git = "https://github.com/facebook/hermes.git" 24 25if ENV.has_key?('HERMES_ENGINE_TARBALL_PATH') 26 Pod::UI.puts '[Hermes] Using pre-built Hermes binaries from local path.' if Object.const_defined?("Pod::UI") 27 source[:http] = "file://#{ENV['HERMES_ENGINE_TARBALL_PATH']}" 28elsif version == '1000.0.0' 29 Pod::UI.puts '[Hermes] Hermes needs to be compiled, installing hermes-engine may take a while...'.yellow if Object.const_defined?("Pod::UI") 30 source[:git] = git 31 source[:commit] = `git ls-remote https://github.com/facebook/hermes main | cut -f 1`.strip 32elsif currentremote.strip.end_with?("facebook/react-native.git") and currentbranch.strip.end_with?("-stable") 33 Pod::UI.puts '[Hermes] Detected that you are on a React Native release branch, building Hermes from source...'.yellow if Object.const_defined?("Pod::UI") 34 hermestag_file = File.join(__dir__, "..", ".hermesversion") 35 hermestag = File.read(hermestag_file).strip 36 source[:git] = git 37 source[:tag] = hermestag 38else 39 if File.exist?(File.join(__dir__, "destroot")) 40 source[:path] = '.' 41 else 42 source[:http] = 'https://github.com/expo/react-native/releases/download/sdk-47.0.0/ABI47_0_0hermes.tar.gz' 43 end 44end 45 46module HermesHelper 47 # BUILD_TYPE = :debug 48 BUILD_TYPE = :release 49end 50 51Pod::Spec.new do |spec| 52 spec.name = "ABI47_0_0hermes-engine" 53 spec.version = version 54 spec.summary = "Hermes is a small and lightweight JavaScript engine optimized for running React Native." 55 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." 56 spec.homepage = "https://hermesengine.dev" 57 spec.license = package["license"] 58 spec.author = "Facebook" 59 spec.source = source 60 spec.platforms = { :osx => "10.13", :ios => "12.4" } 61 62 spec.preserve_paths = ["destroot/bin/*"].concat(HermesHelper::BUILD_TYPE == :debug ? ["**/*.{h,c,cpp}"] : []) 63 spec.source_files = "destroot/include/**/*.h" 64 spec.header_mappings_dir = "destroot/include" 65 66 spec.ios.vendored_frameworks = "destroot/Library/Frameworks/universal/ABI47_0_0hermes.xcframework" 67 spec.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework" 68 69 spec.xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", "CLANG_CXX_LIBRARY" => "compiler-default", "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" } 70 71 if source[:git] then 72 spec.prepare_command = <<-EOS 73 # When true, debug build will be used. 74 # See `build-apple-framework.sh` for details 75 DEBUG=#{HermesHelper::BUILD_TYPE == :debug} 76 77 # Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available 78 #{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""} 79 #{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""} 80 81 # Build iOS framework 82 ./utils/build-ios-framework.sh 83 84 # Build Mac framework 85 ./utils/build-mac-framework.sh 86 EOS 87 end 88end 89