-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cannot build vendored git dependency if it inherits info from a workspace #11192
Comments
Thank you for reporting this bug! @Muscraft and I had a talk, and we feel that it might take longer before a better design for this come out. So, in the meanwhile, we are seeking help for polishing the error message. Something explicitly tells user the cause is great, such like "vendoring a git dependency with inherited fields from a workspace is not supported yet". |
@weihanglo just curious for my own understanding, is the limitation here that I'm interested in supporting dependencies with workspace inheritance in Crane (tl;dr an alternative implementation of |
@ipetkov Haven't dived deep yet but I don't think this affects general cases. So far it seems to happen only when building a vendored git dependency which inherits info from its parent workspace. I guess it's This is a reproducible case in the form of cargo's own test suite if anyone is interested. Click to see test code#[cargo_test]
fn vendor_git_source_from_workspace_with_inheritance() {
let git = git::new("gitworkspace", |p| {
p.file(
"Cargo.toml",
r#"
[workspace]
member = ["foo"]
[workspace.package]
version = "0.1.0"
"#,
)
.file(
"bar/Cargo.toml",
r#"
[package]
name = "bar"
version.workspace = true
"#,
)
.file("bar/src/lib.rs", "")
});
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
bar = {{ git = '{}' }}
"#,
git.url(),
),
)
.file("src/lib.rs", "")
.build();
p.cargo("vendor --respect-source-config")
.run();
p.change_file(
".cargo/config.toml",
&format!(r#"
[source."{url}"]
git = "{url}"
replace-with = 'vendor'
[source.vendor]
directory = 'vendor'
"#,
url = git.url(),
),
);
p.cargo("build").with_stderr("").run();
} Click to see error outputerror: failed to get `bar` as a dependency of package `foo v0.1.0 (/projects/cargo/target/tmp/cit/t0/foo)`
Caused by:
failed to load source for dependency `bar`
Caused by:
Unable to update file:///projects/cargo/target/tmp/cit/t0/gitworkspace#02b3fb58
Caused by:
failed to update replaced source file:///projects/cargo/target/tmp/cit/t0/gitworkspace#02b3fb58
Caused by:
failed to parse manifest at `/projects/cargo/target/tmp/cit/t0/foo/vendor/bar/Cargo.toml`
Caused by:
error inheriting `version` from workspace root manifest's `workspace.package.version`
Caused by:
failed to find a workspace root
', tests/testsuite/vendor.rs:990:38 @hunts I edited the title a bit to reflect the issue more precisely. At this moment I can't see any case other than git dependency having this issue. If we later find it's broader than that, we can always update then. |
@weihanglo can an entire workspace be copied over intact into the vendor directory? I had assumed there was a reason why |
Thanks, the updated title sounds good to me. |
Off the top of my head, there are at least two approach to solve this:
I would say it has technical difficulties in pulling workspace into vendor directory. Firstly, a directory source at this moment is in a flat one-level layout listing all crates on the same level. By copying workspaces into vendor directory, we need to craft a special algorithm to identify the relationship between crates and workspaces. We also need to mind any name conflicts on crate names and our special folders (which I mentioned a while back here #11178 (comment)). Besides, pulling the whole workspace does contribute to size bloat. If we want to tackle it, we might need another way to slim down unnecessary members, which is also hard and might break things. For me, I don't like the first approach, as it modifies the original Cargo.toml. However, before we figure out a better way to circumvent this, it stills sounds feasible than the latter. |
Definitely agree with your sentiment! It looks like cargo will normalize the Cargo.toml by copying the workspace-inherited definitions before publishing a crate. it might be that vendoring will need to take this approach as well :/ |
Just clone main branch of boa ( a rust version of JavaScript) by using it as a local dependency directly and found it's not easy without tweaking. :) Edit: |
Cannot produce reproducible repeatable builds until fixed. |
This bug is also making Firefox work difficult: https://bugzilla.mozilla.org/show_bug.cgi?id=1804530 |
#11414 is a fix for the issue. Kudos to @Muscraft! Reiterate the potential behavior change after that pull request.
There are rooms for improvements, such as only normalizing git deps containing workspace deps, or moreover, using |
Thank you the fix, great work! |
To handle all downloads manually, PTXdist basically fakes vendoring all dependencies. This can cause problems with workspaces where packages inherit from the workspace. 'cargo vendor' used to have the same problem[1] and fixed it by rewriting the Cargo.toml. Do the same thing here to fix this. [1] rust-lang/cargo#11192 Signed-off-by: Michael Olbrich <[email protected]>
Problem
If we
cargo vendor
our dependencies, and one of the crates in the vendor folder is inheriting package info from its Workspace,cargo build --offline
would fail with errors like:Steps
Possible Solution(s)
I'm no familiar with the workspace design, but it feels like we need to replace the workspace variables with real values when vendor a crate, or will need to provide metadata of the workspace the crate is sourced from.
Notes
I've anonymized the package/lib names related to our internal systems, hope that won't cause inconvenience in understanding the problem.
Version
The text was updated successfully, but these errors were encountered: