Skip to content

Commit

Permalink
Fix race condition between hack and hack_ffi targets
Browse files Browse the repository at this point in the history
Summary:
We use `hphp/hack/dev_env.sh` to set up various environment variables for
OCaml and Rust compilation; this ends with `eval $(opam env)`.

It turns out that if you try to run `opam env` while another instance of `opam` is running, the output is:

```
Another process has locked /Users/fredemmott/code/hhvm/build/hphp/hack/opam/hack-switch/.opam-switch/lock, waiting (C-c to abort)... lock acquired. OPAM_SWITCH_PREFIX=...... normal output here
```

... which can't be evaled.

This happens when doing a parallel build as both the `hack` (typechecker) and `hack_ffi` (rust stuff, both for the typechecker and hackc embedded in HHVM) targets use dev_env.sh

Fix this by splitting out a `dev_env_common.sh.in` and a `dev_env_rust_only.sh.in`, and making the `hack_ffi` target use the `dev_env_rust_only.sh`

CMake generates the `.sh` from the `.sh.in`

Reviewed By: kavoor

Differential Revision: D30583055

fbshipit-source-id: 0770bfc6528db15dd455398567f3d31beaed37c3
  • Loading branch information
fredemmott authored and facebook-github-bot committed Aug 26, 2021
1 parent 0377505 commit 6e60915
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
4 changes: 3 additions & 1 deletion hphp/hack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ set(CARGO_BUILD "${CMAKE_SOURCE_DIR}/hphp/hack/scripts/build_rust_to_ocaml.sh")
add_custom_target(
hack_ffi
COMMAND
. "${CMAKE_CURRENT_BINARY_DIR}/dev_env.sh" &&
. "${CMAKE_CURRENT_BINARY_DIR}/dev_env_rust_only.sh" &&
${CARGO_BUILD} hack_parser_ffi rust_parser_ffi &&
${CARGO_BUILD} rust_facts_ffi rust_facts_ffi &&
${CARGO_BUILD} compile_ffi compile_ffi &&
Expand Down Expand Up @@ -185,6 +185,8 @@ add_dependencies(libdecl_cpp_ffi_stubs hack_ffi)
set_target_properties(libdecl_cpp_ffi_stubs PROPERTIES IMPORTED_LOCATION ${LIBRUST_DECL_PATH})

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)
configure_file(dev_env_rust_only.sh.in dev_env_rust_only.sh ESCAPE_QUOTES @ONLY)

install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/hh_client
DESTINATION bin
Expand Down
22 changes: 1 addition & 21 deletions hphp/hack/dev_env.sh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
# Copyright (c) 2019, Facebook, Inc.
# All rights reserved.
#
Expand All @@ -11,24 +10,5 @@
#
# source $BUILD_DIR/hphp/hack/dev_env.sh

export CMAKE_SOURCE_DIR="@CMAKE_SOURCE_DIR@"
export CMAKE_INSTALL_FULL_SYSCONFDIR="@CMAKE_INSTALL_FULL_SYSCONFDIR@"
export CMAKE_INSTALL_FULL_BINDIR="@CMAKE_INSTALL_FULL_BINDIR@"

export HACK_NO_CARGO_VENDOR=true
export OPAMROOT="@OPAMROOT@"
export PYTHONPATH="@HPHP_HOME@" # needed for verify.py for `hack_dune_test`
export CARGO_HOME="@CMAKE_CURRENT_BINARY_DIR@/cargo_home"
export RUSTC="@RUSTC_BIN_DIR@/rustc"
export DUNE_BUILD_DIR="@DUNE_BUILD_DIR@"
export HACK_SOURCE_ROOT="@CMAKE_CURRENT_SOURCE_DIR@"
export HACK_BUILD_ROOT="@HACK_BUILD_ROOT@"
export HACK_BIN_DIR="@CMAKE_BINARY_DIR@/hphp/hack/bin"
export PATH="@RUSTC_BIN_DIR@:@CARGO_BIN_DIR@:$(dirname "@OPAM_EXECUTABLE@"):$PATH"

export HACK_EXTRA_INCLUDE_PATHS="@extra_include_paths@"
export HACK_EXTRA_LINK_OPTS="@extra_link_opts@"
export HACK_EXTRA_LIB_PATHS="@extra_lib_paths@"
export HACK_EXTRA_NATIVE_LIBRARIES="@extra_native_libraries@"

. "@CMAKE_CURRENT_BINARY_DIR@/dev_env_common.sh"
eval $(opam env)
28 changes: 28 additions & 0 deletions hphp/hack/dev_env_common.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# Copyright (c) 2019, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the "hack" directory of this source tree.

# Do not use this file directly - either use dev_env.sh or dev_env_rust_only.sh

export CMAKE_SOURCE_DIR="@CMAKE_SOURCE_DIR@"
export CMAKE_INSTALL_FULL_SYSCONFDIR="@CMAKE_INSTALL_FULL_SYSCONFDIR@"
export CMAKE_INSTALL_FULL_BINDIR="@CMAKE_INSTALL_FULL_BINDIR@"

export HACK_NO_CARGO_VENDOR=true
export OPAMROOT="@OPAMROOT@"
export PYTHONPATH="@HPHP_HOME@" # needed for verify.py for `hack_dune_test`
export CARGO_HOME="@CMAKE_CURRENT_BINARY_DIR@/cargo_home"
export RUSTC="@RUSTC_BIN_DIR@/rustc"
export DUNE_BUILD_DIR="@DUNE_BUILD_DIR@"
export HACK_SOURCE_ROOT="@CMAKE_CURRENT_SOURCE_DIR@"
export HACK_BUILD_ROOT="@HACK_BUILD_ROOT@"
export HACK_BIN_DIR="@CMAKE_BINARY_DIR@/hphp/hack/bin"
export PATH="@RUSTC_BIN_DIR@:@CARGO_BIN_DIR@:$(dirname "@OPAM_EXECUTABLE@"):$PATH"

export HACK_EXTRA_INCLUDE_PATHS="@extra_include_paths@"
export HACK_EXTRA_LINK_OPTS="@extra_link_opts@"
export HACK_EXTRA_LIB_PATHS="@extra_lib_paths@"
export HACK_EXTRA_NATIVE_LIBRARIES="@extra_native_libraries@"
14 changes: 14 additions & 0 deletions hphp/hack/dev_env_rust_only.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2019, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the "hack" directory of this source tree.

# This file is processed by cmake; the produced file is intended for both
# internal usage by the build system, and for direct usage by people working on
# Hack itself from CMake builds:
#
# . $BUILD_DIR/hphp/hack/dev_env_rust_only.sh

. "@CMAKE_CURRENT_BINARY_DIR@/dev_env_common.sh"
# Nothing else to do for rust :)

0 comments on commit 6e60915

Please sign in to comment.