Skip to content

API improvements#78

Open
yozhgoor wants to merge 25 commits intomainfrom
api-improvements
Open

API improvements#78
yozhgoor wants to merge 25 commits intomainfrom
api-improvements

Conversation

@yozhgoor
Copy link
Copy Markdown
Member

@yozhgoor yozhgoor commented Apr 5, 2026

Closes #77

}

#[xtask_wasm::run_example(static_dir = "webapp/static", app_name = "web_app")]
#[xtask_wasm::run_example(assets_dir = "webapp/assets", app_name = "web_app")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should go for public then. Not sure if we should change the name of the function (assets_dir) or nott.

@cecton cecton requested a review from Copilot April 9, 2026 12:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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::runDist::build, static_dir_pathassets_dir, dist_dir_pathdist_dir, and removed run_in_workspace.
  • Simplified dev-server usage: DevServer::xtask("dist").start() replaces arg("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.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
/// 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.

Copilot uses AI. Check for mistakes.

/// Name of the xtask command that is executed when a change is detected.
///
/// See [`command`] to use an arbitrary command.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
/// See [`command`] to use an arbitrary command.
/// See [`command`](Self::command) to use an arbitrary command.

Copilot uses AI. Check for mistakes.
Comment on lines +171 to 179
/// 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
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +324 to +328
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()
};
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +42 to 43
/// at the workspace root, copy the content of the `project/assets` directory,
/// generate JS bindings and output two files: `project.js` and `project.wasm`
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
/// 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`

Copilot uses AI. Check for mistakes.
Comment on lines 183 to 199
/// 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();
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 72 to 82
@@ -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")),
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API improvements

3 participants