Skip to content

Commit

Permalink
Do not build cli tools for iphone targets (facebook#354)
Browse files Browse the repository at this point in the history
Summary:
Currently (in `v0.7.0`) we build the CLI tools for both `iphone` and `macos` targets, which means that, when installing into the same location, cmake will skip installing the CLI tools from the second build. In our current situation, the second installation is the macOS build, which is really the only target from which we want CLI tools.

```
$ tar -zxvf hermes-engine-darwin-0.7.0.tgz
$ file package/destroot/bin/hermesc
package/destroot/bin/hermesc: Mach-O universal binary with 3 architectures: [arm_v7:Mach-O executable arm_v7] [arm_v7s:Mach-O executable arm_v7s] [arm64]
package/destroot/bin/hermesc (for architecture armv7):    Mach-O executable arm_v7
package/destroot/bin/hermesc (for architecture armv7s):    Mach-O executable arm_v7s
package/destroot/bin/hermesc (for architecture arm64):    Mach-O 64-bit executable arm64
```

Put differently, nobody runs `hermesc` on iOS, we always only want the macOS builds of these.

----

I opted to make building CLI tools a simple cmake option and then use that from the apple builds to control wether or not to include them.

Pull Request resolved: facebook#354

Test Plan:
With the `hermes-engine-darwin-0.7.0.tgz` artefact of this `npm` CI job:

```
$ tar -zxvf hermes-engine-darwin-0.7.0.tgz
$ file package/destroot/bin/hermesc
package/destroot/bin/hermesc: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64]
package/destroot/bin/hermesc (for architecture x86_64):	Mach-O 64-bit executable x86_64
package/destroot/bin/hermesc (for architecture arm64):	Mach-O 64-bit executable arm64
```

Reviewed By: tmikov

Differential Revision: D23824972

Pulled By: Huxpro

fbshipit-source-id: 9ec12c7231e1392a5287af510c6f30014784ed41
  • Loading branch information
alloy authored and facebook-github-bot committed Sep 28, 2020
1 parent 836274d commit 67e644d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 51 deletions.
19 changes: 3 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ apple_defaults: &apple_defaults
working_directory: ~/hermes
environment:
- TERM: dumb
- HERMES_WS_DIR: /tmp/hermes
# Homebrew currently breaks while updating:
# https://discuss.circleci.com/t/brew-install-fails-while-updating/32992
- HOMEBREW_NO_AUTO_UPDATE: 1
Expand Down Expand Up @@ -195,14 +196,7 @@ jobs:
ninja check-hermes
macos:
macos:
xcode: "12.0.0-beta"
environment:
- HERMES_WS_DIR: /tmp/hermes
- TERM: dumb
# Homebrew currently breaks while updating:
# https://discuss.circleci.com/t/brew-install-fails-while-updating/32992
- HOMEBREW_NO_AUTO_UPDATE: 1
<<: *apple_defaults
steps:
- checkout
- run:
Expand Down Expand Up @@ -317,14 +311,7 @@ jobs:

test-macos:
# CheckedMalloc.Death fails in release mode, so build a debug version
macos:
xcode: "10.0.0"
environment:
- HERMES_WS_DIR: /tmp/hermes
- TERM: dumb
# Homebrew currently breaks while updating:
# https://discuss.circleci.com/t/brew-install-fails-while-updating/32992
- HOMEBREW_NO_AUTO_UPDATE: 1
<<: *apple_defaults
steps:
- checkout
- run:
Expand Down
75 changes: 44 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ set(HERMES_ENABLE_THREAD_SANITIZER OFF CACHE BOOL
set(HERMES_ENABLE_FUZZING OFF CACHE BOOL
"Enable fuzzing")

set(HERMES_ENABLE_TOOLS ON CACHE BOOL
"Enable CLI tools")

# Enable bitcode
set(HERMES_ENABLE_BITCODE OFF CACHE BOOL
"Include bitcode with the framework")
Expand Down Expand Up @@ -602,14 +605,17 @@ set(CMAKE_CXX_EXTENSIONS OFF)

add_subdirectory(external/llvh)
add_subdirectory(utils/hermes-lit)
add_subdirectory(tools)
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(public)
add_subdirectory(external)
add_subdirectory(API)
add_subdirectory(android/intltest/java/com/facebook/hermes/test)

if(HERMES_ENABLE_TOOLS)
add_subdirectory(tools)
endif()

# Make sure JSI is compiled with PIC
set(save_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand All @@ -623,6 +629,10 @@ endif()
# Configure the test suites
#
if(HERMES_ENABLE_TEST_SUITE)
if(NOT HERMES_ENABLE_TOOLS)
message(FATAL_ERROR, "Running the test-suite requires the CLI tools to be built.")
endif()

add_subdirectory(unittests)

list(APPEND HERMES_TEST_DEPS
Expand Down Expand Up @@ -679,41 +689,44 @@ endif()

set(HERMES_GITHUB_DIR ${HERMES_BINARY_DIR}/github)
string(TOLOWER ${CMAKE_SYSTEM_NAME} HERMES_GITHUB_SYSTEM_NAME)
set(HERMES_CLI_GITHUB_FILE hermes-cli-${HERMES_GITHUB_SYSTEM_NAME}-v${HERMES_RELEASE_VERSION}.tar.gz)
set(HERMES_GITHUB_BUNDLE_DIR ${HERMES_BINARY_DIR}/bundle)

# If the github release should include extra files (like dlls)
if (HERMES_GITHUB_RESOURCE_DIR STREQUAL "")
set(HERMES_GITHUB_EXTRAS "")
else()
if (IS_DIRECTORY ${HERMES_GITHUB_RESOURCE_DIR})
file(GLOB HERMES_GITHUB_EXTRAS "${HERMES_GITHUB_RESOURCE_DIR}/*")
if(HERMES_ENABLE_TOOLS)
set(HERMES_CLI_GITHUB_FILE hermes-cli-${HERMES_GITHUB_SYSTEM_NAME}-v${HERMES_RELEASE_VERSION}.tar.gz)
set(HERMES_GITHUB_BUNDLE_DIR ${HERMES_BINARY_DIR}/bundle)

# If the github release should include extra files (like dlls)
if (HERMES_GITHUB_RESOURCE_DIR STREQUAL "")
set(HERMES_GITHUB_EXTRAS "")
else()
message(FATAL_ERROR "Extra resource dir not found: ${HERMES_GITHUB_RESOURCE_DIR}")
if (IS_DIRECTORY ${HERMES_GITHUB_RESOURCE_DIR})
file(GLOB HERMES_GITHUB_EXTRAS "${HERMES_GITHUB_RESOURCE_DIR}/*")
else()
message(FATAL_ERROR "Extra resource dir not found: ${HERMES_GITHUB_RESOURCE_DIR}")
endif()
endif()
endif()

# We need this as a separate target because Ninja doesn't run PRE_BUILD/PRE_LINKs in time
add_custom_command(
OUTPUT ${HERMES_GITHUB_BUNDLE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${HERMES_GITHUB_BUNDLE_DIR})
add_custom_target(make_bundle_dir DEPENDS ${HERMES_GITHUB_BUNDLE_DIR})

add_custom_command(
OUTPUT ${HERMES_GITHUB_DIR}/${HERMES_CLI_GITHUB_FILE}
WORKING_DIRECTORY ${HERMES_GITHUB_BUNDLE_DIR}
DEPENDS hermes hermesc hdb hbcdump make_bundle_dir
VERBATIM
COMMAND
# We need bin/hermes or Release/bin/hermes.exe in a predictable location
${CMAKE_COMMAND} -E copy $<TARGET_FILE:hermes> $<TARGET_FILE:hermesc> $<TARGET_FILE:hdb> $<TARGET_FILE:hbcdump> ${HERMES_GITHUB_EXTRAS} .
COMMAND
${CMAKE_COMMAND} -E tar zcf ${HERMES_GITHUB_DIR}/${HERMES_CLI_GITHUB_FILE} .
)
# We need this as a separate target because Ninja doesn't run PRE_BUILD/PRE_LINKs in time
add_custom_command(
OUTPUT ${HERMES_GITHUB_BUNDLE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${HERMES_GITHUB_BUNDLE_DIR})
add_custom_target(make_bundle_dir DEPENDS ${HERMES_GITHUB_BUNDLE_DIR})

add_custom_command(
OUTPUT ${HERMES_GITHUB_DIR}/${HERMES_CLI_GITHUB_FILE}
WORKING_DIRECTORY ${HERMES_GITHUB_BUNDLE_DIR}
DEPENDS hermes hermesc hdb hbcdump make_bundle_dir
VERBATIM
COMMAND
# We need bin/hermes or Release/bin/hermes.exe in a predictable location
${CMAKE_COMMAND} -E copy $<TARGET_FILE:hermes> $<TARGET_FILE:hermesc> $<TARGET_FILE:hdb> $<TARGET_FILE:hbcdump> ${HERMES_GITHUB_EXTRAS} .
COMMAND
${CMAKE_COMMAND} -E tar zcf ${HERMES_GITHUB_DIR}/${HERMES_CLI_GITHUB_FILE} .
)

add_custom_target(
github-cli-release
DEPENDS ${HERMES_GITHUB_DIR}/${HERMES_CLI_GITHUB_FILE})
add_custom_target(
github-cli-release
DEPENDS ${HERMES_GITHUB_DIR}/${HERMES_CLI_GITHUB_FILE})
endif()

set(HERMES_PKG_ROOT ${HERMES_GITHUB_DIR}/package-root)
set(HERMES_PKG_FRAMEWORK ${HERMES_PKG_ROOT}/destroot/Library/Frameworks/hermes.framework)
Expand Down
11 changes: 7 additions & 4 deletions utils/build-apple-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ fi

# Utility function to configure an Apple framework
function configure_apple_framework {
local enable_bitcode
if [[ $1 == "macosx" ]]; then
local build_cli_tools enable_bitcode
if [[ $1 == macosx ]]; then
build_cli_tools="true"
enable_bitcode="false"
else
build_cli_tools="false"
enable_bitcode="true"
fi

local cmake_flags=" \
-DHERMES_APPLE_TARGET_PLATFORM:STRING=$1 \
-DCMAKE_OSX_ARCHITECTURES:STRING=$2 \
Expand All @@ -43,7 +45,8 @@ function configure_apple_framework {
-DHERMES_ENABLE_TEST_SUITE:BOOLEAN=false \
-DHERMES_ENABLE_BITCODE:BOOLEAN=$enable_bitcode \
-DHERMES_BUILD_APPLE_FRAMEWORK:BOOLEAN=true \
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true
-DHERMES_BUILD_APPLE_DSYM:BOOLEAN=true \
-DHERMES_ENABLE_TOOLS:BOOLEAN=$build_cli_tools \
-DCMAKE_INSTALL_PREFIX:PATH=../destroot"

./utils/build/configure.py "$BUILD_TYPE" --cmake-flags "$cmake_flags" --build-system="$BUILD_SYSTEM" "build_$1"
Expand Down

0 comments on commit 67e644d

Please sign in to comment.