diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1dbb32..4d3d80b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,8 +33,6 @@ jobs: - i686-unknown-linux-gnu - wasm32-wasi - x86_64-apple-darwin - - x86_64-unknown-redox - - x86_64-unknown-illumos steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -82,7 +80,7 @@ jobs: - run: cargo clippy --all-features --target=${{ matrix.cc }} -- -D warnings - run: cargo update - run: cargo clippy --no-default-features --target=${{ matrix.cc }} -- -D warnings - - run: RUSTFLAGS="--cfg target_os=\"daku\"" cargo clippy --target=${{ matrix.cc }} -- -D warnings + - run: RUSTFLAGS="--cfg daku" cargo clippy --target=${{ matrix.cc }} -- -D warnings test: runs-on: ${{ matrix.os }} strategy: @@ -111,7 +109,7 @@ jobs: toolchain: ${{ matrix.tc }} override: true - run: cargo update - - run: cargo test --all --all-features --target=x86_64-apple-darwin + - run: cargo test --all --all-features cross-compile: runs-on: ${{ matrix.os }} strategy: @@ -139,7 +137,7 @@ jobs: strategy: matrix: os: [macos-latest] - tc: [1.40.0, stable, beta, nightly] + tc: [stable, beta, nightly] cc: [aarch64-apple-ios] steps: - uses: actions/checkout@v2 @@ -185,8 +183,8 @@ jobs: - run: cargo build --all-features --target=${{ matrix.cc }} - run: cargo update - run: cargo build --no-default-features --target=${{ matrix.cc }} - - run: RUSTFLAGS="--cfg target_os=\"daku\"" cargo build --target=${{ matrix.cc }} - cross-compile-illumos: + - run: RUSTFLAGS="--cfg daku" cargo build --target=${{ matrix.cc }} + cross-compile-illumos-and-checks: runs-on: ${{ matrix.os }} strategy: matrix: @@ -198,12 +196,13 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal + components: clippy toolchain: ${{ matrix.tc }} target: ${{ matrix.cc }} override: true - - run: cargo update - run: cargo build --all-features --target=${{ matrix.cc }} - cross-compile-redox: + - run: cargo clippy --all-features --target=${{ matrix.cc }} -- -D warnings + cross-compile-redox-and-checks: runs-on: ${{ matrix.os }} strategy: matrix: @@ -215,8 +214,9 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal + components: clippy toolchain: ${{ matrix.tc }} target: ${{ matrix.cc }} override: true - - run: cargo update - run: cargo build --all-features --target=${{ matrix.cc }} + - run: cargo clippy --all-features --target=${{ matrix.cc }} -- -D warnings diff --git a/CHANGELOG.md b/CHANGELOG.md index d21907a..205c803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. +## [1.5.2] - 2024-09-02 + +### Changed + + - Updated redox\_syscall to 0.5 + - Replace `target_os = daku` with `daku` cfg + - Improved repository documentation + ## [1.5.1] - 2024-03-09 ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 8b7cf96..6ababda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -160,7 +160,7 @@ dependencies = [ [[package]] name = "whoami" -version = "1.5.1" +version = "1.5.2" dependencies = [ "redox_syscall", "wasite", diff --git a/Cargo.toml b/Cargo.toml index db7edd0..89145c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whoami" -version = "1.5.1" +version = "1.5.2" edition = "2018" license = "Apache-2.0 OR BSL-1.0 OR MIT" documentation = "https://docs.rs/whoami" @@ -34,7 +34,7 @@ version = "0.5" version = "0.1" # Target-specific dependency for web browser -[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi"), not(target_os = "daku")))'.dependencies.web-sys] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi"), not(daku)))'.dependencies.web-sys] version = "0.3" features = ["Navigator", "Document", "Window", "Location"] optional = true @@ -44,3 +44,6 @@ default = ["web"] # Enabling this feature indicates that the wasm32-unknown-unknown target should # be assumed to be in a web environment where it can call DOM APIs. web = ["web-sys"] + +[lints.rust] +unexpected_cfgs = { level = "allow", check-cfg = ['cfg(daku)'] } diff --git a/README.md b/README.md index 76ee91f..7d47f24 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Retrieve the current user and environment through simple functions. Check out the [documentation][0] for examples. ### Features + - Get the user's full name - Get the user's username - Get the user's preferred language(s) @@ -27,7 +28,9 @@ Check out the [documentation][0] for examples. - Get the devices's CPU architecture and its width ### Supported Platforms + WhoAmI targets all platforms that can run Rust, including: + - Linux - Windows - Mac OS @@ -45,6 +48,7 @@ WhoAmI targets all platforms that can run Rust, including: - Others? (make a PR or open an issue) ## MSRV + WhoAmI 1.x.y targets Rust 1.40.0 stable and later, and the 1.x.y track will be maintained at least until the release of the Rust 2024 edition. @@ -55,15 +59,18 @@ releases to be supported and receive bugfixes at least until sometime in 2027, bumping MSRV only as needed. ## Binary + [whome](https://crates.io/crates/whome): `whoami` command RiR (Re-written in Rust) that depends on this crate. ## Testing + The testing procedure is documented at . The full manual test suite is run for each change that affects multiple platforms. ## License + Copyright © 2017-2024 The WhoAmI Contributors. Licensed under any of @@ -76,11 +83,13 @@ Licensed under any of at your option. ### Contribution + Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as described above, without any additional terms or conditions. ## Help + If you want help using or contributing to this library, feel free to send me an email at [aldaronlau@gmail.com][13]. diff --git a/TESTING.md b/TESTING.md index c1bb5ee..974a9a5 100644 --- a/TESTING.md +++ b/TESTING.md @@ -282,7 +282,7 @@ Device's CPU Arch whoami::arch(): Unknown: i86pc -Tested on Fedora Silverblue 39 +Tested on Fedora Silverblue 40 ### Update Rust Nightly and Stable @@ -294,7 +294,7 @@ rustup target add --toolchain stable x86_64-unknown-redox ### Install pre-requisites ```shell -sudo dnf install git file autoconf vim bison flex genisoimage gperf glibc-devel.i686 expat expat-devel fuse-devel fuse3-devel gmp-devel perl-HTML-Parser libpng-devel libtool libjpeg-turbo-devel libvorbis-devel SDL2_ttf-devel mesa-libOSMesa-devel m4 nasm po4a syslinux texinfo sdl12-compat-devel ninja-build meson python3-mako make gcc gcc-c++ openssl patch automake perl-Pod-Html perl-FindBin gperf curl gettext-devel perl-Pod-Xhtml pkgconf-pkg-config cmake cbindgen just qemu doxygen 'perl(ExtUtils::MakeMaker)' +sudo dnf install git file autoconf vim bison flex genisoimage gperf glibc-devel.i686 expat expat-devel fuse-devel fuse3-devel gmp-devel perl-HTML-Parser libpng-devel libtool libjpeg-turbo-devel libvorbis-devel SDL2_ttf-devel mesa-libOSMesa-devel m4 nasm po4a syslinux texinfo sdl12-compat-devel ninja-build meson python3-mako make gcc gcc-c++ openssl patch automake perl-Pod-Html perl-FindBin gperf curl gettext-devel perl-Pod-Xhtml pkgconf-pkg-config cmake cbindgen just mpfr-devel qemu doxygen 'perl(ExtUtils::MakeMaker)' cargo install --locked --force --version 0.1.1 cargo-config ``` @@ -305,27 +305,37 @@ cargo install --locked --force --version 0.1.1 cargo-config mkdir -p build/ cd build/ git clone https://gitlab.redox-os.org/redox-os/redox.git --origin upstream --recursive +cd redox +git submodule update --recursive --init ``` ### Create our demo recipe -Make sure whome is updated to the whoami testing branch. +Back in the root whoami directory, make sure whome is updated to the whoami +testing branch. ```shell mkdir -p build/redox/cookbook/recipes/demos/whome/ cp recipe.toml build/redox/cookbook/recipes/demos/whome/ -cp build/redox/config/desktop.toml config/x86_64/ardaku.toml +cp build/redox/config/desktop.toml build/redox/config/x86_64/ardaku.toml ``` -In `config/x86_64/ardaku.toml`, under `[packages]`: +In `build/redox/config/x86_64/ardaku.toml`, under `[packages]`, add: ```toml whome = {} ``` +### Select the config +IN `build/redox/mk/config.mk`, set: + +```make +CONFIG_NAME?=ardaku +``` + ### Build Redox -This takes a while +Back in `cd build/redox`, this takes a while ```shell make all @@ -358,7 +368,7 @@ realname: user username: user devicename: redox hostname: redox -distro: Redox OS 0.8.0 +distro: Redox OS 0.9.0 desktop_env: Orbital platform: Redox arch: Unknown: x86_64 diff --git a/recipe.toml b/recipe.toml index 4304376..63dcc9d 100644 --- a/recipe.toml +++ b/recipe.toml @@ -2,7 +2,7 @@ [source] git = "https://github.com/AldaronLau/whome.git" -rev = "0545b887c8419edddc79e5044e5d67f8ec9e0c30" +rev = "ddcadeae154bf2f907b43aed415a3feb209c7486" [build] template = "cargo" diff --git a/src/api.rs b/src/api.rs index fd4a117..de87664 100644 --- a/src/api.rs +++ b/src/api.rs @@ -173,19 +173,19 @@ pub fn langs() -> Result> { let langs = langs .split(';') .map(ToString::to_string) - .collect::>(); + .filter_map(|lang| { + let lang = lang + .split_terminator('.') + .next() + .unwrap_or_default() + .replace(|x| ['_', '-'].contains(&x), "/"); - Ok(langs.into_iter().filter_map(|lang| { - let lang = lang - .split_terminator('.') - .next() - .unwrap_or_default() - .replace(|x| ['_', '-'].contains(&x), "/"); + if lang == "C" { + return None; + } - if lang == "C" { - return None; - } + Some(Language::__(Box::new(lang))) + }); - Some(Language::__(Box::new(lang))) - })) + Ok(langs.collect::>().into_iter()) } diff --git a/src/os.rs b/src/os.rs index ac43a54..26f0528 100644 --- a/src/os.rs +++ b/src/os.rs @@ -1,10 +1,7 @@ #![allow(unsafe_code)] // Daku -#[cfg_attr( - all(target_arch = "wasm32", target_os = "daku"), - path = "os/daku.rs" -)] +#[cfg_attr(all(target_arch = "wasm32", daku), path = "os/daku.rs")] // Redox #[cfg_attr( all(target_os = "redox", not(target_arch = "wasm32")), @@ -36,7 +33,7 @@ all( target_arch = "wasm32", not(target_os = "wasi"), - not(target_os = "daku"), + not(daku), feature = "web", ), path = "os/web.rs" diff --git a/src/os/target.rs b/src/os/target.rs index b861946..2d9f7ec 100644 --- a/src/os/target.rs +++ b/src/os/target.rs @@ -50,7 +50,7 @@ impl Target for Os { #[inline(always)] fn platform(self) -> Platform { - if cfg!(target_os = "daku") { + if cfg!(daku) { Platform::Unknown("Daku".to_string()) } else if cfg!(target_os = "wasi") { Platform::Unknown("WASI".to_string()) diff --git a/src/os/unix.rs b/src/os/unix.rs index 959e2ca..5aeec34 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -116,6 +116,8 @@ extern "system" { } #[cfg(target_os = "macos")] +// FIXME: seemingly false positive for link lint +#[allow(clippy::duplicated_attributes)] #[link(name = "CoreFoundation", kind = "framework")] #[link(name = "SystemConfiguration", kind = "framework")] extern "system" { diff --git a/src/os/windows.rs b/src/os/windows.rs index 562a376..4f6682c 100644 --- a/src/os/windows.rs +++ b/src/os/windows.rs @@ -2,7 +2,7 @@ use std::{ convert::TryInto, ffi::OsString, io::{Error, ErrorKind}, - mem::MaybeUninit, + mem::{self, MaybeUninit}, os::{ raw::{c_char, c_int, c_uchar, c_ulong, c_ushort, c_void}, windows::ffi::OsStringExt, @@ -351,13 +351,15 @@ impl Target for Os { let get_version: unsafe extern "system" fn( a: *mut OsVersionInfoEx, - ) -> u32 = unsafe { std::mem::transmute(func) }; + ) -> u32 = unsafe { mem::transmute(func) }; let mut version = MaybeUninit::::zeroed(); + // FIXME `mem::size_of` seemingly false positive for lint + #[allow(unused_qualifications)] let version = unsafe { (*version.as_mut_ptr()).os_version_info_size = - std::mem::size_of::() as u32; + mem::size_of::() as u32; get_version(version.as_mut_ptr()); if FreeLibrary(inst) == 0 {