Skip to content

Commit

Permalink
Enable OSS builds for edenfs_ffi
Browse files Browse the repository at this point in the history
Summary: For backingstore as well as edenfs_ffi, we want to use [CXX](http://cxx.rs). However, we hadn't been able to get it working for our CMake based OSS builds. This diff aims to close that gap.

Differential Revision: D50674596
  • Loading branch information
John Elliott authored and facebook-github-bot committed Oct 29, 2023
1 parent 2c219c1 commit 6a89029
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 70 deletions.
2 changes: 1 addition & 1 deletion eden/fs/store/filter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ target_link_libraries(eden_store_filter PUBLIC
eden_config
eden_model
eden_utils
# hg_eden_ffi
edenfs_ffi
${RE2_LIBRARY})
1 change: 1 addition & 0 deletions eden/scm/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.

add_subdirectory(edenfs_ffi)
add_subdirectory(backingstore)
2 changes: 1 addition & 1 deletion eden/scm/lib/backingstore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ else()
)
endif()

# Reqwest links against the security framework.
# Request links against the security framework.
if (APPLE)
target_link_libraries(
backingstore
Expand Down
110 changes: 43 additions & 67 deletions eden/scm/lib/edenfs_ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,56 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.

find_program(CARGO_COMMAND cargo REQUIRED)
set(crate_name edenfs_ffi)
if(DEFINED ARG_FEATURES)
set(cargo_flags build
$<IF:$<CONFIG:Debug>,,--release>
-p ${crate_name}
--features ${ARG_FEATURES})
else()
set(cargo_flags build $<IF:$<CONFIG:Debug>,,--release> -p ${crate_name})
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TARGET_DIR "debug")
else ()
set(TARGET_DIR "release")
endif ()

if(USE_CARGO_VENDOR)
set(extra_cargo_env "CARGO_HOME=${RUST_CARGO_HOME}")
set(cargo_flags ${cargo_flags})
endif()

set(CARGO_MANIFEST ${CMAKE_SOURCE_DIR}/eden/scm/lib/edenfs_ffi/Cargo.toml)
set(CARGO_TARGET_DIR ${CMAKE_SOURCE_DIR}/eden/scm/lib/edenfs_ffi/target)

set(FFI_SOURCE_FILE ${CMAKE_SOURCE_DIR}/eden/scm/lib/edenfs_ffi/src/lib.rs)
set(FFI_BRIDGE_CPP ${CARGO_TARGET_DIR}/cxxbridge/edenfs_ffi/src/lib.rs.cc)
set(FFI_LIB ${CARGO_TARGET_DIR}/${TARGET_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}edenfs_ffi${CMAKE_STATIC_LIBRARY_SUFFIX})

# Add a custom command that builds the rust crate and generates C++ bridge code
add_custom_command(
OUTPUT ${FFI_BRIDGE_CPP} ${FFI_LIB}
COMMAND ${extra_cargo_env}
${CARGO_COMMAND}
${cargo_flags}
--manifest-path ${CARGO_MANIFEST}
DEPENDS ${FFI_SOURCE_FILE}
USES_TERMINAL
COMMENT "Running cargo..."
rust_static_library(rust_edenfs_ffi CRATE edenfs_ffi)
install_rust_static_library(
rust_edenfs_ffi
INSTALL_DIR lib
)

file(GLOB STORE_FFI_SRCS ${FFI_BRIDGE_CPP})

add_library(
hg_eden_ffi STATIC
${FFI_BRIDGE_CPP}
file(GLOB edenfs_ffi_srcs "src/ffi.cpp")
add_library(edenfs_ffi "${edenfs_ffi_srcs}")
set_target_properties(
edenfs_ffi
PROPERTIES
PUBLIC_HEADER
"src/ffi.h"
)

target_include_directories(
hg_eden_ffi
PRIVATE
include/
${CARGO_TARGET_DIR}/eden/scm/lib/edenfs_ffi/src/
edenfs_ffi
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/
)

target_link_libraries(hg_eden_ffi PUBLIC
eden_model
eden_utils
${RE2_LIBRARY}
${FFI_LIB})

set_target_properties(
hg_eden_ffi
PROPERTIES ADDITIONAL_CLEAN_FILES ${CARGO_TARGET_DIR}
target_link_libraries(
edenfs_ffi
PRIVATE
rust_edenfs_ffi
Folly::folly
eden_model
eden_utils
${RE2_LIBRARY}
)

# Windows-only configuration
if(WIN32)
target_link_libraries(hg_eden_ffi userenv ws2_32 bcrypt)
set_target_properties(
hg_eden_ffi
PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
)
target_link_libraries(
edenfs_ffi
userenv
ws2_32
bcrypt
)
set_target_properties(
edenfs_ffi
PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
)
endif()

install(
TARGETS edenfs_ffi
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
PUBLIC_HEADER DESTINATION "include/eden/scm/lib/edenfs_ffi/src"
)
2 changes: 1 addition & 1 deletion eden/scm/lib/edenfs_ffi/src/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#pragma once

#include <folly/futures/Future.h>
#include <rust/cxx.h>
#include <memory>
#include "rust/cxx.h"

namespace facebook::eden {

Expand Down

0 comments on commit 6a89029

Please sign in to comment.