Skip to content

Commit

Permalink
Paramatized rust_static_library to enable CXX support (#205)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/fboss#161

X-link: facebookincubator/delos_core#8

X-link: facebookincubator/zstrong#610

X-link: facebookincubator/crux#10

X-link: facebookexternal/traffixr#3

Pull Request resolved: #205

X-link: facebookincubator/fizz#101

X-link: facebook/sapling#763

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.

Reviewed By: xavierd

Differential Revision: D50772544

fbshipit-source-id: caf00ade9b651965b6dd59e2cf0d8797d3ae1dce
  • Loading branch information
jdelliot authored and facebook-github-bot committed Oct 30, 2023
1 parent c06a5a2 commit f12ad6d
Showing 1 changed file with 12 additions and 2 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

0 comments on commit f12ad6d

Please sign in to comment.