diff --git a/.sqlx/query-ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d.json b/.sqlx/query-ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d.json new file mode 100644 index 000000000..0cb0ae2a8 --- /dev/null +++ b/.sqlx/query-ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d.json @@ -0,0 +1,62 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT\n c.name,\n r.version,\n r.rustdoc_status,\n cov.total_items\n FROM\n crates as c\n INNER JOIN releases AS r ON c.id = r.crate_id\n LEFT OUTER JOIN doc_coverage AS cov ON r.id = cov.release_id\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "name", + "type_info": "Text", + "origin": { + "Table": { + "table": "crates", + "name": "name" + } + } + }, + { + "ordinal": 1, + "name": "version", + "type_info": "Text", + "origin": { + "Table": { + "table": "releases", + "name": "version" + } + } + }, + { + "ordinal": 2, + "name": "rustdoc_status", + "type_info": "Bool", + "origin": { + "Table": { + "table": "releases", + "name": "rustdoc_status" + } + } + }, + { + "ordinal": 3, + "name": "total_items", + "type_info": "Int4", + "origin": { + "Table": { + "table": "doc_coverage", + "name": "total_items" + } + } + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + true, + true + ] + }, + "hash": "ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d" +} diff --git a/crates/bin/docs_rs_builder/.sqlx/query-ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d.json b/crates/bin/docs_rs_builder/.sqlx/query-ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d.json new file mode 100644 index 000000000..0cb0ae2a8 --- /dev/null +++ b/crates/bin/docs_rs_builder/.sqlx/query-ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d.json @@ -0,0 +1,62 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT\n c.name,\n r.version,\n r.rustdoc_status,\n cov.total_items\n FROM\n crates as c\n INNER JOIN releases AS r ON c.id = r.crate_id\n LEFT OUTER JOIN doc_coverage AS cov ON r.id = cov.release_id\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "name", + "type_info": "Text", + "origin": { + "Table": { + "table": "crates", + "name": "name" + } + } + }, + { + "ordinal": 1, + "name": "version", + "type_info": "Text", + "origin": { + "Table": { + "table": "releases", + "name": "version" + } + } + }, + { + "ordinal": 2, + "name": "rustdoc_status", + "type_info": "Bool", + "origin": { + "Table": { + "table": "releases", + "name": "rustdoc_status" + } + } + }, + { + "ordinal": 3, + "name": "total_items", + "type_info": "Int4", + "origin": { + "Table": { + "table": "doc_coverage", + "name": "total_items" + } + } + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + true, + true + ] + }, + "hash": "ae8f4fd21ef7091e80ac67ca2cee23b4bd53b41a30799988f7f498a891115a0d" +} diff --git a/crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs b/crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs index 2a561963f..5ee801d12 100644 --- a/crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs +++ b/crates/bin/docs_rs_builder/src/docbuilder/rustwide_builder.rs @@ -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) + }) }) }; @@ -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}")); @@ -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(()) + } } diff --git a/crates/bin/docs_rs_builder/tests/crates/with-examples/Cargo.lock b/crates/bin/docs_rs_builder/tests/crates/with-examples/Cargo.lock new file mode 100644 index 000000000..27df69ab5 --- /dev/null +++ b/crates/bin/docs_rs_builder/tests/crates/with-examples/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "with-examples" +version = "0.1.0" diff --git a/crates/bin/docs_rs_builder/tests/crates/with-examples/Cargo.toml b/crates/bin/docs_rs_builder/tests/crates/with-examples/Cargo.toml new file mode 100644 index 000000000..bd2e0e38a --- /dev/null +++ b/crates/bin/docs_rs_builder/tests/crates/with-examples/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "with-examples" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/crates/bin/docs_rs_builder/tests/crates/with-examples/examples/example1.rs b/crates/bin/docs_rs_builder/tests/crates/with-examples/examples/example1.rs new file mode 100644 index 000000000..90717c994 --- /dev/null +++ b/crates/bin/docs_rs_builder/tests/crates/with-examples/examples/example1.rs @@ -0,0 +1,5 @@ +use with_examples::add; + +fn main() { + println!("{}", add(1,2)); +} diff --git a/crates/bin/docs_rs_builder/tests/crates/with-examples/src/lib.rs b/crates/bin/docs_rs_builder/tests/crates/with-examples/src/lib.rs new file mode 100644 index 000000000..b93cf3ffd --- /dev/null +++ b/crates/bin/docs_rs_builder/tests/crates/with-examples/src/lib.rs @@ -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); + } +}