/busybox_wasm

Build script of BusyBox for WebAssembly (wasm) using Emscripten

Primary LanguageC

Original README

BusyBox + Emscripten + nanozip + diff3

Inspired by https://github.com/tbfleming/em-busybox and https://github.com/tbfleming/em-shell, this repo contains build script of BusyBox for WebAssembly without being a full fork of BusyBox, so upgrading to a new version of BusyBox is easier.

In addition to BusyBox build script, this repo also contains two custom BusyBox applets:

  • nanozip - miniz-based imitation of zip utility: busybox nanozip [-r] [[-x EXCLUDED_PATH] ...] OUTPUT_NAME.zip INPUT_PATH [...].
  • diff3 - OpenBSD-based implementation of diff3: busybox diff3 [-exEX3] /tmp/d3a.?????????? /tmp/d3b.?????????? file1 file2 file3

em-shell.c, em-shell.h, em-shell.js, arch/em/Makefile are taken from excellent tbfleming/em-shell and tbfleming/em-busybox by Todd Fleming.

Patches not used for now:

# native version 
make build/native/busybox

# wasm version
make build/wasm/busybox_unstripped.js

Nightly build

BusyBox WASM

BusyBox compiled to WASM with emscripten.

  • Runs in Browser & Web Workers.

  • Currently no sh or ash support.

  • Currently defined functions

    BusyBox v1.32.0 (2023-01-20 07:19:55 UTC) multi-call binary.
    BusyBox is copyrighted by many authors between 1998-2015.
    Licensed under GPLv2. See source distribution for detailed
    copyright notices.
    
    Usage: busybox [function [arguments]...]
       or: busybox --list
       or: function [arguments]...
    
      BusyBox is a multi-call binary that combines many common Unix
      utilities into a single executable.  Most people will create a
      link to busybox for each function they wish to use and BusyBox
      will act like whatever it was invoked as.
    
    Currently defined functions:
      cat, clear, cp, diff3, echo, false, ls, mkdir, mv, nanozip, pwd, rm,
      sleep, tar, touch, true
    

Installation

Download an artifact from last successful build.

Append following lines to busybox_unstripped.js

// busybox_unstripped.js
// ...

var resolve

Module.callMain = callMain
Module.onRuntimeInitialized = () => resolve()
thisProgram = 'busybox'

await new Promise(r => resolve = r)

export default Module

Usage

import busybox from "./busybox_unstripped.js"

busybox.callMain(["ls"])
busybox.callMain(["ls", "-al"])