-
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
Cargo vendor regression for git sources containing exclude = ["build.rs"]
#14348
Comments
cxx-bridge-macro has an inferred https://github.com/dtolnay/cxx/blob/master/macro%2FCargo.toml We cover a lot of these cases for cargo/tests/testsuite/package.rs Line 3909 in fa64658
But only had minimal tests for cargo/tests/testsuite/vendor.rs Line 886 in fa64658
|
We are using a Line 222 in fa64658
but only vendoring the normlalized git Line 363 in fa64658
This is not the first time we've been bitten by Line 356 in fa64658
While we might want to do a minimal change for backporting, we should evaluate packaging sources to fully unify these so we stop having these problems. |
Cargo flavored UI test for the situation of excluding build script. Details
#[cargo_test]
fn dont_copy_excluded_build_script_for_git_dep() {
let git = git::new("git_dep", |p| {
p.file(
"Cargo.toml",
r#"
[package]
name = "git_dep"
edition = "2021"
exclude = ["build.rs"]
"#,
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
});
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
edition = "2021"
[dependencies]
git_dep = {{ git = '{}' }}
"#,
git.url()
),
)
.file("src/lib.rs", "")
.build();
let output = p
.cargo("vendor --respect-source-config")
.exec_with_output()
.unwrap();
// Before 1.80.0 `package.build` expected to be false
// After cargo#13713 it normalized Carg.toml before copying source from git repo.
// Taht make `package.build=["build.rs"] get into Cargo.toml.
//
// While the behavior of vendoring a git source is not well-defined,
// this is considered a regression in 1.80.0
//
// See cargo#14348 for more.
assert_e2e().eq(
p.read_file("vendor/git_dep/Cargo.toml"),
str![[r##"
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
bin = []
example = []
test = []
bench = []
[package]
edition = "2021"
name = "git_dep"
build = "build.rs"
exclude = ["build.rs"]
autobins = false
autoexamples = false
autotests = false
autobenches = false
readme = false
[lib]
name = "git_dep"
path = "src/lib.rs"
"##]],
);
let output = String::from_utf8(output.stdout).unwrap();
p.change_file(".cargo/config.toml", &output);
// TODO: this should success when we fix cargo#14348.
p.cargo("check")
.with_status(101)
.with_stderr_data(
str![[r#"
[COMPILING] git_dep v0.0.0 ([ROOTURL]/git_dep#[..])
[ERROR] couldn't read [ROOT]/foo/vendor/git_dep/build.rs: [NOT_FOUND]
[ERROR] could not compile `git_dep` (build script) due to 1 previous error
"#]]
)
.run();
} I am checking if there is any regression beyond build scripts. |
We have |
Summary: This is a workaround for [rust-lang/cargo#14348](rust-lang/cargo#14348), which is a regression in Rust 1.80's `cargo vendor`. 4 crates in fbsource/third-party/rust are currently impacted: - `cxx-build` - `cxxbridge-cmd` - `cxxbridge-macro` - `orjson` (https://github.com/ijl/orjson) The workaround works by writing a build.rs containing just `fn main() {}` for crates where Cargo has injected `build = "build.rs"` into their manifest without vendoring the corresponding build.rs. We can delete this workaround once the Cargo bug is fixed. Reviewed By: diliop Differential Revision: D60855541 fbshipit-source-id: 553c3e45e8f0998fb3091b1f1a82f33b2d7c0a6f
This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes rust-lang#14348
fix(vendor): Strip excluded build targets ### What does this PR try to resolve? Fixes #14348 ### How should we test and review this PR? The commits are setup to be able to show, through the tests, how the `cargo package` and `cargo vendor` behavior diverge and then how `cargo vendor`s behavior changes over time. This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. ### Additional information
This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes rust-lang#14348
#14368 backports this to 1.81 |
This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes rust-lang#14348
This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes rust-lang#14348
This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes rust-lang#14348
This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes rust-lang#14348
Problem
In Rust 1.79 and older releases,
cargo vendor
used to work for crates that have build scripts applying only to their source repo, and not published to crates.io. An example of such a crate is https://github.com/dtolnay/cxx/blob/1.0.124/macro/Cargo.toml#L8. The build script was correctly omitted from being vendored.Since Rust 1.80, Cargo still does not vendor the build script, but now it inserts
build = "build.rs"
into the vendored Cargo.toml, which causes compilation of the vendored sources to fail.Steps
Create an empty project with this Cargo manifest:
Possible Solution(s)
Do not inject
build = "build.rs"
into the vendored manifest if build.rs is not being vendored.Notes
Bisects to 1e60477.
Version
No response
The text was updated successfully, but these errors were encountered: