From 8151682109696530172bc0116935bfe0fe1a0a71 Mon Sep 17 00:00:00 2001 From: John Elliott Date: Sun, 29 Oct 2023 15:11:18 -0700 Subject: [PATCH] Paramatized rust_static_library to enable CXX support (#763) Summary: X-link: https://github.com/facebookincubator/zstrong/pull/610 X-link: https://github.com/facebookincubator/crux/pull/10 X-link: https://github.com/facebookexternal/traffixr/pull/3 X-link: https://github.com/facebookincubator/katran/pull/205 X-link: https://github.com/facebookincubator/fizz/pull/101 X-link: https://github.com/facebookexperimental/rust-shed/pull/43 X-link: https://github.com/facebook/wangle/pull/221 X-link: https://github.com/facebook/openr/pull/150 X-link: https://github.com/facebook/hhvm/pull/9403 X-link: https://github.com/facebook/folly/pull/2092 X-link: https://github.com/facebook/fb303/pull/42 X-link: https://github.com/facebookincubator/velox/pull/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 --- build/fbcode_builder/CMake/RustStaticLibrary.cmake | 14 ++++++++++++-- eden/scm/lib/edenfs_ffi/CMakeLists.txt | 3 +-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build/fbcode_builder/CMake/RustStaticLibrary.cmake b/build/fbcode_builder/CMake/RustStaticLibrary.cmake index dd57b2b3dcaa5..bd1b5f96ac8ac 100644 --- a/build/fbcode_builder/CMake/RustStaticLibrary.cmake +++ b/build/fbcode_builder/CMake/RustStaticLibrary.cmake @@ -80,7 +80,7 @@ set_property(GLOBAL APPEND PROPERTY JOB_POOLS rust_job_pool=1) # Cargo build static library. # # ```cmake -# rust_static_library( [CRATE ] [FEATURES ]) +# rust_static_library( [CRATE ] [FEATURES ] [USE_CXX_INCLUDE]) # ``` # # Parameters: @@ -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 @@ -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}") @@ -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 "$" diff --git a/eden/scm/lib/edenfs_ffi/CMakeLists.txt b/eden/scm/lib/edenfs_ffi/CMakeLists.txt index 0ba901ff159e0..6fef5d3314ce6 100644 --- a/eden/scm/lib/edenfs_ffi/CMakeLists.txt +++ b/eden/scm/lib/edenfs_ffi/CMakeLists.txt @@ -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 @@ -24,7 +24,6 @@ target_include_directories( PUBLIC $ $ - ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/ ) target_link_libraries( edenfs_ffi