1use crate::cmd::run_cmd_directly;
2use crate::install::Tools;
3use crate::parse::{Opts, SnoopServeOpts};
4use crate::{errors::*, get_user_crate_name};
5use std::path::PathBuf;
6
7pub fn snoop_build(dir: PathBuf, tools: &Tools, global_opts: &Opts) -> Result<i32, ExecutionError> {
13 run_cmd_directly(
14 format!(
15 "{} run {}",
16 tools.cargo_engine, global_opts.cargo_engine_args
17 ),
18 &dir,
19 vec![
20 ("PERSEUS_ENGINE_OPERATION", "build"),
21 ("CARGO_TARGET_DIR", "dist/target_engine"),
22 ("RUSTFLAGS", "--cfg=engine"),
23 ],
24 )
25}
26
27pub fn snoop_wasm_build(
31 dir: PathBuf,
32 tools: &Tools,
33 global_opts: &Opts,
34) -> Result<i32, ExecutionError> {
35 let crate_name = get_user_crate_name(&dir)?;
36
37 println!("[NOTE]: You should expect unused code warnings here! Don't worry about them, they're just a product of the target-gating.");
38 let exit_code = run_cmd_directly(
39 format!(
40 "{} build --target wasm32-unknown-unknown {}",
41 tools.cargo_browser, global_opts.cargo_browser_args
42 ),
43 &dir,
44 vec![
45 ("CARGO_TARGET_DIR", "dist/target_wasm"),
46 ("RUSTFLAGS", "--cfg=client"),
47 ],
48 )?;
49 if exit_code != 0 {
50 return Ok(exit_code);
51 }
52 run_cmd_directly(
53 format!(
54 "{cmd} ./dist/target_wasm/wasm32-unknown-unknown/debug/{crate_name}.wasm --out-dir dist/pkg --out-name perseus_engine --target web {args}",
55 cmd=tools.wasm_bindgen,
56 args=global_opts.wasm_bindgen_args,
57 crate_name=crate_name
58 ),
59 &dir,
60 vec![("CARGO_TARGET_DIR", "dist/target_wasm")],
61 )
62}
63
64pub fn snoop_server(
67 dir: PathBuf,
68 opts: &SnoopServeOpts,
69 tools: &Tools,
70 global_opts: &Opts,
71) -> Result<i32, ExecutionError> {
72 run_cmd_directly(
73 format!(
74 "{} run {}",
75 tools.cargo_engine, global_opts.cargo_engine_args
76 ),
77 &dir,
78 vec![
79 ("PERSEUS_ENGINE_OPERATION", "serve"),
80 ("CARGO_TARGET_DIR", "dist/target_engine"),
81 ("PERSEUS_HOST", &opts.host),
82 ("PERSEUS_PORT", &opts.port.to_string()),
83 ("RUSTFLAGS", "--cfg=engine"),
84 ], )
88}