Marine runs multi-module WebAssembly applications with interface-types and shared-nothing linking scheme
Go to file
Valery Antopol a61ddfc404
feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332)
* add js wasm backend crate + blank trait impls

* make wasmtime a default feature for runtime and core

* WIP: mock WASI, greeting almost works

* WIP: added @wasmer/wasi, moved some stuff to JsStore, implementing Caller

* finalize Caller

* remove old code

* changing js API + fmt

* update wasm-bindgen generated and patched code

* update call_module to throw error, fix non-logging tests

* add multi-module test + update js api

* fix last element getting

* refactor interface + pass envs

* get rid of make_*_result

* small refactor

* support passing log function

* get rid of some todos

* use String instead of Vec<u8> for wasi envs

* use Strings for wasi envs in marine js

* little fix

* self-review fixes, import ordering

* self-review fixes, import ordering

* make clippy happy + fmt

* self-review fixes

* self-review fixes

* self-review fixes

* revert example artifact change

* pr fixes

* add __wbg_adapter_N updating code

* add all-types test

* fix build

* update marine_js.js

* Fix I64 handling

* pr fixes

* fix import order

* add copyrights

* Add comments, slightly beautify code

* fmt

* make clippy happy

* update js interface

* split function interface, improve naming

* update Cargo.lock

* update to new wasm-backend traits

* wip

* js glue code update

* improve comment

* use typed index collection

* Add more comments

* Add more comments

* Fix warnings

* pr fixes

* pr fixes
2023-07-25 19:49:55 +03:00
.cargo ci: Add marine e2e (#230) 2022-11-21 13:17:18 +02:00
.github chore: Renaming things (#335) 2023-07-14 16:51:28 +03:00
core feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
crates feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
docs Add developer notes about PR reviewing (#157) 2022-04-26 16:20:02 +03:00
examples feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
images update stack png (#109) 2021-09-04 13:39:39 +03:00
marine feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
marine-js feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
tools chore(deps): update rust crate anyhow to 1.0.71 (#326) 2023-07-11 20:42:35 +03:00
.gitignore chore(deps): update all non-major rust dependencies (#211) 2022-11-28 18:37:07 +03:00
.rustfmt.toml feat!: decouple wasmer from Marine, replace it with generic backend interface (#219) 2023-03-15 00:43:51 +03:00
Cargo.lock feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
Cargo.toml feat(marine-js)!: replace old marine-js with common marine-runtime + backend traits impl for JS (#332) 2023-07-25 19:49:55 +03:00
CHANGELOG.md Rename to marine: part 2 (#84) 2021-05-11 15:44:11 +03:00
CONTRIBUTING.md chore(readme): update README, CONTRIBUTING and LICENSE (#277) 2023-02-09 18:07:36 +03:00
LICENSE chore(readme): update README, CONTRIBUTING and LICENSE (#277) 2023-02-09 18:07:36 +03:00
README.md chore: update readme (#287) 2023-03-01 20:22:10 +03:00
rust-toolchain.toml fix(runtime): support new wasm opcodes by removing unused memory limit setting (#299) 2023-03-17 15:34:55 +03:00

Marine

marine version on crates.io

Marine is a modern general purpose Wasm runtime based on the component model capable of running multi-module Wasm applications, aka services, with interface-types and a shared-nothing linking scheme. This execution model is well suited for a variety of scenarios and especially applicable to implementations following the entity component system (ECS) pattern or plugin-based architectures.

Fluence peers, such as Fluence Rust node, include Marine to execute the hosted Wasm services composed with Aqua.

Motivational example

To illustrate the capabilities of Marine, let's have a look at a multi-module Wasm service as implemented in this example.

cd into the examples/motivational-example directory and have a look at the shrek/src/main.rs file:

// examples/motivational-example/shrek/src/main.rs
use marine_rs_sdk::marine;

fn main() {}

#[marine]
pub fn greeting(name: &str) -> Vec<String> {
    let donkey_greeting = donkey::greeting(name);         // 1
    let shrek_greeting = format!("Shrek: hi, {}", name);  // 2
    
    vec![shrek_greeting, donkey_greeting]                 
}

mod donkey {                                               // 3
    use super::*;

    #[marine]
    #[link(wasm_import_module = "donkey")]                 // 4
    extern "C" {
        pub fn greeting(name: &str) -> String;
    }
}

In this Marine (Wasm) module (and namespace) shrek, we declare a function greeting that creates a donkey_greeting (1) from the donkey module's (3)greeting function, which itself is dependent on importing the donkey Wasm module with Rust's FFI link (4) from donkey/src/main.rs (see below).

// examples/motivational-example/donkey/src/main.rs
use marine_rs_sdk::marine;

fn main() {}

#[marine]
pub fn greeting(name: &str) -> String {
    format!("Donkey: hi, {}", name)
}

In summary, our example is comprised of two independent Wasm modules, shrek and donkey, and illustrates how to link one module into another one, i.e., use the donkey module in the shrek module. Please note that the shrek module is called a facade module following the facade pattern and there can only be one facade module per service.

Make sure you have the Marine tools installed and compile the donkey and shrek, respectively, which we can do with the build.sh script:

$> ./build.sh

which creates two independent Wasm modules that are placed in the artifacts directory:

$> ls artifacts
donkey.wasm    shrek.wasm

Now that we have our modules, we can explore them with the Marine REPL. Note that we use the Config.toml file to help out the REPL by providing the module location and names. Once we got the REPL up and running, we can interact with both modules and, as expected, the shrek module is successfully able to access the donkey module's exposed functions.

$> marine mrepl Config.toml
...
1> interfaces
Loaded modules interface:

shrek:
  fn greeting(name: string) -> []string
donkey:
  fn greeting(name: string) -> string

2> call donkey greeting "no link module"
result: String("Donkey: hi, no link module")
 elapsed time: 42.985µs

3> call donkey greeting "facade with link module"
result: String("Donkey: hi, facade with link module")
 elapsed time: 39.25µs

4> q

Looks like everything is in order and the modules are ready for deployment to the network and composition with Aqua.

Documentation

Do not forget to check our YouTube channel.

Repository structure

  • crates
  • examples: several Marine examples used mostly for tests
  • fluence-faas: a Fluence FaaS layer that provides host closures, IT<->JSON conversion, logger, config handling and other things
  • fluence-app-service: a Fluence Application Service layer that provides basic API for service running
  • runtime: a runtime layer that provides basic functionality for loading, unloading and calling modules
  • marine-js: a web runtime layer aimed to run Marine in a browser
  • tools
    • REPL: a REPL intended to test Marine Wasm modules
    • CLI: a CLI intended to build and extract some info from Marine Wasm modules

Support

Please, file an issue if you find a bug. You can also contact us at Discord or Telegram. We will do our best to resolve the issue ASAP.

Contributing

Any interested person is welcome to contribute to the project. Please, make sure you read and follow some basic rules.

License

All software code is copyright (c) Fluence Labs, Inc. under the Apache-2.0 license.