-
Notifications
You must be signed in to change notification settings - Fork 17
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 (experimental) #99
Changes from all commits
012291c
b654041
2d022e5
9a81615
d284b5f
b6da315
982c6ea
f9c5302
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*build | ||
*build-cross | ||
target | ||
watcher.lua | ||
workspace.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function(emit_cxxrs_header) | ||
set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/rust/") | ||
file(MAKE_DIRECTORY ${output_dir}) | ||
execute_process(COMMAND ${CXXBRIDGE} --header -o ${output_dir}cxx.h) | ||
endfunction() | ||
|
||
function(emit_cxxrs_for_module module_name) | ||
set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/${module_name}/") | ||
file(MAKE_DIRECTORY ${output_dir}) | ||
|
||
add_custom_command( | ||
OUTPUT ${output_dir}lib.rs.h ${output_dir}lib.rs.cc | ||
COMMAND ${CXXBRIDGE} ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/src/lib.rs --header -o ${output_dir}lib.rs.h | ||
COMMAND ${CXXBRIDGE} ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/src/lib.rs -o ${output_dir}lib.rs.cc | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}/src/lib.rs | ||
COMMENT "Generating cxx for ${module_name}" | ||
VERBATIM | ||
) | ||
endfunction() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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) | ||
|
||
add_library(everestrs_sys STATIC | ||
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/everestrs/lib.rs.cc | ||
everestrs_sys/everestrs_sys.cpp | ||
) | ||
|
||
SirVer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target_include_directories(everestrs_sys PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge | ||
) | ||
|
||
# This is a requirement that linking works on systems enforcing PIE. | ||
set_property(TARGET everestrs_sys PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
SirVer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target_link_libraries(everestrs_sys | ||
PRIVATE | ||
everest::framework | ||
everest::log | ||
) | ||
|
||
install(TARGETS everestrs_sys LIBRARY) | ||
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. I wouldn't binary ship this glue code library, as it depends on auto-generated stuff (`rust/cxx.h'), which will only be generated, when its using crate is build. 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. I do understand that you do not like the installing piece, however the comment is not actionable to me, I do not know what to do instead: To build any crate using |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"everestrs", | ||
] | ||
SirVer marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "everestrs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
argh = "0.1.10" | ||
cxx = { version = "1.0.107", features = ["c++17"] } | ||
serde = { version = "1.0.175", features = ["derive"] } | ||
serde_json = "1" | ||
thiserror = "1.0.48" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Rust support for everest | ||
|
||
This is Rust support using cxx.rs to wrap the framework C++ library. | ||
|
||
## Trying it out | ||
|
||
- Install rust as outlined on <https://rustup.rs/>, which should just be this | ||
one line: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` | ||
- Built your workspace as outlined in `everest-core` README, make sure to tell | ||
cMake to enable `EVEREST_ENABLE_RS_SUPPORT`. Note, that the Rust code relies | ||
on being built in a workspace where `make install` was run once. | ||
- You can now try building the code, but it will not do anything: `cd everestrs | ||
&& cargo build --all` | ||
- If you want to play with a node, check out `https://github.com/EVerest/everest-core/pull/344` in your workspace and run make install. | ||
- Go to `everest-core/modules/RsSomkeTest` and run `cargo build` there. | ||
- There is no support for building or installing Rust modules with cMake | ||
currently, so let's fake the installation: | ||
- Go to `everest-core/build/dist/libexec/everest/modules` and create the stuff needed for a module: | ||
~~~bash | ||
mkdir RsSmokeTest | ||
ln -s ../../../../../../modules/RsSmokeTest/target/debug/smoke_test RsSmokeTest | ||
ln -s ../../../../../../modules/RsSmokeTest/manifest.yaml . | ||
~~~ | ||
- You should now be able to configure the `RsSmokeTest` module in your config | ||
YAML. | ||
|
||
## Status | ||
|
||
This code is currently only supporting providing an interface to be implemented, i.e. no variables publish or receiving and no calling of other interfaces. Those features are straightforward, quick and easy to implement, but for now this is probably enough to iron out the integration questions. |
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.
cxx_build::bridge
from within thebuild.rs
cxxrs.cmake
script to figure out the path ofCXXBRIDGE
and not if its including scriptThere 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.