Skip to content

Commit

Permalink
CMake to avoid checking in opcodes.rs (facebook#9030)
Browse files Browse the repository at this point in the history
Summary:
Separate opcodes macro into its own header so it can be as lightweight as possible when we include it in `gen-rust.cpp`. This makes compiling it in CMake much easier as we don't have to deal with many dependencies.

Pull Request resolved: facebook#9030

Pull Request resolved: facebook#9029

Reviewed By: fredemmott

Differential Revision: D34762816

fbshipit-source-id: 0aa4be5657a0d245fe23e3d95f9161489e25a20a
  • Loading branch information
voorka authored and facebook-github-bot committed Mar 10, 2022
1 parent 9733c3d commit af6e875
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 274 deletions.
17 changes: 13 additions & 4 deletions hphp/hack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ invoke_dune(hack_dune all)

set(CARGO_BUILD "${CMAKE_SOURCE_DIR}/hphp/hack/scripts/build_rust_to_ocaml.sh")

set(OPCODES "${CMAKE_BINARY_DIR}/hphp/tools/opcodes.rs")

add_executable(gen-rust1 "${CMAKE_SOURCE_DIR}/hphp/tools/hhbc-gen/gen-rust.cpp")
add_custom_command(
OUTPUT "${OPCODES}"
COMMAND gen-rust1 > "${OPCODES}"
COMMENT "Generating opcodes.rs"
)

if(DEFINED ENV{HACKDEBUG})
set(PROFILE "debug")
else()
Expand Down Expand Up @@ -196,7 +205,7 @@ add_custom_command(
${CARGO_BUILD} ffi_cbindgen ffi_cbindgen --exe
--header "${HHBC_AST_HEADER}" --srcs "${HHBC_AST_SRC_ARG}" --namespaces "HPHP,hackc,hhbc"
--includes "${FFI_HEADER},${NAMING_SPECIAL_NAMES_HEADER},${TYPE_CONSTRAINT_HEADER},${ATTR_HEADER},${FCALL_HEADER},${HHBC_HEADER}"
DEPENDS rustc cargo
DEPENDS rustc cargo "${OPCODES}"
COMMENT "Generating hhbc-ast.h"
)

Expand Down Expand Up @@ -230,7 +239,7 @@ function(build_cxx_bridge NAME FFI_BRIDGE_DIR)
${CMAKE_COMMAND} -E copy "${GENERATED}.rs.cc" "${RUST_PART_CXX}" &&
${CMAKE_COMMAND} -E copy "${GENERATED}.rs.h" "${RUST_PART_HEADER}"
WORKING_DIRECTORY ${FFI_BRIDGE_SRC}
DEPENDS rustc cargo
DEPENDS rustc cargo "${OPCODES}"
)
add_custom_target(
"${NAME}_cxx"
Expand Down Expand Up @@ -264,8 +273,8 @@ endif()
# you're working with Hack, but means that e.g. hhvm can't find
# `hh_single_compile` in the source tree. Keep it around, but require it to be
# explicitly used
add_custom_target(hack ALL DEPENDS hack_dune)
add_custom_target(hack_test DEPENDS hack_dune_test)
add_custom_target(hack ALL DEPENDS hack_dune "${OPCODES}")
add_custom_target(hack_test DEPENDS hack_dune_test "${OPCODES}")

configure_file(dev_env.sh.in dev_env.sh ESCAPE_QUOTES @ONLY)
configure_file(dev_env_common.sh.in dev_env_common.sh ESCAPE_QUOTES @ONLY)
Expand Down
1 change: 1 addition & 0 deletions hphp/hack/dev_env_common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export HACK_NO_CARGO_VENDOR=true
export OPAMROOT="@OPAMROOT@"
export PYTHONPATH="@HPHP_HOME@" # needed for verify.py for `hack_dune_test`
export CARGO_HOME="@CARGO_HOME@"
export CMAKE_BINARY_DIR="@CMAKE_BINARY_DIR@"
export RUSTC="@RUSTC_BIN_DIR@/rustc"
export DUNE_BUILD_DIR="@DUNE_BUILD_DIR@"
export HACK_SOURCE_ROOT="@CMAKE_CURRENT_SOURCE_DIR@"
Expand Down
Loading

0 comments on commit af6e875

Please sign in to comment.