2020-10-10 00:15:13 +03:00
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
module HermesHelper
# BUILD_TYPE = :debug
BUILD_TYPE = :release
end
Pod::Spec.new do |spec|
spec.name = "hermes-engine"
2021-04-28 23:05:09 +03:00
spec.version = "0.8.0"
2020-10-10 00:15:13 +03:00
spec.summary = "Hermes is a small and lightweight JavaScript engine optimized for running React Native."
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."
spec.homepage = "https://hermesengine.dev"
spec.license = { type: "MIT", file: "LICENSE" }
spec.author = "Facebook"
2020-12-17 01:13:55 +03:00
# This env var should be supplied with a CDN URL of the "hermes-runtime-darwin.tgz" on the Github releases before pod push.
2020-10-10 00:15:13 +03:00
# The podspec would be serialized to JSON and people will download prebuilt binaries instead of the source.
2020-12-17 01:13:55 +03:00
# 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}" }
Rework iOS & Mac CI setup to fix creating artefacts (#393)
Summary:
There are a few things that I have reworked in this PR, and I have done my best to explain them in as much details as possible.
## The challenge
First, let me start with the root cause of why I started working on this PR:
> The `hermes-engine-darwin-vX.X.X.tgz` archive created by CircleCI (and later published to npm or CocoaPods) contains iPhone only architectures, and does not contain MacOS and iPhone Simulator ones.
The reason for that is simple {emoji:1f447}
On CircleCI, we use [`cmake` to build a special `hermes-runtime-darwin-cocoapods-release` target](https://github.com/facebook/hermes/blob/master/.circleci/config.yml#L292). In order to actually build it, we need to tell `cmake` the build folder to use.
The challenge is that we have three separate build folders - `build_iphoneos`, `build_iphonesimulator` and `build_macosx` - each, for a different platform that we support. Thanks to that, we can avoid different issues (especially between iPhone/iPhone Simulator and Mac) when building different platforms back and forth, as well as share the cache on subsequent builds. We can be also more explicit when invoking `cmake`, which helps to locate the correct build folder, e.g. [when building CLI tools](https://github.com/facebook/hermes/pull/393/commits/8c3f2fe793e6fc40b46d81fcafa2dcf6161c4e3b).
Side effect of that design decision is that **we can't just use `cmake` to build an archive with all platforms and architectures we want**. It just doesn't work (or I am not aware of a way to make it work).
## The solution
Do not build a custom `cmake` target (named "hermes-runtime-darwin-cocoapods-release"). Use plain bash to build Hermes for each platform we want and then, manually copy and package that into an archive.
We already use that same approach while in development - there is a custom post install phase in `hermes-engine.podspec` It consists of `build_apple_framework` that builds Hermes for a given platform with flags/settings specified and `create_universal_framework` that combines multiple platforms into a single framework (e.g. iPhone and iPhone Simulator).
## Additional benefits
Together with aforementioned, I have implemented several additional improvements.
1. There is no `spec.prepare_command` in a Hermes podspec
We no longer implicitly build a framework when running `pod install` in a `test/ApplePlatformsIntegrationTestApp`. We now need to explicitly run e.g. `./utils/build-mac-framework.sh`.
As a result, I have decided to remove that step from a podspec. We no longer need to conditionally include/remove it, depending on a presence of an environmental variable.
2. Better CircleCI configuration with shared cache
Since scripts were extracted to separate files, they can be now directly run from a CircleCI. We don't need a custom `cmake` target, we can use the same code that is already used in development (and has been tested to work flawlessly).
Thanks to a few different scripts, we can have a set of CircleCI jobs, each responsible for a different aspect of building and packaging Hermes for Darwin:
- build_apple_platforms - to build MacOS, iPhone, iPhone Simulator and CLI
- test_apple_platforms - to run tests on previously built frameworks
- package_apple_platforms - to package frameworks into archives
The build action is performed only once, as a part of `build_apple_platforms` and is cached for subsequent runs and following jobs in the pipeline, to reduce the amount of time needed to test and verify results.
## How to test it
Copy `Hermes-engine-darwin-vx.x.x.tar.gz` from CircleCI `npm` job and paste it into your `Pods` folder. It will replace currently released version to CocoaPods that doesn't contain all the platforms.
Re-run on iPhone Simulator. Linking error with missing files/classes for given architecture will be gone.
--
Fixes https://github.com/facebook/hermes/issues/353 (we no longer build CLI separately).
Pull Request resolved: https://github.com/facebook/hermes/pull/393
Reviewed By: mhorowitz
Differential Revision: D24429589
Pulled By: Huxpro
fbshipit-source-id: 8c0c2f562d841921d6fcd70652e7d526ef3f03d7
2020-10-23 06:05:48 +03:00
spec.platforms = { :osx => "10.13", :ios => "10.0" }
2020-10-10 00:15:13 +03:00
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/iphoneos/hermes.framework"
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" }
2020-10-24 01:08:37 +03:00
unless ENV['hermes-artifact-url']
spec.prepare_command = <<-EOS
# When true, debug build will be used.
# See `build-apple-framework.sh` for details
DEBUG=#{HermesHelper::BUILD_TYPE == :debug}
# Build iOS framework
./utils/build-ios-framework.sh
2020-12-17 01:13:55 +03:00
2020-10-24 01:08:37 +03:00
# Build Mac framework
./utils/build-mac-framework.sh
EOS
end
2020-10-10 00:15:13 +03:00
end