Skip to content

Commit

Permalink
Paramatized rust_static_library to enable CXX support (facebook#763)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookincubator/zstrong#610

X-link: facebookincubator/crux#10

X-link: facebookexternal/traffixr#3

X-link: facebookincubator/katran#205

X-link: facebookincubator/fizz#101


X-link: facebookexperimental/rust-shed#43

X-link: facebook/wangle#221

X-link: facebook/openr#150

X-link: facebook/hhvm#9403

X-link: facebook/folly#2092

X-link: facebook/fb303#42

X-link: facebookincubator/velox#7301

We are now using CXX (and not just bindgen/cbindgen) for building our Rust C/C++ APIS, but our OSS tooling did not ergomically support this. This change adds a single option, `USE_CXX_INCLUDE`, to the CMake function, `rust_static_library`, to enable adding the `cxxbridge` path to the include path.

Differential Revision: D50772544
  • Loading branch information
John Elliott authored and facebook-github-bot committed Oct 29, 2023
1 parent 295e3b0 commit 8151682
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 12 additions & 2 deletions build/fbcode_builder/CMake/RustStaticLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ set_property(GLOBAL APPEND PROPERTY JOB_POOLS rust_job_pool=1)
# Cargo build static library.
#
# ```cmake
# rust_static_library(<TARGET> [CRATE <CRATE_NAME>] [FEATURES <FEATURE_NAME>])
# rust_static_library(<TARGET> [CRATE <CRATE_NAME>] [FEATURES <FEATURE_NAME>] [USE_CXX_INCLUDE])
# ```
#
# Parameters:
Expand All @@ -92,6 +92,8 @@ set_property(GLOBAL APPEND PROPERTY JOB_POOLS rust_job_pool=1)
# fallback to `${TARGET}`.
# - FEATURE_NAME:
# Name of the Rust feature to enable.
# - USE_CXX_INCLUDE:
# Include cxx.rs include path in `${TARGET}` INTERFACE.
#
# This function creates two targets:
# - "${TARGET}": an interface library target contains the static library built
Expand All @@ -103,7 +105,7 @@ set_property(GLOBAL APPEND PROPERTY JOB_POOLS rust_job_pool=1)
# headers with the interface library.
#
function(rust_static_library TARGET)
fb_cmake_parse_args(ARG "" "CRATE;FEATURES" "" "${ARGN}")
fb_cmake_parse_args(ARG "USE_CXX_INCLUDE" "CRATE;FEATURES" "" "${ARGN}")

if(DEFINED ARG_CRATE)
set(crate_name "${ARG_CRATE}")
Expand Down Expand Up @@ -158,6 +160,14 @@ function(rust_static_library TARGET)
INTERFACE_INSTALL_LIBNAME
"${CMAKE_STATIC_LIBRARY_PREFIX}${crate_name}_rs${CMAKE_STATIC_LIBRARY_SUFFIX}"
)

if(DEFINED ARG_USE_CXX_INCLUDE)
target_include_directories(
${TARGET}
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/
)
endif()

target_link_libraries(
${TARGET}
INTERFACE "$<BUILD_INTERFACE:${rust_staticlib}>"
Expand Down
3 changes: 1 addition & 2 deletions eden/scm/lib/edenfs_ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Due to some tools changing '-' to '_' when building,
# this library/crate is named using an '_' so that it can link successfully.
rust_static_library(rust_edenfs_ffi CRATE edenfs_ffi)
rust_static_library(rust_edenfs_ffi CRATE edenfs_ffi USE_CXX_INCLUDE)
install_rust_static_library(
rust_edenfs_ffi
INSTALL_DIR lib
Expand All @@ -24,7 +24,6 @@ target_include_directories(
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/
)
target_link_libraries(
edenfs_ffi
Expand Down

0 comments on commit 8151682

Please sign in to comment.