Skip to content

Commit

Permalink
Keep V2 up to date with V1 patches (#123)
Browse files Browse the repository at this point in the history
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
Co-authored-by: Pino Toscano <toscano.pino@tiscali.it>
  • Loading branch information
3 people authored Nov 13, 2024
1 parent 3cfd63e commit 396957b
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 59 deletions.
48 changes: 36 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ jobs:
- i686-pc-windows-gnu
- i686-unknown-freebsd
- i686-unknown-linux-gnu
- wasm32-wasi
- wasm32-wasip1
- x86_64-apple-darwin
- x86_64-unknown-redox
- x86_64-unknown-illumos
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -111,13 +109,15 @@ jobs:
toolchain: ${{ matrix.tc }}
override: true
- run: cargo update
- run: cargo test --all --all-features --target=x86_64-apple-darwin
cross-compile:
- run: cargo test --all --all-features
# TODO: can be merged back into "cross-compile" after MSRV bumped to 1.78
# only difference is wasi -> wasip1
cross-compile-msrv:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
tc: [1.65.0, stable, beta, nightly]
tc: [1.65.0]
cc:
- aarch64-linux-android
- i686-pc-windows-gnu
Expand All @@ -134,6 +134,28 @@ jobs:
target: ${{ matrix.cc }}
override: true
- run: cargo build --all-features --target=${{ matrix.cc }}
cross-compile:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
tc: [stable, beta, nightly]
cc:
- aarch64-linux-android
- i686-pc-windows-gnu
- i686-unknown-freebsd
- i686-unknown-linux-gnu
- wasm32-wasip1
- x86_64-apple-darwin
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.tc }}
target: ${{ matrix.cc }}
override: true
- run: cargo build --all-features --target=${{ matrix.cc }}
cross-compile-ios:
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -185,8 +207,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:
Expand All @@ -198,12 +220,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:
Expand All @@ -215,8 +238,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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ 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

- Broken link in docs

## [1.5.0] - 2024-03-03

### Added
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)'] }
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -42,9 +45,11 @@ WhoAmI targets all platforms that can run Rust, including:
- Android **planned later**
- iOS / watchOS / tvOS **planned later**
- Fuchsia **planned later**
- GNU/Hurd **untested**
- 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.

Expand All @@ -55,15 +60,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
<https://github.com/ardaku/whoami/blob/v1/TESTING.md>. 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
Expand All @@ -76,11 +84,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].

Expand Down
24 changes: 17 additions & 7 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Device's CPU Arch whoami::arch(): Unknown: i86pc

<https://doc.redox-os.org/book/ch08-01-advanced-build.html#understanding-cross-compilation-for-redox>

Tested on Fedora Silverblue 39
Tested on Fedora Silverblue 40

### Update Rust Nightly and Stable

Expand All @@ -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
```
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion recipe.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[source]
git = "https://github.com/AldaronLau/whome.git"
rev = "0545b887c8419edddc79e5044e5d67f8ec9e0c30"
rev = "ddcadeae154bf2f907b43aed415a3feb209c7486"

[build]
template = "cargo"
30 changes: 15 additions & 15 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub fn realname_os() -> Result<OsString> {

/// Get the host device's hostname.
///
/// Limited to a-z, A-Z, 0-9, and dashes. This limit also applies to
/// [`devicename()`] when targeting Windows. Usually hostnames are
/// case-insensitive, but it's not a hard requirement.
/// Usually hostnames are case-insensitive, but it's not a hard requirement.
///
/// FIXME: Document platform-specific character limitations
#[inline(always)]
pub fn hostname() -> Result<String> {
Target::hostname(Os)
Expand Down Expand Up @@ -130,19 +130,19 @@ pub fn langs() -> Result<impl Iterator<Item = Language>> {
let langs = langs
.split(';')
.map(ToString::to_string)
.collect::<Vec<_>>();
.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::<Vec<_>>().into_iter())
}
8 changes: 3 additions & 5 deletions src/os.rs
Original file line number Diff line number Diff line change
@@ -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")),
Expand All @@ -21,6 +18,7 @@
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "hurd",
),
not(target_arch = "wasm32")
),
Expand All @@ -36,7 +34,7 @@
all(
target_arch = "wasm32",
not(target_os = "wasi"),
not(target_os = "daku"),
not(daku),
feature = "web",
),
path = "os/web.rs"
Expand Down
4 changes: 2 additions & 2 deletions src/os/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Target for Os {
} else if cfg!(target_os = "vita") {
Platform::PlayStation
} else if cfg!(target_os = "hurd") {
Platform::Unknown("GNU Hurd".to_string())
Platform::Hurd
} else if cfg!(target_os = "aix") {
Platform::Unknown("AIX OS".to_string())
} else if cfg!(target_os = "espidf") {
Expand Down
Loading

0 comments on commit 396957b

Please sign in to comment.