Skip to content
Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 67 additions & 4 deletions crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,14 @@ impl RustwideBuilder {
rustdoc_flags,
collect_metrics,
)
.and_then(|command| command.run().map_err(Into::into))
.and_then(|command| {
command
// Enables the unstable rustdoc-scrape-examples feature. We are "soft launching" this feature on
// docs.rs, but once it's stable we can remove this flag.
.arg("-Zrustdoc-scrape-examples")
.run()
.map_err(Into::into)
})
})
};

Expand Down Expand Up @@ -1280,9 +1287,6 @@ impl RustwideBuilder {
format!(
r#"--config=doc.extern-map.registries.crates-io="https://docs.rs/{{pkg_name}}/{{version}}/{target}""#
),
// Enables the unstable rustdoc-scrape-examples feature. We are "soft launching" this feature on
// docs.rs, but once it's stable we can remove this flag.
"-Zrustdoc-scrape-examples".into(),
];
if let Some(cargo_job_limit) = self.config.cargo_job_limit() {
cargo_args.push(format!("-j{cargo_job_limit}"));
Expand Down Expand Up @@ -2364,4 +2368,63 @@ mod tests {

Ok(())
}

#[test]
#[ignore]
fn test_with_examples() -> Result<()> {
// there was a bug where coverage and rustdoc json was broken for
// libraries with examples.
// This test ensures that this works.

let mut config = Config::test_config()?;
config.include_default_targets = false;
let env = TestEnvironment::builder().config(config).build()?;

let mut builder = env.build_builder()?;
builder.update_toolchain()?;
assert!(
builder
.build_local_package(Path::new("tests/crates/with-examples"))?
.successful
);

// check release record in the db
let row = block_on_async_with_conn!(env, |mut conn| async {
sqlx::query!(
r#"SELECT
c.name,
r.version,
r.rustdoc_status,
cov.total_items
FROM
crates as c
INNER JOIN releases AS r ON c.id = r.crate_id
LEFT OUTER JOIN doc_coverage AS cov ON r.id = cov.release_id
"#
)
.fetch_one(&mut *conn)
.await
.map_err(Into::into)
})?;

assert_eq!(row.name, "with-examples");
assert_eq!(row.version, "0.1.0");
assert!(row.total_items.unwrap() > 0);

let storage = env.blocking_storage()?;
assert!(
storage
.list_prefix(&format!(
"rustdoc-json/{}/{}/x86_64-unknown-linux-gnu/",
row.name, row.version
))
.filter_map(|res| res.ok())
.find(|path| {
path.ends_with("with-examples_0.1.0_x86_64-unknown-linux-gnu_latest.json.zst")
})
.is_some()
);

Ok(())
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "with-examples"
version = "0.1.0"
edition = "2024"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use with_examples::add;

fn main() {
println!("{}", add(1,2));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
Loading