diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81b305b..381fb3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: components: rustfmt - run: cargo fmt --all -- --check tests: - name: "Test Rust ${{ matrix.rust }} (${{ matrix.os }}, ${{ matrix.flags }})" + name: "Test Rust ${{ matrix.rust }} (${{ matrix.os }}, ${{ matrix.target }} ${{ matrix.flags }})" runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -69,6 +69,8 @@ jobs: - { rust: stable, os: macos-latest, flags: "--no-default-features" } - { rust: stable, os: ubuntu-latest, flags: "--all-features" } - { rust: stable, os: ubuntu-latest, flags: "--no-default-features" } + - { rust: stable, os: ubuntu-latest, target: wasm32-unknown-unknown, flags: "--all-features" } + - { rust: stable, os: ubuntu-latest, target: wasm32-unknown-unknown, flags: "--no-default-features" } - { rust: 1.58.1, os: ubuntu-latest, flags: "--all-features" } - { rust: 1.58.1, os: ubuntu-latest, flags: "--no-default-features" } steps: @@ -79,7 +81,12 @@ jobs: profile: minimal toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} + - run: cargo test ${{ matrix.flags }} --target ${{ matrix.target }} + if: matrix.target != 0 && matrix.target != 'wasm32-unknown-unknown' + - run: cargo build ${{ matrix.flags }} --target ${{ matrix.target }} + if: matrix.target != 0 && matrix.target == 'wasm32-unknown-unknown' - run: cargo test ${{ matrix.flags }} + if: matrix.target == 0 examples: name: "Run examples using Rust ${{ matrix.rust }} (${{ matrix.os }})" runs-on: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 82cbe8e..ae66574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.7.1] - 2024-02-15 + +* Support `wasm` family for compilation + ## [0.7.0] - 2023-11-04 * Support `no_std` environments, when `default-features = false` is set for the crate diff --git a/Cargo.toml b/Cargo.toml index 9f9c972..2a03d4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "typed-path" description = "Provides typed variants of Path and PathBuf for Unix and Windows" -version = "0.7.0" +version = "0.7.1" edition = "2021" authors = ["Chip Senkbeil "] categories = ["development-tools", "filesystem", "os"] diff --git a/src/common/non_utf8/path.rs b/src/common/non_utf8/path.rs index d9df0f8..75490cb 100644 --- a/src/common/non_utf8/path.rs +++ b/src/common/non_utf8/path.rs @@ -629,7 +629,7 @@ where /// let path = cwd.join(Path::new("a/b/../c/./d")); /// assert_eq!(path.absolutize().unwrap(), cwd.join(Path::new("a/c/d"))); /// ``` - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(target_family = "wasm")))] pub fn absolutize(&self) -> std::io::Result> { if self.is_absolute() { Ok(self.normalize()) diff --git a/src/common/utf8/path.rs b/src/common/utf8/path.rs index f424d26..71809a4 100644 --- a/src/common/utf8/path.rs +++ b/src/common/utf8/path.rs @@ -581,7 +581,7 @@ where /// let path = cwd.join(Utf8Path::new("a/b/../c/./d")); /// assert_eq!(path.absolutize().unwrap(), cwd.join(Utf8Path::new("a/c/d"))); /// ``` - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(target_family = "wasm")))] pub fn absolutize(&self) -> std::io::Result> { if self.is_absolute() { Ok(self.normalize()) diff --git a/src/convert.rs b/src/convert.rs index cd688c5..3f7c0f3 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -7,12 +7,14 @@ use std::{ #[cfg(feature = "std")] use crate::{ - native::{Utf8NativePath, Utf8NativePathBuf}, unix::UnixComponent, windows::{WindowsComponent, WindowsPrefixComponent}, Encoding, Path, PathBuf, }; +#[cfg(all(feature = "std", not(target_family = "wasm")))] +use crate::native::{Utf8NativePath, Utf8NativePathBuf}; + /// Interface to try to perform a cheap reference-to-reference conversion. pub trait TryAsRef { fn try_as_ref(&self) -> Option<&T>; @@ -306,7 +308,7 @@ impl<'a> TryFrom> for WindowsComponent<'a> { } } -#[cfg(feature = "std")] +#[cfg(all(feature = "std", not(target_family = "wasm")))] impl AsRef for Utf8NativePath { /// Converts a native utf8 path (based on compilation family) into [`std::path::Path`]. /// @@ -324,7 +326,7 @@ impl AsRef for Utf8NativePath { } } -#[cfg(feature = "std")] +#[cfg(all(feature = "std", not(target_family = "wasm")))] impl AsRef for Utf8NativePathBuf { /// Converts a native utf8 pathbuf (based on compilation family) into [`std::path::Path`]. /// @@ -342,7 +344,7 @@ impl AsRef for Utf8NativePathBuf { } } -#[cfg(feature = "std")] +#[cfg(all(feature = "std", not(target_family = "wasm")))] impl<'a> From<&'a Utf8NativePath> for StdPathBuf { /// Converts a native utf8 path (based on compilation family) into [`std::path::PathBuf`]. /// @@ -360,7 +362,7 @@ impl<'a> From<&'a Utf8NativePath> for StdPathBuf { } } -#[cfg(feature = "std")] +#[cfg(all(feature = "std", not(target_family = "wasm")))] impl From for StdPathBuf { /// Converts a native utf8 pathbuf (based on compilation family) into [`std::path::PathBuf`]. /// diff --git a/src/lib.rs b/src/lib.rs index 7cd2cec..28fb957 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub struct ReadmeDoctests; extern crate alloc; mod no_std_compat { + #[allow(unused_imports)] pub use alloc::{ boxed::Box, string::{String, ToString}, @@ -19,10 +20,11 @@ mod no_std_compat { #[macro_use] mod common; mod convert; +#[cfg(not(target_family = "wasm"))] mod native; mod typed; mod unix; -#[cfg(feature = "std")] +#[cfg(all(feature = "std", not(target_family = "wasm")))] pub mod utils; mod windows; @@ -33,6 +35,7 @@ mod private { pub use common::*; pub use convert::*; +#[cfg(not(target_family = "wasm"))] pub use native::*; pub use typed::*; pub use unix::*; diff --git a/src/typed/non_utf8/path.rs b/src/typed/non_utf8/path.rs index 4b1dc9b..a554abb 100644 --- a/src/typed/non_utf8/path.rs +++ b/src/typed/non_utf8/path.rs @@ -2,7 +2,10 @@ use alloc::borrow::Cow; use core::fmt; #[cfg(feature = "std")] -use std::{io, path::Path}; +use std::path::Path; + +#[cfg(all(feature = "std", not(target_family = "wasm")))] +use std::io; use crate::common::StripPrefixError; use crate::convert::TryAsRef; @@ -534,7 +537,7 @@ impl<'a> TypedPath<'a> { /// let path = cwd.join("a/b/../c/./d"); /// assert_eq!(path.absolutize().unwrap(), cwd.join("a/c/d")); /// ``` - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(target_family = "wasm")))] pub fn absolutize(&self) -> io::Result { Ok(match self { Self::Unix(path) => TypedPathBuf::Unix(path.absolutize()?), diff --git a/src/typed/non_utf8/pathbuf.rs b/src/typed/non_utf8/pathbuf.rs index f56c7a3..6bad34f 100644 --- a/src/typed/non_utf8/pathbuf.rs +++ b/src/typed/non_utf8/pathbuf.rs @@ -750,7 +750,7 @@ impl TypedPathBuf { /// let path = cwd.join("a/b/../c/./d"); /// assert_eq!(path.absolutize().unwrap(), cwd.join("a/c/d")); /// ``` - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(target_family = "wasm")))] pub fn absolutize(&self) -> io::Result { self.to_path().absolutize() } diff --git a/src/typed/utf8/path.rs b/src/typed/utf8/path.rs index 34de957..bf5dfc7 100644 --- a/src/typed/utf8/path.rs +++ b/src/typed/utf8/path.rs @@ -490,7 +490,7 @@ impl<'a> Utf8TypedPath<'a> { /// let path = cwd.join("a/b/../c/./d"); /// assert_eq!(path.absolutize().unwrap(), cwd.join("a/c/d")); /// ``` - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(target_family = "wasm")))] pub fn absolutize(&self) -> std::io::Result { Ok(match self { Self::Unix(path) => Utf8TypedPathBuf::Unix(path.absolutize()?), diff --git a/src/typed/utf8/pathbuf.rs b/src/typed/utf8/pathbuf.rs index 5cbbe54..942bac2 100644 --- a/src/typed/utf8/pathbuf.rs +++ b/src/typed/utf8/pathbuf.rs @@ -710,7 +710,7 @@ impl Utf8TypedPathBuf { /// let path = cwd.join("a/b/../c/./d"); /// assert_eq!(path.absolutize().unwrap(), cwd.join("a/c/d")); /// ``` - #[cfg(feature = "std")] + #[cfg(all(feature = "std", not(target_family = "wasm")))] pub fn absolutize(&self) -> std::io::Result { self.to_path().absolutize() }