Skip to content

Add extra_cargo_args support for prepare phase#119

Open
enthropy7 wants to merge 2 commits into
rust-lang:mainfrom
enthropy7:extra-cargo-args
Open

Add extra_cargo_args support for prepare phase#119
enthropy7 wants to merge 2 commits into
rust-lang:mainfrom
enthropy7:extra-cargo-args

Conversation

@enthropy7

Copy link
Copy Markdown

this adds an extra_cargo_args() method to BuildBuilder that forwards extra arguments to all cargo commands during Prepare::prepare(): validate_manifest, capture_lockfile, and fetch_deps. without this, crates that require unstable cargo flags for manifest parsing (e.g. -Zbindeps for artifact dependencies) fail at the prepare phase with InvalidCargoTomlSyntax, because there's no way for callers to pass these flags.

needed by docs.rs: rust-lang/docs.rs#3111

@syphar syphar self-requested a review April 7, 2026 05:41

@syphar syphar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This is missing tests.

we have "integration-like" tests / examples in tests/.

@enthropy7

Copy link
Copy Markdown
Author

added and tested :)

@syphar

syphar commented May 22, 2026

Copy link
Copy Markdown
Member

added and tested :)

I realized that I totally missed this comment, and in my "reviews requested" this PR didn't pop up. Will recheck.

( generally: I did "some" refactoring in the codebase that means you need to update this PR too

enthropy7 added 2 commits May 22, 2026 14:16
Test that extra cargo args are forwarded to cargo during the prepare
phase: a positive test with --quiet and a negative test with an invalid
flag to prove args are actually passed through.
@enthropy7

Copy link
Copy Markdown
Author

done! :)

@syphar syphar self-requested a review May 26, 2026 06:08

@syphar syphar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small API change, two small things for the tests.

Generally:
Right now we assume that the same extra_cargo_args are accepted by cargo metadata, generate-lockfile andfetch, and probably other commands that come later.

Also I wonder if users of the lib would expect that these commands are also automatically added to other cargo calls in the same build.

But: I think when we do the small things from above, we can merge / release this.

Comment thread src/build.rs
krate: &'a Crate,
sandbox: SandboxBuilder,
patches: Vec<CratePatch>,
extra_cargo_args: Vec<String>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's follow the pattern we have in cmd::Command

Suggested change
extra_cargo_args: Vec<String>,
extra_cargo_args: Vec<OsString>,

Comment thread src/build.rs
/// })?;
/// # Ok(())
/// # }
pub fn extra_cargo_args(mut self, args: Vec<String>) -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, the pattern from Command::args()

    pub fn extra_cargo_args<S: Into<OsString>>(
        mut self,
        args: impl IntoIterator<Item = S>,
    ) -> Self {
        self.extra_cargo_args
            .extend(args.into_iter().map(Into::into));

        self
    }

Comment thread tests/buildtest/mod.rs
});
assert!(
res.is_err(),
"expected extra cargo args to cause a prepare failure"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we assert something that ensures that the invalid flag is the actual error? perhaps just reading stdout and checking what's in it?

Comment thread tests/buildtest/mod.rs
runner::run("hello-world", |run| {
run.build(SandboxBuilder::new().enable_networking(false), |builder| {
builder
.extra_cargo_args(vec!["--quiet".into()])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we somehow assert that this cargo arg is actually working?

Like, checking stdout for the output that this suppresses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants