corrosion-rs / corrosion

Marrying Rust and CMake - Easy Rust and C/C++ Integration!
https://corrosion-rs.github.io/corrosion/
MIT License
1.07k stars 103 forks source link

unused crates in a workspace not included in package, but still expected #494

Closed djmitche closed 6 months ago

djmitche commented 6 months ago

Current Behavior

https://github.com/GothenburgBitFactory/taskwarrior/blob/19f2c0d7b4bb023a938cc35fce3e45872ff3f07f/src/tc/CMakeLists.txt#L11

corrosion_import_crate(
  MANIFEST_PATH "${CMAKE_SOURCE_DIR}/Cargo.toml"
  LOCKED
  CRATES "taskchampion-lib")

https://github.com/GothenburgBitFactory/taskwarrior/blob/19f2c0d7b4bb023a938cc35fce3e45872ff3f07f/Cargo.toml#L3

// Cargo.toml
members = [
    "taskchampion/taskchampion",
    "taskchampion/sync-server",
    "taskchampion/lib",
    "taskchampion/integration-tests",
    "taskchampion/xtask",
]

Of those, taskchampion-lib depends on taskchampion, and the other three are not used from C++. I wouldn't mind including them in the package. However, from https://github.com/GothenburgBitFactory/taskwarrior/issues/3294

$:/tmp> tar -xf task-3.0.0.tar.gz 
$:/tmp> cmake -S task-3.0.0 -B build
-- Configuring C++17
-- System: Linux
-- Looking for libshared
-- Found libshared
-- Looking for SHA1 references
-- Looking for libuuid
-- Found libuuid
-- Configuring cmake.h
-- Rust Target: x86_64-unknown-linux-gnu
-- Using Corrosion as a subdirectory
error: failed to load manifest for workspace member `/tmp/task-3.0.0/taskchampion/integration-tests`

Caused by:
  failed to read `/tmp/task-3.0.0/taskchampion/integration-tests/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

so it seems that the source for the crates not required are not included in the package.

Expected Behavior

Package builds without error!

Steps To Reproduce

Build the Taskwarrior 3.0.0 release from its package.

Environment

No response

CMake configure log with Debug log-level

No response

CMake Build step log

No response

jschwe commented 6 months ago

error: failed to load manifest for workspace member /tmp/task-3.0.0/taskchampion/integration-tests

Corrosion internally uses cargo-metadata to get information on the workspace and expects cargo-metadata to work. This error looks like it comes straight out of cargo metadata - Could you verify if cargo metadata --manifest-path /path/to/your/Cargo.toml works on your package without corrosion?

jschwe commented 6 months ago

I downloaded the tarball and indeed cargo metadata does not work - neither do any other cargo commands. I also tried running cargo metadata just on the library crate, but that still causes an error. I'd recommend replacing your workspace Cargo.toml during the release processs, to avoid this issue, since removing the missing workspace member indeed seems to fix the problem. I'll be closing this issue, since corrosion requires cargo metadata to work.

djmitche commented 6 months ago

Thanks!

I filed this on the assumption that something in Corrosion identified the files that would be packed, and did not include the other crates in the workspace. Since cargo metadata then requires those files, that seemed a bug.

However, I suppose CPack is really just gathering all of the source files referenced in the build, without specific support from Corrosion.