Giter Club home page Giter Club logo

rustybox's Introduction

rustybox

RustyBox is a free-range, non-GMO fork of BusyBox written entirely in Rust. It includes all your favorite commands like ls, mount, and top, but without a single line of C code! Like BusyBox, rustybox weighs in at just under 1 megabyte and includes all the basic utilities you need to set up a small Linux OS.

screenshot

Status

rustybox is a work-in-progress! It started out life as a direct c2rust transpile of the busybox project, and has been steadily improving since then. This has the benefit of ensuring that rustybox is "bug-for-bug" compatible with busybox, but it does mean that we have inherited the raw pointers and unsafes that come from C land. If making essential software memory-safe is your cup of tea then join the party with a PR!

Contributing to rustybox

Contributing to rustybox is a great way to get started with rust, dig into the bowels of linux, or to help to free the world from the diabolical tyranny of C.

There's lots to be done, so we're happy to have you! Here are just a few ideas:

  • Replace some extern "C" includes with more idiomatic uses. Pretty straightforward find/replace-all usually does the trick.
  • Pick a utility, like cat or touch, and work on translating it into safer, more idiomatic rust. There are plenty of unsafes lying around that you can tackle!
  • Try building Alpine linux with rustybox in place of busybox. This could be an awesome drop-in replacement for the popular alpine Docker image.

Check out the contributing doc for more info!

And of course please test out rustybox and report any and all issues, concerns, and comments!

Building rustybox

Rustybox requires a Linux system to build. Developing in Docker works just as well on macOS and Windows. You'll need GCC and its development headers (esp. quadmath.h) in order to build the f128 dependency. Running sudo apt install build-essential should do the trick on Ubuntu/Debian.

Please open an issue if you have trouble building!

Customizing your rustybox distribution

By default, rustybox does not include any utility. You can include all of them:

cargo build --all-features

Chances are you don't actually need or want everything in rustybox, especially for a release. If you'd like to build rustybox with only a specific set of utilities:

cargo build --release --features "cat ls which"

Check out the [features] section of Cargo.toml for the full list of utilities on tap.

After building, you can remove unnecessary debug sections with strip. This is recommended if you are particularly size-conscious.

Acknowledgements

There's simply no way this project would be possible without the hard work from the wonderful busybox and c2rust teams. Both projects are dope, and you should check them out. Much of the code you find in this repo is transpiled from the work of the busybox AUTHORS.

rustybox's People

Contributors

akeboshiwind avatar chlongv avatar kamilaborowska avatar samuela avatar zapanton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rustybox's Issues

Errors while building on Ubuntu 18.04 on WSL2 with Rust nightly

Trying to build it in WSL2 gives the error:

error: legacy asm! syntax is no longer supported
archival/dpkg.rs:2451:3
     |
2451 |   asm!("" : : : "memory" : "volatile");
     |   ----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |   |
     |   help: replace with: `llvm_asm!

in a bunch of places (422 errors)

Here's the relevant system information:
Linux Version: 4.4.0-18362-Microsoft x86_64 x86_64 x86_64 GNU/Linux
Ubuntu Version: Ubuntu 18.04.4 LTS
Windows Version: Windows 10 Pro 1909 (v. 18363.836)
Rust version: 1.45.0-nightly (4bd32c980 2020-05-29)

Rustybox won't compile with latest nightly toolchain

So I was trying to compile rustybox and obviously, I have the latest nightly toolchain.
But I'm afraid that the build failed viciously πŸ˜…
I wonder, would it require the nightly toolchain which was present back at the time of the last commit made on May 31, 2020 ?

I've attached the log below.
log.txt

Static / musl build

I get the build working with a glibc based Host and nightly channel.

But it isn't static and it should be musl linux target.

  1. Is it possible to build for musl target? Musl host build fails I know. So I would try to build on a glibc host with musl target. Should that work?

  2. Or how else I could build a small static binary?

'yes' is always called as though arg[0] is the util itself

This isn't the case if you call it through the raw binary, e.g:

$ rustybox yes test

This will print something like the following:

yes test
yes test
yes test

Where it should be printing the following instead:

test
test
test

This is because it doesn't use the args that were passed into the function but instead get's the args from the env crate directly.

no method named `wrapping_offset_from` found for raw pointer `*mut i8`errors

I get errors like the following when running on Ubuntu 18.04 on the master branch. Does any ideas what the cause could be?
error[E0599]: no method named `wrapping_offset_from` found for raw pointer `*mut i8` in the current scope --> util_linux/mdev.rs:582:17 | 582 | s.wrapping_offset_from(val) as libc::c_long as libc::c_int, | ^^^^^^^^^^^^^^^^^^^^ help: there is an associated function with a similar name: `wrapping_offset` | = note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref = note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior

is is cold inside here? :)

Just to make sure you get that I can use some "harsh language" from time to time, but it is getting cool here? Guess it's this project! (and somethings can get lost by translation as well).

Nice done!

Possibly clearer applet_tables

Do you think it would be clearer if the entrypoints used the full path names (here)[https://github.com/samuela/rustybox/blob/master/applets/applet_tables.rs#L424]?

Great work in cleaning up that file btw, it looks great now.

quadmath.h: No such file or directory

After cloning the repository and running cargo build --release (Ubuntu 19.10 arm64), an error is thrown:

$ cargo build --release
info: syncing channel updates for 'nightly-aarch64-unknown-linux-gnu'
info: latest update on 2019-12-03, rust version 1.41.0-nightly (fdc001156 2019-12-02)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-12-02-aarch64-unknown-linux-gnu'
info: latest update on 2019-12-02, rust version 1.41.0-nightly (4007d4ef2 2019-12-01)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-12-01-aarch64-unknown-linux-gnu'
info: latest update on 2019-12-01, rust version 1.41.0-nightly (d8bdb3fdc 2019-11-30)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-11-30-aarch64-unknown-linux-gnu'
info: latest update on 2019-11-30, rust version 1.41.0-nightly (25d8a9494 2019-11-29)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-11-29-aarch64-unknown-linux-gnu'
info: latest update on 2019-11-29, rust version 1.41.0-nightly (bbb664a99 2019-11-28)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-11-28-aarch64-unknown-linux-gnu'
info: latest update on 2019-11-28, rust version 1.41.0-nightly (e87a205c2 2019-11-27)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-11-27-aarch64-unknown-linux-gnu'
info: latest update on 2019-11-27, rust version 1.41.0-nightly (797fd9262 2019-11-26)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-11-26-aarch64-unknown-linux-gnu'
info: latest update on 2019-11-26, rust version 1.41.0-nightly (a44774c3a 2019-11-25)
info: skipping nightly which is missing installed component 'clippy-preview'
info: syncing channel updates for 'nightly-2019-11-25-aarch64-unknown-linux-gnu'
info: latest update on 2019-11-25, rust version 1.41.0-nightly (412f43ac5 2019-11-24)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustc-dev'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustc-dev'
info: installing component 'rustfmt'
    Updating crates.io index
  Downloaded libc v0.2.65
  Downloaded lazy_static v1.4.0
  Downloaded c2rust-asm-casts v0.1.1
  Downloaded f128 v0.2.6
  Downloaded c2rust-bitfields v0.3.0
  Downloaded c2rust-bitfields-derive v0.2.0
  Downloaded quote v0.6.13
  Downloaded syn v0.15.44
  Downloaded num-traits v0.2.9
  Downloaded f128_input v0.2.1
  Downloaded f128_internal v0.2.1
  Downloaded unicode-xid v0.1.0
  Downloaded autocfg v0.1.7
  Downloaded proc-macro2 v0.4.30
  Downloaded cc v1.0.47
   Compiling proc-macro2 v0.4.30
   Compiling autocfg v0.1.7
   Compiling libc v0.2.65
   Compiling cc v1.0.47
   Compiling unicode-xid v0.1.0
   Compiling syn v0.15.44
   Compiling rustybox v0.0.0 (/home/ubuntu/src/github.com/samuela/rustybox)
   Compiling lazy_static v1.4.0
   Compiling c2rust-asm-casts v0.1.1
   Compiling num-traits v0.2.9
   Compiling quote v0.6.13
   Compiling f128_internal v0.2.1
error: failed to run custom build command for `f128_internal v0.2.1`

Caused by:
  process didn't exit successfully: `/home/ubuntu/src/github.com/samuela/rustybox/target/release/build/f128_internal-7dde1865362d42db/build-script-build` (exit code: 1)
--- stdout
TARGET = Some("aarch64-unknown-linux-gnu")
OPT_LEVEL = Some("z")
HOST = Some("aarch64-unknown-linux-gnu")
CC_aarch64-unknown-linux-gnu = None
CC_aarch64_unknown_linux_gnu = None
HOST_CC = None
CC = None
CFLAGS_aarch64-unknown-linux-gnu = None
CFLAGS_aarch64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fp,neon")
running: "cc" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-Bstatic" "-lgfortran" "-lquadmath" "-o" "/home/ubuntu/src/github.com/samuela/rustybox/target/release/build/f128_internal-cd7ce17671f7d9fd/out/src/f128.o" "-c" "src/f128.c"
cargo:warning=src/f128.c:2:10: fatal error: quadmath.h: No such file or directory
cargo:warning=    2 | #include <quadmath.h>
cargo:warning=      |          ^~~~~~~~~~~~
cargo:warning=compilation terminated.
exit code: 1

--- stderr


error occurred: Command "cc" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-Bstatic" "-lgfortran" "-lquadmath" "-o" "/home/ubuntu/src/github.com/samuela/rustybox/target/release/build/f128_internal-cd7ce17671f7d9fd/out/src/f128.o" "-c" "src/f128.c" with args "cc" did not execute successfully (status code exit code: 1).



warning: build failed, waiting for other jobs to finish...
error: build failed

Lots of magic numbers

It seems like c2rust has removed a lot of the named constants so we've ended up with a bunch of magic numbers which are a lot less readable.

A good example might dumpkmap which has the following on line 77:

write(
  1i32,
  bb_common_bufsiz1.as_mut_ptr() as *const libc::c_void,
  (7i32 + 256i32) as size_t,
);

Versus the busybox version:

write(
  STDOUT_FILENO,
  flags,
  7 + MAX_NR_KEYMAPS
);

If and when someone gets c2rust refactor going this might be something good to tackle.

abandoned?

Is this project abandoned? If so please archive it.

Also this still has no license #1

Consider adding notes about unsafe usages to README

As users have pointed out on HN, since this is a direct conversion from C, there’s a lot of usages of unsafe. I think it would be nice to denote this in two ways:

  • A statement exclaiming such somewhere near the top, like β€œThis is still a work in progress and contains memory-unsafe code as translated from C.”

  • A bullet point in the contributing section about reducing unsafe usages, as imaginably that would be a useful goal.

I am interested in trying to contribute and if I do this may be a focus area for me.

Cheers.

Build fails with debian / alpine based build environment

Hi,
I tried to built rustybox inside of a docker container, but it fails with debian and alpine based Dockerfiles.

FROM    liuchong/rustup:stable-musl AS build
#FROM   rust:alpine

RUN     apt-get update && apt-get install -y \
        build-essential \
        pkg-config \
        clang \
        git

#RUN    apk --update --no-cache add \
#       build-base \
#       pkgconfig \
#       clang \
#       gcc \
#       git

RUN     git clone https://github.com/samuela/rustybox.git /mnt/gitrepo-rustybox

WORKDIR /mnt/gitrepo-rustybox

RUN     cargo build --all-features

error:

info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2020-02-19, rust version 1.43.0-nightly (e620d0f33 2020-02-18)
warning: Force-skipping unavailable component 'clippy-x86_64-unknown-linux-gnu'
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
    Updating crates.io index
 Downloading crates ...
  Downloaded lazy_static v1.4.0
  Downloaded c2rust-bitfields v0.3.0
  Downloaded c2rust-asm-casts v0.1.1
  Downloaded libc v0.2.65
  Downloaded c2rust-bitfields-derive v0.2.0
  Downloaded quote v0.6.13
  Downloaded syn v0.15.44
  Downloaded proc-macro2 v0.4.30
  Downloaded unicode-xid v0.1.0
   Compiling proc-macro2 v0.4.30
   Compiling unicode-xid v0.1.0
   Compiling syn v0.15.44
   Compiling libc v0.2.65
   Compiling rustybox v0.0.0 (/mnt/gitrepo-rustybox)
   Compiling lazy_static v1.4.0
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-unknown-linux-musl` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `lazy_static`.
warning: build failed, waiting for other jobs to finish...
error: build failed

Any plans for a windows build?

I tried building it on windows without success. Are there any plans for a Windows version too? What might be the effort required for that?

modprobe or modprobe_small?

Hi,
I again try to move to rustybox because it would be easier to build (if musl / static build works) for custom needs.

With busybox binary I have some problems with modprobe_small which not handle (soft) deps as should.
Supports rustybox modprobe, modprobe_small or both?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.