Struct xtask_wasm::Dist

source ·
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

source

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.

source

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.

source

pub fn static_dir_path(self, path: impl Into<PathBuf>) -> Self

Set the directory for the static artifacts (like index.html).

source

pub fn app_name(self, app_name: impl Into<String>) -> Self

Set the resulting package name.

The default is app.

source

pub fn run_in_workspace(self, res: bool) -> Self

Set the dist process current directory as the workspace root.

source

pub fn sass_options(self, output_style: Options) -> Self

Set the output style for SCSS/SASS

source

pub fn example(self, example: impl Into<String>) -> Self

Set the example to build.

source

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

source§

fn group_id() -> Option<Id>

Report the [ArgGroup::id][crate::ArgGroup::id] for this set of arguments
source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to [Command] so it can instantiate Self. Read more
source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to [Command] so it can update self. Read more
source§

impl CommandFactory for Dist

source§

fn command<'b>() -> Command

Build a [Command] that can instantiate Self. Read more
source§

fn command_for_update<'b>() -> Command

Build a [Command] that can update self. Read more
source§

impl Debug for Dist

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Dist

source§

fn default() -> Dist

Returns the “default value” for a type. Read more
source§

impl FromArgMatches for Dist

source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from [ArgMatches], parsing the arguments as needed. Read more
source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches ) -> Result<Self, Error>

Instantiate Self from [ArgMatches], parsing the arguments as needed. Read more
source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches ) -> Result<(), Error>

Assign values from ArgMatches to self.
source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches ) -> Result<(), Error>

Assign values from ArgMatches to self.
source§

impl Parser for Dist

§

fn parse() -> Self

Parse from std::env::args_os(), [exit][Error::exit] on error.
§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, [exit][Error::exit] on error.
§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, [exit][Error::exit] on error.
§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.