Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bin/docs_rs_builder/src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {

#[test]
fn test_invalidate_cdn_after_error() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;
let queue = env.blocking_build_queue()?;

let builder_metrics = BuilderMetrics::new(env.context.meter_provider());
Expand All @@ -115,7 +115,7 @@ mod tests {

#[test]
fn test_invalidate_cdn_after_build() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;
let queue = env.blocking_build_queue()?;
let builder_metrics = BuilderMetrics::new(env.context.meter_provider());

Expand Down
96 changes: 75 additions & 21 deletions crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ fn load_metadata_from_rustwide(
workspace: &Workspace,
toolchain: &Toolchain,
source_dir: &Path,
unstable_flags: &[String],
) -> Result<CargoMetadata> {
let mut args = vec!["metadata", "--format-version", "1"];
// Add unstable flags (e.g., `-Z bindeps`) to support crates using unstable cargo features.
// See https://github.com/rust-lang/docs.rs/issues/2710
let unstable_flags_refs: Vec<&str> = unstable_flags.iter().map(|s| s.as_str()).collect();
args.extend(unstable_flags_refs);

let res = Command::new(workspace, toolchain.cargo())
.args(&["metadata", "--format-version", "1"])
.args(&args)
.cd(source_dir)
.log_output(false)
.run_capture()?;
Expand Down Expand Up @@ -500,10 +507,15 @@ impl RustwideBuilder {
}

pub fn build_local_package(&mut self, path: &Path) -> Result<BuildPackageSummary> {
let metadata = load_metadata_from_rustwide(&self.workspace, &self.toolchain, path)
.map_err(|err| {
err.context(format!("failed to load local package {}", path.display()))
})?;
// Read docsrs metadata first to get unstable cargo flags (e.g., `-Z bindeps`)
let docsrs_metadata = Metadata::from_crate_root(path).unwrap_or_default();
let unstable_flags = docsrs_metadata.unstable_cargo_flags();

let metadata =
load_metadata_from_rustwide(&self.workspace, &self.toolchain, path, &unstable_flags)
.map_err(|err| {
err.context(format!("failed to load local package {}", path.display()))
})?;
let package = metadata.root();
self.build_package(
&package.name,
Expand Down Expand Up @@ -686,18 +698,28 @@ impl RustwideBuilder {
if !res.result.successful && cargo_lock.exists() {
info!("removing lockfile and reattempting build");
std::fs::remove_file(cargo_lock)?;

// Get unstable cargo flags for commands that need them (e.g., `-Z bindeps`)
let unstable_flags = metadata.unstable_cargo_flags();

{
let _span = info_span!("cargo_generate_lockfile").entered();
let mut args = vec!["generate-lockfile"];
let flags_refs: Vec<&str> = unstable_flags.iter().map(|s| s.as_str()).collect();
args.extend(flags_refs.iter());
Command::new(&self.workspace, self.toolchain.cargo())
.cd(build.host_source_dir())
.args(&["generate-lockfile"])
.args(&args)
.run_capture()?;
}
{
let _span = info_span!("cargo fetch --locked").entered();
let mut args = vec!["fetch", "--locked"];
let flags_refs: Vec<&str> = unstable_flags.iter().map(|s| s.as_str()).collect();
args.extend(flags_refs.iter());
Command::new(&self.workspace, self.toolchain.cargo())
.cd(build.host_source_dir())
.args(&["fetch", "--locked"])
.args(&args)
.run_capture()?;
}
res =
Expand Down Expand Up @@ -1108,6 +1130,7 @@ impl RustwideBuilder {
&self.workspace,
&self.toolchain,
&build.host_source_dir(),
&metadata.unstable_cargo_flags(),
)?;

let mut rustdoc_flags = vec![
Expand Down Expand Up @@ -1421,7 +1444,7 @@ mod tests {
#[test]
#[ignore]
fn test_build_crate() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let crate_ = DUMMY_CRATE_NAME;
let crate_path = crate_.replace('-', "_");
Expand Down Expand Up @@ -1641,7 +1664,7 @@ mod tests {
#[test]
#[ignore]
fn test_build_binary_crate() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

// some binary crate
let crate_ = "heater";
Expand Down Expand Up @@ -1703,7 +1726,7 @@ mod tests {
#[test]
#[ignore]
fn test_failed_build_with_existing_successful_release() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

// rand 0.8.5 fails to build with recent nightly versions
// https://github.com/rust-lang/docs.rs/issues/26750
Expand Down Expand Up @@ -1800,7 +1823,7 @@ mod tests {
#[test_case("thiserror-impl", Version::new(1, 0, 26))]
#[ignore]
fn test_proc_macro(crate_: &str, version: Version) -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
Expand All @@ -1826,7 +1849,7 @@ mod tests {
#[test]
#[ignore]
fn test_cross_compile_non_host_default() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let crate_ = "windows-win";
let version = Version::new(2, 4, 1);
Expand Down Expand Up @@ -1927,7 +1950,7 @@ mod tests {
#[test]
#[ignore]
fn test_rustflags_are_passed_to_build_script() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let crate_ = "proc-macro2";
let version = Version::new(1, 0, 95);
Expand All @@ -1944,7 +1967,7 @@ mod tests {
#[test]
#[ignore]
fn test_sources_are_added_even_for_build_failures_before_build() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

// https://github.com/rust-lang/docs.rs/issues/2523
// package with invalid cargo metadata.
Expand Down Expand Up @@ -1975,7 +1998,7 @@ mod tests {
#[test]
#[ignore]
fn test_build_failures_before_build() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

// https://github.com/rust-lang/docs.rs/issues/2491
// package without Cargo.toml, so fails directly in the fetch stage.
Expand Down Expand Up @@ -2021,7 +2044,7 @@ mod tests {
#[test]
#[ignore]
fn test_implicit_features_for_optional_dependencies() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let crate_ = "serde";
let version = Version::new(1, 0, 152);
Expand All @@ -2046,7 +2069,7 @@ mod tests {
#[test]
#[ignore]
fn test_no_implicit_features_for_optional_dependencies_with_dep_syntax() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
Expand Down Expand Up @@ -2075,7 +2098,7 @@ mod tests {
#[test]
#[ignore]
fn test_build_std() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
Expand All @@ -2090,7 +2113,7 @@ mod tests {
#[test]
#[ignore]
fn test_workspace_reinitialize_at_once() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
Expand Down Expand Up @@ -2133,7 +2156,7 @@ mod tests {
#[test]
#[ignore]
fn test_new_builder_detects_existing_rustc() -> Result<()> {
let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
Expand Down Expand Up @@ -2183,7 +2206,7 @@ mod tests {
);
}

let env = TestEnvironment::new_with_runtime()?;
let env = TestEnvironment::new()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
Expand Down Expand Up @@ -2227,4 +2250,35 @@ mod tests {

Ok(())
}

#[test]
#[ignore] // Requires full build environment
fn test_bindeps_crate_builds_with_unstable_flags() -> Result<()> {
// This test verifies that the fix for issue #2710 works: crates using
// unstable cargo features like `bindeps` can now build because the unstable
// flags from `cargo-args` are correctly passed to `cargo metadata` and
// `cargo fetch` commands.
//
// The test crate has `cargo-args = ["-Zbindeps"]` in its Cargo.toml.
// With the fix, `load_metadata_from_rustwide` accepts unstable flags and
// passes them to `cargo metadata`, allowing the build to succeed.

let env = TestEnvironment::new()?;
let mut builder = env.build_builder()?;
builder.update_toolchain()?;

// With the fix, cargo metadata is called with the `-Zbindeps` flag
// from cargo-args, allowing the build to succeed
let result = builder.build_local_package(Path::new("tests/crates/bindeps-test"));

assert!(result.is_ok(), "build should succeed with bindeps fix");
if let Ok(summary) = result {
assert!(
summary.successful,
"build should be successful with bindeps fix"
);
}

Ok(())
}
}
12 changes: 12 additions & 0 deletions crates/bin/docs_rs_builder/tests/crates/bindeps-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
Copy link
Member

Choose a reason for hiding this comment

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

this crate should be moved to the "new" location

crates/bin/docs_rs_builder/tests/crates/

name = "bindeps-test"
version = "0.1.0"
edition = "2021"

[package.metadata.docs.rs]
cargo-args = ["-Zbindeps"]

[lib]
name = "bindeps_test"
path = "src/lib.rs"

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Test crate for bindeps support
//!
//! This crate uses unstable cargo feature `bindeps` (artifact dependencies).
//! It should build on docs.rs when the fix for #2710 is applied.

pub fn hello() -> &'static str {
"Hello from bindeps-test!"
}

Loading