Skip to content

Commit 15a0c13

Browse files
committed
Add rustc runtime libraries to rurs_loader_impl project.
1 parent 3d70f0f commit 15a0c13

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

cmake/FindRust.cmake

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# CARGO_HOME - Cargo home folder
2424
# CARGO_EXECUTABLE - Cargo package manager executable path
2525
# RUSTC_EXECUTABLE - Rust compiler executable path
26+
# RUSTC_SYSROOT - Rust compiler root location (includes binaries and libraries)
27+
# RUSTC_LIBRARIES - Rust compiler runtime library list
2628
# RUSTDOC_EXECUTABLE - Rust doc executable plath
2729
# RUSTUP_EXECUTABLE - Rustup executable path
2830
# RUST_GDB_EXECUTABLE - Rust GDB debugger executable path
@@ -42,6 +44,8 @@ if(NOT DEFINED CARGO_HOME)
4244
endif()
4345
endif()
4446

47+
set(CARGO_HOME "${CARGO_HOME}" CACHE PATH "Rust Cargo Home")
48+
4549
set(RUST_PATHS
4650
/usr
4751
/usr/local
@@ -78,28 +82,40 @@ find_program(RUST_LLDB_EXECUTABLE rust-lldb
7882
PATH_SUFFIXES "bin"
7983
)
8084

81-
if(CARGO_EXECUTABLE AND RUSTC_EXECUTABLE AND RUSTDOC_EXECUTABLE)
82-
set(CARGO_HOME "${CARGO_HOME}" CACHE PATH "Rust Cargo Home")
85+
if(RUSTC_EXECUTABLE)
8386
execute_process(
8487
COMMAND ${RUSTC_EXECUTABLE} --version
8588
OUTPUT_VARIABLE RUSTC_VERSION
8689
OUTPUT_STRIP_TRAILING_WHITESPACE
8790
)
8891
string(REGEX REPLACE "rustc ([^ ]+) .*" "\\1" RUSTC_VERSION "${RUSTC_VERSION}")
92+
93+
execute_process(
94+
COMMAND ${RUSTC_EXECUTABLE} --print sysroot
95+
OUTPUT_VARIABLE RUSTC_SYSROOT
96+
OUTPUT_STRIP_TRAILING_WHITESPACE
97+
)
98+
99+
file(
100+
GLOB RUSTC_LIBRARIES
101+
${RUSTC_SYSROOT}/lib/*${CMAKE_SHARED_LIBRARY_SUFFIX}
102+
)
89103
endif()
90104

91105
include(FindPackageHandleStandardArgs)
92106

93107
find_package_handle_standard_args(Rust
94108
FOUND_VAR RUST_FOUND
95-
REQUIRED_VARS CARGO_EXECUTABLE RUSTC_EXECUTABLE
109+
REQUIRED_VARS CARGO_EXECUTABLE RUSTC_EXECUTABLE RUSTC_LIBRARIES
96110
VERSION_VAR RUSTC_VERSION
97111
)
98112

99113
mark_as_advanced(
100114
RUST_FOUND
101115
CARGO_EXECUTABLE
102116
RUSTC_EXECUTABLE
117+
RUSTC_SYSROOT
118+
RUSTC_LIBRARIES
103119
RUSTUP_EXECUTABLE
104120
RUSTDOC_EXECUTABLE
105121
RUST_GDB_EXECUTABLE

source/loaders/rs_loader/rust/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ endif()
4040

4141
set(TARGET_OUTPUT ${TARGET_OUTPUT_PATH}/${TARGET_OUTPUT_NAME})
4242

43+
add_custom_target(${target}_runtime
44+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RUSTC_LIBRARIES} ${TARGET_OUTPUT_PATH}
45+
)
46+
4347
add_custom_target(${target} ALL
4448
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
4549
COMMAND ${CARGO_EXECUTABLE} build ${TARGET_BUILD_TYPE}
46-
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_BUILD_PATH} ${TARGET_OUTPUT}
50+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TARGET_BUILD_PATH} ${TARGET_OUTPUT}
51+
DEPENDS ${target}_runtime
4752
)
4853

4954
set_property(TARGET ${target}
@@ -54,9 +59,16 @@ set_property(TARGET ${target}
5459
# Deployment
5560
#
5661

57-
# Files
62+
# Library
5863
install(FILES
5964
${TARGET_OUTPUT}
6065
DESTINATION ${INSTALL_LIB}
6166
COMPONENT runtime
6267
)
68+
69+
# Rust Runtime (pack the runtime meanwhile Rust runtime is not distributed as a library)
70+
install(FILES
71+
${RUSTC_LIBRARIES}
72+
DESTINATION ${INSTALL_LIB}
73+
COMPONENT runtime
74+
)

0 commit comments

Comments
 (0)