Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
- clean target still needs to be fixed

Signed-off-by: aw <aw@pionix.de>
  • Loading branch information
a-w50 committed Oct 26, 2023
1 parent e244e3f commit af1c7fb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 49 deletions.
19 changes: 0 additions & 19 deletions cmake/cxxrs.cmake

This file was deleted.

94 changes: 66 additions & 28 deletions everestrs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,45 +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
${EVERESTRS_FFI_SOURCE}
everestrs_sys/everestrs_sys.cpp
)
add_library(everest::everestrs_sys ALIAS everestrs_sys)

set_property(
TARGET
framework
everestrs_sys
PROPERTY
EVERESTRS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/everestrs
)

# FIXME (aw): this is still broken
# we need a custom target, which does builds the everestrs/lib.rs.h first
# because everestrs_sys depends on it
add_library(everestrs_sys STATIC
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/everestrs/lib.rs.cc
everestrs_sys/everestrs_sys.cpp
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}/cxxbridge
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)
2 changes: 1 addition & 1 deletion everestrs/everestrs_sys/everestrs_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdlib>
#include <stdexcept>

#include "everestrs/lib.rs.h"
#include "cxxbridge/lib.rs.h"

namespace {

Expand Down
2 changes: 1 addition & 1 deletion everestrs/everestrs_sys/everestrs_sys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <memory>
#include <string>

#include "rust/cxx.h"
#include "cxxbridge/rust.h"

struct JsonBlob;
struct Runtime;
Expand Down

0 comments on commit af1c7fb

Please sign in to comment.