Skip to content

Commit

Permalink
support specifying features when building examples for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Nov 15, 2023
1 parent 01b9ddd commit 69e3d63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tools/build-wasm-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ struct Args {
#[arg(short, long)]
/// Optimize the wasm file for size with wasm-opt
optimize_size: bool,

#[arg(long)]
/// Additional features to enable
features: Vec<String>,
}

fn main() {
Expand All @@ -41,7 +45,7 @@ fn main() {
assert!(!cli.examples.is_empty(), "must have at least one example");

let mut default_features = true;
let mut features = vec![];
let mut features: Vec<&str> = cli.features.iter().map(|f| f.as_str()).collect();
if let Some(frames) = cli.frames {
let mut file = File::create("ci_testing_config.ron").unwrap();
file.write_fmt(format_args!("(exit_after: Some({frames}))"))
Expand Down
13 changes: 11 additions & 2 deletions tools/example-showcase/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,26 @@ header_message = \"Examples ({})\"
for to_build in work_to_do() {
let sh = Shell::new().unwrap();
let example = &to_build.technical_name;
let required_features = if to_build.required_features.is_empty() {
vec![]
} else {
vec![
"--features".to_string(),
to_build.required_features.join(","),
]
};

if optimize_size {
cmd!(
sh,
"cargo run -p build-wasm-example -- --api {api} {example} --optimize-size"
"cargo run -p build-wasm-example -- --api {api} {example} --optimize-size {required_features...}"
)
.run()
.unwrap();
} else {
cmd!(
sh,
"cargo run -p build-wasm-example -- --api {api} {example}"
"cargo run -p build-wasm-example -- --api {api} {example} {required_features...}"
)
.run()
.unwrap();
Expand Down

0 comments on commit 69e3d63

Please sign in to comment.