pub fn ensure_installed() -> BTreeMap<String, String> {
    check_installation("rustup",
        &["target", "add", "wasm32-unknown-emscripten"],
        "rustup installation not found. Try installing from https://rustup.rs and rerunning?");

    // check if just already in path and working
    if let Ok(_) = Command::new("emcc").args(&["--version"]).output() {
        print_prefix();
        eprintln!("using emcc already in $PATH");
        return BTreeMap::new();
    }

    // install emsdk if necessary, and then see if we can just use the env vars to get an emcc
    check_dependencies();
    let mut target_dir = std::env::home_dir().unwrap_or_else(|| { panic!("failed to get home directory") });
    target_dir.push(".emsdk");
    let mut emsdk_path = target_dir.clone();
    if cfg!(target_os = "windows") {
        emsdk_path.push("emsdk.bat");
    } else {
        emsdk_path.push("emsdk");
    }
    if check_emsdk_install(&emsdk_path) {
        print_prefix();
        eprintln!("found emsdk installation at {}", target_dir.display());
    } else {
        print_prefix();
        eprintln!("emsdk not found, installing to {}...", target_dir.display());
        install_emsdk(&target_dir);
    }
    print_prefix();
    eprintln!("setting environment variables...");
    let env = get_env(&emsdk_path);
    let cmd_res = Command::new("emcc")
        .args(&["--version"])
        .envs(env.iter().map(|(k,v)| (OsStr::new(k), OsStr::new(v))))
        .output();
    if let Ok(_) = cmd_res {
        return env;
    }

    // well I guess that didn't work, so we'll have to actually update and activate our emsdk
    print_prefix();
    eprintln!("installing emcc with emsdk...");
    Command::new(&emsdk_path).args(&["update"])
        .current_dir(&target_dir)
        .status()
        .unwrap_or_else(|e| { panic!("failed to execute emsdk: {}", e) });
    Command::new(&emsdk_path).args(&["install", "sdk-1.37.22-64bit"])
        .current_dir(&target_dir)
        .status()
        .unwrap_or_else(|e| { panic!("failed to execute emsdk: {}", e) });
    Command::new(&emsdk_path).args(&["activate", "sdk-1.37.22-64bit"])
        .current_dir(&target_dir)
        .output()
        .unwrap_or_else(|e| { panic!("failed to execute emsdk: {}", e) });

    print_prefix();
    eprintln!("resetting environment variables...");
    let env = get_env(&emsdk_path);
    let cmd_res = Command::new("emcc")
        .args(&["--version"])
        .envs(env.iter().map(|(k,v)| (OsStr::new(k), OsStr::new(v))))
        .output();
    if let Ok(_) = cmd_res {
        return env;
    } else {
        print_prefix();
        eprintln!("failed to install emcc successfully");
        exit(1);
    }
}
// returns env needed to use emcc
returns env needed to use emcc
returns env needed to use emcc
pub fn ensure_installed() -> BTreeMap<String, String> {
    check_installation("rustup",
        &["target", "add", "wasm32-unknown-emscripten"],
        "rustup installation not found. Try installing from https://rustup.rs and rerunning?");
    // check if just already in path and working
    if let Ok(_) = Command::new("emcc").args(&["--version"]).output() {
        print_prefix();
        eprintln!("using emcc already in $PATH");
        return BTreeMap::new();
    }
    // install emsdk if necessary, and then see if we can just use the env vars to get an emcc
    check_dependencies();
    let mut target_dir = std::env::home_dir().unwrap_or_else(|| { panic!("failed to get home directory") });
    target_dir.push(".emsdk");
    let mut emsdk_path = target_dir.clone();
    if cfg!(target_os = "windows") {
        emsdk_path.push("emsdk.bat");
    } else {
        emsdk_path.push("emsdk");
    }
    if check_emsdk_install(&emsdk_path) {
        print_prefix();
        eprintln!("found emsdk installation at {}", target_dir.display());
    } else {
        print_prefix();
        eprintln!("emsdk not found, installing to {}...", target_dir.display());
        install_emsdk(&target_dir);
    }
    print_prefix();
    eprintln!("setting environment variables...");
    let env = get_env(&emsdk_path);
    let cmd_res = Command::new("emcc")
        .args(&["--version"])
        .envs(env.iter().map(|(k,v)| (OsStr::new(k), OsStr::new(v))))
        .output();
    if let Ok(_) = cmd_res {
        return env;
    }
    // well I guess that didn't work, so we'll have to actually update and activate our emsdk
    print_prefix();
    eprintln!("installing emcc with emsdk...");
    Command::new(&emsdk_path).args(&["update"])
        .current_dir(&target_dir)
        .status()
        .unwrap_or_else(|e| { panic!("failed to execute emsdk: {}", e) });
    Command::new(&emsdk_path).args(&["install", "sdk-1.37.22-64bit"])
        .current_dir(&target_dir)
        .status()
        .unwrap_or_else(|e| { panic!("failed to execute emsdk: {}", e) });
    Command::new(&emsdk_path).args(&["activate", "sdk-1.37.22-64bit"])
        .current_dir(&target_dir)
        .output()
        .unwrap_or_else(|e| { panic!("failed to execute emsdk: {}", e) });
    print_prefix();
    eprintln!("resetting environment variables...");
    let env = get_env(&emsdk_path);
    let cmd_res = Command::new("emcc")
        .args(&["--version"])
        .envs(env.iter().map(|(k,v)| (OsStr::new(k), OsStr::new(v))))
        .output();
    if let Ok(_) = cmd_res {
        return env;
    } else {
        print_prefix();
        eprintln!("failed to install emcc successfully");
        exit(1);
    }
}
pub fn ensure_installed ( ) -> BTreeMap < String , String > { check_installation ( " " , & [ " " , " " , " " ] , " " ) ; // check if just already in path and working if let Ok ( _ ) = Command :: new ( " " ) . args ( & [ " " ] ) . output ( ) { print_prefix ( ) ; eprintln ! ( " " ) ; return BTreeMap :: new ( ) ; } // install emsdk if necessary, and then see if we can just use the env vars to get an emcc check_dependencies ( ) ; let mut target_dir = std :: env :: home_dir ( ) . unwrap_or_else ( | | { panic ! ( " " ) } ) ; target_dir . push ( " " ) ; let mut emsdk_path = target_dir . clone ( ) ; if cfg ! ( target_os " " ) { emsdk_path . push ( " " ) ; } else { emsdk_path . push ( " " ) ; } if check_emsdk_install ( & emsdk_path ) { print_prefix ( ) ; eprintln ! ( " " target_dir display ( ) ) ; } else { print_prefix ( ) ; eprintln ! ( " " target_dir display ( ) ) ; install_emsdk ( & target_dir ) ; } print_prefix ( ) ; eprintln ! ( " " ) ; let env = get_env ( & emsdk_path ) ; let cmd_res = Command :: new ( " " ) . args ( & [ " " ] ) . envs ( env . iter ( ) . map ( | ( k , v ) | ( OsStr :: new ( k ) , OsStr :: new ( v ) ) ) ) . output ( ) ; if let Ok ( _ ) = cmd_res { return env ; } // well I guess that didn't work, so we'll have to actually update and activate our emsdk print_prefix ( ) ; eprintln ! ( " " ) ; Command :: new ( & emsdk_path ) . args ( & [ " " ] ) . current_dir ( & target_dir ) . status ( ) . unwrap_or_else ( | e | { panic ! ( " " e ) } ) ; Command :: new ( & emsdk_path ) . args ( & [ " " , " " ] ) . current_dir ( & target_dir ) . status ( ) . unwrap_or_else ( | e | { panic ! ( " " e ) } ) ; Command :: new ( & emsdk_path ) . args ( & [ " " , " " ] ) . current_dir ( & target_dir ) . output ( ) . unwrap_or_else ( | e | { panic ! ( " " e ) } ) ; print_prefix ( ) ; eprintln ! ( " " ) ; let env = get_env ( & emsdk_path ) ; let cmd_res = Command :: new ( " " ) . args ( & [ " " ] ) . envs ( env . iter ( ) . map ( | ( k , v ) | ( OsStr :: new ( k ) , OsStr :: new ( v ) ) ) ) . output ( ) ; if let Ok ( _ ) = cmd_res { return env ; } else { print_prefix ( ) ; eprintln ! ( " " ) ; exit ( 1 ) ; } }
returns env needed to use emcc
returns env needed to use emcc