forked from TobiasFella/vodozemac-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There's a pretty nasty bug where Cargo can't generate the shared library itself, and we need to do in CMake. This isn't a huge deal, as we can simply link to the static library created by Cargo. This is an upstream issue where Rust marks unknown symbols as local, and they never appear in the dynamic symbol table. There is an open issue to allow more granular filtering (rust-lang/rust#104130) as well as an upstream CXX issue (dtolnay/cxx#1331)
- Loading branch information
Showing
2 changed files
with
10 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
# 3.24 is needed for LINK_LIBRARY:WHOLE_ARCHIVE support | ||
cmake_minimum_required(VERSION 3.24) | ||
|
||
project(Vodozemac-cpp) | ||
project(vodozemac-cpp) | ||
|
||
find_package(Corrosion REQUIRED) | ||
|
||
corrosion_import_crate( | ||
MANIFEST_PATH Cargo.toml | ||
) | ||
|
||
add_custom_target(copy_header ALL DEPENDS cargo-build_vodozemac BYPRODUCTS ${CMAKE_BINARY_DIR}/vodozemac.h VERBATIM COMMAND | ||
cp -L ${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET}/cxxbridge/vodozemac/src/lib.rs.h ${CMAKE_BINARY_DIR}/vodozemac.h | ||
) | ||
|
||
corrosion_install(TARGETS vodozemac) | ||
install(FILES "${CMAKE_BINARY_DIR}/vodozemac.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vodozemac) | ||
# We create our own shared library instead of having Cargo do it | ||
# To work around https://github.com/dtolnay/cxx/issues/1331 | ||
add_library(vodozemac-cpp SHARED) | ||
# We need a dummy file so CMake will have something to link with | ||
target_sources(vodozemac-cpp PRIVATE src/dummy.cpp) | ||
# We need to link to the whole archive, otherwise important symbols are thrown away | ||
target_link_libraries(vodozemac-cpp PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,vodozemac-static>") |
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 @@ | ||
// This file is intentionally left blank |