-
Notifications
You must be signed in to change notification settings - Fork 565
Cargo: decouple crate from main Cargo.toml workspace #7525
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
Conversation
|
From today's cloud hypervisor office meeting: Yes, it is a great improvement, we want to go that way (Rob) |
4d0b9d2 to
544c9ab
Compare
378de4b to
0259156
Compare
|
ping @RuoqingHe - I needed to take special care for the riscv job: bc4a2bd |
796c055 to
bc4a2bd
Compare
alyssais
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the direction. :)
7615b35 to
cc3bd62
Compare
| let target_cmd_path = format!("{target_artifact_dir}/{cmd}"); | ||
|
|
||
| let full_path = workspace_root.join(&target_cmd_path); | ||
| String::from(full_path.to_str().unwrap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought, not a blocker at all: I wonder if we could use e.g. env!("CARGO_BIN_EXE_cloud-hypervisor") and get rid of this function. It should at least work for the code in tests/, but I'm not sure if it would be set when the test_infra crate is built, so if not it would require the two other users of this function to be adjusted to take an executable path as a parameter passed by code in tests/.
This will also prevent some useless rebuilds. Using `--verbose` we can observe that the build.rs causes frequent useless rebuilds - having less is a good thing. They come from the dependency of `build.rs` to the local git repository. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
TL;DR: cargo clippy|check|... now runs on whole workspace by default. ## Steps - add new workspace member `cloud-hypervisor` - move `./src` to new workspace member - move `./tests` to new workspace member - move relevant parts from Cargo.toml to new workspace member - kept necessary parts in main Cargo.toml, such as profile configurations ## About The main Cargo.toml historically mixes workspace and crate definitions for cloud-hypervisor and ch-remote. This makes it hard to read and requires `--workspace` to run cargo clippy or cargo test on all workspace members, which is counter-intuitive. This patch separates the workspace from the crate definition in the main Cargo.toml file. After this, cargo clippy, cargo test, etc., work on the whole workspace naturally, giving a smoother developer experience. The Cargo.toml without a package definition is also called a virtual workspace or virtual manifest by Cargo [0]. Backporting is not a concern: CHV no longer backports, but the affected files are rarely modified anyway. [0] https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-workspace Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Unrelated but necessary to also always format code for all architectures and all features. Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
It is no longer needed to add `--all` (which is an alias for `--workspace`). The documentation says "Commands run in the workspace root will run against all workspace members by default" [0]. We however still need `--tests` as this activates the building of tests in `<crate>/tests` directories. [0] https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-workspace Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
`cargo rustc` is incompatible with virtual manifests, so the CI needs to use cargo build instead. However, passing `RUSTFLAGS="-D warnings"` via the environment would propagate to all dependencies, and some of them currently fail to build under ``-D warnings` due to issues like [0]: ``` error: creating a mutable reference to mutable static --> src/temp.rs:97:5 | 97 | DIRS.pop() | ^^^^^^^^^^ mutable reference to mutable static ``` To resolve this, apply ``-D warnings` only to the `cargo clippy` commands (which apply to our workspace only) and avoid enforcing it for the entire cargo build. [0]: https://github.com/cloud-hypervisor/cloud-hypervisor/actions/runs/19962283528/job/57245376263?pr=7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This is the first commit of the cherry-pick from [0]. [0] cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This is the last commit of the cherry-pick from [1]. `cargo rustc` is incompatible with virtual manifests, so the CI needs to use cargo build instead. However, passing `RUSTFLAGS="-D warnings"` via the environment would propagate to all dependencies, and some of them currently fail to build under ``-D warnings` due to issues like [0]: ``` error: creating a mutable reference to mutable static --> src/temp.rs:97:5 | 97 | DIRS.pop() | ^^^^^^^^^^ mutable reference to mutable static ``` To resolve this, apply ``-D warnings` only to the `cargo clippy` commands (which apply to our workspace only) and avoid enforcing it for the entire cargo build. [0]: https://github.com/cloud-hypervisor/cloud-hypervisor/actions/runs/19962283528/job/57245376263?pr=7525 [1]: cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
0be7d1b
This is the first commit of the cherry-pick from [0]. [0] cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This is the last commit of the cherry-pick from [1]. `cargo rustc` is incompatible with virtual manifests, so the CI needs to use cargo build instead. However, passing `RUSTFLAGS="-D warnings"` via the environment would propagate to all dependencies, and some of them currently fail to build under ``-D warnings` due to issues like [0]: ``` error: creating a mutable reference to mutable static --> src/temp.rs:97:5 | 97 | DIRS.pop() | ^^^^^^^^^^ mutable reference to mutable static ``` To resolve this, apply ``-D warnings` only to the `cargo clippy` commands (which apply to our workspace only) and avoid enforcing it for the entire cargo build. [0]: https://github.com/cloud-hypervisor/cloud-hypervisor/actions/runs/19962283528/job/57245376263?pr=7525 [1]: cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This is the first commit of the cherry-pick from [0]. [0] cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This is the last commit of the cherry-pick from [1]. `cargo rustc` is incompatible with virtual manifests, so the CI needs to use cargo build instead. However, passing `RUSTFLAGS="-D warnings"` via the environment would propagate to all dependencies, and some of them currently fail to build under ``-D warnings` due to issues like [0]: ``` error: creating a mutable reference to mutable static --> src/temp.rs:97:5 | 97 | DIRS.pop() | ^^^^^^^^^^ mutable reference to mutable static ``` To resolve this, apply ``-D warnings` only to the `cargo clippy` commands (which apply to our workspace only) and avoid enforcing it for the entire cargo build. [0]: https://github.com/cloud-hypervisor/cloud-hypervisor/actions/runs/19962283528/job/57245376263?pr=7525 [1]: cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50. As our v49-based CHV version backported these changes already, we need to adapt the Nix build of CHV. [0] cloud-hypervisor/cloud-hypervisor#7525
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50. As our v49-based CHV version backported these changes already, we need to adapt the Nix build of CHV. [0] cloud-hypervisor/cloud-hypervisor#7525 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50. Since we updated our Cloud Hypervisor to v50 [1], we need to adjust that here. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded our Cloud Hypervisor patchset to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded our Cloud Hypervisor patchset to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
Since PR #7525 (Dec 2025)[0], Cloud Hypervisor uses a virtual Cargo manifest and the main package was moved to the `./cloud-hypervisor` subdirectory. This change is effective since v50, which we just upgraded our Cloud Hypervisor patchset to [1]. [0] cloud-hypervisor/cloud-hypervisor#7525 [1] cyberus-technology/cloud-hypervisor#60 Signed-off-by: Philipp Schuster <[email protected]> On-behalf-of: SAP [email protected]
This is my solution for #7524 which we discussed in todays Cloud Hypervisor office hour. I think it improves certain things:
TL;DR improvements
cargo test|check|clippynow run on the whole workspace by default (without explicit--all/--workspace)Cargo.tomlis not so overwhelming anymore-D warningsall the time)More info in ticket or commit message.
Steps
cloud-hypervisor./srcto new workspace member./teststo new workspace member