Git Product home page Git Product logo

wasmer-toml's Introduction

The wasmer.toml Format

Continuous Integration

(API Docs)

A parser for the wasmer.toml file used by Wasmer.

For Developers

Releasing

This repository uses Release Please to automate a lot of the work around creating releases.

Every time a commit following the Conventional Commit Style is merged into main, the release-please.yml workflow will run and update the "Release PR" to reflect the new changes.

For commits that just fix bugs (i.e. the message starts with "fix: "), the associated crate will receive a changelog entry and a patch version bump. Similarly, adding a new feature (i.e. "feat:") does a minor version bump and adding breaking changes (i.e. "fix!:" or "feat!:") will result in a major version bump.

When the release PR is merged, the updated changelogs and bumped version numbers will be merged into the main branch, the release-please.yml workflow will automatically generate GitHub Releases, and CI will publish the crate if necessary.

TL;DR:

  1. Use Conventional Commit Messages whenever you make a noteworthy change
  2. Merge the release PR when ready to release
  3. Let the automation do everything else

License

This project is licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT).

It is recommended to always use cargo crev to verify the trustworthiness of each of your dependencies, including this one.

wasmer-toml's People

Contributors

michael-f-bryan avatar fschutt avatar ayys avatar maminrayej avatar

Stargazers

Serg Alex avatar masx200 avatar

Watchers

James Cloos avatar Johnathan Sharratt avatar  avatar

wasmer-toml's Issues

Nested paths don't work as expected

Observed Error

When working with nested paths such as:

[package]
name = "dynamite-bud/py-worker-test-1"
version = "0.1.3"
description = "dynamite-bud/py-worker-test-1 py worker"

[dependencies]
"wasmer/python" = "^3.12.6"

[fs]
"/app/src" = "./src"

[[command]]
name = "script"
module = "wasmer/python:python"
runner = "wasi"

[command.annotations.wasi]
main-args = ["/app/src/main.py"]

Error

Running it with wasmer run . results in an error:
script: can't open file '/app/src/main.py': [Errno 44] No such file or directory

Expected Behaviour

Ideal toml file that works

[package]
name = "dynamite-bud/py-worker-test-1"
version = "0.1.3"
description = "dynamite-bud/py-worker-test-1 py worker"

[dependencies]
"wasmer/python" = "^3.12.6"

[fs]
"/src" = "./src"

[[command]]
name = "script"
module = "wasmer/python:python"
runner = "wasi"

[command.annotations.wasi]
main-args = ["/src/main.py"]

The above ๐Ÿ‘†๐Ÿผ works

Pull module name out into its own type so we can enforce wapm2pirita's assumptions

On wapm.io, the adamz/quickjs package uses adamz/quickjs as its module name.

wapm.toml file
[package]
name = "adamz/quickjs"
version = "0.20210327.0"
description = "QuickJS is a small and embeddable JavaScript engine. It supports the ES2019 specification including modules, asynchronous generators and proxies."
repository = "https://github.com/saghul/wasi-lab"
homepage = "https://bellard.org/quickjs/"

[[module]]
name = "adamz/quickjs"   # <----------
source = "build/qjs.wasm"
abi = "wasi"

[module.interfaces]
wasi = "0.0.0-unstable"

[[command]]
name = "qjs"
module = "adamz/quickjs"

[[command]]
name = "quickjs"
module = "adamz/quickjs"

When wapm2pirita turns the tarball into a *.webc file, we rename the atom to just quickjs... However, the manifest still thinks it is called adamz/quickjs.

Manifest and volumes for the WEBC file according to wapm2pirita
$ wapm2pirita dump volumes bin.webc
{
  "atoms": [
    {
      "name": "quickjs",
      "offset": 1983,
      "size": 2562768
    }
  ],
  "filesystem": {
    "atom": [],
    "metadata": []
  }
}

$ wapm2pirita dump manifest bin.webc
{
  "package": {
    "wapm": {
      "name": "adamz/quickjs",
      "version": "0.20210327.0",
      "homepage": "https://bellard.org/quickjs/",
      "repository": "https://github.com/saghul/wasi-lab",
      "description": "QuickJS is a small and embeddable JavaScript engine. It supports the ES2019 specification including modules, asynchronous generators and proxies."
    }
  },
  "atoms": {
    "adamz/quickjs": {
      "kind": "https://webc.org/kind/wasm",
      "signature": "sha256:b2KmvFyPjj4SpU4uy8VnTM/hx1+R2OTdbrs/7EIqTWw="
    }
  },
  "commands": {
    "qjs": {
      "runner": "https://webc.org/runner/wasi/command@unstable_",
      "annotations": {
        "wasi": {
          "atom": "adamz/quickjs",                <-----------------
          "package": null,
          "main_args": null
        }
      }
    ...
    }
  }
}

That means anything looking up the particular atom will fail because we're looking for adamz/quickjs when we should look for quickjs. That causes things like wasmer-pack to fail downstream.

$ wasmer-pack show ~/Downloads/quickjs-0.20210327.0.tar.gz
Error: Unable to load the package

Caused by:
    Could not find file "adamz/quickjs": could not find file or directory "adamz" (os error 2)

To fix this, we should change wasmer_pack::Module's name field from a String to some sort of ModuleName type which makes sure the manifest name is valid (e.g. it is an "identifier" that doesn't contain a /).

Here are the tarball and *.webc files we were testing against:

quickjs-0.20210327.0.tar.gz
quickjs-0.20210327.0.webc.zip

Add support for runner annotations in the toml

It would be ideal to support wcgi custom annotations (for example, to annotate if the program is on rfc mode or not).

That configuration should live in the toml runner annotations, but currently is not possible to define those in the toml.

Add syntax for specifying a command that uses a dependency's atom

Imagine you have a package containing some Python scripts. Rather than embedding a copy of the Python interpreter, you would prefer to use a Python package as a dependency and just add your *.py files to the package.

Your wasmer.toml might look like this:

[package]
name = "my/python-program"
version = "1.2.3"

[dependencies]
"wasmer/python" = "3.12"

[fs]
"/app/src" = "./src"
"/app/.env" = "./.env/" # Bundle the virtualenv

[[command]]
name = "script"
module = "wasmer/python:python" # The "python" atom from "wasmer/python"
runner = "wasi"

[annotations.wasi]
args = ["/app/main.py", "with", "--extra=flags"]
env = ["PYTHON_PATH=/app/.env:/etc/python3.12/site-packages"] # Make our virtualenv accessible

To make this use case work, we need a way to express module = "wasmer/python:python".

Allow developers to specify a package's entrypoint command

The wasmer.toml format doesn't give package developers a way to specify the entrypoint command, so code turning it into a webc manifest has to guess:

/// Infer the package's entrypoint.
///
/// there is no way to explicitly specify an entrypoint in a
/// `wasmer.toml` file. If there is exactly one command, we'll use that,
/// otherwise the entrypoint will be left unspecified.
fn entrypoint(manifest: &WasmerManifest) -> Option<String> {
    match manifest.command.as_deref() {
        Some([only_command]) => Some(only_command.get_name()),
        _ => None,
    }
}

We should allow package developers to specify the entrypoint so downstream users don't need to do wasmer run my/package --command=some-command every time.

Possible Syntax

Given a package with multiple commands, there are a couple different ways the entrypoint could be specified.

Option 1 - put it in [package]

[package]
name = "sharrattj/bash"
version = "1.2.3"
entrypoint = "bash"

[[module]]
name = "bash"
source = "./bash.wasm"
abi = "wasi"

[[command]]
name = "bash"
module = "bash"

[[command]]
name = "sh"
module = "bash"

Option 2 - put it in the command

[package]
name = "sharrattj/bash"
version = "1.2.3"

[[module]]
name = "bash"
source = "./bash.wasm"
abi = "wasi"

[[command]]
name = "bash"
module = "bash"
entrypoint = true

[[command]]
name = "sh"
module = "bash"

Option 3 - create a separate section

[package]
name = "sharrattj/bash"
version = "1.2.3"

[[module]]
name = "bash"
source = "./bash.wasm"
abi = "wasi"

[[command]]
name = "bash"
module = "bash"

[[command]]
name = "sh"
module = "bash"

[defaults]
entrypoint = "bash"

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.