-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust integration: Adding variables & clients. #102
Changes from all commits
a0826bb
c4b9056
bbbfda6
b74694d
b01e92b
7b6d8e2
88e1c44
167c3b2
8afcad0
52723a0
0197d68
14b5a1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,83 @@ | ||
include(cxxrs) | ||
|
||
find_program(CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/") | ||
if (CXXBRIDGE STREQUAL "CXXBRIDGE-NOTFOUND") | ||
message("Could not find cxxbridge, trying to install with `cargo install cxxbridge-cmd'") | ||
find_program(CARGO cargo PATHS "$ENV{HOME}/.cargo/bin/") | ||
if (CARGO STREQUAL "CARGO-NOTFOUND") | ||
message(FATAL_ERROR "Requires cargo available in path, install via rustup https://rustup.rs/") | ||
endif() | ||
execute_process(COMMAND ${CARGO} install cxxbridge-cmd --version 1.0.107) | ||
find_program(CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/") | ||
endif() | ||
|
||
emit_cxxrs_header() | ||
emit_cxxrs_for_module(everestrs) | ||
set(CXXBRIDGE_BINARY ${CMAKE_CURRENT_BINARY_DIR}/cargo/bin/cxxbridge) | ||
if (NOT EXISTS ${CXXBRIDGE_BINARY}) | ||
message(STATUS "Fetching rust cxxbridge cli tool") | ||
execute_process( | ||
COMMAND | ||
cargo install cxxbridge-cmd --root ${CMAKE_CURRENT_BINARY_DIR}/cargo | ||
WORKING_DIRECTORY | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
RESULT_VARIABLE | ||
CARGO_INSTALL_RESULT | ||
OUTPUT_QUIET | ||
ERROR_VARIABLE | ||
CARGO_INSTALL_ERROR | ||
) | ||
|
||
if (CARGO_INSTALL_RESULT) | ||
message(FATAL_ERROR "cargo install cxxbridge-cmd failed with:\n${CARGO_INSTALL_ERROR}") | ||
endif () | ||
endif () | ||
|
||
set(CXXBRIDGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge) | ||
set(EVERESTRS_FFI_HEADER ${CXXBRIDGE_OUTPUT_DIR}/lib.rs.h) | ||
set(EVERESTRS_FFI_SOURCE ${CXXBRIDGE_OUTPUT_DIR}/lib.rs.cc) | ||
set(CXXBRIDGE_HEADER ${CXXBRIDGE_OUTPUT_DIR}/rust.h) | ||
|
||
add_custom_command( | ||
OUTPUT | ||
${CXXBRIDGE_OUTPUT_DIR} | ||
${EVERESTRS_FFI_HEADER} | ||
${EVERESTRS_FFI_SOURCE} | ||
${CXXBRIDGE_HEADER} | ||
COMMAND | ||
${CMAKE_COMMAND} -E make_directory ${CXXBRIDGE_OUTPUT_DIR} | ||
COMMAND | ||
${CXXBRIDGE_BINARY} --header -o ${CXXBRIDGE_HEADER} | ||
COMMAND | ||
${CXXBRIDGE_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/everestrs/src/lib.rs --header -o ${EVERESTRS_FFI_HEADER} | ||
COMMAND | ||
${CXXBRIDGE_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/everestrs/src/lib.rs -o ${EVERESTRS_FFI_SOURCE} | ||
DEPENDS | ||
everestrs/src/lib.rs | ||
COMMENT "Generating cxxbridge glue for everestrs" | ||
VERBATIM | ||
DEPENDS | ||
${CXXBRIDGE_BINARY} | ||
) | ||
|
||
add_library(everestrs_sys STATIC | ||
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/everestrs/lib.rs.cc | ||
everestrs_sys/everestrs_sys.cpp | ||
${EVERESTRS_FFI_SOURCE} | ||
everestrs_sys/everestrs_sys.cpp | ||
) | ||
add_library(everest::everestrs_sys ALIAS everestrs_sys) | ||
|
||
target_include_directories(everestrs_sys PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge | ||
set_property( | ||
TARGET | ||
everestrs_sys | ||
PROPERTY | ||
EVERESTRS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/everestrs | ||
) | ||
|
||
set_property( | ||
TARGET | ||
everestrs_sys | ||
PROPERTY | ||
EVERESTRS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/everestrs | ||
) | ||
|
||
target_include_directories(everestrs_sys | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
# This is a requirement that linking works on systems enforcing PIE. | ||
# This is a requirement that linking works on systems enforcing PIE | ||
# FIXME (aw): investicate why this is really necessary | ||
set_property(TARGET everestrs_sys PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
target_link_libraries(everestrs_sys | ||
PRIVATE | ||
everest::framework | ||
everest::log | ||
everest::framework | ||
everest::log | ||
) | ||
|
||
install(TARGETS everestrs_sys LIBRARY) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ struct Libraries { | |
} | ||
|
||
fn find_everest_workspace_root() -> PathBuf { | ||
if let Ok(everest_framework_dir) = env::var("EVEREST_RS_FRAMEWORK_SOURCE_LOCATION") { | ||
return PathBuf::from(everest_framework_dir); | ||
} | ||
|
||
let mut cur_dir = | ||
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("always set in build.rs execution")); | ||
|
||
|
@@ -24,8 +28,19 @@ fn find_everest_workspace_root() -> PathBuf { | |
/// Returns the Libraries path if this is a standalone build of everest-framework or None if it is | ||
/// not. | ||
fn find_libs_in_everest_framework(root: &Path) -> Option<Libraries> { | ||
let everestrs_sys = root.join("everest-framework/build/everestrs/libeverestrs_sys.a"); | ||
let framework = root.join("everest-framework/build/lib/libframework.so"); | ||
let (everestrs_sys, framework) = | ||
if let Ok(everest_framework_dir) = env::var("EVEREST_RS_FRAMEWORK_BINARY_LOCATION") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compare the naming: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do need the binary location here, not the source location, which are usually not identical There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you pass locations by environment variables, why don't you pass the the complete path to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely, would add yet another environment variable but I guess the cost of that is quite low |
||
let everest_framework_path = PathBuf::from(everest_framework_dir); | ||
( | ||
everest_framework_path.join("everestrs/libeverestrs_sys.a"), | ||
everest_framework_path.join("lib/libframework.so"), | ||
) | ||
} else { | ||
( | ||
root.join("everest-framework/build/everestrs/libeverestrs_sys.a"), | ||
root.join("everest-framework/build/lib/libframework.so"), | ||
) | ||
}; | ||
Comment on lines
+32
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about rust best practices, but for me this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd prefer a match statement here too. The implicit returns are rustic - i.e. idiomatic. They are like meaningful whitespace in Python - one first finds them appalling, once used to them they become rather nice. |
||
if everestrs_sys.exists() && framework.exists() { | ||
Some(Libraries { | ||
everestrs_sys, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is a bit off here, is it everest framework dir OR everestrs framework source location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention with naming here was that this environment variable is meant for everestrs and contains the location to the source of everest-framework