Skip to content

Commit

Permalink
Support Redox (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau authored Mar 3, 2024
1 parent 5bc73e4 commit 953e702
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 26 deletions.
20 changes: 17 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ jobs:
- i686-unknown-linux-gnu
- wasm32-wasi
- x86_64-apple-darwin
- x86_64-unknown-redox
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -198,8 +197,23 @@ jobs:
matrix:
os: [ubuntu-latest]
tc: [1.65.0, stable, beta, nightly]
cc:
- x86_64-unknown-illumos
cc: [x86_64-unknown-illumos]
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-redox:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
tc: [1.65.0, stable, beta, nightly]
cc: [x86_64-unknown-redox]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Cargo.lock
/ignore/
/a.out
/**/*.swp
/build/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog], and this project adheres to
### Added

- WASI support
- Redox support
- Fallible functions
- `whoami::fallible::devicename()`
- `whoami::fallible::devicename_os()`
Expand Down
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ include = [
]
rust-version = "1.40"

# Target-specific dependency required to work with wasm-bindgen
# Target specific dependencies for redox
[target.'cfg(all(target_os = "redox", not(target_arch = "wasm32")))'.dependencies.redox_syscall]
version = "0.4"

# Target specific dependencies for wasite
[target.'cfg(all(target_arch = "wasm32", target_os = "wasi"))'.dependencies.wasite]
version = "0.1"

# Target-specific dependency for wasm-bindgen
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi"), not(target_os = "daku")))'.dependencies.web-sys]
version = "0.3"
features = ["Navigator", "Document", "Window", "Location"]
Expand All @@ -34,9 +42,6 @@ optional = true
version = "0.2"
optional = true

[target.'cfg(all(target_arch = "wasm32", target_os = "wasi"))'.dependencies.wasite]
version = "0.1"

[features]
default = ["web"]
# Enabling this feature indicates that the wasm32-unknown-unknown target should
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ WhoAmI targets all platforms that can run Rust, including:
- Windows
- Mac OS
- BSD variants (FreeBSD, others)
- Illumos variants (SmartOS, OmniOS, others) **Target-Specific MSRV 1.65**
- Redox **Target-Specific MSRV 1.65**
- [Web Assembly](https://github.com/ardaku/whoami/blob/stable/WASM.md)
- Mock implementation
- Web Browser - DOM
- WASI (Wasite, others) **may partially or fully work - but untested**
- Daku (Ardaku/Quantii, others) **mock implementation, full implementation planned later**
- Illumos variants (SmartOS, OmniOS, others) **may partially or fully work - but untested**
- Android **may partially or fully work - but untested, planned later**
- iOS **planned later**
- Redox **planned later**
- Fuchsia **planned later**
- Various game consoles **planned later**
- Others? (make a PR or open an issue)
Expand All @@ -49,8 +49,11 @@ WhoAmI targets all platforms that can run Rust, including:
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.

The MSRV will only be updated on major version bumps, and version 2.0.0 will
target Rust 1.65.0 and later to make use of the `let else` syntax.
The MSRV will not be updated until version 2.0.0, after which breaking changes
may happen on minor releases, and version 2.0.0 will target Rust 1.65.0 and
later to make use of the `let else` syntax. The current plan is for all 2.x
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
Expand Down
89 changes: 89 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Testing

This file outlines the regression testing plan for all platforms.

## Redox

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

Tested on Fedora Silverblue 39

### Update Rust Nightly and Stable

```shell
rustup update nightly stable
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)'

cargo install --locked --force --version 0.1.1 cargo-config
```

### Get redox source

```shell
mkdir -p build/
cd build/
git clone https://gitlab.redox-os.org/redox-os/redox.git --origin upstream --recursive
```

### Create our demo recipe

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
```

In `config/x86_64/ardaku.toml`, under `[packages]`:

```toml
whome = {}
```

### Build Redox

This takes a while

```shell
make all
```

or

```shell
make rebuild
```

### Run Redox

```shell
make qemu
```

### Test it

Verify you are on the new version

```shell
whome --version
```

Default settings should output:

```console
realname: user
username: user
devicename: redox
hostname: redox
distro: Redox OS 0.8.0
desktop_env: Orbital
platform: Redox
arch: Unknown: x86_64
```
7 changes: 7 additions & 0 deletions recipe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Redox recipe for testing whoami

[source]
git = "https://github.com/AldaronLau/whome.git"

[build]
template = "cargo"
31 changes: 26 additions & 5 deletions src/os.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(unsafe_code)]

// Redox - FIXME: Currently routes to fake.rs
// Redox
#[cfg_attr(
all(target_os = "redox", not(target_arch = "wasm32")),
path = "os/fake.rs"
path = "os/redox.rs"
)]
// Unix
#[cfg_attr(
Expand All @@ -14,10 +14,10 @@
)),
path = "os/unix.rs"
)]
// Wasm32 (Daku) - FIXME: Currently routes to fake.rs
// Wasm32 (Daku)
#[cfg_attr(
all(target_arch = "wasm32", target_os = "daku"),
path = "os/fake.rs"
path = "os/daku.rs"
)]
// Wasm32 (Wasi)
#[cfg_attr(
Expand Down Expand Up @@ -51,7 +51,10 @@
)]
mod target;

use std::ffi::OsString;
use std::{
ffi::OsString,
io::{Error, ErrorKind},
};

pub(crate) use self::target::*;
use crate::{Arch, DesktopEnv, Language, Platform, Result};
Expand Down Expand Up @@ -81,3 +84,21 @@ pub(crate) trait Target {
/// Return the computer's CPU architecture.
fn arch(self) -> Result<Arch>;
}

// This is only used on some platforms
#[allow(dead_code)]
fn err_missing_record() -> Error {
Error::new(ErrorKind::NotFound, "Missing record")
}

// This is only used on some platforms
#[allow(dead_code)]
fn err_null_record() -> Error {
Error::new(ErrorKind::NotFound, "Null record")
}

// This is only used on some platforms
#[allow(dead_code)]
fn err_empty_record() -> Error {
Error::new(ErrorKind::NotFound, "Empty record")
}
66 changes: 66 additions & 0 deletions src/os/daku.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! This is mostly the same as fake.rs for now
#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
compile_error!("Unexpected pointer width for target platform");

use std::ffi::OsString;

use crate::{
os::{Os, Target},
Arch, DesktopEnv, Language, Platform, Result,
};

#[inline(always)]
pub(crate) fn lang() -> impl Iterator<Item = String> {
std::iter::once("en/US".to_string())
}

impl Target for Os {
fn langs(self) -> Vec<Language> {
todo!()
}

#[inline(always)]
fn realname(self) -> Result<OsString> {
Ok("Anonymous".to_string().into())
}

#[inline(always)]
fn username(self) -> Result<OsString> {
Ok("anonymous".to_string().into())
}

#[inline(always)]
fn devicename(self) -> Result<OsString> {
Ok("Unknown".to_string().into())
}

#[inline(always)]
fn hostname(self) -> Result<String> {
Ok("localhost".to_string())
}

#[inline(always)]
fn distro(self) -> Result<String> {
Ok("Emulated".to_string())
}

#[inline(always)]
fn desktop_env(self) -> DesktopEnv {
DesktopEnv::Unknown("Unknown Daku".to_string())
}

#[inline(always)]
fn platform(self) -> Platform {
Platform::Unknown("Daku".to_string())
}

#[inline(always)]
fn arch(self) -> Result<Arch> {
Ok(if cfg!(target_pointer_width = "64") {
Arch::Wasm64
} else {
Arch::Wasm32
})
}
}
2 changes: 1 addition & 1 deletion src/os/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{

#[inline(always)]
pub(crate) fn lang() -> impl Iterator<Item = String> {
std::iter::once("en-US".to_string())
std::iter::once("en/US".to_string())
}

impl Target for Os {
Expand Down
Loading

0 comments on commit 953e702

Please sign in to comment.