From 67e644d1a0c00b88d520a49571af48ceb249d8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Mon, 28 Sep 2020 15:04:05 -0700 Subject: [PATCH] Do not build cli tools for iphone targets (#354) 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: https://github.com/facebook/hermes/pull/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 --- .circleci/config.yml | 19 ++------- CMakeLists.txt | 75 ++++++++++++++++++++-------------- utils/build-apple-framework.sh | 11 +++-- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0df0d7e0275..9646816bbff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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: @@ -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: diff --git a/CMakeLists.txt b/CMakeLists.txt index 57ac59e205a..962675aa2ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -602,7 +605,6 @@ 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) @@ -610,6 +612,10 @@ 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) @@ -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 @@ -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 $ $ $ $ ${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 $ $ $ $ ${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) diff --git a/utils/build-apple-framework.sh b/utils/build-apple-framework.sh index 3c853d2abc6..4e257b30127 100755 --- a/utils/build-apple-framework.sh +++ b/utils/build-apple-framework.sh @@ -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 \ @@ -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"