From a35695fadf23731eaedbc65ede48d957e9a5cabe Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Mon, 22 Apr 2024 17:28:21 -0400 Subject: [PATCH] Webassembly gha test. Add GHA test target wasm32-unknown-unknown. Switch from `use std::*` to qualified `std::` calls. --- .github/workflows/rust.yml | 13 +++++++++++++ src/lib.rs | 17 +++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f7889be..04ad12c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -50,3 +50,16 @@ jobs: run: cargo build --locked --all-targets --verbose - name: Run tests run: cargo test --locked --all-targets --verbose + + build-and-test-wasm: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f + - name: Report cargo version + run: cargo --version + - name: Report rustc version + run: rustc --version + - name: Build + run: cargo build --locked --target wasm32-unknown-unknown --verbose + - name: Run tests + run: cargo test --locked --target wasm32-unknown-unknown --verbose diff --git a/src/lib.rs b/src/lib.rs index 389b177..6e6c3f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,9 +20,6 @@ //! } //! ``` -use std::env; -use std::path::PathBuf; - #[cfg(unix)] /// Returns the path of the current user’s home directory if known. /// @@ -39,27 +36,27 @@ use std::path::PathBuf; /// /// This function returns `None` when the environment variable is set but empty. /// Those implementations return the empty string `""` instead. -pub fn env_home_dir() -> Option { - let home = env::var("HOME"); +pub fn env_home_dir() -> Option { + let home = std::env::var("HOME"); match home { - Ok(val) if !val.is_empty() => Some(PathBuf::from(val)), + Ok(val) if !val.is_empty() => Some(std::path::PathBuf::from(val)), _ => None, } } #[cfg(windows)] /// Returns the path of the current user’s home directory if known. -pub fn env_home_dir() -> Option { - let home = env::var("USERPROFILE"); +pub fn env_home_dir() -> Option { + let home = std::env::var("USERPROFILE"); match home { - Ok(val) if !val.is_empty() => Some(PathBuf::from(val)), + Ok(val) if !val.is_empty() => Some(std::path::PathBuf::from(val)), _ => None, } } #[cfg(all(not(windows), not(unix)))] /// Returns the path of the current user’s home directory if known. -pub fn env_home_dir() -> Option { +pub fn env_home_dir() -> Option { None }