From 9ee208dd6ecf1e8e2e50d7e174da370ffa9fbb9d Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 14 Feb 2025 02:38:53 +0100 Subject: [PATCH 01/12] trait tags --- .github/workflows/docs.yml | 3 +- Cargo.toml | 11 +- docs-rs/README.md | 33 ------ docs-rs/trait-tags.html | 172 ---------------------------- tools/rustdoc-wrapper/.gitignore | 1 + tools/rustdoc-wrapper/Cargo.toml | 8 ++ tools/rustdoc-wrapper/README.md | 10 ++ tools/rustdoc-wrapper/rustdoc.sh | 8 ++ tools/rustdoc-wrapper/src/main.rs | 180 ++++++++++++++++++++++++++++++ 9 files changed, 216 insertions(+), 210 deletions(-) delete mode 100644 docs-rs/README.md delete mode 100644 docs-rs/trait-tags.html create mode 100644 tools/rustdoc-wrapper/.gitignore create mode 100644 tools/rustdoc-wrapper/Cargo.toml create mode 100644 tools/rustdoc-wrapper/README.md create mode 100755 tools/rustdoc-wrapper/rustdoc.sh create mode 100644 tools/rustdoc-wrapper/src/main.rs diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8a04fadc94530..8366a43785d2b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -73,7 +73,8 @@ jobs: --exclude bevy_mobile_example \ --exclude build-wasm-example \ --exclude build-templated-pages \ - --exclude example-showcase + --exclude example-showcase \ + --config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" # This adds the following: # - A top level redirect to the bevy crate documentation diff --git a/Cargo.toml b/Cargo.toml index 2c5785346e303..a60a019e0e2b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4122,14 +4122,17 @@ rustc-args = ["--cfg", "docsrs_dep"] rustdoc-args = [ "-Zunstable-options", "--generate-link-to-definition", +] +all-features = true +cargo-args = [ + "-Zunstable-options", + "-Zrustdoc-scrape-examples", # Embed tags to the top of documentation pages for common Bevy traits # that are implemented by the current type, like `Component` or `Resource`. # This makes it easier to see at a glance what types are used for. - "--html-after-content", - "docs-rs/trait-tags.html", + "--config", + "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"", ] -all-features = true -cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] [[example]] name = "monitor_info" diff --git a/docs-rs/README.md b/docs-rs/README.md deleted file mode 100644 index 5d9092b806185..0000000000000 --- a/docs-rs/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Docs.rs Extensions - -This directory includes some templates and styling to extend and modify [rustdoc]'s output -for Bevy's documentation on [docs.rs]. Currently this consists of tags indicating core -`bevy_ecs` traits. - -## 3rd Party Crates - -To use in your own crate, first copy this folder into your project, -then add the following to your Cargo.toml: - -```toml -[package.metadata.docs.rs] -rustc-args = ["--cfg", "docsrs_dep"] -rustdoc-args = [ - "--cfg", "docsrs_dep", - "--html-after-content", "docs-rs/trait-tags.html", -] - -[lints.rust] -unexpected_cfgs = { check-cfg = ['cfg(docsrs_dep)'] } -``` - -## Local Testing - -Build the documentation with the extension enabled like this: - -```bash -RUSTDOCFLAGS="--html-after-content docs-rs/trait-tags.html --cfg docsrs_dep" RUSTFLAGS="--cfg docsrs_dep" cargo doc --no-deps --package -``` - -[rustdoc]: https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html -[docs.rs]: https://docs.rs diff --git a/docs-rs/trait-tags.html b/docs-rs/trait-tags.html deleted file mode 100644 index bdd7ba1fb2338..0000000000000 --- a/docs-rs/trait-tags.html +++ /dev/null @@ -1,172 +0,0 @@ - - - \ No newline at end of file diff --git a/tools/rustdoc-wrapper/.gitignore b/tools/rustdoc-wrapper/.gitignore new file mode 100644 index 0000000000000..ea8c4bf7f35f6 --- /dev/null +++ b/tools/rustdoc-wrapper/.gitignore @@ -0,0 +1 @@ +/target diff --git a/tools/rustdoc-wrapper/Cargo.toml b/tools/rustdoc-wrapper/Cargo.toml new file mode 100644 index 0000000000000..b421a297b18be --- /dev/null +++ b/tools/rustdoc-wrapper/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rustdoc-wrapper" +version = "0.1.0" +edition = "2024" + +[dependencies] +nipper = "0.1" +walkdir = "2" diff --git a/tools/rustdoc-wrapper/README.md b/tools/rustdoc-wrapper/README.md new file mode 100644 index 0000000000000..6a986821a61d8 --- /dev/null +++ b/tools/rustdoc-wrapper/README.md @@ -0,0 +1,10 @@ +# Rustdoc Postprocessor + +We want to adjust rustdoc's html output to make it more obvious +which types are `Component`s, `Plugin`s etc. To do so, this +tool wraps rustdoc and modifies its output by adding relevant tags +to the top of a type's doc page. + +The wrapper is called by passing +`--config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\""` +to cargo doc. diff --git a/tools/rustdoc-wrapper/rustdoc.sh b/tools/rustdoc-wrapper/rustdoc.sh new file mode 100755 index 0000000000000..7be83270f688c --- /dev/null +++ b/tools/rustdoc-wrapper/rustdoc.sh @@ -0,0 +1,8 @@ +#!/bin/env sh + +# Gets clobbered, so make a backup. +export SET_CARGO_MANIFEST_PATH="$CARGO_MANIFEST_PATH" +# Pass on all arguments to our rustdoc wrapper. +# Use a different target directory because the workspace-level one +# will be locked. +cargo run --package rustdoc-wrapper --target-dir tools/rustdoc-wrapper/target --color always -- "$@" diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs new file mode 100644 index 0000000000000..d1f78da6a7727 --- /dev/null +++ b/tools/rustdoc-wrapper/src/main.rs @@ -0,0 +1,180 @@ +use std::{ + collections::{HashMap, HashSet}, + ffi::OsStr, + fs::read_to_string, + ops::Deref, + path::{Path, PathBuf}, + process::Command, + sync::LazyLock, +}; + +use nipper::Document; +use walkdir::WalkDir; + +fn main() { + // Use workspace dir + let rustdoc_wrapper_dir = PathBuf::from( + std::env::var("CARGO_MANIFEST_DIR") + .expect("Please run via cargo or set CARGO_MANIFEST_DIR"), + ); + let working_dir = rustdoc_wrapper_dir.join("../..").canonicalize().unwrap(); + std::env::set_current_dir(working_dir).unwrap(); + + // Generate HTML as normal + assert!(Command::new("rustdoc") + .args(std::env::args().skip(1)) + // Restore clobbered env var. + // This is required by our derive macros. + .env( + "CARGO_MANIFEST_PATH", + std::env::var("SET_CARGO_MANIFEST_PATH").unwrap() + ) + .status() + .unwrap() + .success(),); + + // Find package name + let package = std::env::args() + .skip_while(|arg| *arg != "--crate-name") + .nth(1) + .expect("No crate name passed") + .clone(); + + // Post-process HTML to apply our modifications + for entry in WalkDir::new(Path::new("target/doc/").join(package)) { + let path = entry.unwrap(); + let path = path.path(); + if path.extension() == Some(OsStr::new("html")) { + let mut doc = Document::from(&read_to_string(path).unwrap()); + post_process_type(&mut doc); + std::fs::write(path, doc.html().as_bytes()).unwrap(); + } + } +} + +// We only use the HTML and not rustdoc's JSON output because +fn post_process_type(doc: &mut Document) { + let traits = implemented_bevy_traits(doc); + + let mut heading = doc.select(".main-heading h1"); + heading.append_html("
"); + let mut container = heading.select(".bevy-tag-container"); + + for (mut tag, url) in traits { + if (tag == "Component") + & doc + .select(".trait-impl.associatedtype .code-header") + .iter() + .any(|assoc| assoc.text().contains("type Mutability = Immutable")) + { + tag = "Immutable Component".to_owned() + } + + container.append_html(format!( + "{tag}", + tag.to_lowercase(), + url.unwrap_or_default() + )); + } + + doc.select("html").append_html(STYLE); +} + +fn implemented_bevy_traits(doc: &Document) -> HashMap> { + doc.select("#rustdoc-toc .trait-implementation a") + .iter() + .filter_map(|label| { + let name = label.text(); + BEVY_TRAITS + .contains(&*name) + .then(|| ((*name).to_owned(), trait_url(doc, &name))) + }) + .collect() +} + +fn trait_url(doc: &Document, name: &str) -> Option { + let search = format!("trait.{name}.html"); + doc.select("a").iter().find_map(|a| { + a.attr("href") + .and_then(|url| url.ends_with(&search).then_some(url.deref().to_owned())) + }) +} + +static BEVY_TRAITS: LazyLock> = LazyLock::new(|| { + [ + "Plugin", + "PluginGroup", + "Component", + "Resource", + "Asset", + "Event", + "ScheduleLabel", + "SystemSet", + "SystemParam", + "Relationship", + "RelationshipTarget", + ] + .iter() + .map(|s| s.to_string()) + .collect() +}); + +const STYLE: &str = " + +"; From c2a088accc3e2cfcaefceb8dedacf67c3889517f Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 14 Feb 2025 03:33:58 +0100 Subject: [PATCH 02/12] downgrade edition --- Cargo.toml | 5 +---- tools/rustdoc-wrapper/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a60a019e0e2b1..9d9159f11bf7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4119,10 +4119,7 @@ panic = "abort" # for details on why this is needed. Since dependencies don't expect to be built # with `--cfg docsrs` (and thus fail to compile) we use a different cfg. rustc-args = ["--cfg", "docsrs_dep"] -rustdoc-args = [ - "-Zunstable-options", - "--generate-link-to-definition", -] +rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"] all-features = true cargo-args = [ "-Zunstable-options", diff --git a/tools/rustdoc-wrapper/Cargo.toml b/tools/rustdoc-wrapper/Cargo.toml index b421a297b18be..f54f5d4f66bc0 100644 --- a/tools/rustdoc-wrapper/Cargo.toml +++ b/tools/rustdoc-wrapper/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustdoc-wrapper" version = "0.1.0" -edition = "2024" +edition = "2021" [dependencies] nipper = "0.1" From f5e477c742448c59b3330b12e1f444b5a9c32891 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 14 Feb 2025 03:54:18 +0100 Subject: [PATCH 03/12] format --- tools/rustdoc-wrapper/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index d1f78da6a7727..1eb124d610a2a 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -31,7 +31,7 @@ fn main() { ) .status() .unwrap() - .success(),); + .success()); // Find package name let package = std::env::args() From fdc7dc6acb94858bbddcda285b9a645553862153 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 14 Feb 2025 10:12:37 +0100 Subject: [PATCH 04/12] Add missing comment --- tools/rustdoc-wrapper/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index 1eb124d610a2a..054618a879725 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -53,9 +53,15 @@ fn main() { } // We only use the HTML and not rustdoc's JSON output because +// we would need to be able to match Rust items to HTML files. +// There is an index from HTML to source file we could use, but +// it's in JS instead of in an easily parsable format. +// Scanning the HTML is also bit simpler as we don't need to e.g. +// manually resolver blob imports. fn post_process_type(doc: &mut Document) { let traits = implemented_bevy_traits(doc); + // Tags sit below headline let mut heading = doc.select(".main-heading h1"); heading.append_html("
"); let mut container = heading.select(".bevy-tag-container"); @@ -80,7 +86,12 @@ fn post_process_type(doc: &mut Document) { doc.select("html").append_html(STYLE); } +/// If this is the documentation page of a single type, +/// returns which of the relavant traits it implements, +/// alongside a (relative) url to the trait, if available. fn implemented_bevy_traits(doc: &Document) -> HashMap> { + // Scanning the table of contents is easiest, but we need to find the link + // elsewhere as the ToC just points at the impls section. doc.select("#rustdoc-toc .trait-implementation a") .iter() .filter_map(|label| { From 3cd86f4288338059a4cacacbf161a2f33803bae7 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 14 Feb 2025 10:17:08 +0100 Subject: [PATCH 05/12] typo --- tools/rustdoc-wrapper/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index 054618a879725..90eeb8365dbad 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -87,7 +87,7 @@ fn post_process_type(doc: &mut Document) { } /// If this is the documentation page of a single type, -/// returns which of the relavant traits it implements, +/// returns which of the relevant traits it implements, /// alongside a (relative) url to the trait, if available. fn implemented_bevy_traits(doc: &Document) -> HashMap> { // Scanning the table of contents is easiest, but we need to find the link From f3af52521b3ba32dc2a14b9e552cd0fc901b010e Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 14 Feb 2025 23:43:28 +0100 Subject: [PATCH 06/12] move css to static.files --- tools/rustdoc-wrapper/src/main.rs | 120 +++++++++++++++++------------- 1 file changed, 67 insertions(+), 53 deletions(-) diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index 90eeb8365dbad..d8a3bfb1c6cd4 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -40,13 +40,31 @@ fn main() { .expect("No crate name passed") .clone(); + // Find target directory + let target_dir = std::env::args() + .skip_while(|arg| (*arg != "-o") & (*arg != "--output")) + .nth(1) + .unwrap() + .clone(); + let target_dir = Path::new(&target_dir); + + // Extra style sheet is shared between files + std::fs::write( + target_dir.join("static.files/bevy_style.css"), + STYLE.as_bytes(), + ) + .unwrap(); + // Post-process HTML to apply our modifications - for entry in WalkDir::new(Path::new("target/doc/").join(package)) { - let path = entry.unwrap(); - let path = path.path(); + for entry in WalkDir::new(target_dir.join(package)) { + let entry = entry.unwrap(); + let path = entry.path(); if path.extension() == Some(OsStr::new("html")) { let mut doc = Document::from(&read_to_string(path).unwrap()); post_process_type(&mut doc); + let style_url = "../".repeat(entry.depth()) + "static.files/bevy_style.css"; + doc.select("head") + .append_html(format!("")); std::fs::write(path, doc.html().as_bytes()).unwrap(); } } @@ -82,8 +100,6 @@ fn post_process_type(doc: &mut Document) { url.unwrap_or_default() )); } - - doc.select("html").append_html(STYLE); } /// If this is the documentation page of a single type, @@ -131,61 +147,59 @@ static BEVY_TRAITS: LazyLock> = LazyLock::new(|| { }); const STYLE: &str = " - +.relationship-tag, +.relationshiptarget-tag { + --tag-color: oklch(50% 27% 150); +} "; From 4af4053ba20defc9409bdc51a4ba5298a4578eb9 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sat, 15 Feb 2025 09:50:38 +0100 Subject: [PATCH 07/12] make easier to run --- .github/workflows/docs.yml | 4 +++- tools/rustdoc-wrapper/README.md | 29 ++++++++++++++++++++++++++--- tools/rustdoc-wrapper/rustdoc.sh | 1 + tools/rustdoc-wrapper/src/main.rs | 28 ++++++++++++---------------- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8366a43785d2b..1fe1eb14819bf 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -50,10 +50,12 @@ jobs: # This does the following: # - Replaces the docs icon with one that clearly denotes it's not the released package on crates.io # - Adds a meta tag that forces Google not to index any page on the site. + # - compiles our rustdoc wrapper - name: Pre-docs-build run: | sed -i.bak "s/icon.png/icon-docs-dev.png/" src/lib.rs echo "" > header.html + cargo build --release --package rustdoc-wrapper - name: Build docs env: @@ -74,7 +76,7 @@ jobs: --exclude build-wasm-example \ --exclude build-templated-pages \ --exclude example-showcase \ - --config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" + --config "build.rustdoc = \"target/release/rustdoc-wrapper\"" # This adds the following: # - A top level redirect to the bevy crate documentation diff --git a/tools/rustdoc-wrapper/README.md b/tools/rustdoc-wrapper/README.md index 6a986821a61d8..a179023a7694f 100644 --- a/tools/rustdoc-wrapper/README.md +++ b/tools/rustdoc-wrapper/README.md @@ -5,6 +5,29 @@ which types are `Component`s, `Plugin`s etc. To do so, this tool wraps rustdoc and modifies its output by adding relevant tags to the top of a type's doc page. -The wrapper is called by passing -`--config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\""` -to cargo doc. +On docs.rs and dev-docs.bevyengine.org the wrapper is invoked via + +```bash +cargo doc --config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" +``` + +If you want to build Bevy's documentation with these customizations +applied yourself and are not on Unix or want to run the wrapper in release mode, +first compile it: + +```bash +cargo build --release --package rustdoc-wrapper +``` + +and then point `build.rustdoc` at it. + +If you want to be able to run cargo doc without passing the right rustdoc path every time, you can set it in your `.cargo/config.toml`: + +```toml +[build] +rustdoc = "target/release/rustdoc-wrapper" +``` + +## 3rd-Party Crates + +The above also works with other crates that use Bevy. diff --git a/tools/rustdoc-wrapper/rustdoc.sh b/tools/rustdoc-wrapper/rustdoc.sh index 7be83270f688c..cb2fc3cb76b9a 100755 --- a/tools/rustdoc-wrapper/rustdoc.sh +++ b/tools/rustdoc-wrapper/rustdoc.sh @@ -2,6 +2,7 @@ # Gets clobbered, so make a backup. export SET_CARGO_MANIFEST_PATH="$CARGO_MANIFEST_PATH" +export SET_CARGO_MANIFEST_DIR="$CARGO_MANIFEST_DIR" # Pass on all arguments to our rustdoc wrapper. # Use a different target directory because the workspace-level one # will be locked. diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index d8a3bfb1c6cd4..8d32f36dc40a8 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -3,7 +3,7 @@ use std::{ ffi::OsStr, fs::read_to_string, ops::Deref, - path::{Path, PathBuf}, + path::Path, process::Command, sync::LazyLock, }; @@ -12,23 +12,19 @@ use nipper::Document; use walkdir::WalkDir; fn main() { - // Use workspace dir - let rustdoc_wrapper_dir = PathBuf::from( - std::env::var("CARGO_MANIFEST_DIR") - .expect("Please run via cargo or set CARGO_MANIFEST_DIR"), - ); - let working_dir = rustdoc_wrapper_dir.join("../..").canonicalize().unwrap(); - std::env::set_current_dir(working_dir).unwrap(); - // Generate HTML as normal - assert!(Command::new("rustdoc") - .args(std::env::args().skip(1)) - // Restore clobbered env var. + let mut rustdoc = Command::new("rustdoc"); + if let Ok(manifest_path) = std::env::var("SET_CARGO_MANIFEST_PATH") { + // Restore clobbered env var if invoked through `cargo run`. // This is required by our derive macros. - .env( - "CARGO_MANIFEST_PATH", - std::env::var("SET_CARGO_MANIFEST_PATH").unwrap() - ) + rustdoc.env("CARGO_MANIFEST_PATH", manifest_path); + rustdoc.env( + "CARGO_MANIFEST_DIR", + std::env::var("SET_CARGO_MANIFEST_DIR").unwrap(), + ); + } + assert!(rustdoc + .args(std::env::args().skip(1)) .status() .unwrap() .success()); From 60b203559ea3064e1786610db3c796b68925b0c6 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sat, 15 Feb 2025 10:32:17 +0100 Subject: [PATCH 08/12] fix dependency workspaces --- .github/workflows/docs.yml | 4 +--- tools/rustdoc-wrapper/.gitignore | 2 +- tools/rustdoc-wrapper/README.md | 11 ++++++----- tools/rustdoc-wrapper/rustdoc.sh | 9 +++------ tools/rustdoc-wrapper/src/main.rs | 12 +----------- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 1fe1eb14819bf..8366a43785d2b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -50,12 +50,10 @@ jobs: # This does the following: # - Replaces the docs icon with one that clearly denotes it's not the released package on crates.io # - Adds a meta tag that forces Google not to index any page on the site. - # - compiles our rustdoc wrapper - name: Pre-docs-build run: | sed -i.bak "s/icon.png/icon-docs-dev.png/" src/lib.rs echo "" > header.html - cargo build --release --package rustdoc-wrapper - name: Build docs env: @@ -76,7 +74,7 @@ jobs: --exclude build-wasm-example \ --exclude build-templated-pages \ --exclude example-showcase \ - --config "build.rustdoc = \"target/release/rustdoc-wrapper\"" + --config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" # This adds the following: # - A top level redirect to the bevy crate documentation diff --git a/tools/rustdoc-wrapper/.gitignore b/tools/rustdoc-wrapper/.gitignore index ea8c4bf7f35f6..2f7896d1d1365 100644 --- a/tools/rustdoc-wrapper/.gitignore +++ b/tools/rustdoc-wrapper/.gitignore @@ -1 +1 @@ -/target +target/ diff --git a/tools/rustdoc-wrapper/README.md b/tools/rustdoc-wrapper/README.md index a179023a7694f..0a70d58168ae0 100644 --- a/tools/rustdoc-wrapper/README.md +++ b/tools/rustdoc-wrapper/README.md @@ -5,15 +5,16 @@ which types are `Component`s, `Plugin`s etc. To do so, this tool wraps rustdoc and modifies its output by adding relevant tags to the top of a type's doc page. -On docs.rs and dev-docs.bevyengine.org the wrapper is invoked via +Note that the format of rustdoc's html output is (and always will be) unstable. These customizations may therefor break at time, at which point they should be enabled until fixed. -```bash -cargo doc --config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" +On docs.rs and dev-docs.bevyengine.org the wrapper is invoked by passing the following flag: + +``` +--config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" ``` If you want to build Bevy's documentation with these customizations -applied yourself and are not on Unix or want to run the wrapper in release mode, -first compile it: +applied yourself, first compile it: ```bash cargo build --release --package rustdoc-wrapper diff --git a/tools/rustdoc-wrapper/rustdoc.sh b/tools/rustdoc-wrapper/rustdoc.sh index cb2fc3cb76b9a..cac419ed9ca96 100755 --- a/tools/rustdoc-wrapper/rustdoc.sh +++ b/tools/rustdoc-wrapper/rustdoc.sh @@ -1,9 +1,6 @@ #!/bin/env sh -# Gets clobbered, so make a backup. -export SET_CARGO_MANIFEST_PATH="$CARGO_MANIFEST_PATH" -export SET_CARGO_MANIFEST_DIR="$CARGO_MANIFEST_DIR" +# Use a different target directory because the workspace-level one will be locked. +cargo build --release --target-dir tools/rustdoc-wrapper/target # Pass on all arguments to our rustdoc wrapper. -# Use a different target directory because the workspace-level one -# will be locked. -cargo run --package rustdoc-wrapper --target-dir tools/rustdoc-wrapper/target --color always -- "$@" +tools/rustdoc-wrapper/target/release/rustdoc-wrapper "$@" diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index 8d32f36dc40a8..ac7bad6ae6f8c 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -13,17 +13,7 @@ use walkdir::WalkDir; fn main() { // Generate HTML as normal - let mut rustdoc = Command::new("rustdoc"); - if let Ok(manifest_path) = std::env::var("SET_CARGO_MANIFEST_PATH") { - // Restore clobbered env var if invoked through `cargo run`. - // This is required by our derive macros. - rustdoc.env("CARGO_MANIFEST_PATH", manifest_path); - rustdoc.env( - "CARGO_MANIFEST_DIR", - std::env::var("SET_CARGO_MANIFEST_DIR").unwrap(), - ); - } - assert!(rustdoc + assert!(Command::new("rustdoc") .args(std::env::args().skip(1)) .status() .unwrap() From 957176bcc29b160a448cfdc506009d5ec63a2f10 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sat, 15 Feb 2025 11:43:10 +0100 Subject: [PATCH 09/12] markdownlint & color --- tools/rustdoc-wrapper/README.md | 2 +- tools/rustdoc-wrapper/rustdoc.sh | 2 +- tools/rustdoc-wrapper/src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/rustdoc-wrapper/README.md b/tools/rustdoc-wrapper/README.md index 0a70d58168ae0..55d5f817ca028 100644 --- a/tools/rustdoc-wrapper/README.md +++ b/tools/rustdoc-wrapper/README.md @@ -9,7 +9,7 @@ Note that the format of rustdoc's html output is (and always will be) unstable. On docs.rs and dev-docs.bevyengine.org the wrapper is invoked by passing the following flag: -``` +```none --config "build.rustdoc = \"tools/rustdoc-wrapper/rustdoc.sh\"" ``` diff --git a/tools/rustdoc-wrapper/rustdoc.sh b/tools/rustdoc-wrapper/rustdoc.sh index cac419ed9ca96..0f0a359f6f6bc 100755 --- a/tools/rustdoc-wrapper/rustdoc.sh +++ b/tools/rustdoc-wrapper/rustdoc.sh @@ -1,6 +1,6 @@ #!/bin/env sh # Use a different target directory because the workspace-level one will be locked. -cargo build --release --target-dir tools/rustdoc-wrapper/target +cargo build --package rustdoc-wrapper --release --target-dir tools/rustdoc-wrapper/target --color always # Pass on all arguments to our rustdoc wrapper. tools/rustdoc-wrapper/target/release/rustdoc-wrapper "$@" diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index ac7bad6ae6f8c..2f77a076eec81 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -66,7 +66,7 @@ fn post_process_type(doc: &mut Document) { let traits = implemented_bevy_traits(doc); // Tags sit below headline - let mut heading = doc.select(".main-heading h1"); + let mut heading = doc.select("h1").first(); heading.append_html("
"); let mut container = heading.select(".bevy-tag-container"); From 4faa0f54cca8ae54525b4be66304a59f95ac3760 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sun, 2 Mar 2025 13:10:50 +0100 Subject: [PATCH 10/12] dom_query --- tools/rustdoc-wrapper/Cargo.toml | 3 ++- tools/rustdoc-wrapper/src/main.rs | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tools/rustdoc-wrapper/Cargo.toml b/tools/rustdoc-wrapper/Cargo.toml index f54f5d4f66bc0..39f8061de140c 100644 --- a/tools/rustdoc-wrapper/Cargo.toml +++ b/tools/rustdoc-wrapper/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -nipper = "0.1" walkdir = "2" +kuchikiki = "0.8" +dom_query = "0.15" diff --git a/tools/rustdoc-wrapper/src/main.rs b/tools/rustdoc-wrapper/src/main.rs index 2f77a076eec81..a8f77425f08d0 100644 --- a/tools/rustdoc-wrapper/src/main.rs +++ b/tools/rustdoc-wrapper/src/main.rs @@ -8,7 +8,7 @@ use std::{ sync::LazyLock, }; -use nipper::Document; +use dom_query::Document; use walkdir::WalkDir; fn main() { @@ -26,29 +26,26 @@ fn main() { .expect("No crate name passed") .clone(); - // Find target directory + // Find output directory let target_dir = std::env::args() .skip_while(|arg| (*arg != "-o") & (*arg != "--output")) .nth(1) .unwrap() .clone(); - let target_dir = Path::new(&target_dir); + let package_dir = Path::new(&target_dir).join(package); - // Extra style sheet is shared between files - std::fs::write( - target_dir.join("static.files/bevy_style.css"), - STYLE.as_bytes(), - ) - .unwrap(); + // Extra style sheet is shared between files. + // It's not shared between docs.rs packages though, so don't put it in static.files + std::fs::write(package_dir.join("bevy_style.css"), STYLE.as_bytes()).unwrap(); // Post-process HTML to apply our modifications - for entry in WalkDir::new(target_dir.join(package)) { + for entry in WalkDir::new(package_dir) { let entry = entry.unwrap(); let path = entry.path(); if path.extension() == Some(OsStr::new("html")) { - let mut doc = Document::from(&read_to_string(path).unwrap()); + let mut doc = Document::from(&*read_to_string(path).unwrap()); post_process_type(&mut doc); - let style_url = "../".repeat(entry.depth()) + "static.files/bevy_style.css"; + let style_url = "../".repeat(entry.depth() - 1) + "bevy_style.css"; doc.select("head") .append_html(format!("")); std::fs::write(path, doc.html().as_bytes()).unwrap(); @@ -66,9 +63,9 @@ fn post_process_type(doc: &mut Document) { let traits = implemented_bevy_traits(doc); // Tags sit below headline - let mut heading = doc.select("h1").first(); + let heading = doc.select("h1").first(); heading.append_html("
"); - let mut container = heading.select(".bevy-tag-container"); + let container = heading.select(".bevy-tag-container"); for (mut tag, url) in traits { if (tag == "Component") From aa6ea0b8913ba03989f9e7b3c3c420aacc536fd5 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Wed, 5 Mar 2025 13:48:16 -0800 Subject: [PATCH 11/12] Fix require() IDE integration by moving require docs back to Component trait --- .../bevy_core_pipeline/src/motion_blur/mod.rs | 5 +-- crates/bevy_core_pipeline/src/taa/mod.rs | 2 +- crates/bevy_ecs/macros/src/component.rs | 43 ++++++------------- crates/bevy_ecs/macros/src/lib.rs | 10 +---- crates/bevy_ecs/src/component.rs | 2 - crates/bevy_ecs/src/entity/clone_entities.rs | 1 - crates/bevy_ecs/src/lib.rs | 4 +- crates/bevy_ecs/src/system/commands/mod.rs | 2 +- crates/bevy_ecs/src/system/system_registry.rs | 2 +- crates/bevy_gizmos/src/retained.rs | 5 +-- crates/bevy_input/src/gamepad.rs | 1 - crates/bevy_pbr/src/atmosphere/mod.rs | 2 +- crates/bevy_pbr/src/decal/clustered.rs | 2 +- crates/bevy_pbr/src/decal/forward.rs | 2 +- crates/bevy_pbr/src/light_probe/mod.rs | 2 +- crates/bevy_pbr/src/meshlet/mod.rs | 2 +- crates/bevy_pbr/src/ssao/mod.rs | 2 +- crates/bevy_pbr/src/ssr/mod.rs | 2 +- crates/bevy_pbr/src/volumetric_fog/mod.rs | 6 +-- crates/bevy_render/src/camera/camera.rs | 2 +- crates/bevy_render/src/mesh/components.rs | 2 +- crates/bevy_scene/src/components.rs | 5 +-- crates/bevy_sprite/src/sprite.rs | 5 +-- crates/bevy_text/src/text2d.rs | 2 +- .../src/components/transform.rs | 2 +- crates/bevy_ui/src/ui_material.rs | 5 +-- crates/bevy_ui/src/widget/button.rs | 5 +-- crates/bevy_ui/src/widget/text.rs | 2 +- 28 files changed, 39 insertions(+), 88 deletions(-) diff --git a/crates/bevy_core_pipeline/src/motion_blur/mod.rs b/crates/bevy_core_pipeline/src/motion_blur/mod.rs index 7703698f1ab10..58466d7c825bb 100644 --- a/crates/bevy_core_pipeline/src/motion_blur/mod.rs +++ b/crates/bevy_core_pipeline/src/motion_blur/mod.rs @@ -9,10 +9,7 @@ use crate::{ use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, weak_handle, Handle}; use bevy_ecs::{ - component::{require, Component}, - query::With, - reflect::ReflectComponent, - schedule::IntoSystemConfigs, + component::Component, query::With, reflect::ReflectComponent, schedule::IntoSystemConfigs, }; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_render::{ diff --git a/crates/bevy_core_pipeline/src/taa/mod.rs b/crates/bevy_core_pipeline/src/taa/mod.rs index 55eb25ae02ebf..2f30544be9e73 100644 --- a/crates/bevy_core_pipeline/src/taa/mod.rs +++ b/crates/bevy_core_pipeline/src/taa/mod.rs @@ -8,7 +8,7 @@ use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, weak_handle, Handle}; use bevy_diagnostic::FrameCount; use bevy_ecs::{ - prelude::{require, Component, Entity, ReflectComponent}, + prelude::{Component, Entity, ReflectComponent}, query::{QueryItem, With}, resource::Resource, schedule::IntoSystemConfigs, diff --git a/crates/bevy_ecs/macros/src/component.rs b/crates/bevy_ecs/macros/src/component.rs index 06dd9b1591e69..62f393d2f9e6a 100644 --- a/crates/bevy_ecs/macros/src/component.rs +++ b/crates/bevy_ecs/macros/src/component.rs @@ -1,4 +1,4 @@ -use proc_macro::{TokenStream, TokenTree}; +use proc_macro::TokenStream; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{format_ident, quote, ToTokens}; use std::collections::HashSet; @@ -202,6 +202,18 @@ pub fn derive_component(input: TokenStream) -> TokenStream { let struct_name = &ast.ident; let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl(); + let required_component_docs = attrs.requires.map(|r| { + let paths = r + .iter() + .map(|r| format!("[`{}`]", r.path.to_token_stream())) + .collect::>() + .join(", "); + let doc = format!("**Required Components**: {paths}. \n\n A component's Required Components are inserted whenever it is inserted. Note that this will also insert the required components _of_ the required components, recursively, in depth-first order."); + quote! { + #[doc = #doc] + } + }); + let mutable_type = (attrs.immutable || relationship.is_some()) .then_some(quote! { #bevy_ecs_path::component::Immutable }) .unwrap_or(quote! { #bevy_ecs_path::component::Mutable }); @@ -218,6 +230,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream { // This puts `register_required` before `register_recursive_requires` to ensure that the constructors of _all_ top // level components are initialized first, giving them precedence over recursively defined constructors for the same component type TokenStream::from(quote! { + #required_component_docs impl #impl_generics #bevy_ecs_path::component::Component for #struct_name #type_generics #where_clause { const STORAGE_TYPE: #bevy_ecs_path::component::StorageType = #storage; type Mutability = #mutable_type; @@ -402,34 +415,6 @@ pub(crate) fn ident_or_index(ident: Option<&Ident>, index: usize) -> Member { ) } -pub fn document_required_components(attr: TokenStream, item: TokenStream) -> TokenStream { - let paths = parse_macro_input!(attr with Punctuated::::parse_terminated) - .iter() - .map(|r| format!("[`{}`]", r.path.to_token_stream())) - .collect::>() - .join(", "); - - let bevy_ecs_path = crate::bevy_ecs_path() - .to_token_stream() - .to_string() - .replace(' ', ""); - let required_components_path = bevy_ecs_path + "::component::Component#required-components"; - - // Insert information about required components after any existing doc comments - let mut out = TokenStream::new(); - let mut end_of_attributes_reached = false; - for tt in item { - if !end_of_attributes_reached & matches!(tt, TokenTree::Ident(_)) { - end_of_attributes_reached = true; - let doc: TokenStream = format!("#[doc = \"\n\n# Required Components\n{paths} \n\n A component's [required components]({required_components_path}) are inserted whenever it is inserted. Note that this will also insert the required components _of_ the required components, recursively, in depth-first order.\"]").parse().unwrap(); - out.extend(doc); - } - out.extend(Some(tt)); - } - - out -} - pub const COMPONENT: &str = "component"; pub const STORAGE: &str = "storage"; pub const REQUIRE: &str = "require"; diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index f61889651df1e..9887f1fabe2c1 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -597,20 +597,12 @@ pub fn derive_resource(input: TokenStream) -> TokenStream { #[proc_macro_derive( Component, - attributes(component, relationship, relationship_target, entities) + attributes(component, require, relationship, relationship_target, entities) )] pub fn derive_component(input: TokenStream) -> TokenStream { component::derive_component(input) } -/// Allows specifying a component's required components. -/// -/// See `Component` docs for usage. -#[proc_macro_attribute] -pub fn require(attr: TokenStream, item: TokenStream) -> TokenStream { - component::document_required_components(attr, item) -} - #[proc_macro_derive(States)] pub fn derive_states(input: TokenStream) -> TokenStream { states::derive_states(input) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index eeb6820bae69d..b3ff8ed37c654 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -32,8 +32,6 @@ use core::{ use disqualified::ShortName; use thiserror::Error; -pub use bevy_ecs_macros::require; - /// A data type that can be used to store data for an [entity]. /// /// `Component` is a [derivable trait]: this means that a data type can implement it by applying a `#[derive(Component)]` attribute to it. diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index 61aa1b9a4e689..289f732d8f1ca 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -825,7 +825,6 @@ mod tests { world::{FromWorld, World}, }; use alloc::vec::Vec; - use bevy_ecs_macros::require; use bevy_ptr::OwningPtr; use bevy_reflect::Reflect; use core::{alloc::Layout, ops::Deref}; diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 8d415d7469183..bae3dbfed2438 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -72,7 +72,7 @@ pub mod prelude { bundle::Bundle, change_detection::{DetectChanges, DetectChangesMut, Mut, Ref}, children, - component::{require, Component}, + component::Component, entity::{Entity, EntityBorrow, EntityMapper}, event::{Event, EventMutator, EventReader, EventWriter, Events}, hierarchy::{ChildOf, ChildSpawner, ChildSpawnerCommands, Children}, @@ -132,7 +132,7 @@ mod tests { use crate::{ bundle::Bundle, change_detection::Ref, - component::{require, Component, ComponentId, RequiredComponents, RequiredComponentsError}, + component::{Component, ComponentId, RequiredComponents, RequiredComponentsError}, entity::Entity, entity_disabling::DefaultQueryFilters, prelude::Or, diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 442c4185dc464..12c5427225b5d 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -2222,7 +2222,7 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> { #[cfg(test)] mod tests { use crate::{ - component::{require, Component}, + component::Component, resource::Resource, system::Commands, world::{CommandQueue, FromWorld, World}, diff --git a/crates/bevy_ecs/src/system/system_registry.rs b/crates/bevy_ecs/src/system/system_registry.rs index cf42d0d875896..f1837f99dd6f5 100644 --- a/crates/bevy_ecs/src/system/system_registry.rs +++ b/crates/bevy_ecs/src/system/system_registry.rs @@ -7,7 +7,7 @@ use crate::{ world::World, }; use alloc::boxed::Box; -use bevy_ecs_macros::{require, Component, Resource}; +use bevy_ecs_macros::{Component, Resource}; #[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; use core::marker::PhantomData; diff --git a/crates/bevy_gizmos/src/retained.rs b/crates/bevy_gizmos/src/retained.rs index 435f417552463..51170144b1632 100644 --- a/crates/bevy_gizmos/src/retained.rs +++ b/crates/bevy_gizmos/src/retained.rs @@ -3,10 +3,7 @@ use core::ops::{Deref, DerefMut}; use bevy_asset::Handle; -use bevy_ecs::{ - component::{require, Component}, - reflect::ReflectComponent, -}; +use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::Reflect; use bevy_transform::components::Transform; diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index 30d503cf7947f..4487a3caa33ab 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -12,7 +12,6 @@ use bevy_ecs::{ entity::Entity, event::{Event, EventReader, EventWriter}, name::Name, - prelude::require, system::{Commands, Query}, }; use bevy_math::ops; diff --git a/crates/bevy_pbr/src/atmosphere/mod.rs b/crates/bevy_pbr/src/atmosphere/mod.rs index f525c0e2b8d3d..82dc201c5de2d 100644 --- a/crates/bevy_pbr/src/atmosphere/mod.rs +++ b/crates/bevy_pbr/src/atmosphere/mod.rs @@ -36,7 +36,7 @@ use bevy_app::{App, Plugin}; use bevy_asset::load_internal_asset; use bevy_core_pipeline::core_3d::graph::Node3d; use bevy_ecs::{ - component::{require, Component}, + component::Component, query::{Changed, QueryItem, With}, schedule::IntoSystemConfigs, system::{lifetimeless::Read, Query}, diff --git a/crates/bevy_pbr/src/decal/clustered.rs b/crates/bevy_pbr/src/decal/clustered.rs index 43edcd0bc34d5..d382d50c8ced4 100644 --- a/crates/bevy_pbr/src/decal/clustered.rs +++ b/crates/bevy_pbr/src/decal/clustered.rs @@ -20,7 +20,7 @@ use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, weak_handle, AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - component::{require, Component}, + component::Component, entity::{hash_map::EntityHashMap, Entity}, prelude::ReflectComponent, query::With, diff --git a/crates/bevy_pbr/src/decal/forward.rs b/crates/bevy_pbr/src/decal/forward.rs index 7732f1d3a4ab3..95bc45cd7bc49 100644 --- a/crates/bevy_pbr/src/decal/forward.rs +++ b/crates/bevy_pbr/src/decal/forward.rs @@ -4,7 +4,7 @@ use crate::{ }; use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, weak_handle, Asset, Assets, Handle}; -use bevy_ecs::component::{require, Component}; +use bevy_ecs::component::Component; use bevy_math::{prelude::Rectangle, Quat, Vec2, Vec3}; use bevy_reflect::{Reflect, TypePath}; use bevy_render::{ diff --git a/crates/bevy_pbr/src/light_probe/mod.rs b/crates/bevy_pbr/src/light_probe/mod.rs index c728a1cc6b863..65a7ee6740668 100644 --- a/crates/bevy_pbr/src/light_probe/mod.rs +++ b/crates/bevy_pbr/src/light_probe/mod.rs @@ -5,7 +5,7 @@ use bevy_asset::{load_internal_asset, weak_handle, AssetId, Handle}; use bevy_core_pipeline::core_3d::Camera3d; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - component::{require, Component}, + component::Component, entity::Entity, query::With, reflect::ReflectComponent, diff --git a/crates/bevy_pbr/src/meshlet/mod.rs b/crates/bevy_pbr/src/meshlet/mod.rs index 4057f29e39a3c..bf701acb1c032 100644 --- a/crates/bevy_pbr/src/meshlet/mod.rs +++ b/crates/bevy_pbr/src/meshlet/mod.rs @@ -65,7 +65,7 @@ use bevy_core_pipeline::{ }; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - component::{require, Component}, + component::Component, entity::Entity, query::Has, reflect::ReflectComponent, diff --git a/crates/bevy_pbr/src/ssao/mod.rs b/crates/bevy_pbr/src/ssao/mod.rs index 4d97f52cff4ff..3422f511c5167 100644 --- a/crates/bevy_pbr/src/ssao/mod.rs +++ b/crates/bevy_pbr/src/ssao/mod.rs @@ -7,7 +7,7 @@ use bevy_core_pipeline::{ prepass::{DepthPrepass, NormalPrepass, ViewPrepassTextures}, }; use bevy_ecs::{ - prelude::{require, Component, Entity}, + prelude::{Component, Entity}, query::{Has, QueryItem, With}, reflect::ReflectComponent, resource::Resource, diff --git a/crates/bevy_pbr/src/ssr/mod.rs b/crates/bevy_pbr/src/ssr/mod.rs index 15b783cef5d5f..fa7424145f51b 100644 --- a/crates/bevy_pbr/src/ssr/mod.rs +++ b/crates/bevy_pbr/src/ssr/mod.rs @@ -12,7 +12,7 @@ use bevy_core_pipeline::{ }; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - component::{require, Component}, + component::Component, entity::Entity, query::{Has, QueryItem, With}, reflect::ReflectComponent, diff --git a/crates/bevy_pbr/src/volumetric_fog/mod.rs b/crates/bevy_pbr/src/volumetric_fog/mod.rs index 4b90d63afccb7..ff0b913f1d3cc 100644 --- a/crates/bevy_pbr/src/volumetric_fog/mod.rs +++ b/crates/bevy_pbr/src/volumetric_fog/mod.rs @@ -36,11 +36,7 @@ use bevy_core_pipeline::core_3d::{ graph::{Core3d, Node3d}, prepare_core_3d_depth_textures, }; -use bevy_ecs::{ - component::{require, Component}, - reflect::ReflectComponent, - schedule::IntoSystemConfigs as _, -}; +use bevy_ecs::{component::Component, reflect::ReflectComponent, schedule::IntoSystemConfigs as _}; use bevy_image::Image; use bevy_math::{ primitives::{Cuboid, Plane3d}, diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 298be27c5fa9e..0c67f0ea049b0 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -25,7 +25,7 @@ use bevy_ecs::{ component::{Component, HookContext}, entity::{Entity, EntityBorrow}, event::EventReader, - prelude::{require, With}, + prelude::With, query::Has, reflect::ReflectComponent, resource::Resource, diff --git a/crates/bevy_render/src/mesh/components.rs b/crates/bevy_render/src/mesh/components.rs index b5b03ac2b8f27..f55897ce6d82a 100644 --- a/crates/bevy_render/src/mesh/components.rs +++ b/crates/bevy_render/src/mesh/components.rs @@ -5,7 +5,7 @@ use crate::{ use bevy_asset::{AsAssetId, AssetEvent, AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ - change_detection::DetectChangesMut, component::Component, event::EventReader, prelude::require, + change_detection::DetectChangesMut, component::Component, event::EventReader, reflect::ReflectComponent, system::Query, }; use bevy_platform_support::{collections::HashSet, hash::FixedHasher}; diff --git a/crates/bevy_scene/src/components.rs b/crates/bevy_scene/src/components.rs index 8709c7990fd50..355628c6c7300 100644 --- a/crates/bevy_scene/src/components.rs +++ b/crates/bevy_scene/src/components.rs @@ -1,9 +1,6 @@ use bevy_asset::Handle; use bevy_derive::{Deref, DerefMut}; -use bevy_ecs::{ - component::{require, Component}, - prelude::ReflectComponent, -}; +use bevy_ecs::{component::Component, prelude::ReflectComponent}; use bevy_reflect::{prelude::ReflectDefault, Reflect}; use bevy_transform::components::Transform; use derive_more::derive::From; diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index 59c60071a0293..82d5f155a88e5 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -1,9 +1,6 @@ use bevy_asset::{Assets, Handle}; use bevy_color::Color; -use bevy_ecs::{ - component::{require, Component}, - reflect::ReflectComponent, -}; +use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_image::{Image, TextureAtlas, TextureAtlasLayout}; use bevy_math::{Rect, UVec2, Vec2}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 13e9760f29a13..394b12d03b7be 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -10,7 +10,7 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::entity::hash_set::EntityHashSet; use bevy_ecs::{ change_detection::{DetectChanges, Ref}, - component::{require, Component}, + component::Component, entity::Entity, prelude::{ReflectComponent, With}, query::{Changed, Without}, diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 2949015848470..8dc4d2453c718 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -3,7 +3,7 @@ use bevy_math::{Affine3A, Dir3, Isometry3d, Mat3, Mat4, Quat, Vec3}; use core::ops::Mul; #[cfg(feature = "bevy-support")] -use bevy_ecs::{component::Component, prelude::require}; +use bevy_ecs::component::Component; #[cfg(feature = "bevy_reflect")] use {bevy_ecs::reflect::ReflectComponent, bevy_reflect::prelude::*}; diff --git a/crates/bevy_ui/src/ui_material.rs b/crates/bevy_ui/src/ui_material.rs index a9d712d5be548..9f56e834a4c73 100644 --- a/crates/bevy_ui/src/ui_material.rs +++ b/crates/bevy_ui/src/ui_material.rs @@ -1,10 +1,7 @@ use crate::Node; use bevy_asset::{Asset, AssetId, Handle}; use bevy_derive::{Deref, DerefMut}; -use bevy_ecs::{ - component::{require, Component}, - reflect::ReflectComponent, -}; +use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::{prelude::ReflectDefault, Reflect}; use bevy_render::{ extract_component::ExtractComponent, diff --git a/crates/bevy_ui/src/widget/button.rs b/crates/bevy_ui/src/widget/button.rs index 8445a4ad6266b..a4e5afc6fae48 100644 --- a/crates/bevy_ui/src/widget/button.rs +++ b/crates/bevy_ui/src/widget/button.rs @@ -1,8 +1,5 @@ use crate::{FocusPolicy, Interaction, Node}; -use bevy_ecs::{ - prelude::{require, Component}, - reflect::ReflectComponent, -}; +use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::{std_traits::ReflectDefault, Reflect}; /// Marker struct for buttons diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index 42c91fd833415..0be96febabc25 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -7,8 +7,8 @@ use bevy_color::Color; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ change_detection::DetectChanges, + component::Component, entity::Entity, - prelude::{require, Component}, query::With, reflect::ReflectComponent, system::{Query, Res, ResMut}, From 4e5f0d2656b25b367f658d88052ae46a8f961b9a Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Wed, 5 Mar 2025 14:18:27 -0800 Subject: [PATCH 12/12] Fix depth prepass doc which is (surprisingly) broken on main? --- crates/bevy_pbr/src/decal/forward.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/decal/forward.rs b/crates/bevy_pbr/src/decal/forward.rs index 95bc45cd7bc49..8490017fbbae6 100644 --- a/crates/bevy_pbr/src/decal/forward.rs +++ b/crates/bevy_pbr/src/decal/forward.rs @@ -63,7 +63,7 @@ impl Plugin for ForwardDecalPlugin { /// # Usage Notes /// /// * Spawn this component on an entity with a [`crate::MeshMaterial3d`] component holding a [`ForwardDecalMaterial`]. -/// * Any camera rendering a forward decal must have the [`bevy_core_pipeline::DepthPrepass`] component. +/// * Any camera rendering a forward decal must have the [`bevy_core_pipeline::prepass::DepthPrepass`] component. /// * Looking at forward decals at a steep angle can cause distortion. This can be mitigated by padding your decal's /// texture with extra transparent pixels on the edges. #[derive(Component, Reflect)]