Skip to content
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

Refactor detecting required link libraries #422

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(Corrosion
# tagged release. Users don't need to care about this, it is mainly to
# clearly see in configure logs which version was used, without needing to
# rely on `git`, since Corrosion may be installed or otherwise packaged.
VERSION 0.4.2
VERSION 0.4.2.1
LANGUAGES NONE
HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/"
)
Expand Down
27 changes: 7 additions & 20 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,15 @@ function(_corrosion_parse_target_triple target_triple out_arch out_vendor out_os
endfunction()

function(_corrosion_determine_libs_new target_triple out_libs)
set(package_dir "${CMAKE_BINARY_DIR}/corrosion/required_libs")
# Cleanup on reconfigure to get a cleans state (in case we change something in the future)
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/corrosion/required_libs")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/corrosion")
# Create a staticlib application for testing purposes
execute_process(
COMMAND "${Rust_CARGO_CACHED}" new --lib required_libs
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/corrosion"
RESULT_VARIABLE cargo_new_result
ERROR_QUIET
)
if(cargo_new_result)
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/corrosion/required_libs")
message(DEBUG "Determining required link libraries: failed to create test library: ${cargo_new_result}")
return()
endif()
# Cargo new may create a Cargo.toml which attempts to reference keys from an outside workspace,
# but our package is not part of that workspace, so we need to overwrite the Cargo.toml with
# our own.
set(manifest_path "${CMAKE_BINARY_DIR}/corrosion/required_libs/Cargo.toml")
file(REMOVE_RECURSE "${package_dir}")
file(MAKE_DIRECTORY "${package_dir}")
set(manifest "[package]\nname = \"required_libs\"\nedition = \"2018\"\nversion = \"0.1.0\"\n")
string(APPEND manifest "\n[lib]\ncrate-type=[\"staticlib\"]\n[workspace]\n")
file(WRITE "${manifest_path}" "${manifest}")
string(APPEND manifest "\n[lib]\ncrate-type=[\"staticlib\"]\npath = \"lib.rs\"\n")
string(APPEND manifest "\n[workspace]\n")
file(WRITE "${package_dir}/Cargo.toml" "${manifest}")
file(WRITE "${package_dir}/lib.rs" "pub fn add(left: usize, right: usize) -> usize {left + right}\n")

execute_process(
COMMAND ${CMAKE_COMMAND} -E env
Expand Down