Conversation
…`default_dist_dir_release`
61551f6 to
af672b2
Compare
| } | ||
|
|
||
| #[xtask_wasm::run_example(static_dir = "webapp/static", app_name = "web_app")] | ||
| #[xtask_wasm::run_example(assets_dir = "webapp/assets", app_name = "web_app")] |
There was a problem hiding this comment.
Common conventions:
- For files processed/packed by webpack (imported from JS/CSS): put them under src/assets (or src/images, src/styles, etc.).
- For static files served as-is (no bundling): put them in public or static (e.g., public/, static/ or public/assets/).
Most common names: "src/assets" for bundled assets and "public" for static assets. Recommendation: use src/assets for anything you import into code and public/ for favicons/index.html or truly static files.
There was a problem hiding this comment.
We should go for public then. Not sure if we should change the name of the function (assets_dir) or nott.
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #77 by refining the xtask-wasm public API to remove confusing boolean parameters, clarify dev-server configuration, and align naming (e.g., “assets” vs “static”), while updating documentation/examples accordingly.
Changes:
- Renamed/reshaped key APIs:
Dist::run→Dist::build,static_dir_path→assets_dir,dist_dir_path→dist_dir, and removedrun_in_workspace. - Simplified dev-server usage:
DevServer::xtask("dist").start()replacesarg("dist").start(default_dist_dir(false)). - Updated README, crate docs, and demo assets/examples to match the new API and add logger initialization.
Reviewed changes
Copilot reviewed 9 out of 16 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/dist.rs |
Introduces build() API, assets terminology, and new default dist-dir helpers; removes older APIs. |
src/dev_server.rs |
Adds xtask() and command pipeline (pre/main/post), changes start() to use an internal default dist dir. |
xtask-wasm-run-example/src/lib.rs |
Updates proc-macro args and generated CLI code to the new assets_dir / xtask().start() API. |
src/lib.rs |
Updates crate-level docs/examples to the new API and adds logger init in examples. |
README.md |
Updates the getting-started snippet to match the new API and logger initialization. |
examples/demo/xtask/src/main.rs |
Adapts demo xtask CLI to assets_dir + build() + xtask().start(). |
examples/demo/webapp/examples/run_example.rs |
Updates the proc-macro invocation to assets_dir = .... |
examples/demo/webapp/assets/** |
Adds new asset files used by the updated demo (HTML + SASS/SCSS). |
src/wasm_opt.rs |
Minor error formatting change. |
Cargo.toml |
Bumps rust-version and adds env_logger dev-dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let handle = std::thread::spawn(|| match watch.run(command) { | ||
| Ok(()) => log::trace!("Starting to watch"), | ||
| Err(err) => log::error!("an error occurred when starting to watch: {}", err), | ||
| /// If `dist_dir` has not been provided, [`default_dist_dir_debug`] will be used. |
There was a problem hiding this comment.
The rustdoc link in this comment points to default_dist_dir_debug, but that symbol doesn’t exist anymore. Update it to reference the actual default (Dist::default_debug_dir()), or link to DevServer::dist_dir and describe the default path in plain text so the docs don’t contain a broken intra-doc link.
| /// If `dist_dir` has not been provided, [`default_dist_dir_debug`] will be used. | |
| /// If `dist_dir` has not been provided, [`Dist::default_debug_dir()`] will be used. |
|
|
||
| /// Name of the xtask command that is executed when a change is detected. | ||
| /// | ||
| /// See [`command`] to use an arbitrary command. |
There was a problem hiding this comment.
In this rustdoc, See [command] is not an explicit intra-doc link to the command method and may resolve incorrectly or produce warnings. Prefer an explicit link like [command](Self::command) for consistency with the surrounding docs.
| /// See [`command`] to use an arbitrary command. | |
| /// See [`command`](Self::command) to use an arbitrary command. |
| /// Adds an argument to pass to the [`command`](Self::command) executed when changes are | ||
| /// detected. | ||
| /// | ||
| /// This will use the xtask command by default. | ||
| /// This is no-op unless a [`command`](Self::command) or an [`xtask`](Self::xtask) is provided. | ||
| pub fn arg<S: AsRef<ffi::OsStr>>(mut self, arg: S) -> Self { | ||
| self.set_xtask_command().arg(arg); | ||
| if let Some(command) = self.command.as_mut() { | ||
| command.arg(arg); | ||
| } | ||
| self |
There was a problem hiding this comment.
arg/args/env/envs are now documented as a no-op unless command()/xtask() was called first. This is a silent behavioral change compared to the previous API (where calling arg() implicitly prepared an xtask command) and can lead to a dev server that watches/serves but never rebuilds without any error. Consider buffering these args/envs until a command is set, or returning an error when start() is called with pending args but no command configured.
| let assets_dir = if let Some(assets_dir) = self.assets_dir { | ||
| assets_dir | ||
| } else { | ||
| metadata.workspace_root.join("public").as_std_path().to_path_buf() | ||
| }; |
There was a problem hiding this comment.
The docs say the default assets directory is public “at crate level”, but the implementation defaults to metadata.workspace_root.join("public"). In a workspace, this will look for public/ at the workspace root, not at the package/crate root, and may silently skip copying assets. Either adjust the docs to say “workspace root”, or compute the package directory from package_name (e.g., via crate::package(...)) and default to <package_root>/public.
| /// at the workspace root, copy the content of the `project/assets` directory, | ||
| /// generate JS bindings and output two files: `project.js` and `project.wasm` |
There was a problem hiding this comment.
This usage docs paragraph refers to copying project/assets, but the example crate is my-project above. Consider aligning the path in the prose with the rest of the example (my-project/assets) to avoid confusion.
| /// at the workspace root, copy the content of the `project/assets` directory, | |
| /// generate JS bindings and output two files: `project.js` and `project.wasm` | |
| /// at the workspace root, copy the content of the `my-project/assets` directory, | |
| /// generate JS bindings and output two files: `my-project.js` and `my-project.wasm` |
| /// Build the given package for Wasm. | ||
| /// | ||
| /// This will generate JS bindings via [`wasm-bindgen`](https://docs.rs/wasm-bindgen/latest/wasm_bindgen/) | ||
| /// and copy files from a given static directory if any to finally return | ||
| /// and copy files from a given assets directory if any to finally return | ||
| /// the path of the generated artifacts. | ||
| /// | ||
| /// Wasm optimizations can be achieved using [`crate::WasmOpt`] if the | ||
| /// feature `wasm-opt` is enabled. | ||
| pub fn run(self, package_name: &str) -> Result<PathBuf> { | ||
| #[cfg_attr( | ||
| feature = "wasm-opt", | ||
| doc = "Wasm optimizations can be achieved using [`WasmOpt`](crate::WasmOpt) if the feature `wasm-opt` is enabled." | ||
| )] | ||
| #[cfg_attr( | ||
| not(feature = "wasm-opt"), | ||
| doc = "Wasm optimizations can be achieved using `WasmOpt` if the feature `wasm-opt` is enabled." | ||
| )] | ||
| pub fn build(self, package_name: &str) -> Result<PathBuf> { | ||
| log::trace!("Getting package's metadata"); | ||
| let metadata = metadata(); |
There was a problem hiding this comment.
This is a breaking rename from run() to build() (and related builder renames/removals). If you intend to keep this compatible within the 0.5.x line, consider adding #[deprecated] wrapper methods (e.g., run delegating to build) so downstream crates get compile-time guidance instead of hard breakage.
| @@ -76,7 +76,7 @@ impl RunExample { | |||
|
|
|||
| match ident.to_string().as_str() { | |||
| "index" => index = Some(expr), | |||
| "static_dir" => static_dir = Some(expr), | |||
| "assets_dir" => assets_dir = Some(expr), | |||
| "app_name" => app_name = Some(expr), | |||
| _ => return Err(parse::Error::new(ident.span(), "unrecognized argument")), | |||
| } | |||
There was a problem hiding this comment.
The proc-macro attribute key was renamed from static_dir to assets_dir, which will break existing downstream uses. If compatibility is desired, consider accepting static_dir as a deprecated alias that maps to assets_dir, and emitting a clear compile-time warning/error message guiding users to the new name.
Closes #77