An alternative `std`-like implementation built on origin

Overview

origin-studio

An alternative `std`-like implementation built on origin

Github Actions CI Status zulip chat crates.io page docs.rs docs

origin-stdio is an alternative std-like implementation built on origin.

At this time, it only works on Linux (x86-64, aarch64, riscv64, 32-bit x86), requires Rust nightly, lacks full std compatibility, and is overall experimental. But it supports threads and stuff.

Quick start:

In an empty directory, on Linux, with Rust nightly, run these commands:

cargo init
cargo add origin_studio
cargo add compiler_builtins --features=mem
echo 'fn main() { println!("cargo:rustc-link-arg=-nostartfiles"); }' > build.rs
sed -i '1s/^/#![no_std]\n#![no_main]\norigin_studio::no_problem!();\n\n/' src/main.rs
cargo run --quiet

This will produce a crate and print "Hello, world!".

Yes, you might say, I could have already done that, with just the first and last commands. But this version uses origin to start and stop the program, and rustix to do the printing.

And beyond that, origin-studio uses origin to start and stop threads, rustix-futex-sync and lock_api to do locking for threads, rustix-dlmalloc to do memory allocation, and unwinding to do stack unwinding, so it doesn't use libc at all.

What are those commands doing?

cargo init

This creates a new Rust project containing a "Hello, world!" program.

cargo add origin_studio

This adds a dependency on origin_studio, which is this crate.

cargo add compiler_builtins --features=mem

This adds a dependency on compiler_builtins, which is a crate that provides definitions of library functions that rustc and libcore use. The mem feature enables implementations of memcpy, memset, strlen, and others.

echo 'fn main() { println!("cargo:rustc-link-arg=-nostartfiles"); }' > build.rs

This creates a build.rs file that arranges for -nostartfiles to be passed to the link command, which disables the use of libc's crt1.o and other startup object files. This allows origin to define its own symbol named _start which serves as the program entrypoint, and handle the entire process of starting the program itself.

sed -i '1s/^/#![no_std]\n#![no_main]\norigin_studio::no_problem!();\n\n/' src/main.rs

This inserts three lines to the top of src/main.rs:

  • #![no_std], which disables the use of Rust's standard library implementation, since origin-studio provides its own implementation that using rustix and origin.
  • #![no_main], which tells Rust to disable its code that calls the user's main function, since origin-studio will be handling that.
  • origin_studio::no_problem!() inserts code to set up a Rust panic handler, and optionally a global allocator (with the "alloc" feature).

cargo run --quiet

This runs the program, which will be started by origin, prints "Hello, world!" using origin-studio's println! macro, which uses origin-studio's std::io::stdout() and std::io::Write and rustix-futex-sync's Mutex to do the locking, and rustix to do the actual I/O system call, and ends the program, using origin.

Similar crates

Other alternative implementations of std include steed, tiny-std and veneer.

mustang is a crate that uses origin to build a libc implementation that can slide underneath existing std builds, rather than having its own std implementation.

relibc also includes a Rust implementation of program and thread startup and shutdown.

Why?

Right now, this is a demo of how to use origin. If you're interested in seeing this grow into something specific, or interested in seeing projects which might be inspired by this, please reach out!

You might also like...
Alternative to *fetch, uwuifies all stats.
Alternative to *fetch, uwuifies all stats.

owofetch-rs Alternative to *fetch, uwuifies all stats. Installation: Arch: AUR Other Linux distros: Either compile the source with cargo build --relea

Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

fcp is a significantly faster alternative to the classic Unix cp(1) command
fcp is a significantly faster alternative to the classic Unix cp(1) command

A significantly faster alternative to the classic Unix cp(1) command, copying large files and directories in a fraction of the time.

⚡ A Blazing fast alternative to the stock windows folder delete function!
⚡ A Blazing fast alternative to the stock windows folder delete function!

Turbo Delete A blazing fast alternative to the default Windows delete. Turbodelete is a blazing fast alternative to the default Windows delete functio

Faster and better alternative to Vtop written in Rust.
Faster and better alternative to Vtop written in Rust.

Rtop Faster and better alternative to Vtop written in Rust. Work in Progress Features Lightweight 1MB Responsive UI Sort Process by Memory, CPU Usag

Sugar is an alternative to the current Metaplex Candy Machine CLI

Sugar: A Candy Machine CLI Sugar is an alternative to the current Metaplex Candy Machine CLI. It has been written from the ground up and includes seve

A pretty (simple) alternative to strace

lurk lurk is a simple and pretty alternative to strace. It allows the user to trace system calls of a process or of a command. In contrast to strace,

Lightweight alternative Discord client with a smaller footprint and some fancy extensible features.
Lightweight alternative Discord client with a smaller footprint and some fancy extensible features.

Dorion Dorion is an alternative Discord client aimed and lower-spec or storage-sensitive PCs that supports themes, plugins, and more! Table of Content

Bonk - The blazingly fast touch alternative written in rust
Bonk - The blazingly fast touch alternative written in rust

Bonk The blazingly fast touch alternative written in rust. Made for the sole purpose to create files. Explore the docs » View Demo · Report Bug · Requ

Owner
Dan Gohman
I'm working on Wasmtime, WASI, and lots of things related to WebAssembly.
Dan Gohman
A micro crate that simplifies a bit the use of the std macro thread_local!.

with-thread-local A micro crate that simplifies a bit the use of the std macro thread_local!. extern crate regex; use with_thread_local::with_thread_

Cecile Tonglet 3 Jan 11, 2023
🍬 shell-candy is a library that wraps Rust's `std::process::Command`

?? shell-candy is a library that wraps Rust's `std::process::Command`, providing a functional mechanism for handling stdout/stderr streams of spawned tasks..

Avery Harnish 6 Oct 25, 2022
Prototype of the `std::io::ensure!` family of macros

io-ensure Prototype of the `std::io::ensure` family of macros API Docs | Releases | Contributing Installation $ cargo add io-ensure Safety This crate

Yosh 4 Feb 27, 2023
This library provides a convenient derive macro for the standard library's std::error::Error trait.

derive(Error) This library provides a convenient derive macro for the standard library's std::error::Error trait. [dependencies] therror = "1.0" Compi

Sebastian Thiel 5 Oct 23, 2023
A drop-in replacement for std::time::Instant that is faster and more accurate.

Fastant A drop-in replacement for std::time::Instant that measures time with high performance and high accuracy powered by Time Stamp Counter (TSC). U

FastLabs 8 Sep 15, 2024
A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Armin Ronacher 259 Jan 3, 2023
`ls` alternative with useful info and a splash of color 🎨

?? Natls ?? Why Natls? Showing file permissions Showing file size Showing the date that the file was modified last Showing the user that the file belo

Will 1.2k Dec 19, 2022
This is choose, a human-friendly and fast alternative to cut and (sometimes) awk

Choose This is choose, a human-friendly and fast alternative to cut and (sometimes) awk Features terse field selection syntax similar to Python's list

Ryan Geary 1.4k Jan 7, 2023
fd is a program to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find

fd is a program to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find. While it does not aim to support all of find's powerful functionality, it provides sensible (opinionated) defaults for a majority of use cases.

David Peter 25.9k Jan 9, 2023
Intuitive find & replace CLI (sed alternative)

sd - s[earch] & d[isplace] sd is an intuitive find & replace CLI. The Pitch Why use it over any existing tools? Painless regular expressions sd uses r

Gregory 4k Jan 4, 2023