From a0c2b25829ffb319f8939b31f1330c9805fbf6a5 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Wed, 3 Jan 2024 09:12:22 +1100 Subject: [PATCH] Fix xtask wasm-bindgen install (#4944) Co-authored-by: Connor Fitzgerald --- xtask/src/run_wasm.rs | 18 +++++++++++++++--- xtask/src/util.rs | 23 ++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/xtask/src/run_wasm.rs b/xtask/src/run_wasm.rs index bf175dbd5..d53d33a2c 100644 --- a/xtask/src/run_wasm.rs +++ b/xtask/src/run_wasm.rs @@ -2,16 +2,28 @@ use anyhow::Context; use pico_args::Arguments; -use crate::util::check_all_programs; +use crate::util::{check_all_programs, Program}; pub(crate) fn run_wasm(mut args: Arguments) -> Result<(), anyhow::Error> { let no_serve = args.contains("--no-serve"); let release = args.contains("--release"); let programs_needed: &[_] = if no_serve { - &["wasm-bindgen"] + &[Program { + crate_name: "wasm-bindgen-cli", + binary_name: "wasm-bindgen", + }] } else { - &["wasm-bindgen", "simple-http-server"] + &[ + Program { + crate_name: "wasm-bindgen-cli", + binary_name: "wasm-bindgen", + }, + Program { + crate_name: "simple-http-server", + binary_name: "simple-http-server", + }, + ] }; check_all_programs(programs_needed)?; diff --git a/xtask/src/util.rs b/xtask/src/util.rs index 3b2456a89..85f4444c4 100644 --- a/xtask/src/util.rs +++ b/xtask/src/util.rs @@ -1,21 +1,30 @@ use std::{io, process::Command}; -pub(crate) fn check_all_programs(programs: &[&str]) -> anyhow::Result<()> { +pub(crate) struct Program { + pub binary_name: &'static str, + pub crate_name: &'static str, +} + +pub(crate) fn check_all_programs(programs: &[Program]) -> anyhow::Result<()> { let mut failed = Vec::new(); - for &program in programs { - let mut cmd = Command::new(program); + for Program { + binary_name, + crate_name, + } in programs + { + let mut cmd = Command::new(binary_name); cmd.arg("--help"); let output = cmd.output(); match output { Ok(_output) => { - log::info!("Checking for {program} in PATH: ✅"); + log::info!("Checking for {binary_name} in PATH: ✅"); } Err(e) if matches!(e.kind(), io::ErrorKind::NotFound) => { - log::error!("Checking for {program} in PATH: ❌"); - failed.push(program); + log::error!("Checking for {binary_name} in PATH: ❌"); + failed.push(*crate_name); } Err(e) => { - log::error!("Checking for {program} in PATH: ❌"); + log::error!("Checking for {binary_name} in PATH: ❌"); panic!("Unknown IO error: {:?}", e); } }