-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic test for installing libraries.
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_project VERSION 0.1.0) | ||
include(ExternalProject) | ||
|
||
add_library(static_lib STATIC IMPORTED) | ||
add_library(shared_lib SHARED IMPORTED) | ||
set(install_prefix "${CMAKE_CURRENT_BINARY_DIR}/rust_lib") | ||
set(static_lib_install_path "${install_prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}rust_lib${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||
set(shared_lib_install_path "${install_prefix}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}rust_lib${CMAKE_SHARED_LIBRARY_SUFFIX}") | ||
|
||
|
||
set_target_properties(static_lib PROPERTIES | ||
IMPORTED_LOCATION | ||
"${static_lib_install_path}") | ||
|
||
set_target_properties(shared_lib PROPERTIES | ||
IMPORTED_LOCATION | ||
"${shared_lib_install_path}") | ||
|
||
add_executable(main-static main.cpp) | ||
target_link_libraries(main-static PRIVATE static_lib) | ||
|
||
ExternalProject_Add( | ||
rust_lib | ||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/rust_lib" | ||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust_lib" | ||
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${install_prefix}" | ||
# INSTALL_BYPRODUCTS "${static_lib_install_path}" | ||
) | ||
|
||
# Dummy target since INSTALL_BYPRODUCTS requires CMake 3.26 | ||
add_custom_target(build_rust_project_dummy | ||
COMMAND echo dummy | ||
BYPRODUCTS "${static_lib_install_path}" "${shared_lib_install_path}" | ||
DEPENDS rust_lib) | ||
|
||
add_dependencies(main-static build_rust_project_dummy) | ||
|
||
set(CMAKE_BUILD_RPATH ${install_prefix}/lib) | ||
add_executable(main-shared main.cpp) | ||
target_link_libraries(main-shared | ||
PUBLIC shared_lib) | ||
|
||
add_dependencies(main-shared build_rust_project_dummy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdint.h> | ||
#include <assert.h> | ||
#include <iostream> | ||
|
||
extern "C" uint64_t add(uint64_t a, uint64_t b); | ||
|
||
int main(int argc, char **argv) { | ||
uint64_t sum = add(5, 6); | ||
assert(sum == 11); | ||
std::cout << "The sum is " << sum << std::endl; | ||
} |
17 changes: 17 additions & 0 deletions
17
test/corrosion_install/install_lib/rust_lib/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_project VERSION 0.1.0) | ||
include(../../../test_header.cmake) | ||
|
||
corrosion_import_crate(MANIFEST_PATH Cargo.toml) | ||
|
||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") | ||
corrosion_add_target_local_rustflags(rust_lib "-Clink-arg=-Wl,-soname,librust_lib.so") | ||
set_target_properties(rust_lib-shared PROPERTIES IMPORTED_SONAME librust_lib.so) | ||
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") | ||
corrosion_add_target_local_rustflags(rust_lib -Clink-arg=-Wl,-install_name,@rpath/librust_lib.dylib,-current_version,1.0,-compatibility_version,1.0) | ||
set_target_properties(rust_lib-shared PROPERTIES IMPORTED_NO_SONAME 0) | ||
set_target_properties(rust_lib-shared PROPERTIES IMPORTED_SONAME librust_lib.dylib) | ||
endif() | ||
|
||
|
||
corrosion_install(TARGETS rust_lib) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "rust_lib" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
|
||
[lib] | ||
crate-type = ["staticlib", "cdylib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
#[no_mangle] | ||
pub extern "C" fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
} |