#[non_exhaustive]pub struct Dist {Show 20 fields
pub quiet: bool,
pub jobs: Option<String>,
pub profile: Option<String>,
pub release: bool,
pub features: Vec<String>,
pub all_features: bool,
pub no_default_features: bool,
pub verbose: bool,
pub color: Option<String>,
pub frozen: bool,
pub locked: bool,
pub offline: bool,
pub ignore_rust_version: bool,
pub example: Option<String>,
pub build_command: Command,
pub dist_dir_path: Option<PathBuf>,
pub static_dir_path: Option<PathBuf>,
pub app_name: Option<String>,
pub run_in_workspace: bool,
pub sass_options: Options,
}
Expand description
A helper to generate the distributed package.
§Usage
use std::process;
use xtask_wasm::{anyhow::Result, clap};
#[derive(clap::Parser)]
enum Opt {
Dist(xtask_wasm::Dist),
}
fn main() -> Result<()> {
let opt: Opt = clap::Parser::parse();
match opt {
Opt::Dist(dist) => {
log::info!("Generating package...");
dist
.static_dir_path("my-project/static")
.app_name("my-project")
.run_in_workspace(true)
.run("my-project")?;
}
}
Ok(())
}
In this example, we added a dist
subcommand to build and package the
my-project
crate. It will run the default_build_command
at the workspace root, copy the content of the project/static
directory,
generate JS bindings and output two files: project.js
and project.wasm
into the dist directory.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.quiet: bool
No output printed to stdout.
jobs: Option<String>
Number of parallel jobs, defaults to # of CPUs.
profile: Option<String>
Build artifacts with the specified profile.
release: bool
Build artifacts in release mode, with optimizations.
features: Vec<String>
Space or comma separated list of features to activate.
all_features: bool
Activate all available features.
no_default_features: bool
Do not activate the default
features.
verbose: bool
Use verbose output
color: Option<String>
Coloring: auto, always, never.
frozen: bool
Require Cargo.lock and cache are up to date.
locked: bool
Require Cargo.lock is up to date.
offline: bool
Run without accessing the network.
ignore_rust_version: bool
Ignore rust-version
specification in packages.
example: Option<String>
Name of the example target to run.
build_command: Command
Command passed to the build process.
dist_dir_path: Option<PathBuf>
Directory of all generated artifacts.
static_dir_path: Option<PathBuf>
Directory of all static artifacts.
app_name: Option<String>
Set the resulting app name, default to app
.
run_in_workspace: bool
Set the command’s current directory as the workspace root.
sass_options: Options
Output style for SASS/SCSS
Implementations§
Source§impl Dist
impl Dist
Sourcepub fn build_command(self, command: Command) -> Self
pub fn build_command(self, command: Command) -> Self
Set the command used by the build process.
The default command is the result of the default_build_command
.
Sourcepub fn dist_dir_path(self, path: impl Into<PathBuf>) -> Self
pub fn dist_dir_path(self, path: impl Into<PathBuf>) -> Self
Set the directory for the generated artifacts.
The default for debug build is target/debug/dist
and
target/release/dist
for the release build.
Sourcepub fn static_dir_path(self, path: impl Into<PathBuf>) -> Self
pub fn static_dir_path(self, path: impl Into<PathBuf>) -> Self
Set the directory for the static artifacts (like index.html
).
Sourcepub fn app_name(self, app_name: impl Into<String>) -> Self
pub fn app_name(self, app_name: impl Into<String>) -> Self
Set the resulting package name.
The default is app
.
Sourcepub fn run_in_workspace(self, res: bool) -> Self
pub fn run_in_workspace(self, res: bool) -> Self
Set the dist process current directory as the workspace root.
Sourcepub fn sass_options(self, output_style: Options) -> Self
pub fn sass_options(self, output_style: Options) -> Self
Set the output style for SCSS/SASS
Sourcepub fn run(self, package_name: &str) -> Result<PathBuf>
pub fn run(self, package_name: &str) -> Result<PathBuf>
Build the given package for Wasm.
This will generate JS bindings via wasm-bindgen
and copy files from a given static 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.
Trait Implementations§
Source§impl Args for Dist
impl Args for Dist
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command
so it can instantiate self
via
FromArgMatches::update_from_arg_matches_mut
Read moreSource§impl CommandFactory for Dist
impl CommandFactory for Dist
Source§impl FromArgMatches for Dist
impl FromArgMatches for Dist
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches
to self
.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches
to self
.Source§impl Parser for Dist
impl Parser for Dist
Source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
Auto Trait Implementations§
impl Freeze for Dist
impl !RefUnwindSafe for Dist
impl Send for Dist
impl Sync for Dist
impl Unpin for Dist
impl !UnwindSafe for Dist
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more