Skip to content

Commit

Permalink
feat(cli): added support for wasm profiling builds
Browse files Browse the repository at this point in the history
Use `perseus snoop wasm-build --profiling` to generate a build
compatible with `twiggy` or similar.
  • Loading branch information
arctic-hen7 committed Jan 2, 2022
1 parent 1a7f6ed commit c2de025
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/perseus-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ async fn core_watch(dir: PathBuf, opts: Opts) -> Result<i32, Error> {
}
Subcommand::Snoop(snoop_subcmd) => match snoop_subcmd {
SnoopSubcommand::Build => snoop_build(dir)?,
SnoopSubcommand::WasmBuild => snoop_wasm_build(dir)?,
SnoopSubcommand::WasmBuild(snoop_wasm_opts) => snoop_wasm_build(dir, snoop_wasm_opts)?,
SnoopSubcommand::Serve(snoop_serve_opts) => snoop_server(dir, snoop_serve_opts)?,
},
Subcommand::Prep => {
Expand Down
13 changes: 10 additions & 3 deletions packages/perseus-cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct ExportOpts {
/// The port to host your exported app on
#[clap(long, default_value = "8080")]
pub port: u16,
/// Whether or not to watch the files in your working directory for changes (exluding `target/` and `.perseus/`)
/// Watch the files in your working directory for changes (exluding `target/` and `.perseus/`)
#[clap(short, long)]
pub watch: bool,
}
Expand All @@ -102,7 +102,7 @@ pub struct ServeOpts {
/// The server integration to use
#[clap(short, long, default_value = "warp")]
pub integration: Integration,
/// Whether or not to watch the files in your working directory for changes (exluding `target/` and `.perseus/`)
/// Watch the files in your working directory for changes (exluding `target/` and `.perseus/`)
#[clap(short, long)]
pub watch: bool,
}
Expand Down Expand Up @@ -145,11 +145,18 @@ pub enum SnoopSubcommand {
/// Snoops on the static generation process (this will let you see `dbg!` calls and the like)
Build,
/// Snoops on the Wasm building process (mostly for debugging errors)
WasmBuild,
WasmBuild(SnoopWasmOpts),
/// Snoops on the server process (run `perseus build` before this)
Serve(SnoopServeOpts),
}

#[derive(Parser)]
pub struct SnoopWasmOpts {
/// Produce a profiling build (for use with `twiggy` and the like)
#[clap(short, long)]
pub profiling: bool,
}

#[derive(Parser)]
pub struct SnoopServeOpts {
/// The server integration to use
Expand Down
13 changes: 9 additions & 4 deletions packages/perseus-cli/src/snoop.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::errors::*;
use crate::parse::SnoopServeOpts;
use crate::parse::{SnoopServeOpts, SnoopWasmOpts};
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
Expand Down Expand Up @@ -48,12 +48,17 @@ pub fn snoop_build(dir: PathBuf) -> Result<i32, ExecutionError> {
}

/// Runs the commands to build the user's app to Wasm directly so they can see detailed logs.
pub fn snoop_wasm_build(dir: PathBuf) -> Result<i32, ExecutionError> {
pub fn snoop_wasm_build(dir: PathBuf, opts: SnoopWasmOpts) -> Result<i32, ExecutionError> {
let target = dir.join(".perseus");
run_cmd_directly(
format!(
"{} build --target web --dev",
env::var("PERSEUS_WASM_PACK_PATH").unwrap_or_else(|_| "wasm-pack".to_string())
"{} build --target web {}",
env::var("PERSEUS_WASM_PACK_PATH").unwrap_or_else(|_| "wasm-pack".to_string()),
if opts.profiling {
"--profiling"
} else {
"--dev"
}
),
&target,
)
Expand Down

0 comments on commit c2de025

Please sign in to comment.