Skip to content

Commit

Permalink
Fix detecting required libraries with cargo 1.71 and workspaces
Browse files Browse the repository at this point in the history
`cargo new` now seems to write `version.workspace` into the
Cargo.toml, which we don't want, since our crate should not belong
to the workspace.

Instead of relying on the generated Cargo.toml we overwrite the generated
Cargo.toml with our own. This should prevent similar future issues.
  • Loading branch information
jschwe authored Jul 15, 2023
1 parent 419f615 commit 89841b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmake/FindRust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ function(_corrosion_determine_libs_new target_triple out_libs)
message(DEBUG "Determining required link libraries: failed to create test library: ${cargo_new_result}")
return()
endif()
file(APPEND "${CMAKE_BINARY_DIR}/corrosion/required_libs/Cargo.toml"
"[lib]\ncrate-type=[\"staticlib\"]\n[workspace]")
# 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")
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}")

execute_process(
COMMAND ${CMAKE_COMMAND} -E env
"CARGO_BUILD_RUSTC=${Rust_COMPILER_CACHED}"
Expand Down
3 changes: 3 additions & 0 deletions test/workspace/workspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[workspace]
members=["member1", "member2", "member3"]

[workspace.package]
version = "0.1.0"

0 comments on commit 89841b2

Please sign in to comment.