Cargo wrapper for working with Webassembly wasi(x).

Overview

cargo-wasix

A cargo subcommand that wraps regular cargo commands for compiling Rust code to wasix, a superset of Websassembly wasi with additional functionality.

See wasix.org for more.

Installation

To install this Cargo subcommand, first you'll want to install Rust and then you'll execute:

$ cargo install cargo-wasix

After that you can verify it works via:

$ cargo wasix --version

Usage

The cargo wasix subcommand is a thin wrapper around cargo subcommands, providing optimized defaults for the wasm64-wasi target. Using cargo wasix looks very similar to using cargo:

  • cargo wasix build — build your code in debug mode for the wasix target.

  • cargo wasix build --release — build the optimized version of your *.wasm.

  • cargo wasix run — execute a binary.

  • cargo wasix test — run your tests in wasm64-wasi.

  • cargo wasix bench — run your benchmarks in wasm64-wasi.

In general, if you'd otherwise execute cargo foo --flag you can likely execute cargo wasix foo --flag and everything will "just work" for the wasm64-wasi target.

To give it a spin yourself, try out the hello-world versions of programs!

$ cargo new wasix-hello-world
     Created binary (application) `wasix-hello-world` package
$ cd wasix-hello-world
$ cargo wasix run
   Compiling wasix-hello-world v0.1.0 (/code/wasix-hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `cargo-wasix target/wasm64-wasi/debug/wasix-hello-world.wasm`
     Running `target/wasm64-wasi/debug/wasix-hello-world.wasm`
Hello, world!

Or a library with some tests:

$ cargo new wasix-hello-world --lib
     Created library `wasix-hello-world` package
$ cd wasix-hello-world
$ cargo wasix test
   Compiling wasix-hello-world v0.1.0 (/code/wasix-hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running target/wasm64-wasi/debug/deps/wasix_hello_world-9aa88657c21196a1.wasm
     Running `/code/wasix-hello-world/target/wasm64-wasi/debug/deps/wasix_hello_world-9aa88657c21196a1.wasm`

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

License

This project is license under the Apache 2.0 license with the LLVM exception. See [LICENSE] for more details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

Comments
  • Request for changing the name of WASIX

    Request for changing the name of WASIX

    Hey all, first off: congratulations on putting this system interface and tooling around it together! I know how much work goes into something like this, even if you can reuse so much existing code.

    Unfortunately there is a sizable problem with the name you chose, which I have no doubt is a simple oversight: since early in 2022, WASIX has been in use for an open source project by SingleStore Labs, originally developed for their port of cpython to WASI. At one point it was also used by the official cpython distribution.

    Given that this project is very much in the same space as your system interface, this name collision would be bound to cause a great deal of confusion once you announce more widely.

    I'm glad I stumbled upon this before a big announcement could be made, since I know @syrusakbary's very strong stance against using names already taken by other projects in a related space (see e.g. here, here, and here), and hence that he'd certainly agree that continued use of this name would be the wrong thing to do.

    (Note: I would have filed this on the wasix-libc repo, but it has issues disabled.)

    opened by tschneidereit 5
  • WASIX toolchain issue on Windows

    WASIX toolchain issue on Windows

    Hi, I installed WASIX on windows. Now when I try to execute the cargo wasix build, I am getting toolchain not found error. I can understand if WASIX has no windows gnu toolchain. Here I have no idea why it is looking for "x86_64-pc-windows-gnu" even tough I use "x86_64-pc-windows-msvc".

    image

    bug 
    opened by Loga-Shanmugam 3
  • Wrong wasmer install URL

    Wrong wasmer install URL

    The link https://wasmer.io/install.sh does not exist now, and I think curl https://get.wasmer.io -sSfL | sh is a correct way for installation.

    # cargo wasix run
    error: failed to find `wasmer` in $PATH, you'll want to install `wasmer` before running this command
    you can also install through a shell:
    
            curl https://wasmer.io/install.sh -sSf | bash
    
    opened by maekawatoshiki 0
  • Absence of pre-built toolchain for Intel MacOS

    Absence of pre-built toolchain for Intel MacOS

    Unable to use on Intel based Mac.

    cargo wasix build --release
    Finding latest release... (https://api.github.com/repos/wasix-org/rust/releases/latest)...
    Could not download pre-built toolchain: Release v2023-05-26.1 does not have a prebuilt toolchain for host x86_64-apple-darwin
    error: Download of pre-built toolchain failed
    
    opened by fckt 0
  • Issue with Windows toolchain naming

    Issue with Windows toolchain naming

    There is still issue with the naming of toolchain for windows image

    Originally posted by @Loga-Shanmugam in https://github.com/wasix-org/cargo-wasix/issues/11#issuecomment-1581884526

    opened by Loga-Shanmugam 0
  • 'cargo' is not installed for the toolchain 'wasix'

    'cargo' is not installed for the toolchain 'wasix'

    Outcome

    cargo wasix build fails with error 'cargo' is not installed for the toolchain 'wasix'.

    Expected Result

    Should build successfully.

    Replication Steps

    # Dockerfile
    
    FROM rust:1.70-bookworm
    
    WORKDIR /src
    
    RUN cargo init
    RUN cargo install cargo-wasix
    RUN cargo wasix build
    
    $ docker build -t cargo-wasix-test:latest .
    [+] Building 73.1s (8/8) FINISHED
     => [internal] load build definition from Dockerfile                                                                                                                                                                        0.0s
     => => transferring dockerfile: 143B                                                                                                                                                                                        0.0s
     => [internal] load .dockerignore                                                                                                                                                                                           0.0s
     => => transferring context: 2B                                                                                                                                                                                             0.0s
     => [internal] load metadata for docker.io/library/rust:1.70-bookworm                                                                                                                                                       1.5s
     => CACHED [1/5] FROM docker.io/library/rust:1.70-bookworm@sha256:79ca6896ecfe3787599bba6fd9dcd98b28f2742396df96a5b33f737ca7749730                                                                                          0.0s
     => [2/5] WORKDIR /src                                                                                                                                                                                                      0.0s
     => [3/5] RUN cargo init                                                                                                                                                                                                    1.0s
     => [4/5] RUN cargo install cargo-wasix                                                                                                                                                                                    26.7s
     => ERROR [5/5] RUN cargo wasix build                                                                                                                                                                                      43.8s
    ------
     > [5/5] RUN cargo wasix build:
    #0 0.494 Finding latest release... (https://api.github.com/repos/wasix-org/rust/releases/latest)...
    #0 0.844 Downloading sysroot from url 'https://github.com/wasix-org/rust/releases/download/v2023-05-26.1/wasix-libc.tar.gz'...
    #0 1.417 Extracting...
    #0 1.555 Downloading Rust toolchain from url 'https://github.com/wasix-org/rust/releases/download/v2023-05-26.1/rust-toolchain-x86_64-unknown-linux-gnu.tar.gz'...
    #0 2.118 Extracting...
    #0 40.61 Downloaded toolchain x86_64-unknown-linux-gnu to /root/.local/share/cargo-wasix/toolchains/x86_64-unknown-linux-gnu_v2023-05-26.1/rust
    #0 40.61 Activating rustup toolchain wasix at /root/.local/share/cargo-wasix/toolchains/x86_64-unknown-linux-gnu_v2023-05-26.1/rust...
    #0 40.62 Running rustup toolchain link wasix /root/.local/share/cargo-wasix/toolchains/x86_64-unknown-linux-gnu_v2023-05-26.1/rust:
    #0 40.62 rustup toolchain wasix was linked and is now available!
    #0 40.72 error: 'cargo' is not installed for the toolchain 'wasix'
    #0 40.72 note: this is a custom toolchain, which cannot use `rustup component add`
    #0 40.72 help: if you built this toolchain from source, and used `rustup toolchain link`, then you may be able to build the component with `x.py`
    ------
    Dockerfile:7
    --------------------
       5 |     RUN cargo init
       6 |     RUN cargo install cargo-wasix
       7 | >>> RUN cargo wasix build
       8 |
    --------------------
    ERROR: failed to solve: process "/bin/sh -c cargo wasix build" did not complete successfully: exit code: 1
    
    opened by bcheidemann 2
  • GLIBC_2.36 not found

    GLIBC_2.36 not found

    Running cargo wasix build produces the following output:

    $ cargo wasix build
    /home/ben/.rustup/toolchains/wasix/bin/rustc: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.36' not found (required by /home/ben/.rustup/toolchains/wasix/lib/librustc_driver-239bacfa42cce6c3.so)
    error: Could not execute rustc
    
    Caused by:
        failed to execute "rustc" "+wasix" "--print" "sysroot"
            status: exit status: 1
    

    My currently installed version of glibc is 2.35.

    Will wasix support glibc version 2.35 or will people need to update their glibc version to run wasix?

    opened by bcheidemann 6
  • Web Hello world example

    Web Hello world example

    Hi I'm a bit compile hello world and then load it in the browser with the following. Are you able to do an example with this to point people in the right direction

    Thanks

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset='utf-8'>
        <meta http-equiv='X-UA-Compatible' content='IE=edge'>
        <title>Page Title</title>
        <meta name='viewport' content='width=device-width, initial-scale=1'>
        <!-- <link rel='stylesheet' type='text/css' media='screen' href='main.css'> -->
        <script lang="ts">
            const importObject = {
                module: {},
                env: {
                    memory: new WebAssembly.Memory({ initial: 256 }),
                }
            };
            const response = fetch('/wasmix-play.wasm').then((response) =>
                response.arrayBuffer()
            ).then((bytes) =>  WebAssembly.instantiate(bytes, importObject)
            ).then((instance) => {
                console.log(instance.exports);
            });
        </script>
    </head>
    <body>
    </body>
    </html>```
    opened by lantos1618 0
Owner
WASIX
WASIX is the long term stabilization and support of the existing WASI ABI plus additional non-invasive syscall extensions
WASIX
cargo-lambda is a Cargo subcommand to help you work with AWS Lambda.

cargo-lambda cargo-lambda is a Cargo subcommand to help you work with AWS Lambda. The new subcommand creates a basic Rust package from a well defined

null 184 Jan 5, 2023
A cargo subcommand that extends cargo's capabilities when it comes to code generation.

cargo-px Cargo Power eXtensions Check out the announcement post to learn more about cargo-px and the problems it solves with respect to code generatio

Luca Palmieri 33 May 7, 2023
Convenience wrapper for cargo buildscript input/output

A convenience wrapper for cargo buildscript input/output. Why? The cargo buildscript API is (necessarily) stringly-typed.

Christopher Durham 6 Sep 25, 2022
Toolkit for working with scripts used by REDengine in Cyberpunk 2077.

redscript Toolkit for working with scripts used by REDengine in Cyberpunk 2077. Currently includes a compiler, a decompiler and a disassembler. usage

jac3km4 268 Jan 6, 2023
Estimate the amount of time spent working on a Git repository

jikyuu (時給) A tool to estimate the amount of time spent working on a Git repository. It is a direct port of git-hours, written in Node.js, because the

null 18 Nov 16, 2022
A working example of multi targets compilation for Rust using Github Actions.

A working example of multi targets compilation for Rust using Github Actions. Supports Windows, MacOSX, x86_64, ARM and Raspberry PI Linux.

Nicolas Vanhoren 41 Dec 17, 2022
IDX is a Rust crate for working with RuneScape .idx-format caches.

This image proudly made in GIMP License Licensed under GNU GPL, Version 3.0, (LICENSE-GPL3 or https://choosealicense.com/licenses/gpl-3.0/) Contributi

Ceikry 5 May 27, 2022
Rust libraries for working with GPT (GUID Partition Table) disk data

gpt-disk-rs no_std libraries related to GPT (GUID Partition Table) disk data. There are three Rust packages in this repository: uguid The uguid packag

Google 25 Dec 24, 2022
A Rust utility library, making easier by taking the hassle out of working. :octocat:

reddish A Rust utility library, making easier by taking the hassle out of working. Usage Add this to your Cargo.toml: [dependencies] reddish = "0.2.0"

Rogério Araújo 12 Jan 21, 2023
cargo, make me a project

cargo-generate cargo, make me a project cargo-generate is a developer tool to help you get up and running quickly with a new Rust project by leveragin

null 1.2k Jan 3, 2023
Render cargo dependency tree in online

Cargo Tree Online Check out rendered page Render cargo dependency tree in online. Usage trunk serve Copy and paste the content of Cargo.lock file to

Kangwook Lee (이강욱) 2 Sep 23, 2021
Generate a THIRDPARTY file with all licenses in a cargo project.

cargo-bundle-licenses Bundle all third-party licenses into a single file. NOTE This tools is not a lawyer and no guarantee of correctness can be made

Seth 58 Jan 7, 2023
Rust+Cargo lightweight hello world with the most minimum binary size possible.

Lightweight Cargo Hello World Rust+Cargo lightweight hello world with the most minimum binary size possible. requirements 1: Rustup (Rustc, Cargo) Ins

Raymond 1 Dec 13, 2021
Plugin to request a relaunch when uploading a Skyline plugin through cargo skyline

restart-plugin A skyline plugin for allowing cargo-skyline (or other tools) to restart your game without you having to touch your controller. Install

null 1 Nov 21, 2021
A cargo subcommand that displays the assembly generated for Rust source code

cargo-show-asm A cargo subcommand that displays the assembly generated for Rust source code.

null 193 Dec 29, 2022
Cargo subcommand for optimizing binaries with PGO and BOLT.

cargo-pgo Cargo subcommand that makes it easier to use PGO and BOLT to optimize Rust binaries. Installation $ cargo install cargo-pgo You will also ne

Jakub Beránek 229 Dec 28, 2022
Mommy's here to support you when running cargo~

cargo-mommy Mommy's here to support you when running cargo~ ❤️ Installation Install cargo-mommy like you would any other cargo extension~ > cargo inst

Aria Beingessner 198 Jan 5, 2023
Load and resolve Cargo configuration.

cargo-config2 Load and resolve Cargo configuration. This library is intended to accurately emulate the actual behavior of Cargo configuration, for exa

Taiki Endo 6 Jan 10, 2023
Cargo-BOJ: test and submit solutions to BOJ problems

Cargo-BOJ Test and submit solutions to BOJ (Baekjoon Online Judge) problems. Defaults are geared towards Rust solutions, but non-Rust usage is support

null 5 Apr 3, 2023