├── marine-js ├── npm-package │ ├── src │ │ └── index.js │ ├── .gitignore │ ├── tsconfig.build.json │ ├── .prettierrc.cjs │ ├── jest.config.cjs │ ├── tsconfig.json │ └── package.json ├── build.sh ├── Cargo.toml └── src │ ├── global_state.rs │ └── lib.rs ├── marine ├── tests │ ├── config_tests │ │ ├── dir_without_modules │ │ │ └── .gitkeep │ │ ├── renamed_records_passing │ │ │ ├── records_passing_pure.wasm │ │ │ └── records_passing_effector_renamed.wasm │ │ ├── ModulesDirConfig.toml │ │ ├── SpecifiedPathConfig.toml │ │ └── SpecifiedDirConfig.toml │ ├── wasm_tests │ │ ├── wasi │ │ │ ├── some_dir │ │ │ │ └── some_file │ │ │ ├── ParentDir.toml │ │ │ ├── PreopenAbsolutePath.toml │ │ │ ├── MapToAbsolutePath.toml │ │ │ ├── MapFromAbsolutePath.toml │ │ │ ├── PreopenMappedDuplicate.toml │ │ │ ├── Cargo.toml │ │ │ ├── Config.toml │ │ │ └── src │ │ │ │ └── effector.rs │ │ ├── records_passing │ │ │ ├── .cargo │ │ │ │ └── config.toml │ │ │ ├── Config.toml │ │ │ └── Cargo.toml │ │ ├── call_parameters_v0 │ │ │ ├── Config.toml │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── main.rs │ │ ├── call_parameters_v1 │ │ │ ├── Config.toml │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── main.rs │ │ ├── call_parameters_v2 │ │ │ ├── Config.toml │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── main.rs │ │ ├── call_parameters_v3 │ │ │ ├── Config.toml │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ └── main.rs │ │ ├── arrays_passing │ │ │ ├── Config.toml │ │ │ └── Cargo.toml │ │ ├── memory_limiting │ │ │ ├── 64MiB_limit.toml │ │ │ ├── 2MiB_limit_fail_on_startup.toml │ │ │ ├── Cargo.toml │ │ │ └── src │ │ │ │ ├── effector.rs │ │ │ │ └── pure.rs │ │ ├── build.sh │ │ └── arguments_passing │ │ │ ├── Config.toml │ │ │ └── Cargo.toml │ └── utils.rs ├── src │ ├── host_imports │ │ ├── logger │ │ │ └── mod.rs │ │ └── mod.rs │ ├── config │ │ ├── path_utils.rs │ │ └── mod.rs │ └── module_loading │ │ └── mod.rs └── Cargo.toml ├── .github ├── actionlint.yaml ├── renovate.json ├── workflows │ ├── lint-pr.yml │ ├── e2e-label.yml │ ├── lint.yml │ └── snapshot-cargo.yml └── release-please │ ├── manifest.json │ └── config.json ├── images ├── fce_info.png ├── aqua_marine_stack.png └── fluence_stack_overview.png ├── .cargo └── config.toml ├── .rustfmt.toml ├── examples ├── failing │ ├── artifacts │ │ └── failing.wasm │ ├── Config.toml │ ├── build.sh │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── greeting │ ├── artifacts │ │ └── greeting.wasm │ ├── Config.toml │ ├── build.sh │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── ipfs-node │ ├── artifacts │ │ ├── ipfs_pure.wasm │ │ └── ipfs_effector.wasm │ ├── pure │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── effector │ │ ├── Cargo.toml │ │ └── src │ │ │ └── path.rs │ ├── Config.toml │ └── build.sh ├── records │ ├── artifacts │ │ ├── records_pure.wasm │ │ └── records_effector.wasm │ ├── Config.toml │ ├── test-record │ │ ├── Cargo.toml │ │ └── src │ │ │ └── test_record.rs │ ├── pure │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── effector │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ └── build.sh ├── call_parameters │ ├── artifacts │ │ └── call_parameters.wasm │ ├── Config.toml │ ├── build.sh │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── greeting_record │ ├── artifacts │ │ └── greeting-record.wasm │ ├── Config.toml │ ├── build.sh │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── motivational-example │ ├── Config.toml │ ├── donkey │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── shrek │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ └── build.sh ├── build.sh ├── sqlite │ ├── Cargo.toml │ ├── build.sh │ └── Config.toml └── url-downloader │ ├── curl_adapter │ ├── Cargo.toml │ └── src │ │ └── main.rs │ ├── facade │ ├── Cargo.toml │ └── src │ │ └── main.rs │ ├── local_storage │ ├── Cargo.toml │ └── src │ │ └── main.rs │ ├── Config.toml │ └── build.sh ├── core ├── tests │ └── wasm_tests │ │ ├── lilo_after_2gb │ │ ├── Config.toml │ │ ├── Cargo.toml │ │ └── src │ │ │ └── pure.rs │ │ └── build.sh ├── src │ ├── misc │ │ ├── mod.rs │ │ ├── version_checker.rs │ │ └── errors.rs │ ├── host_imports │ │ ├── lifting │ │ │ ├── mod.rs │ │ │ └── li_helper.rs │ │ ├── lowering │ │ │ └── mod.rs │ │ ├── mod.rs │ │ └── errors.rs │ └── module │ │ ├── mod.rs │ │ └── exports.rs └── Cargo.toml ├── rust-toolchain.toml ├── crates ├── utils │ ├── Cargo.toml │ ├── CHANGELOG.md │ └── src │ │ ├── wasm_mem_pages_conversion.rs │ │ └── lib.rs ├── min-it-version │ ├── Cargo.toml │ ├── CHANGELOG.md │ └── src │ │ └── lib.rs ├── it-interfaces │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ └── errors.rs ├── wasm-backend-traits │ ├── Cargo.toml │ └── src │ │ ├── impl_utils.rs │ │ ├── caller.rs │ │ ├── exports.rs │ │ ├── module.rs │ │ ├── wasi.rs │ │ ├── macros.rs │ │ ├── store.rs │ │ └── instance.rs ├── it-json-serde │ ├── Cargo.toml │ └── src │ │ ├── errors.rs │ │ └── lib.rs ├── module-interface │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── interface │ │ ├── errors.rs │ │ ├── mod.rs │ │ ├── itype_to_text.rs │ │ └── interface_transformer.rs │ │ └── it_interface │ │ ├── errors.rs │ │ ├── mod.rs │ │ └── it_module_interface.rs ├── it-generator │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── errors.rs │ │ └── instructions_generator │ │ └── record_instructions.rs ├── module-info-parser │ ├── Cargo.toml │ └── src │ │ ├── sdk_version │ │ ├── mod.rs │ │ └── errors.rs │ │ ├── manifest │ │ └── mod.rs │ │ ├── lib.rs │ │ ├── errors.rs │ │ └── custom_section_extractor.rs ├── js-backend │ ├── Cargo.toml │ ├── src │ │ ├── wasi │ │ │ └── js_imports.rs │ │ ├── single_shot_async_executor.rs │ │ └── lib.rs │ └── js │ │ └── wasi_bindings.js ├── it-parser │ ├── Cargo.toml │ └── src │ │ ├── custom.rs │ │ ├── deleter.rs │ │ ├── embedder.rs │ │ ├── extractor.rs │ │ └── lib.rs ├── wasmtime-backend │ ├── Cargo.toml │ └── src │ │ └── imports.rs └── fluence-app-service │ ├── Cargo.toml │ └── src │ ├── config.rs │ └── raw_toml_config.rs ├── .config └── nextest.toml ├── docs └── developer-notes.md ├── .gitignore ├── tools ├── cli │ ├── Cargo.toml │ └── src │ │ ├── generate.rs │ │ └── errors.rs └── repl │ ├── Cargo.toml │ └── src │ ├── repl │ └── print_state.rs │ └── logger.rs ├── CONTRIBUTING.md └── Cargo.toml /marine-js/npm-package/src/index.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /marine/tests/config_tests/dir_without_modules/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/some_dir/some_file: -------------------------------------------------------------------------------- 1 | some data 2 | -------------------------------------------------------------------------------- /.github/actionlint.yaml: -------------------------------------------------------------------------------- 1 | self-hosted-runner: 2 | labels: 3 | - builder 4 | -------------------------------------------------------------------------------- /images/fce_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/images/fce_info.png -------------------------------------------------------------------------------- /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [registries] 2 | fluence = { index = "git://crates.fluence.dev/index" } 3 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2021" 2 | 3 | reorder_imports = false 4 | reorder_modules = false 5 | -------------------------------------------------------------------------------- /images/aqua_marine_stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/images/aqua_marine_stack.png -------------------------------------------------------------------------------- /images/fluence_stack_overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/images/fluence_stack_overview.png -------------------------------------------------------------------------------- /marine-js/npm-package/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | *.tgz 4 | 5 | # auto-generated files 6 | src/*.wasm 7 | snippets 8 | -------------------------------------------------------------------------------- /examples/failing/artifacts/failing.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/failing/artifacts/failing.wasm -------------------------------------------------------------------------------- /examples/greeting/artifacts/greeting.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/greeting/artifacts/greeting.wasm -------------------------------------------------------------------------------- /examples/ipfs-node/artifacts/ipfs_pure.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/ipfs-node/artifacts/ipfs_pure.wasm -------------------------------------------------------------------------------- /examples/records/artifacts/records_pure.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/records/artifacts/records_pure.wasm -------------------------------------------------------------------------------- /examples/ipfs-node/artifacts/ipfs_effector.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/ipfs-node/artifacts/ipfs_effector.wasm -------------------------------------------------------------------------------- /marine-js/npm-package/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "dist", "src/__test__"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/records/artifacts/records_effector.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/records/artifacts/records_effector.wasm -------------------------------------------------------------------------------- /marine/tests/wasm_tests/records_passing/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.wasm32-wasi] 2 | rustflags = [ 3 | "-C", "link-args=-zstack-size=52428800", 4 | ] 5 | -------------------------------------------------------------------------------- /examples/call_parameters/artifacts/call_parameters.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/call_parameters/artifacts/call_parameters.wasm -------------------------------------------------------------------------------- /examples/greeting_record/artifacts/greeting-record.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/examples/greeting_record/artifacts/greeting-record.wasm -------------------------------------------------------------------------------- /examples/failing/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "failing" 6 | logger_enabled = false 7 | -------------------------------------------------------------------------------- /examples/greeting/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "greeting" 6 | 7 | logger_enabled = false 8 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v0/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "call_parameters_v0" 6 | 7 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v1/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "call_parameters_v1" 6 | 7 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v2/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "call_parameters_v2" 6 | 7 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v3/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "call_parameters_v3" 6 | 7 | -------------------------------------------------------------------------------- /examples/call_parameters/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "call_parameters" 6 | logger_enabled = false 7 | -------------------------------------------------------------------------------- /examples/greeting_record/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "greeting-record" 6 | logger_enabled = false 7 | -------------------------------------------------------------------------------- /examples/motivational-example/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "donkey" 6 | 7 | [[module]] 8 | name = "shrek" 9 | -------------------------------------------------------------------------------- /core/tests/wasm_tests/lilo_after_2gb/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "3 GiB" 3 | 4 | [[module]] 5 | name = "lilo_after_2gb_pure" 6 | logger_enabled = true 7 | -------------------------------------------------------------------------------- /marine/tests/config_tests/renamed_records_passing/records_passing_pure.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/marine/tests/config_tests/renamed_records_passing/records_passing_pure.wasm -------------------------------------------------------------------------------- /marine-js/npm-package/.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: true, 3 | trailingComma: 'all', 4 | singleQuote: true, 5 | printWidth: 120, 6 | tabWidth: 4, 7 | useTabs: false, 8 | }; 9 | -------------------------------------------------------------------------------- /marine/tests/config_tests/renamed_records_passing/records_passing_effector_renamed.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluencelabs/marine/HEAD/marine/tests/config_tests/renamed_records_passing/records_passing_effector_renamed.wasm -------------------------------------------------------------------------------- /marine-js/build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | wasm-pack build -d marine-js-pkg --target web 4 | 5 | MARINE_JS_JS_DEST=npm-package/src/snippets/marine-js-6faa67b8af9cc173/ 6 | mkdir -p $MARINE_JS_JS_DEST 7 | cp marine-js.js $MARINE_JS_JS_DEST 8 | -------------------------------------------------------------------------------- /examples/call_parameters/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cargo run --release -p marine -- build --release; 4 | 5 | rm -f artifacts/* || true; 6 | mkdir -p artifacts; 7 | 8 | cp ../../target/wasm32-wasi/release/call_parameters.wasm artifacts/; 9 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly-2023-11-11" 3 | targets = [ 4 | "x86_64-unknown-linux-gnu", 5 | "x86_64-unknown-linux-musl", 6 | "x86_64-apple-darwin", 7 | "wasm32-wasi", 8 | "wasm32-unknown-unknown", 9 | ] 10 | -------------------------------------------------------------------------------- /examples/records/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "records_effector" 6 | logger_enabled = true 7 | 8 | [[module]] 9 | name = "records_pure" 10 | logger_enabled = true 11 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/ParentDir.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "wasi_effector" 6 | logger_enabled = true 7 | [module.wasi] 8 | mapped_dirs = { "tmp" = "tmp/../../../../../etc" } 9 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/PreopenAbsolutePath.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "wasi_effector" 6 | logger_enabled = true 7 | [module.wasi] 8 | preopened_files = ["/tmp"] 9 | 10 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/MapToAbsolutePath.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "wasi_effector" 6 | logger_enabled = true 7 | [module.wasi] 8 | mapped_dirs = { "tmp" = "/tmp" } 9 | 10 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/arrays_passing/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "arrays_passing_effector" 6 | logger_enabled = true 7 | 8 | [[module]] 9 | name = "arrays_passing_pure" 10 | logger_enabled = true 11 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/MapFromAbsolutePath.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "wasi_effector" 6 | logger_enabled = true 7 | [module.wasi] 8 | mapped_dirs = { "/tmp" = "tests/wasm_tests/wasi/some_dir" } 9 | 10 | -------------------------------------------------------------------------------- /examples/failing/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | cargo run --release -p marine -- build --release 5 | 6 | rm artifacts/* || true 7 | mkdir -p artifacts 8 | 9 | cp ../../target/wasm32-wasi/release/failing.wasm artifacts/ 10 | -------------------------------------------------------------------------------- /examples/greeting/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | cargo run --release -p marine -- build --release 5 | 6 | rm artifacts/* || true 7 | mkdir -p artifacts 8 | 9 | cp ../../target/wasm32-wasi/release/greeting.wasm artifacts/ 10 | -------------------------------------------------------------------------------- /examples/records/test-record/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test-record" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [lib] 9 | name = "test_record" 10 | path = "src/test_record.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "0.14.0" 14 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/PreopenMappedDuplicate.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "wasi_effector" 6 | logger_enabled = true 7 | [module.wasi] 8 | preopened_files = ["tmp"] 9 | mapped_dirs = { "tmp" = "./some_dir" } 10 | -------------------------------------------------------------------------------- /examples/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | for dir in ./*; do 6 | # skip non-directory entries 7 | [ -d "$dir" ] || continue 8 | 9 | # skip if there's no build.sh in the directory 10 | [ -e "$dir/build.sh" ] || continue 11 | 12 | (cd "$dir"; ./build.sh) 13 | done 14 | -------------------------------------------------------------------------------- /examples/greeting_record/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | cargo run --release -p marine -- build --release 5 | 6 | rm artifacts/* || true 7 | mkdir -p artifacts 8 | 9 | cp ../../target/wasm32-wasi/release/greeting-record.wasm artifacts/ 10 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/memory_limiting/64MiB_limit.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "64 MiB" # 1024 wasm pages 3 | 4 | 5 | [[module]] 6 | name = "memory_limiting_effector" 7 | logger_enabled = true 8 | 9 | [[module]] 10 | name = "memory_limiting_pure" 11 | logger_enabled = true 12 | -------------------------------------------------------------------------------- /core/tests/wasm_tests/build.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | # This script builds all tests 4 | ( 5 | cd lilo_after_2gb || exit; 6 | cargo run --release -p marine -- build --release; 7 | rm artifacts/* || true; 8 | mkdir artifacts 9 | ) 10 | 11 | cp ../../../target/wasm32-wasi/release/lilo_after_2gb.wasm lilo_after_2gb/artifacts/ 12 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/records_passing/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "256 MiB" 3 | 4 | [[module]] 5 | name = "records_passing_effector" 6 | logger_enabled = true 7 | 8 | [[module]] 9 | name = "records_passing_pure" 10 | random_field = true 11 | logger_enabled = true 12 | -------------------------------------------------------------------------------- /examples/sqlite/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm-sqlite-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "sqlite_test" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "0.14.0" 14 | marine-sqlite-connector = "0.9.0" 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/memory_limiting/2MiB_limit_fail_on_startup.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "2 MiB" # 32 wasm pages 3 | 4 | 5 | [[module]] 6 | name = "memory_limiting_effector" 7 | logger_enabled = true 8 | 9 | [[module]] 10 | name = "memory_limiting_pure" 11 | logger_enabled = true 12 | -------------------------------------------------------------------------------- /examples/motivational-example/donkey/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "donkey" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "donkey" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | -------------------------------------------------------------------------------- /examples/motivational-example/shrek/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "shrek" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | path = "src/main.rs" 10 | name = "shrek" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasi-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "wasi_effector" 10 | path = "src/effector.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "0.14.0" 14 | safe-transmute = "0.11.0" 15 | -------------------------------------------------------------------------------- /examples/records/pure/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "record-pure" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "records_pure" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "0.14.0" 14 | test-record = { path = "../test-record" } 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "wasi_effector" 6 | logger_enabled = true 7 | [module.wasi] 8 | preopened_files = ["tests/wasm_tests/wasi/some_dir"] 9 | mapped_dirs = { "some_dir" = "tests/wasm_tests/wasi/some_dir" } 10 | -------------------------------------------------------------------------------- /crates/utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-utils" 3 | description = "Fluence Marine utils crate" 4 | version = "0.5.1" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_utils" 12 | path = "src/lib.rs" 13 | -------------------------------------------------------------------------------- /core/tests/wasm_tests/lilo_after_2gb/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lilo-after-2gb-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "lilo_after_2gb" 10 | path = "src/pure.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "0.14.0" 14 | safe-transmute = "0.11.0" 15 | -------------------------------------------------------------------------------- /examples/failing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm-failing" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | description = "The failing module for the Fluence network" 6 | edition = "2021" 7 | publish = false 8 | 9 | [[bin]] 10 | name = "failing" 11 | path = "src/main.rs" 12 | 13 | [dependencies] 14 | marine-rs-sdk = "0.14.0" 15 | -------------------------------------------------------------------------------- /examples/ipfs-node/pure/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ipfs-pure" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "ipfs_pure" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | log = "0.4.14" 15 | -------------------------------------------------------------------------------- /examples/greeting/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm-greeting" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | description = "The greeting module for the Fluence network" 6 | edition = "2021" 7 | publish = false 8 | 9 | [[bin]] 10 | name = "greeting" 11 | path = "src/main.rs" 12 | 13 | [dependencies] 14 | marine-rs-sdk = "0.14.0" 15 | -------------------------------------------------------------------------------- /examples/records/effector/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "record-effector" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "records_effector" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "0.14.0" 14 | test-record = { path = "../test-record" } 15 | -------------------------------------------------------------------------------- /examples/ipfs-node/effector/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ipfs-effector" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "ipfs_effector" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | log = "0.4.14" 15 | -------------------------------------------------------------------------------- /examples/url-downloader/curl_adapter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "curl_adapter" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | path = "src/main.rs" 10 | name = "curl_adapter" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | log = "0.4.8" 15 | -------------------------------------------------------------------------------- /marine/tests/config_tests/ModulesDirConfig.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "renamed_records_passing" 2 | total_memory_limit = "Infinity" 3 | 4 | [[module]] 5 | name = "records_passing_effector" 6 | file_name = "records_passing_effector_renamed.wasm" 7 | logger_enabled = true 8 | 9 | [[module]] 10 | name = "records_passing_pure" 11 | random_field = true 12 | logger_enabled = true 13 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/build.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # Build all tests 4 | for test in *; do 5 | if [[ -d $test ]]; then 6 | echo "Building $test" 7 | cd $test 8 | cargo run --release -p marine -- build --release 9 | mkdir artifacts -p 10 | cp ../../../../target/wasm32-wasi/release/$test_*.wasm artifacts/ 11 | cd - 12 | fi 13 | done 14 | -------------------------------------------------------------------------------- /examples/call_parameters/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "call_parameters" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "call_parameters" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | serde_json = "1.0.111" 15 | -------------------------------------------------------------------------------- /examples/url-downloader/facade/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "facade" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "facade" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | anyhow = "1.0.31" 15 | log = "0.4.8" 16 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/arguments_passing/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "./artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "arguments_passing_effector" 6 | total_memory_limit = "10 KiB" 7 | logger_enabled = true 8 | 9 | [[module]] 10 | name = "arguments_passing_pure" 11 | total_memory_limit = "10 KiB" 12 | logger_enabled = true 13 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "github>fluencelabs/renovate", 4 | "github>fluencelabs/renovate:cargo", 5 | "github>fluencelabs/renovate:np," 6 | ], 7 | "enabledManagers": ["cargo", "npm"], 8 | "packageRules": [ 9 | { 10 | "matchPackagePatterns": ["^@wasmer", "^wasmer", "^wasm-bindgen"], 11 | "enabled": false 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v0/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "call-parameters-v0-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "call_parameters_v0" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "=0.10.3" # do not update, host API v0 test 14 | serde_json = "1.0.111" 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v1/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "call-parameters-v1-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "call_parameters_v1" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "=0.12.0" # do not update, host API v1 test 14 | serde_json = "1.0.111" 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "call-parameters-v2-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "call_parameters_v2" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "=0.13.0" # do not update, host API v2 test 14 | serde_json = "1.0.111" 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "call-parameters-v3-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "call_parameters_v3" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = "=0.14.0" # do not update, host API v3 test 14 | serde_json = "1.0.111" 15 | -------------------------------------------------------------------------------- /examples/url-downloader/local_storage/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "local_storage" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "local_storage" 10 | path = "src/main.rs" 11 | 12 | [dependencies] 13 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 14 | wasm-tracing-allocator = "0.1.0" 15 | 16 | log = "0.4.8" 17 | -------------------------------------------------------------------------------- /examples/sqlite/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | cargo run --release -p marine -- build --release 5 | 6 | rm artifacts/* || true 7 | mkdir -p artifacts 8 | 9 | cp ../../target/wasm32-wasi/release/sqlite_test.wasm artifacts/ 10 | wget https://github.com/fluencelabs/sqlite/releases/download/v0.14.0_w/sqlite3.wasm 11 | mv sqlite3.wasm artifacts/ 12 | -------------------------------------------------------------------------------- /marine/tests/config_tests/SpecifiedPathConfig.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "dir_without_modules" 2 | total_memory_limit = "Infinity" 3 | 4 | [[module]] 5 | name = "records_passing_effector" 6 | load_from = "renamed_records_passing/records_passing_effector_renamed.wasm" 7 | logger_enabled = true 8 | 9 | [[module]] 10 | name = "records_passing_pure" 11 | load_from = "renamed_records_passing/records_passing_pure.wasm" 12 | logger_enabled = true 13 | -------------------------------------------------------------------------------- /examples/ipfs-node/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "ipfs_effector" 6 | logger_enabled = true 7 | 8 | [module.mounted_binaries] 9 | ipfs = "/usr/local/bin/ipfs" 10 | 11 | [module.wasi] 12 | envs = { "IPFS_ADDR" = "/dns4/relay02.fluence.dev/tcp/15001", "timeout" = "1s" } 13 | 14 | [[module]] 15 | name = "ipfs_pure" 16 | logger_enabled = true 17 | -------------------------------------------------------------------------------- /marine/tests/config_tests/SpecifiedDirConfig.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "dir_without_modules" 2 | total_memory_limit = "Infinity" 3 | 4 | [[module]] 5 | name = "records_passing_effector" 6 | file_name = "records_passing_effector_renamed.wasm" 7 | load_from = "renamed_records_passing" 8 | logger_enabled = true 9 | 10 | [[module]] 11 | name = "records_passing_pure" 12 | load_from = "renamed_records_passing" 13 | random_field = true 14 | logger_enabled = true 15 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/arrays_passing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "arrays-passing-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "arrays_passing_pure" 10 | path = "src/pure.rs" 11 | 12 | [[bin]] 13 | name = "arrays_passing_effector" 14 | path = "src/effector.rs" 15 | 16 | [dependencies] 17 | marine-rs-sdk = "0.14.0" 18 | safe-transmute = "0.11.0" 19 | -------------------------------------------------------------------------------- /examples/greeting_record/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm-greeting-record" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | description = "The greeting module with records for the Fluence network" 6 | edition = "2021" 7 | publish = false 8 | 9 | [[bin]] 10 | name = "greeting-record" 11 | path = "src/main.rs" 12 | 13 | [dependencies] 14 | marine-rs-sdk = { version = "0.14.0", features = ["logger"] } 15 | log = "0.4.8" 16 | 17 | -------------------------------------------------------------------------------- /examples/sqlite/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "sqlite3" 6 | logger_enabled = false 7 | 8 | [module.wasi] 9 | preopened_files = ["/tmp"] 10 | mapped_dirs = { "tmp" = "/tmp" } 11 | 12 | [[module]] 13 | name = "sqlite_test" 14 | logger_enabled = false 15 | 16 | [module.wasi] 17 | preopened_files = ["/tmp"] 18 | mapped_dirs = { "tmp" = "/tmp" } 19 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/memory_limiting/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "memory-limiting-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "memory_limiting_pure" 10 | path = "src/pure.rs" 11 | 12 | [[bin]] 13 | name = "memory_limiting_effector" 14 | path = "src/effector.rs" 15 | 16 | [dependencies] 17 | marine-rs-sdk = "0.14.0" 18 | safe-transmute = "0.11.0" 19 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/records_passing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "records-passing-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "records_passing_effector" 10 | path = "src/effector.rs" 11 | 12 | [[bin]] 13 | name = "records_passing_pure" 14 | path = "src/pure.rs" 15 | 16 | [dependencies] 17 | marine-rs-sdk = "0.14.0" 18 | safe-transmute = "0.11.0" 19 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/arguments_passing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "arguments-passing-test" 3 | version = "0.1.0" 4 | authors = ["Fluence DAO, Clouldless Labs"] 5 | edition = "2021" 6 | publish = false 7 | 8 | [[bin]] 9 | name = "arguments_passing_pure" 10 | path = "src/pure.rs" 11 | 12 | [[bin]] 13 | name = "arguments_passing_effector" 14 | path = "src/effector.rs" 15 | 16 | [dependencies] 17 | marine-rs-sdk = "0.14.0" 18 | safe-transmute = "0.11.0" 19 | -------------------------------------------------------------------------------- /marine-js/npm-package/jest.config.cjs: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | module.exports = { 3 | extensionsToTreatAsEsm: ['.ts'], 4 | moduleNameMapper: { 5 | '^(\\.{1,2}/.*)\\.js$': '$1', 6 | }, 7 | testPathIgnorePatterns: ['dist'], 8 | transform: { 9 | '^.+\\.tsx?$': [ 10 | 'ts-jest', 11 | { 12 | useESM: true, 13 | }, 14 | ], 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /crates/min-it-version/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-min-it-version" 3 | version = "0.3.2" 4 | description = "Fluence Marine interface types minimum supported version checker" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_min_it_version" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | once_cell = "1.16.0" 16 | semver = "1.0.20" 17 | -------------------------------------------------------------------------------- /.config/nextest.toml: -------------------------------------------------------------------------------- 1 | # https://nexte.st/book/configuration.html 2 | [store] 3 | dir = "target/nextest" 4 | 5 | [profile.default] 6 | retries = 0 7 | test-threads = "num-cpus" 8 | threads-required = 1 9 | status-level = "pass" 10 | final-status-level = "fail" 11 | failure-output = "immediate" 12 | success-output = "never" 13 | fail-fast = false 14 | slow-timeout = { period = "60s", terminate-after = 2 } 15 | leak-timeout = "100ms" 16 | 17 | [profile.ci] 18 | [profile.ci.junit] 19 | path = "junit.xml" 20 | -------------------------------------------------------------------------------- /docs/developer-notes.md: -------------------------------------------------------------------------------- 1 | In the Marine we use the following conventions for PR reviewing: 2 | - **Concept ACK** - agree with the idea and overall concept, but haven't reviewed the code changes or tested them, 3 | - **utACK (untested ACK)** - reviewed and agree with the code changes but haven't actually tested them, 4 | - **Tested ACK** - reviewed the code changes and have verified the functionality or a bug fix, 5 | - **NACK** - disagree with the code changes/concept, should be accompanied by an explanation. 6 | -------------------------------------------------------------------------------- /.github/workflows/lint-pr.yml: -------------------------------------------------------------------------------- 1 | name: lint PR 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | 10 | concurrency: 11 | group: "${{ github.workflow }}-${{ github.ref }}" 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | title: 16 | name: Validate PR title 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: amannn/action-semantic-pull-request@v5 20 | env: 21 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | -------------------------------------------------------------------------------- /marine-js/npm-package/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es2015", "dom"], 4 | "outDir": "./dist/", 5 | "target": "ESNext", 6 | "module": "ESNext", 7 | "skipLibCheck": true, 8 | "strict": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "allowJs": true, 11 | "declaration": true, 12 | "moduleResolution": "nodenext" 13 | }, 14 | "exclude": ["node_modules", "dist"], 15 | "include": ["src"] 16 | } 17 | -------------------------------------------------------------------------------- /crates/it-interfaces/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-it-interfaces" 3 | description = "Fluence Marine interface types helper crate" 4 | version = "0.10.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_it_interfaces" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 16 | multimap = "0.8.3" 17 | -------------------------------------------------------------------------------- /examples/ipfs-node/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | ( 5 | cd effector || exit; 6 | cargo run --release -p marine -- build --release; 7 | ) 8 | 9 | ( 10 | cd pure || exit; 11 | cargo run --release -p marine -- build --release; 12 | ) 13 | 14 | rm artifacts/* || true 15 | mkdir -p artifacts 16 | 17 | cp ../../target/wasm32-wasi/release/ipfs_effector.wasm artifacts/ 18 | cp ../../target/wasm32-wasi/release/ipfs_pure.wasm artifacts/ 19 | -------------------------------------------------------------------------------- /examples/motivational-example/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | ( 5 | cd shrek || exit; 6 | cargo run --release -p marine -- build --release; 7 | ) 8 | 9 | ( 10 | cd donkey || exit; 11 | cargo run --release -p marine -- build --release; 12 | ) 13 | 14 | rm -f artifacts/* || true 15 | mkdir -p artifacts 16 | 17 | cp ../../target/wasm32-wasi/release/shrek.wasm artifacts/ 18 | cp ../../target/wasm32-wasi/release/donkey.wasm artifacts/ 19 | -------------------------------------------------------------------------------- /examples/records/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | ( 5 | cd effector || exit; 6 | cargo run --release -p marine -- build --release; 7 | ) 8 | 9 | ( 10 | cd pure || exit; 11 | cargo run --release -p marine -- build --release; 12 | ) 13 | 14 | rm artifacts/* || true 15 | mkdir -p artifacts 16 | 17 | cp ../../target/wasm32-wasi/release/records_effector.wasm artifacts/ 18 | cp ../../target/wasm32-wasi/release/records_pure.wasm artifacts/ 19 | -------------------------------------------------------------------------------- /examples/url-downloader/Config.toml: -------------------------------------------------------------------------------- 1 | modules_dir = "artifacts/" 2 | total_memory_limit = "10 MiB" 3 | 4 | [[module]] 5 | name = "local_storage" 6 | logger_enabled = true 7 | 8 | [module.wasi] 9 | preopened_files = ["./sites"] 10 | # this is where files will be stored 11 | mapped_dirs = { "sites" = "./sites" } 12 | 13 | [[module]] 14 | name = "curl_adapter" 15 | logger_enabled = true 16 | 17 | [module.mounted_binaries] 18 | curl = "/usr/bin/curl" 19 | 20 | [[module]] 21 | name = "facade" 22 | logger_enabled = true 23 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-wasm-backend-traits" 3 | description = "Fluence Marine generic Wasm backend interface" 4 | version = "0.7.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 12 | it-memory-traits = "0.5.0" 13 | 14 | thiserror = "1.0.50" 15 | anyhow = "1.0.75" 16 | wasmparser = "0.101.1" 17 | paste = "1.0.14" 18 | multimap = "0.8.3" 19 | futures = "0.3.29" 20 | -------------------------------------------------------------------------------- /crates/it-json-serde/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "it-json-serde" 3 | description = "Fluence Marine interface-types serde tools" 4 | version = "0.6.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "it_json_serde" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 16 | 17 | serde = { version = "1.0.147", features = ["derive"] } 18 | serde_json = "1.0.107" 19 | serde_derive = "1.0.147" 20 | thiserror = "1.0.50" 21 | -------------------------------------------------------------------------------- /.github/workflows/e2e-label.yml: -------------------------------------------------------------------------------- 1 | name: "e2e label" 2 | 3 | on: 4 | pull_request_review: 5 | types: [submitted] 6 | 7 | concurrency: 8 | group: "${{ github.workflow }}-${{ github.ref }}" 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | label: 13 | name: "Add e2e label to approved PR" 14 | if: github.event.review.state == 'approved' 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Label when approved 18 | uses: pullreminders/label-when-approved-action@v1.0.7 19 | env: 20 | APPROVALS: "1" 21 | GITHUB_TOKEN: ${{ secrets.FLUENCEBOT_RELEASE_PLEASE_PAT }} 22 | ADD_LABEL: "e2e" 23 | -------------------------------------------------------------------------------- /.github/release-please/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "crates/fluence-app-service": "0.36.0", 3 | "crates/it-generator": "0.18.0", 4 | "crates/it-interfaces": "0.10.0", 5 | "crates/it-json-serde": "0.6.0", 6 | "crates/it-parser": "0.17.0", 7 | "crates/min-it-version": "0.3.2", 8 | "crates/module-info-parser": "0.16.0", 9 | "crates/module-interface": "0.9.0", 10 | "crates/utils": "0.5.1", 11 | "crates/wasm-backend-traits": "0.7.0", 12 | "crates/wasmtime-backend": "0.7.0", 13 | "core": "0.31.0", 14 | "marine": "0.37.0", 15 | "tools/cli": "0.20.1", 16 | "tools/repl": "0.31.0", 17 | "marine-js": "0.14.0", 18 | "crates/js-backend": "0.4.1" 19 | } 20 | -------------------------------------------------------------------------------- /examples/url-downloader/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script builds all subprojects and puts all created Wasm modules in one dir 4 | ( 5 | cd local_storage || exit; 6 | cargo run --release -p marine -- build --release; 7 | ) 8 | 9 | ( 10 | cd curl_adapter || exit; 11 | cargo run --release -p marine -- build --release; 12 | ) 13 | 14 | ( 15 | cd facade || exit; 16 | cargo run --release -p marine -- build --release; 17 | ) 18 | 19 | rm -f artifacts/* || true 20 | mkdir -p artifacts 21 | 22 | cp ../../target/wasm32-wasi/release/local_storage.wasm artifacts/ 23 | cp ../../target/wasm32-wasi/release/curl_adapter.wasm artifacts/ 24 | cp ../../target/wasm32-wasi/release/facade.wasm artifacts/ 25 | -------------------------------------------------------------------------------- /crates/module-interface/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-module-interface" 3 | description = "Fluence Marine module interface" 4 | version = "0.9.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_module_interface" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | marine-it-interfaces = { path = "../it-interfaces", version = "0.10.0" } 16 | 17 | anyhow = "1.0.75" 18 | walrus = "0.20.1" 19 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 20 | nom = "7.1.3" 21 | 22 | itertools = "0.10.5" 23 | semver = "1.0.20" 24 | serde = "1.0.147" 25 | thiserror = "1.0.50" 26 | -------------------------------------------------------------------------------- /crates/it-generator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-it-generator" 3 | description = "Fluence Marine interface types generator" 4 | version = "0.18.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_it_generator" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | marine-it-parser = { path = "../it-parser", version = "0.17.0" } 16 | marine-macro-impl = "0.14.0" 17 | 18 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 19 | it-lilo = "0.7.0" 20 | 21 | thiserror = "1.0.50" 22 | walrus = "0.20.1" 23 | once_cell = "1.16.0" 24 | serde = { version = "1.0.147", features = ["derive"] } 25 | serde_json = "1.0.107" 26 | -------------------------------------------------------------------------------- /crates/module-info-parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-module-info-parser" 3 | description = "Fluence Marine Wasm module info (manifest and version) parser" 4 | version = "0.16.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_module_info_parser" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | marine-rs-sdk-main = { version = "0.14.0", default-features = false } 16 | 17 | marine-wasm-backend-traits = { path = "../wasm-backend-traits", version = "0.7.0" } 18 | 19 | anyhow = "1.0.75" 20 | chrono = "0.4.31" 21 | walrus = "0.20.1" 22 | semver = "1.0.20" 23 | derivative = "2.2.0" 24 | serde = "1.0.147" 25 | thiserror = "1.0.50" 26 | -------------------------------------------------------------------------------- /crates/js-backend/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-js-backend" 3 | version = "0.4.1" 4 | edition = "2021" 5 | description = "Fluence Marine Wasm backend interface implementation for JS environment" 6 | authors = ["Fluence DAO, Clouldless Labs"] 7 | repository = "https://github.com/fluencelabs/marine" 8 | license = "AGPL-3.0-only" 9 | 10 | [dependencies] 11 | marine-wasm-backend-traits = {path = "../wasm-backend-traits", version = "0.7.0" } 12 | it-memory-traits = "0.5.0" 13 | 14 | wasm-bindgen = "0.2.84" 15 | wasm-bindgen-futures = "0.4.38" 16 | serde-wasm-bindgen = "0.5.0" 17 | js-sys = "0.3.61" 18 | web-sys = { version = "0.3.61", features = ["console"] } 19 | anyhow = "1.0.75" 20 | paste = "1.0.14" 21 | maplit = "1.0.2" 22 | log = "0.4.20" 23 | typed-index-collections = "3.1.0" 24 | derive_more = "0.99.17" 25 | wasmparser = "0.110.0" 26 | futures = "0.3.29" 27 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/impl_utils.rs: -------------------------------------------------------------------------------- 1 | pub use multimap::MultiMap; 2 | 3 | pub fn custom_sections(bytes: &[u8]) -> Result>, String> { 4 | use wasmparser::Parser; 5 | use wasmparser::Payload; 6 | 7 | Parser::new(0) 8 | .parse_all(bytes) 9 | .filter_map(|payload| { 10 | let payload = match payload { 11 | Ok(payload) => payload, 12 | Err(e) => return Some(Err(e.to_string())), 13 | }; 14 | match payload { 15 | Payload::CustomSection(reader) => { 16 | let name = reader.name().to_string(); 17 | let data = reader.data().to_vec(); 18 | Some(Ok((name, data))) 19 | } 20 | _ => None, 21 | } 22 | }) 23 | .collect() 24 | } 25 | -------------------------------------------------------------------------------- /crates/it-parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-it-parser" 3 | description = "Fluence Marine interface types parser" 4 | version = "0.17.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_it_parser" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | marine-it-interfaces = { path = "../it-interfaces", version = "0.10.0" } 16 | marine-module-interface = { path = "../module-interface", version = "0.9.0" } 17 | marine-wasm-backend-traits = { path = "../wasm-backend-traits", version = "0.7.0" } 18 | 19 | anyhow = "1.0.75" 20 | walrus = "0.20.1" 21 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 22 | nom = "7.1" 23 | 24 | itertools = "0.10.5" 25 | semver = "1.0.20" 26 | serde = "1.0.147" 27 | thiserror = "1.0.50" 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/*.rs.bk 3 | .idea 4 | node_modules/ 5 | 6 | # MacOS misc file 7 | *.DS_Store 8 | 9 | # Wasm files 10 | *.wasm 11 | *.wat 12 | 13 | # REPL history files 14 | *.repl_history 15 | 16 | # marine-js tmp files 17 | /marine-js/marine-js-pkg 18 | 19 | # local storage of the url-downloader service 20 | /examples/url-downloader/sites/* 21 | 22 | # Allowed Wasm files for examples 23 | !/examples/call_parameters/artifacts/*.wasm 24 | !/examples/greeting/artifacts/*.wasm 25 | !/examples/ipfs-node/artifacts/*.wasm 26 | !/examples/records/artifacts/*.wasm 27 | !/examples/sqlite/artifacts/sqlite_test.wasm 28 | !/examples/url-downloader/artifacts/*.wasm 29 | 30 | # Allowed Wasm files for test 31 | !/fluence-faas/tests/wasm_tests/arguments_passing/artifacts/*.wasm 32 | !/fluence-faas/tests/wasm_tests/arrays_passing/artifacts/*.wasm 33 | !/fluence-faas/tests/wasm_tests/records_passing/artifacts/*.wasm 34 | -------------------------------------------------------------------------------- /crates/wasmtime-backend/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-wasmtime-backend" 3 | description = "Fluence Marine Wasm backend interface implementation for Wasmtime" 4 | version = "0.7.0" 5 | edition = "2021" 6 | authors = ["Fluence DAO, Clouldless Labs"] 7 | repository = "https://github.com/fluencelabs/marine" 8 | license = "AGPL-3.0-only" 9 | 10 | [dependencies] 11 | marine-wasm-backend-traits = {path = "../wasm-backend-traits", version = "0.7.0" } 12 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 13 | it-memory-traits = "0.5.0" 14 | 15 | # all default features except async 16 | wasmtime = {version = "13.0.0", default-features = false, features = ["cache", "wat", "jitdump", "parallel-compilation", "cranelift", "pooling-allocator", "vtune"]} 17 | wasmtime-wasi = "13.0.0" 18 | multimap = "0.8.3" 19 | paste = "1.0.14" 20 | anyhow = "1.0.75" 21 | log = "0.4.20" 22 | futures = "0.3.29" 23 | -------------------------------------------------------------------------------- /.github/release-please/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap-sha": "58c74be12e952ecacc504e17c1f066aa3681be66", 3 | "release-type": "rust", 4 | "bump-minor-pre-major": true, 5 | "bump-patch-for-minor-pre-major": true, 6 | "plugins": [ 7 | { 8 | "type": "cargo-workspace", 9 | "merge": false 10 | } 11 | ], 12 | "packages": { 13 | "crates/fluence-app-service": {}, 14 | "crates/it-generator": {}, 15 | "crates/it-interfaces": {}, 16 | "crates/it-json-serde": {}, 17 | "crates/it-parser": {}, 18 | "crates/min-it-version": {}, 19 | "crates/module-info-parser": {}, 20 | "crates/module-interface": {}, 21 | "crates/utils": {}, 22 | "crates/wasm-backend-traits": {}, 23 | "crates/wasmtime-backend": {}, 24 | "core": {}, 25 | "marine": {}, 26 | "tools/cli": {}, 27 | "tools/repl": {}, 28 | "marine-js": { 29 | "component": "marine-js" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /marine-js/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-js" 3 | version = "0.14.0" 4 | edition = "2021" 5 | description = "Web version of the marine runtime" 6 | publish = false 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | [lib] 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | marine-js-backend = {path = "../crates/js-backend", version = "0.4.1" } 14 | marine-runtime = {path = "../marine", default-features = false} 15 | marine-wasm-backend-traits = {path = "../crates/wasm-backend-traits", version = "0.7.0" } 16 | 17 | wasm-bindgen = "0.2.86" 18 | once_cell = "1.18.0" 19 | wasm-bindgen-futures = "0.4.38" 20 | serde = { version = "1.0.159", features = ["derive"] } 21 | serde_json = "1.0.107" 22 | serde-wasm-bindgen = "0.5.0" 23 | maplit = "1.0.2" 24 | web-sys = {version = "0.3.61", features = ["console"]} 25 | js-sys = "0.3.63" 26 | wasm-bindgen-console-logger = "0.1.1" 27 | log = "0.4.20" 28 | -------------------------------------------------------------------------------- /crates/utils/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.5.1](https://github.com/fluencelabs/marine/compare/marine-utils-v0.5.0...marine-utils-v0.5.1) (2024-01-07) 4 | 5 | 6 | ### Bug Fixes 7 | 8 | * **docs:** add correct repository link for every published crate ([#403](https://github.com/fluencelabs/marine/issues/403)) ([ebb0bcb](https://github.com/fluencelabs/marine/commit/ebb0bcb1d15d37e8b5c10096ce42171a87abe0fa)) 9 | 10 | ## [0.5.0](https://github.com/fluencelabs/marine/compare/marine-utils-v0.4.0...marine-utils-v0.5.0) (2023-03-14) 11 | 12 | 13 | ### ⚠ BREAKING CHANGES 14 | 15 | * decouple wasmer from Marine, replace it with generic backend interface ([#219](https://github.com/fluencelabs/marine/issues/219)) 16 | 17 | ### Features 18 | 19 | * decouple wasmer from Marine, replace it with generic backend interface ([#219](https://github.com/fluencelabs/marine/issues/219)) ([d3a773d](https://github.com/fluencelabs/marine/commit/d3a773df4f7ec80ab8146f68922802a4b9a450d0)) 20 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/**" 7 | - ".github/renovate.json" 8 | 9 | concurrency: 10 | group: "${{ github.workflow }}-${{ github.ref }}" 11 | cancel-in-progress: true 12 | 13 | jobs: 14 | reviewdog: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | 20 | - name: Lint actions 21 | uses: reviewdog/action-actionlint@v1 22 | env: 23 | SHELLCHECK_OPTS: "-e SC2086 -e SC2207 -e SC2128" 24 | with: 25 | reporter: github-pr-check 26 | fail_on_error: true 27 | 28 | renovate: 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v4 33 | 34 | - name: Renovate Config Validator 35 | uses: tj-actions/renovate-config-validator@v2 36 | with: 37 | config_file: .github/renovate.json 38 | -------------------------------------------------------------------------------- /examples/failing/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | use marine_rs_sdk::module_manifest; 22 | 23 | module_manifest!(); 24 | 25 | pub fn main() {} 26 | 27 | #[marine] 28 | pub fn failing() { 29 | unreachable!() 30 | } 31 | -------------------------------------------------------------------------------- /crates/fluence-app-service/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fluence-app-service" 3 | description = "Fluence Application Service" 4 | version = "0.36.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | marine-runtime = { path = "../../marine", version = "0.37.0" } 12 | marine-min-it-version = { path = "../../crates/min-it-version", version = "0.3.2" } 13 | marine-wasm-backend-traits = {path = "../wasm-backend-traits", version = "0.7.0" } 14 | marine-wasmtime-backend = { path = "../wasmtime-backend", version = "0.7.0", optional = true } 15 | 16 | maplit = "1.0.2" 17 | log = "0.4.20" 18 | serde = "1.0.147" 19 | serde_derive = "1.0.147" 20 | serde_json = "1.0.107" 21 | toml = "0.5.9" 22 | 23 | [features] 24 | default = ["wasmtime"] 25 | raw-module-api = ["marine-runtime/raw-module-api"] 26 | wasmtime = ["marine-runtime/marine-wasmtime-backend", "dep:marine-wasmtime-backend"] 27 | -------------------------------------------------------------------------------- /examples/motivational-example/donkey/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | 22 | use marine_rs_sdk::marine; 23 | 24 | fn main() {} 25 | 26 | #[marine] 27 | pub fn greeting(name: &str) -> String { 28 | format!("Donkey: hi, {}", name) 29 | } 30 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/wasi/src/effector.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(clippy::all)] 21 | 22 | use marine_rs_sdk::marine; 23 | 24 | fn main() {} 25 | 26 | #[marine] 27 | pub fn read_from_mapped_dir() -> Vec { 28 | std::fs::read("/some_dir/some_file").unwrap() 29 | } 30 | -------------------------------------------------------------------------------- /examples/greeting/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | use marine_rs_sdk::module_manifest; 22 | 23 | module_manifest!(); 24 | 25 | pub fn main() {} 26 | 27 | #[marine] 28 | pub fn greeting(name: String) -> String { 29 | format!("Hi, {}", name) 30 | } 31 | -------------------------------------------------------------------------------- /marine/src/host_imports/logger/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod logger_filter; 21 | mod log_utf8_string_impl; 22 | 23 | pub use marine_rs_sdk_main::WASM_LOG_ENV_NAME; 24 | 25 | pub(crate) use logger_filter::LoggerFilter; 26 | pub(crate) use log_utf8_string_impl::log_utf8_string_closure; 27 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v0/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | 22 | pub fn main() {} 23 | 24 | #[marine] 25 | pub fn call_parameters() -> String { 26 | let cp = marine_rs_sdk::get_call_parameters(); 27 | serde_json::to_string(&cp).unwrap() 28 | } 29 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v1/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | 22 | pub fn main() {} 23 | 24 | #[marine] 25 | pub fn call_parameters() -> String { 26 | let cp = marine_rs_sdk::get_call_parameters(); 27 | serde_json::to_string(&cp).unwrap() 28 | } 29 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v2/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | 22 | pub fn main() {} 23 | 24 | #[marine] 25 | pub fn call_parameters() -> String { 26 | let cp = marine_rs_sdk::get_call_parameters(); 27 | serde_json::to_string(&cp).unwrap() 28 | } 29 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/call_parameters_v3/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | 22 | pub fn main() {} 23 | 24 | #[marine] 25 | pub fn call_parameters() -> String { 26 | let cp = marine_rs_sdk::get_call_parameters(); 27 | serde_json::to_string(&cp).unwrap() 28 | } 29 | -------------------------------------------------------------------------------- /crates/it-json-serde/src/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use thiserror::Error; 21 | 22 | //TODO: use enum with strict errors instead of String 23 | #[derive(Debug, Error)] 24 | pub enum ITJsonSeDeError { 25 | #[error("{0}")] 26 | Se(String), 27 | 28 | #[error("{0}")] 29 | De(String), 30 | } 31 | -------------------------------------------------------------------------------- /core/src/misc/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod errors; 21 | mod version_checker; 22 | 23 | pub(crate) use errors::PrepareError; 24 | pub(crate) use version_checker::check_sdk_version; 25 | pub(crate) use version_checker::check_it_version; 26 | 27 | type PrepareResult = std::result::Result; 28 | -------------------------------------------------------------------------------- /crates/module-interface/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![warn(rust_2018_idioms)] 21 | #![deny( 22 | dead_code, 23 | nonstandard_style, 24 | unused_imports, 25 | unused_mut, 26 | unused_variables, 27 | unused_unsafe, 28 | unreachable_patterns 29 | )] 30 | 31 | pub mod interface; 32 | pub mod it_interface; 33 | -------------------------------------------------------------------------------- /crates/js-backend/src/wasi/js_imports.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use wasm_bindgen::prelude::*; 21 | 22 | #[wasm_bindgen(module = "/js/wasi_bindings.js")] 23 | extern "C" { 24 | pub fn create_wasi(env: JsValue) -> JsValue; 25 | pub fn generate_wasi_imports(module: &JsValue, wasi: &JsValue) -> JsValue; 26 | pub fn bind_to_instance(wasi: &JsValue, memory: &JsValue); 27 | } 28 | -------------------------------------------------------------------------------- /crates/it-interfaces/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #![warn(rust_2018_idioms)] 20 | #![deny( 21 | dead_code, 22 | nonstandard_style, 23 | unused_imports, 24 | unused_mut, 25 | unused_variables, 26 | unused_unsafe, 27 | unreachable_patterns 28 | )] 29 | 30 | mod errors; 31 | mod mit_interfaces; 32 | 33 | pub use errors::*; 34 | pub use self::mit_interfaces::*; 35 | -------------------------------------------------------------------------------- /marine/tests/utils.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #[macro_export] 21 | macro_rules! call_faas { 22 | ($faas:expr, $module_name:expr, $func_name:expr, $args:expr) => { 23 | $faas 24 | .call_with_json_async($module_name, $func_name, $args, <_>::default()) 25 | .await 26 | .unwrap_or_else(|e| panic!("faas failed with {:?}", e)) 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /crates/js-backend/js/wasi_bindings.js: -------------------------------------------------------------------------------- 1 | import { WASI } from "@wasmer/wasi" 2 | import { WasmFs } from "@wasmer/wasmfs" 3 | import bindingsRaw from '@wasmer/wasi/lib/bindings/browser.js'; 4 | import { defaultImport } from 'default-import'; 5 | 6 | const bindings = defaultImport(bindingsRaw); 7 | 8 | export function create_wasi(env) { 9 | return new WASI({ 10 | args: [], // TODO: pass args maybe? 11 | env: Object.fromEntries(env), 12 | bindings: { 13 | ...bindings, 14 | fs: new WasmFs().fs, 15 | }, 16 | }) 17 | } 18 | 19 | export function generate_wasi_imports(module, wasi) { 20 | return hasWasiImports(module) ? wasi.getImports(module) : {}; 21 | } 22 | 23 | export function bind_to_instance(wasi, instance) { 24 | wasi.setMemory(instance.exports["memory"]); 25 | } 26 | 27 | function hasWasiImports(module) { 28 | const imports = WebAssembly.Module.imports(module); 29 | const firstWasiImport = imports.find((x) => { 30 | return x.module === 'wasi_snapshot_preview1' || x.module === 'wasi_unstable'; 31 | }); 32 | return firstWasiImport !== undefined; 33 | } 34 | -------------------------------------------------------------------------------- /core/src/host_imports/lifting/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /// Contain functions intended to create (lift) IValues from raw WValues (Wasm types). 21 | 22 | mod li_helper; 23 | mod lift_ivalues; 24 | 25 | pub(crate) use li_helper::LiHelper; 26 | pub(crate) use lift_ivalues::wvalues_to_ivalues; 27 | 28 | use super::WValue; 29 | use super::WType; 30 | use super::HostImportError; 31 | use super::HostImportResult; 32 | -------------------------------------------------------------------------------- /crates/module-interface/src/interface/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::it_interface::ITInterfaceError; 21 | use thiserror::Error as ThisError; 22 | 23 | #[derive(Debug, ThisError)] 24 | pub enum InterfaceError { 25 | #[error("record type with type id {0} not found")] 26 | NotFoundRecordTypeId(u64), 27 | 28 | #[error(transparent)] 29 | ITInterfaceError(#[from] ITInterfaceError), 30 | } 31 | -------------------------------------------------------------------------------- /tools/cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine" 3 | description = "Fluence Marine command line tool" 4 | version = "0.20.1" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [[bin]] 11 | name = "marine" 12 | path = "src/main.rs" 13 | 14 | [dependencies] 15 | marine-it-generator = { path = "../../crates/it-generator", version = "0.18.0" } 16 | marine-it-parser = { path = "../../crates/it-parser", version = "0.17.0" } 17 | marine-module-info-parser = { path = "../../crates/module-info-parser", version = "0.16.0" } 18 | 19 | cargo_toml = "0.15.2" 20 | cargo-lock = "8.0.3" 21 | cargo_metadata = "0.15.4" 22 | semver = "1.0.20" 23 | walrus = "0.20.1" 24 | Inflector = "0.11.4" 25 | toml = "0.7.2" 26 | atty = "0.2.14" 27 | thiserror = "1.0.50" 28 | anyhow = "1.0.75" 29 | check-latest = { version = "1.0.2", optional = true } 30 | clap = "2.34.0" 31 | exitfailure = "0.5.1" 32 | serde = "1.0.147" 33 | serde_json = "1.0.107" 34 | crossterm = "0.27.0" 35 | log = "0.4.20" 36 | env_logger = "0.10.0" 37 | 38 | [features] 39 | check-latest = ["dep:check-latest"] 40 | -------------------------------------------------------------------------------- /core/src/host_imports/lowering/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /// Contain functions intended to put (lower) IValues to Wasm memory 21 | /// and pass it to a Wasm module as raw WValues (Wasm types). 22 | mod lo_helper; 23 | mod lower_ivalues; 24 | 25 | pub(crate) use lo_helper::LoHelper; 26 | pub(crate) use lower_ivalues::ivalue_to_wvalues; 27 | 28 | use super::WValue; 29 | use super::AllocateFunc; 30 | use super::HostImportResult; 31 | -------------------------------------------------------------------------------- /crates/utils/src/wasm_mem_pages_conversion.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | pub const WASM_PAGE_SIZE: u32 = 65356; 21 | 22 | pub fn bytes_to_wasm_pages_ceil(offset: u32) -> u32 { 23 | match offset { 24 | 0 => 0, 25 | // ceiling 26 | n => 1 + (n - 1) / WASM_PAGE_SIZE, 27 | } 28 | } 29 | 30 | pub fn wasm_pages_to_bytes(pages_count: u32) -> u64 { 31 | (pages_count as u64) * (WASM_PAGE_SIZE as u64) 32 | } 33 | -------------------------------------------------------------------------------- /crates/module-info-parser/src/sdk_version/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod errors; 21 | mod version_embedder; 22 | mod version_extractor; 23 | 24 | pub use errors::SDKVersionError; 25 | pub use version_extractor::extract_from_path; 26 | pub use version_extractor::extract_from_module; 27 | pub use version_extractor::extract_from_compiled_module; 28 | pub use version_embedder::embed_from_path; 29 | pub use version_embedder::embed_from_module; 30 | -------------------------------------------------------------------------------- /marine-js/src/global_state.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_js_backend::JsWasmBackend; 21 | use marine::generic::Marine; 22 | 23 | use once_cell::sync::Lazy; 24 | 25 | use std::cell::RefCell; 26 | use std::sync::Mutex; 27 | 28 | thread_local!(pub(crate) static MARINE_OLD: RefCell>> = RefCell::new(None)); 29 | pub(crate) static MARINE: Lazy>>> = 30 | Lazy::new(|| Mutex::new(None)); 31 | -------------------------------------------------------------------------------- /marine/src/host_imports/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | pub(crate) mod logger; 21 | mod call_parameters; 22 | mod mounted_binaries; 23 | 24 | pub(crate) use call_parameters::create_call_parameters_import; 25 | pub(crate) use call_parameters::call_parameters_v3_to_v0; 26 | pub(crate) use call_parameters::call_parameters_v3_to_v1; 27 | pub(crate) use call_parameters::call_parameters_v3_to_v2; 28 | pub(crate) use mounted_binaries::create_mounted_binary_import; 29 | -------------------------------------------------------------------------------- /crates/module-info-parser/src/manifest/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod errors; 21 | mod manifest_extractor; 22 | mod module_manifest; 23 | #[cfg(test)] 24 | mod tests; 25 | 26 | pub use errors::ManifestError; 27 | pub use manifest_extractor::extract_from_path; 28 | pub use manifest_extractor::extract_from_module; 29 | pub use manifest_extractor::extract_from_compiled_module; 30 | pub use manifest_extractor::extract_from_bytes; 31 | pub use module_manifest::ModuleManifest; 32 | -------------------------------------------------------------------------------- /examples/call_parameters/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::CallParameters; 21 | #[cfg(target_arch = "wasm32")] 22 | use marine_rs_sdk::marine; 23 | #[cfg(target_arch = "wasm32")] 24 | use marine_rs_sdk::module_manifest; 25 | 26 | #[cfg(target_arch = "wasm32")] 27 | module_manifest!(); 28 | 29 | pub fn main() {} 30 | 31 | #[marine] 32 | #[cfg(target_arch = "wasm32")] 33 | pub fn call_parameters() -> CallParameters { 34 | marine_rs_sdk::get_call_parameters() 35 | } 36 | -------------------------------------------------------------------------------- /crates/fluence-app-service/src/config.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine::generic::MarineConfig; 21 | 22 | use std::path::PathBuf; 23 | use marine_wasm_backend_traits::WasmBackend; 24 | 25 | /// Describes behaviour of the Fluence AppService. 26 | #[derive(Default)] 27 | pub struct AppServiceConfig { 28 | /// Used for preparing filesystem on the service initialization stage. 29 | pub service_working_dir: PathBuf, 30 | pub marine_config: MarineConfig, 31 | } 32 | -------------------------------------------------------------------------------- /examples/records/test-record/src/test_record.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | 22 | #[marine] 23 | pub struct TestRecord { 24 | pub field_0: bool, 25 | pub field_1: i8, 26 | pub field_2: i16, 27 | pub field_3: i32, 28 | pub field_4: i64, 29 | pub field_5: u8, 30 | pub field_6: u16, 31 | pub field_7: u32, 32 | pub field_8: u64, 33 | pub field_9: f32, 34 | pub field_10: f64, 35 | pub field_11: String, 36 | pub field_12: Vec, 37 | } 38 | -------------------------------------------------------------------------------- /marine-js/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod api; 21 | mod global_state; 22 | mod logger; 23 | 24 | use crate::logger::MarineLogger; 25 | 26 | use wasm_bindgen::prelude::*; 27 | 28 | #[wasm_bindgen(start)] 29 | fn main() { 30 | log::set_boxed_logger(Box::new(MarineLogger::new(log::LevelFilter::Info))).unwrap(); 31 | // Trace is required to accept all logs from a service. 32 | // Max level for this crate is set in MarineLogger constructor. 33 | log::set_max_level(log::LevelFilter::Trace); 34 | } 35 | -------------------------------------------------------------------------------- /crates/it-parser/src/custom.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use walrus::CustomSection; 21 | use walrus::IdsToIndices; 22 | 23 | use std::borrow::Cow; 24 | 25 | pub const IT_SECTION_NAME: &str = "interface-types"; 26 | 27 | #[derive(Debug, Clone)] 28 | pub(super) struct ITCustomSection(pub Vec); 29 | 30 | impl CustomSection for ITCustomSection { 31 | fn name(&self) -> &str { 32 | IT_SECTION_NAME 33 | } 34 | 35 | fn data(&self, _ids_to_indices: &IdsToIndices) -> Cow<'_, [u8]> { 36 | Cow::Borrowed(&self.0) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tools/repl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mrepl" 3 | description = "Fluence Marine REPL intended for testing purposes" 4 | version = "0.31.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [[bin]] 11 | name = "mrepl" 12 | path = "src/main.rs" 13 | 14 | [dependencies] 15 | fluence-app-service = { path = "../../crates/fluence-app-service", version = "0.36.0", features = ["raw-module-api"] } 16 | marine-rs-sdk-main = { version = "0.14.0", default-features = false, features = ["logger"] } 17 | marine-wasm-backend-traits = {path = "../../crates/wasm-backend-traits", version = "0.7.0" } 18 | marine-wasmtime-backend = { version = "0.7.0", path = "../../crates/wasmtime-backend" } 19 | 20 | anyhow = "1.0.75" 21 | clap = "2.34.0" 22 | serde = "1.0.147" 23 | serde_json = "1.0.107" 24 | tokio = { version = "1.33.0", features = ["rt", "macros"] } 25 | 26 | env_logger = "0.10.0" 27 | check-latest = { version = "1.0.2", optional = true } 28 | log = "0.4.20" 29 | rustyline = { version = "10.0.0" } 30 | rustyline-derive = "0.7.0" 31 | rustop = "1.1.2" 32 | itertools = "0.10.5" 33 | uuid = { version = "1.4.0", features = ["v4"] } 34 | crossterm = "0.27.0" 35 | 36 | [features] 37 | check-latest = ["dep:check-latest"] 38 | -------------------------------------------------------------------------------- /crates/min-it-version/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.3.2](https://github.com/fluencelabs/marine/compare/marine-min-it-version-v0.3.1...marine-min-it-version-v0.3.2) (2024-01-07) 4 | 5 | 6 | ### Bug Fixes 7 | 8 | * **docs:** add correct repository link for every published crate ([#403](https://github.com/fluencelabs/marine/issues/403)) ([ebb0bcb](https://github.com/fluencelabs/marine/commit/ebb0bcb1d15d37e8b5c10096ce42171a87abe0fa)) 9 | 10 | ## [0.3.1](https://github.com/fluencelabs/marine/compare/marine-min-it-version-v0.3.0...marine-min-it-version-v0.3.1) (2023-11-07) 11 | 12 | 13 | ### Features 14 | 15 | * **deps:** update rust crate semver to 1.0.20 ([7b666ae](https://github.com/fluencelabs/marine/commit/7b666aeb40590cccda2d9a542024cf0928d9b2fa)) 16 | 17 | ## [0.3.0](https://github.com/fluencelabs/marine/compare/marine-min-it-version-v0.2.1...marine-min-it-version-v0.3.0) (2023-03-14) 18 | 19 | 20 | ### ⚠ BREAKING CHANGES 21 | 22 | * decouple wasmer from Marine, replace it with generic backend interface ([#219](https://github.com/fluencelabs/marine/issues/219)) 23 | 24 | ### Features 25 | 26 | * decouple wasmer from Marine, replace it with generic backend interface ([#219](https://github.com/fluencelabs/marine/issues/219)) ([d3a773d](https://github.com/fluencelabs/marine/commit/d3a773df4f7ec80ab8146f68922802a4b9a450d0)) 27 | -------------------------------------------------------------------------------- /examples/motivational-example/shrek/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | 22 | use marine_rs_sdk::marine; 23 | 24 | fn main() {} 25 | 26 | #[marine] 27 | pub fn greeting(name: &str) -> Vec { 28 | let donkey_greeting = donkey::greeting(name); 29 | let shrek_greeting = format!("Shrek: hi, {}", name); 30 | 31 | vec![shrek_greeting, donkey_greeting] 32 | } 33 | 34 | mod donkey { 35 | use super::*; 36 | 37 | #[marine] 38 | #[module_import("donkey")] 39 | extern "C" { 40 | pub fn greeting(name: &str) -> String; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /crates/module-info-parser/src/sdk_version/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use semver::Error as SemVerError; 21 | use thiserror::Error as ThisError; 22 | use std::str::Utf8Error; 23 | 24 | #[derive(Debug, ThisError)] 25 | pub enum SDKVersionError { 26 | /// Version can't be parsed to Utf8 string. 27 | #[error("embedded to the Wasm file version isn't valid UTF8 string: '{0}'")] 28 | VersionNotValidUtf8(Utf8Error), 29 | 30 | /// Version can't be parsed with semver. 31 | #[error("embedded to the Wasm file version is corrupted: '{0}'")] 32 | VersionCorrupted(#[from] SemVerError), 33 | } 34 | -------------------------------------------------------------------------------- /crates/it-generator/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![warn(rust_2018_idioms)] 21 | #![deny( 22 | dead_code, 23 | nonstandard_style, 24 | unused_imports, 25 | unused_mut, 26 | unused_variables, 27 | unused_unsafe, 28 | unreachable_patterns 29 | )] 30 | 31 | mod default_export_api_config; 32 | mod errors; 33 | mod instructions_generator; 34 | mod interface_generator; 35 | 36 | pub use interface_generator::embed_it; 37 | pub use errors::ITGeneratorError; 38 | 39 | pub const TYPE_RESOLVE_RECURSION_LIMIT: u32 = 1024; 40 | 41 | pub(crate) type Result = std::result::Result; 42 | -------------------------------------------------------------------------------- /crates/utils/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![warn(rust_2018_idioms)] 21 | #![deny( 22 | dead_code, 23 | nonstandard_style, 24 | unused_imports, 25 | unused_mut, 26 | unused_variables, 27 | unused_unsafe, 28 | unreachable_patterns 29 | )] 30 | 31 | mod wasm_mem_pages_conversion; 32 | 33 | pub use wasm_mem_pages_conversion::*; 34 | 35 | use std::sync::Arc; 36 | 37 | #[derive(Debug, Clone, PartialEq, Eq, Default, Hash)] 38 | pub struct SharedString(pub Arc); 39 | 40 | impl std::borrow::Borrow for SharedString { 41 | fn borrow(&self) -> &str { 42 | self.0.as_str() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /crates/module-interface/src/it_interface/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_it_interfaces::MITInterfacesError; 21 | use thiserror::Error as ThisError; 22 | 23 | #[derive(Debug, ThisError)] 24 | pub enum ITInterfaceError { 25 | #[error("type with idx = {0} isn't a function type")] 26 | ITTypeNotFunction(u32), 27 | 28 | #[error("record type with type id {0} not found")] 29 | NotFoundRecordTypeId(u64), 30 | 31 | #[error("mailformed module: a record contains more recursion level then allowed")] 32 | TooManyRecursionLevels, 33 | 34 | #[error(transparent)] 35 | MITInterfacesError(#[from] MITInterfacesError), 36 | } 37 | -------------------------------------------------------------------------------- /core/src/host_imports/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod errors; 21 | mod lifting; 22 | mod lowering; 23 | mod imports; 24 | mod utils; 25 | 26 | use marine_wasm_backend_traits::TypedFunc; 27 | 28 | pub use errors::HostImportError; 29 | pub(crate) use imports::create_host_import_func; 30 | 31 | use marine_wasm_backend_traits::WValue; 32 | use marine_wasm_backend_traits::WType; 33 | 34 | type HostImportResult = std::result::Result; 35 | type AllocateFunc = TypedFunc; 36 | 37 | const ALLOCATE_FUNC_NAME: &str = "allocate"; 38 | const SET_PTR_FUNC_NAME: &str = "set_result_ptr"; 39 | const SET_SIZE_FUNC_NAME: &str = "set_result_size"; 40 | -------------------------------------------------------------------------------- /crates/module-info-parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #![warn(rust_2018_idioms)] 20 | #![deny( 21 | dead_code, 22 | nonstandard_style, 23 | unused_imports, 24 | unused_mut, 25 | unused_variables, 26 | unused_unsafe, 27 | unreachable_patterns 28 | )] 29 | 30 | pub mod manifest; 31 | pub mod sdk_version; 32 | pub mod effects; 33 | mod custom_section_extractor; 34 | mod errors; 35 | 36 | pub use errors::ModuleInfoError; 37 | 38 | pub(crate) use custom_section_extractor::extract_custom_sections_by_name; 39 | pub(crate) use custom_section_extractor::try_as_one_section; 40 | 41 | pub(crate) type ModuleInfoResult = std::result::Result; 42 | -------------------------------------------------------------------------------- /crates/it-generator/src/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use thiserror::Error as ThisError; 21 | use serde_json::Error as SerdeDeserializationError; 22 | 23 | #[derive(Debug, ThisError)] 24 | pub enum ITGeneratorError { 25 | /// An error related to serde deserialization. 26 | #[error("Embedded by rust-sdk metadata couldn't be parsed by serde: {0:?}")] 27 | DeserializationError(#[from] SerdeDeserializationError), 28 | 29 | /// Various errors related to records 30 | #[error("{0}")] 31 | CorruptedRecord(String), 32 | 33 | /// Various errors occurred during the parsing/emitting a Wasm file. 34 | #[error("I/O error occurred: {0}")] 35 | IOError(String), 36 | } 37 | -------------------------------------------------------------------------------- /marine/src/config/path_utils.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::MarineError; 21 | use crate::MarineResult; 22 | 23 | use std::path::Path; 24 | use std::path::PathBuf; 25 | 26 | pub fn as_relative_to_base(base: Option<&Path>, path: &Path) -> MarineResult { 27 | if path.is_absolute() { 28 | return Ok(PathBuf::from(path)); 29 | } 30 | 31 | let path = match base { 32 | None => PathBuf::from(path), 33 | Some(base) => base.join(path), 34 | }; 35 | 36 | path.canonicalize().map_err(|e| { 37 | MarineError::IOError(format!( 38 | "Failed to canonicalize path {}: {}", 39 | path.display(), 40 | e 41 | )) 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /tools/repl/src/repl/print_state.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_wasm_backend_traits::WasiState; 21 | 22 | pub(super) fn print_envs(module_name: &str, wasi_state: &dyn WasiState) { 23 | let envs = wasi_state.envs(); 24 | if envs.is_empty() { 25 | println!("{} don't have environment variables", module_name); 26 | return; 27 | } 28 | 29 | println!("Environment variables:"); 30 | for env in envs.iter() { 31 | match String::from_utf8(env.clone()) { 32 | Ok(string) => println!("{}", string), 33 | Err(_) => println!("{:?}", env), 34 | } 35 | } 36 | } 37 | 38 | pub(super) fn print_fs_state(_wasi_state: &dyn WasiState) { 39 | println!("Printing WASI filesystem state is not supported now."); 40 | } 41 | -------------------------------------------------------------------------------- /crates/it-json-serde/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #![warn(rust_2018_idioms)] 20 | #![deny( 21 | dead_code, 22 | nonstandard_style, 23 | unused_imports, 24 | unused_mut, 25 | unused_variables, 26 | unused_unsafe, 27 | unreachable_patterns 28 | )] 29 | mod ivalues_to_json; 30 | mod json_to_ivalues; 31 | mod errors; 32 | 33 | pub type JsonResult = Result; 34 | pub use errors::ITJsonSeDeError; 35 | pub use ivalues_to_json::ivalues_to_json; 36 | pub use json_to_ivalues::json_to_ivalues; 37 | 38 | use std::collections::HashMap; 39 | use std::sync::Arc; 40 | 41 | pub(crate) use wasmer_it::IValue; 42 | pub(crate) use wasmer_it::IType; 43 | pub(crate) use wasmer_it::IRecordType; 44 | pub(crate) type MRecordTypes = HashMap>; 45 | -------------------------------------------------------------------------------- /crates/module-interface/src/interface/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod errors; 21 | mod interface_transformer; 22 | mod itype_to_text; 23 | mod module_interface; 24 | mod records_transformer; 25 | 26 | pub use errors::InterfaceError; 27 | pub use interface_transformer::it_to_module_interface; 28 | pub use itype_to_text::*; 29 | pub use module_interface::*; 30 | 31 | pub type InterfaceResult = std::result::Result; 32 | 33 | use marine_it_interfaces::MITInterfaces; 34 | 35 | /// Returns interface of a Marine module. 36 | pub fn get_interface(mit: &MITInterfaces<'_>) -> InterfaceResult { 37 | let it_interface = crate::it_interface::get_interface(mit)?; 38 | let interface = it_to_module_interface(it_interface)?; 39 | 40 | Ok(interface) 41 | } 42 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contribute Code 2 | 3 | You are welcome to contribute to Fluence! 4 | 5 | Things you need to know: 6 | 7 | 1. You need to **agree to the [Contributor License Agreement](https://gist.github.com/fluencelabs-org/3f4cbb3cc14c1c0fb9ad99d8f7316ed7) (CLA)**. This is a common practice in all major Open Source projects. At the current moment, we are unable to accept contributions made on behalf of a company. Only individual contributions will be accepted. 8 | 9 | 2. **Not all proposed contributions can be accepted**. Some features may, e.g., just fit a third-party add-on better. The contribution must fit the overall direction of Fluence and really improve it. The more effort you invest, the better you should clarify in advance whether the contribution fits: the best way would be to just open an issue to discuss the contribution you plan to make. 10 | 11 | ### Contributor License Agreement 12 | 13 | When you contribute, you have to be aware that your contribution is covered by [GNU Affero General Public License version 3](./LICENSE), but might relicensed under few other software licenses mentioned in the **Contributor License Agreement**. In particular, you need to agree to the Contributor License Agreement. If you agree to its content, you simply have to click on the link posted by the CLA assistant as a comment to the pull request. Click it to check the CLA, then accept it on the following screen if you agree to it. The CLA assistant will save this decision for upcoming contributions and will notify you if there is any change to the CLA in the meantime. -------------------------------------------------------------------------------- /core/src/host_imports/lifting/li_helper.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::MRecordTypes; 21 | use crate::IRecordType; 22 | use it_lilo::traits::RecordResolvable; 23 | use it_lilo::traits::RecordResolvableError; 24 | 25 | use std::sync::Arc; 26 | 27 | pub(crate) struct LiHelper { 28 | record_types: Arc, 29 | } 30 | 31 | impl LiHelper { 32 | pub(crate) fn new(record_types: Arc) -> Self { 33 | Self { record_types } 34 | } 35 | } 36 | 37 | impl RecordResolvable for LiHelper { 38 | fn resolve_record(&self, record_type_id: u64) -> Result<&IRecordType, RecordResolvableError> { 39 | self.record_types 40 | .get(&record_type_id) 41 | .map(|r| r.as_ref()) 42 | .ok_or(RecordResolvableError::RecordNotFound(record_type_id)) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/records/effector/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | use marine_rs_sdk::module_manifest; 22 | 23 | use test_record::TestRecord; 24 | 25 | module_manifest!(); 26 | 27 | pub fn main() {} 28 | 29 | #[marine] 30 | pub fn mutate_struct(mut test_record: test_record::TestRecord) -> TestRecord { 31 | test_record.field_0 = true; 32 | test_record.field_1 = 1; 33 | test_record.field_2 = 2; 34 | test_record.field_3 = 3; 35 | test_record.field_4 = 4; 36 | test_record.field_5 = 5; 37 | test_record.field_6 = 6; 38 | test_record.field_7 = 7; 39 | test_record.field_8 = 8; 40 | test_record.field_9 = 9f32; 41 | test_record.field_10 = 10f64; 42 | test_record.field_11 = "field_11".to_string(); 43 | test_record.field_12 = vec![0x13, 0x37]; 44 | 45 | test_record 46 | } 47 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/memory_limiting/src/effector.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | #![allow(clippy::all)] 22 | #![allow(non_snake_case)] 23 | 24 | use marine_rs_sdk::marine; 25 | 26 | pub fn main() {} 27 | 28 | #[marine] 29 | pub fn allocate_single_module_single_piece(size: i64) -> u32 { 30 | let addr = Vec::::with_capacity(size as usize).leak().as_ptr(); 31 | unsafe { std::mem::transmute::<*const u8, usize>(addr) as u32 } 32 | } 33 | 34 | #[marine] 35 | pub fn allocate_single_module_64KB_pieces(n_pieces: u32) -> u32 { 36 | let mut acc: u32 = 0; 37 | 38 | for _ in 0..n_pieces { 39 | unsafe { 40 | let addr = Box::leak(Box::new([0u8; 1024 * 64])); 41 | acc ^= std::mem::transmute::<*const u8, usize>(addr.as_ptr()) as u32; 42 | } 43 | } 44 | 45 | acc 46 | } 47 | -------------------------------------------------------------------------------- /examples/url-downloader/curl_adapter/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | 22 | use marine_rs_sdk::marine; 23 | use marine_rs_sdk::module_manifest; 24 | 25 | use marine_rs_sdk::WasmLoggerBuilder; 26 | use marine_rs_sdk::MountedBinaryResult; 27 | 28 | module_manifest!(); 29 | 30 | /// Log level can be changed by `RUST_LOG` env as well. 31 | pub fn main() { 32 | WasmLoggerBuilder::new().build().unwrap(); 33 | } 34 | 35 | #[marine] 36 | pub fn download(url: String) -> String { 37 | log::info!("download called with url {}\n", url); 38 | 39 | let result = curl(vec![url]); 40 | 41 | String::from_utf8(result.stdout).unwrap() 42 | } 43 | 44 | /// Permissions in `Config.toml` should exist to use host functions. 45 | #[marine] 46 | #[host_import] 47 | extern "C" { 48 | fn curl(cmd: Vec) -> MountedBinaryResult; 49 | } 50 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/caller.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::AsContextMut; 21 | use crate::FuncGetter; 22 | use crate::WasmBackend; 23 | 24 | /// `ImportCallContext` is a structure used to pass context to imports. 25 | /// It serves as a handle to `Store`, and also provides access to `Memory` and export functions 26 | /// from the caller instance, if there is one. 27 | pub trait ImportCallContext: 28 | FuncGetter 29 | + FuncGetter 30 | + FuncGetter 31 | + FuncGetter 32 | + FuncGetter 33 | + FuncGetter 34 | + AsContextMut 35 | + Sync 36 | { 37 | /// Gets the `Memory` from the caller instance. 38 | /// Returns `None` if function was called directly from host. 39 | fn memory(&mut self, memory_index: u32) -> Option<::Memory>; 40 | } 41 | -------------------------------------------------------------------------------- /examples/records/pure/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | 22 | use marine_rs_sdk::marine; 23 | use marine_rs_sdk::module_manifest; 24 | 25 | use test_record::TestRecord; 26 | 27 | module_manifest!(); 28 | 29 | pub fn main() {} 30 | 31 | #[marine] 32 | pub fn invoke() -> TestRecord { 33 | let test_record = TestRecord { 34 | field_0: false, 35 | field_1: 0, 36 | field_2: 0, 37 | field_3: 0, 38 | field_4: 0, 39 | field_5: 0, 40 | field_6: 0, 41 | field_7: 0, 42 | field_8: 0, 43 | field_9: 0f32, 44 | field_10: 0f64, 45 | field_11: String::new(), 46 | field_12: Vec::new(), 47 | }; 48 | 49 | mutate_struct(test_record) 50 | } 51 | 52 | #[marine] 53 | #[module_import("records_effector")] 54 | extern "C" { 55 | pub fn mutate_struct(test_record: TestRecord) -> TestRecord; 56 | } 57 | -------------------------------------------------------------------------------- /marine/src/config/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod raw_marine_config; 21 | mod to_marine_config; 22 | mod marine_config; 23 | mod path_utils; 24 | 25 | pub use marine_config::ConfigContext; 26 | pub use marine_config::WithContext; 27 | pub use marine_config::MarineModuleConfig; 28 | pub use marine_config::MarineConfig; 29 | pub use marine_config::MarineWASIConfig; 30 | pub use marine_config::ModuleDescriptor; 31 | 32 | pub use raw_marine_config::TomlMarineNamedModuleConfig; 33 | pub use raw_marine_config::TomlWASIConfig; 34 | pub use raw_marine_config::TomlMarineConfig; 35 | pub use raw_marine_config::TomlMarineModuleConfig; 36 | 37 | // reexport toml types, so users don't have to directly depend on the same version of toml crate 38 | pub use toml::Value as TomlValue; 39 | pub use toml::value::Table as TomlValueTable; 40 | 41 | pub(crate) use to_marine_config::make_marine_config; 42 | pub(crate) use path_utils::as_relative_to_base; 43 | -------------------------------------------------------------------------------- /core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-core" 3 | description = "Core of Marine, the Fluence Wasm Runtime" 4 | version = "0.31.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine_core" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | marine-module-info-parser = { path = "../crates/module-info-parser", version = "0.16.0" } 16 | marine-it-interfaces = { path = "../crates/it-interfaces", version = "0.10.0" } 17 | marine-it-parser = { path = "../crates/it-parser", version = "0.17.0" } 18 | marine-it-generator = { path = "../crates/it-generator", version = "0.18.0" } 19 | marine-module-interface = { path = "../crates/module-interface", version = "0.9.0" } 20 | marine-utils = { path = "../crates/utils", version = "0.5.1" } 21 | marine-min-it-version = { path = "../crates/min-it-version", version = "0.3.2" } 22 | marine-wasm-backend-traits = {path = "../crates/wasm-backend-traits", version = "0.7.0" } 23 | marine-wasmtime-backend = { path = "../crates/wasmtime-backend", version = "0.7.0", optional = true} 24 | 25 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 26 | it-lilo = "0.7.0" 27 | it-memory-traits = "0.5.0" 28 | bytesize = "1.2.0" 29 | futures = "0.3.29" 30 | 31 | multimap = "0.8.3" 32 | once_cell = "1.16.0" 33 | semver = "1.0.20" 34 | serde = "1.0.147" 35 | log = "0.4.20" 36 | 37 | paste = "1.0.14" 38 | 39 | anyhow = "1.0.75" 40 | thiserror = "1.0.50" 41 | 42 | [dev-dependencies] 43 | reqwest = "0.11.18" 44 | bytes = "1.3.0" 45 | tokio = { version = "1.22.0", features = ["rt", "macros"] } 46 | once_cell = "1.16.0" 47 | 48 | [features] 49 | default = ["marine-wasmtime-backend"] 50 | -------------------------------------------------------------------------------- /crates/module-interface/src/it_interface/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod errors; 21 | mod export_it_functions; 22 | mod export_it_records; 23 | mod it_module_interface; 24 | 25 | pub use errors::*; 26 | pub use export_it_functions::*; 27 | pub use export_it_records::*; 28 | pub use it_module_interface::*; 29 | 30 | pub type RIResult = std::result::Result; 31 | 32 | use marine_it_interfaces::MITInterfaces; 33 | 34 | /// Returns Marine module interface that includes both export and all record types. 35 | pub fn get_interface(mit: &MITInterfaces<'_>) -> RIResult { 36 | let function_signatures = get_export_funcs(mit)?; 37 | let FullRecordTypes { 38 | record_types, 39 | export_record_types, 40 | } = get_record_types(mit, function_signatures.iter())?; 41 | 42 | let mm_interface = IModuleInterface { 43 | export_record_types, 44 | record_types, 45 | function_signatures, 46 | }; 47 | 48 | Ok(mm_interface) 49 | } 50 | -------------------------------------------------------------------------------- /crates/module-interface/src/it_interface/it_module_interface.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use wasmer_it::IType; 21 | use wasmer_it::ast::FunctionArg as IFunctionArg; 22 | use wasmer_it::IRecordType; 23 | 24 | use serde::Serialize; 25 | use serde::Deserialize; 26 | 27 | use std::collections::HashMap; 28 | use std::sync::Arc; 29 | 30 | pub type IRecordTypes = HashMap>; 31 | 32 | /// Represent a function type inside Marine module. 33 | #[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] 34 | pub struct IFunctionSignature { 35 | pub name: Arc, 36 | pub arguments: Arc>, 37 | pub outputs: Arc>, 38 | pub adapter_function_type: u32, 39 | } 40 | 41 | /// Represent an interface of a Wasm module. 42 | #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] 43 | pub struct IModuleInterface { 44 | pub export_record_types: IRecordTypes, 45 | pub record_types: IRecordTypes, 46 | pub function_signatures: Vec, 47 | } 48 | -------------------------------------------------------------------------------- /examples/greeting_record/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | use marine_rs_sdk::module_manifest; 22 | use marine_rs_sdk::WasmLoggerBuilder; 23 | 24 | module_manifest!(); 25 | 26 | pub fn main() { 27 | WasmLoggerBuilder::new().build().unwrap(); 28 | } 29 | 30 | #[marine] 31 | pub struct GreetingRecord { 32 | pub str: String, 33 | pub num: i32, 34 | } 35 | 36 | #[marine] 37 | pub fn greeting_record() -> GreetingRecord { 38 | GreetingRecord { 39 | str: String::from("Hello, world!"), 40 | num: 42, 41 | } 42 | } 43 | 44 | #[marine] 45 | pub fn log_info() { 46 | log::info!("info"); 47 | } 48 | 49 | #[marine] 50 | pub fn log_warn() { 51 | log::warn!("warn"); 52 | } 53 | 54 | #[marine] 55 | pub fn log_error() { 56 | log::error!("error"); 57 | } 58 | 59 | #[marine] 60 | pub fn log_debug() { 61 | log::debug!("debug"); 62 | } 63 | 64 | #[marine] 65 | pub fn log_trace() { 66 | log::trace!("trace"); 67 | } 68 | 69 | #[marine] 70 | pub fn void_fn() {} 71 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = [ 4 | "core", 5 | "core/tests/wasm_tests/lilo_after_2gb", 6 | "crates/fluence-app-service", 7 | "crates/it-generator", 8 | "crates/it-interfaces", 9 | "crates/it-parser", 10 | "crates/it-json-serde", 11 | "crates/js-backend", 12 | "crates/min-it-version", 13 | "crates/module-info-parser", 14 | "crates/module-interface", 15 | "crates/wasm-backend-traits", 16 | "crates/wasmtime-backend", 17 | "crates/utils", 18 | "examples/call_parameters", 19 | "examples/failing", 20 | "examples/greeting", 21 | "examples/greeting_record", 22 | "examples/ipfs-node/effector", 23 | "examples/ipfs-node/pure", 24 | "examples/motivational-example/donkey", 25 | "examples/motivational-example/shrek", 26 | "examples/records/effector", 27 | "examples/records/pure", 28 | "examples/records/test-record", 29 | "examples/sqlite", 30 | "examples/url-downloader/curl_adapter", 31 | "examples/url-downloader/facade", 32 | "examples/url-downloader/local_storage", 33 | "marine", 34 | "marine/tests/wasm_tests/arguments_passing", 35 | "marine/tests/wasm_tests/arrays_passing", 36 | "marine/tests/wasm_tests/call_parameters_v0", 37 | "marine/tests/wasm_tests/call_parameters_v1", 38 | "marine/tests/wasm_tests/call_parameters_v2", 39 | "marine/tests/wasm_tests/call_parameters_v3", 40 | "marine/tests/wasm_tests/memory_limiting", 41 | "marine/tests/wasm_tests/records_passing", 42 | "marine/tests/wasm_tests/wasi", 43 | "marine-js", 44 | "tools/cli", 45 | "tools/repl", 46 | ] 47 | 48 | [profile.release] 49 | opt-level = 3 50 | debug = false 51 | lto = true 52 | debug-assertions = false 53 | overflow-checks = false 54 | panic = "abort" 55 | -------------------------------------------------------------------------------- /marine/src/module_loading/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::MarineError; 21 | use crate::MarineResult; 22 | 23 | use std::collections::HashMap; 24 | use std::path::PathBuf; 25 | 26 | /// Loads modules from a directory at a given path. Non-recursive, ignores subdirectories. 27 | pub(crate) fn load_modules_from_fs( 28 | modules: &HashMap, 29 | ) -> MarineResult>> { 30 | let loaded = modules 31 | .iter() 32 | .try_fold(HashMap::new(), |mut hash_map, (import_name, path)| { 33 | let module_bytes = std::fs::read(path).map_err(|e| { 34 | MarineError::IOError(format!("failed to load {}: {}", path.display(), e)) 35 | })?; 36 | 37 | if hash_map.insert(import_name.clone(), module_bytes).is_some() { 38 | return Err(MarineError::InvalidConfig(String::from( 39 | "module {} is duplicated in config", 40 | ))); 41 | } 42 | 43 | Ok(hash_map) 44 | })?; 45 | 46 | Ok(loaded) 47 | } 48 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/exports.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | pub static STANDARD_MEMORY_EXPORT_NAME: &str = "memory"; 21 | pub static STANDARD_MEMORY_INDEX: u32 = 0; 22 | 23 | use crate::DelayedContextLifetime; 24 | use crate::WasmBackend; 25 | 26 | /// Contains Wasm exports necessary for internal usage. 27 | #[derive(Clone)] 28 | pub enum Export { 29 | Memory(::Memory), 30 | Function(::ExportFunction), 31 | Other, 32 | } 33 | 34 | // TODO: add read/write/etc methods to the `Memory` trait, 35 | // and then make a generic implementation of interface-types traits 36 | /// A wasm memory handle. 37 | /// As it is only a handle to an object in `Store`, cloning is cheap. 38 | pub trait Memory: 39 | it_memory_traits::Memory<::MemoryView, DelayedContextLifetime> 40 | + Clone 41 | + Send 42 | + Sync 43 | + 'static 44 | { 45 | /// Get the size of the allocated memory in bytes. 46 | fn size(&self, store: &mut ::ContextMut<'_>) -> usize; 47 | } 48 | -------------------------------------------------------------------------------- /examples/ipfs-node/effector/src/path.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | pub(super) fn to_full_path(cmd: S) -> String 21 | where 22 | S: Into, 23 | { 24 | use std::path::Path; 25 | use std::path::Component; 26 | 27 | let cmd = cmd.into(); 28 | let path = Path::new(&cmd); 29 | 30 | let mut components = path.components(); 31 | let is_absolute = components.next() == Some(Component::RootDir); 32 | 33 | if !is_absolute { 34 | return cmd; 35 | } 36 | 37 | let parent = match components.next() { 38 | Some(Component::Normal(path)) => path.to_str().unwrap(), 39 | _ => return cmd, 40 | }; 41 | 42 | match std::env::var(parent) { 43 | Ok(to_dir) => { 44 | let mut full_path = std::path::PathBuf::from(to_dir); 45 | 46 | // TODO: optimize this 47 | #[allow(clippy::while_let_on_iterator)] 48 | while let Some(component) = components.next() { 49 | full_path.push(component); 50 | } 51 | full_path.to_string_lossy().into_owned() 52 | } 53 | Err(_) => cmd, 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /crates/js-backend/src/single_shot_async_executor.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_wasm_backend_traits::WValue; 21 | 22 | use futures::future::BoxFuture; 23 | use futures::task::waker_ref; 24 | use futures::task::ArcWake; 25 | 26 | use std::future::Future; 27 | use std::pin::Pin; 28 | use std::sync::Arc; 29 | use std::task::Context; 30 | use std::task::Poll; 31 | 32 | struct DummyTask(); 33 | impl ArcWake for DummyTask { 34 | fn wake_by_ref(_arc_self: &Arc) {} 35 | } 36 | 37 | pub(crate) fn execute_future_blocking( 38 | mut future: BoxFuture>>, 39 | ) -> anyhow::Result> { 40 | let task = Arc::new(DummyTask()); 41 | let waker = waker_ref(&task); 42 | let context = &mut Context::from_waker(&waker); 43 | 44 | #[allow(unused_assignments)] 45 | let mut result: anyhow::Result> = Ok(Vec::default()); 46 | loop { 47 | match Pin::new(&mut future).poll(context) { 48 | Poll::Pending => continue, 49 | Poll::Ready(value) => { 50 | result = value; 51 | break; 52 | } 53 | } 54 | } 55 | 56 | result 57 | } 58 | -------------------------------------------------------------------------------- /examples/url-downloader/facade/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #![allow(improper_ctypes)] 20 | 21 | use marine_rs_sdk::marine; 22 | use marine_rs_sdk::module_manifest; 23 | use marine_rs_sdk::WasmLoggerBuilder; 24 | 25 | module_manifest!(); 26 | 27 | pub fn main() { 28 | WasmLoggerBuilder::new().build().unwrap(); 29 | } 30 | 31 | /// Combining of modules: `curl` and `local_storage`. 32 | /// Calls `curl` and stores returned result into a file. 33 | #[marine] 34 | pub fn get_n_save(url: String, file_name: String) -> String { 35 | log::info!("get_n_save called with {} {}\n", url, file_name); 36 | 37 | let result = download(url); 38 | file_put(file_name, result.into_bytes()); 39 | 40 | String::from("Ok") 41 | } 42 | 43 | /// Importing `curl` module 44 | #[marine] 45 | #[module_import("curl_adapter")] 46 | extern "C" { 47 | pub fn download(url: String) -> String; 48 | } 49 | 50 | /// Importing `local_storage` module 51 | #[marine] 52 | #[module_import("local_storage")] 53 | extern "C" { 54 | #[link_name = "get"] 55 | pub fn file_get(file_name: String) -> Vec; 56 | 57 | #[link_name = "put"] 58 | pub fn file_put(name: String, file_content: Vec) -> String; 59 | } 60 | -------------------------------------------------------------------------------- /core/src/module/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod exports; 21 | mod marine_module; 22 | mod wit_function; 23 | mod wit_instance; 24 | mod type_converters; 25 | 26 | use marine_wasm_backend_traits::WValue; 27 | 28 | pub use wit_instance::MRecordTypes; 29 | 30 | pub use wasmer_it::IType; 31 | pub use wasmer_it::IRecordType; 32 | pub use wasmer_it::ast::FunctionArg as IFunctionArg; 33 | pub use wasmer_it::IValue; 34 | pub use wasmer_it::from_interface_values; 35 | pub use wasmer_it::to_interface_value; 36 | 37 | use serde::Serialize; 38 | use serde::Deserialize; 39 | use std::sync::Arc; 40 | 41 | /// Represent a function type inside Marine module. 42 | #[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] 43 | pub struct MFunctionSignature { 44 | pub name: Arc, 45 | pub arguments: Arc>, 46 | pub outputs: Arc>, 47 | } 48 | 49 | pub(crate) use marine_module::MModule; 50 | 51 | // types that often used together 52 | pub(crate) mod wit_prelude { 53 | pub(super) use super::wit_instance::ITInstance; 54 | pub(super) use super::exports::ITExport; 55 | pub(super) use crate::MError; 56 | pub(super) use super::wit_function::WITFunction; 57 | } 58 | -------------------------------------------------------------------------------- /tools/cli/src/generate.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use std::process::Command; 21 | 22 | const MARINE_TEMPLATE_URL: &str = "https://github.com/fluencelabs/marine-template"; 23 | 24 | pub(crate) fn generate( 25 | project_name: Option<&str>, 26 | should_be_initialized: bool, 27 | ) -> Result<(), anyhow::Error> { 28 | if !is_cargo_generate_installed()? { 29 | println!( 30 | "to use generate `cargo-generate` should be installed:\ncargo install cargo-generate" 31 | ); 32 | return Ok(()); 33 | } 34 | 35 | let mut cargo = Command::new("cargo"); 36 | cargo.arg("generate").arg("--git").arg(MARINE_TEMPLATE_URL); 37 | 38 | if let Some(project_name) = project_name { 39 | cargo.arg("--name").arg(project_name); 40 | } 41 | if should_be_initialized { 42 | cargo.arg("--init"); 43 | } 44 | 45 | crate::utils::run_command_inherited(cargo).map(|_| ()) 46 | } 47 | 48 | fn is_cargo_generate_installed() -> Result { 49 | let mut cargo = Command::new("cargo"); 50 | cargo.arg("install").arg("--list"); 51 | 52 | let output = crate::utils::run_command_piped(cargo)?; 53 | Ok(output.contains("cargo-generate")) 54 | } 55 | -------------------------------------------------------------------------------- /crates/module-info-parser/src/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::manifest::ManifestError; 21 | use crate::sdk_version::SDKVersionError; 22 | 23 | use thiserror::Error as ThisError; 24 | 25 | #[derive(Debug, ThisError)] 26 | pub enum ModuleInfoError { 27 | /// Version section is absent. 28 | #[error("the module doesn't contain section with '{0}', probably it's compiled with an old sdk version")] 29 | NoCustomSection(&'static str), 30 | 31 | /// Multiple sections with the same name. 32 | #[error("the module contains {1} sections with name '{0}' - it's corrupted")] 33 | MultipleCustomSections(&'static str, usize), 34 | 35 | /// Errors related to corrupted version. 36 | #[error(transparent)] 37 | VersionError(#[from] SDKVersionError), 38 | 39 | /// Errors related to corrupted manifest. 40 | #[error(transparent)] 41 | ManifestError(#[from] ManifestError), 42 | 43 | /// An error occurred while parsing Wasm file. 44 | #[error("provided Wasm file is corrupted: {0}")] 45 | CorruptedWasmFile(anyhow::Error), 46 | 47 | /// Wasm emitting file error. 48 | #[error("emitting resulted Wasm file failed with: {0}")] 49 | WasmEmitError(anyhow::Error), 50 | } 51 | -------------------------------------------------------------------------------- /core/src/host_imports/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::WType; 21 | use super::WValue; 22 | 23 | use it_lilo::lifter::LiError; 24 | use it_lilo::lowerer::LoError; 25 | use it_lilo::traits::RecordResolvableError; 26 | use thiserror::Error as ThisError; 27 | 28 | #[derive(Debug, ThisError)] 29 | pub enum HostImportError { 30 | /// An error occurred when host functions tries to lift IValues from WValues 31 | /// and the latter has different type. 32 | #[error( 33 | "Expected {0} type, but found {1:?} value during interface values lifting from Wasm memory" 34 | )] 35 | MismatchWValues(WType, WValue), 36 | 37 | /// An error occurred when a host functions tries to lift IValues from WValues 38 | /// and the latter is not enough for that. 39 | #[error("Not enough WValue arguments are provided from the Wasm side")] 40 | MismatchWValuesCount, 41 | 42 | #[error(transparent)] 43 | LifterError(#[from] LiError), 44 | 45 | #[error(transparent)] 46 | LowererError(#[from] LoError), 47 | 48 | #[error(transparent)] 49 | RecordNotFound(#[from] RecordResolvableError), 50 | 51 | #[error(transparent)] 52 | InvalidUTF8String(#[from] std::string::FromUtf8Error), 53 | } 54 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/module.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::ModuleCreationResult; 21 | use crate::InstantiationResult; 22 | use crate::WasmBackend; 23 | 24 | use futures::future::BoxFuture; 25 | 26 | /// A handle to compiled wasm module. 27 | pub trait Module: Sized { 28 | /// Compiles a wasm bytes into a module and extracts custom sections. 29 | fn new(store: &mut ::Store, wasm: &[u8]) -> ModuleCreationResult; 30 | 31 | /// Returns custom sections corresponding to `name`, empty slice if there is no sections. 32 | fn custom_sections(&self, name: &str) -> &[Vec]; 33 | 34 | /// Instantiates module by allocating memory, VM state and linking imports with ones from `import` argument. 35 | /// Does not call `_start` or `_initialize` functions. 36 | /// 37 | /// # Panics: 38 | /// 39 | /// If the `Store` given is not the same with `Store` used to create `Imports` and this object. 40 | fn instantiate<'args>( 41 | &'args self, 42 | store: &'args mut ::Store, 43 | imports: &'args ::Imports, 44 | ) -> BoxFuture<'args, InstantiationResult<::Instance>>; 45 | } 46 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/wasi.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::WasiError; 21 | use crate::WasmBackend; 22 | 23 | use std::path::PathBuf; 24 | use std::collections::HashMap; 25 | 26 | /// A type that provides WASI functionality to the given Wasm backend. 27 | pub trait WasiImplementation { 28 | /// Configures WASI state and adds WASI functions to the `imports` object. 29 | /// # Errors: 30 | /// Returns an error if failed to open a open a directory/file. 31 | fn register_in_linker( 32 | store: &mut ::ContextMut<'_>, 33 | linker: &mut ::Imports, 34 | config: WasiParameters, 35 | ) -> Result<(), WasiError>; 36 | 37 | /// Optional API for getting current WASI state. 38 | /// Returns None if not supported by current backend. 39 | fn get_wasi_state<'s>( 40 | instance: &'s mut ::Instance, 41 | ) -> Box; 42 | } 43 | 44 | #[derive(Default)] 45 | pub struct WasiParameters { 46 | pub args: Vec, 47 | pub envs: HashMap, 48 | pub mapped_dirs: HashMap, 49 | } 50 | 51 | pub trait WasiState { 52 | fn envs(&self) -> &[Vec]; 53 | } 54 | -------------------------------------------------------------------------------- /crates/module-info-parser/src/custom_section_extractor.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::ModuleInfoResult; 21 | use crate::ModuleInfoError; 22 | 23 | use walrus::IdsToIndices; 24 | use walrus::Module; 25 | 26 | use std::borrow::Cow; 27 | 28 | pub(super) fn extract_custom_sections_by_name<'w>( 29 | wasm_module: &'w Module, 30 | section_name: &str, 31 | ) -> ModuleInfoResult>> { 32 | let default_ids = IdsToIndices::default(); 33 | 34 | let sections = wasm_module 35 | .customs 36 | .iter() 37 | .filter(|(_, section)| section.name() == section_name) 38 | .map(|s| s.1.data(&default_ids)) 39 | .collect::>(); 40 | 41 | Ok(sections) 42 | } 43 | 44 | pub(super) fn try_as_one_section<'s, T: Sized>( 45 | sections: &'s [T], 46 | section_name: &'static str, 47 | ) -> ModuleInfoResult<&'s T> { 48 | let sections_count = sections.len(); 49 | 50 | if sections_count > 1 { 51 | return Err(ModuleInfoError::MultipleCustomSections( 52 | section_name, 53 | sections_count, 54 | )); 55 | } 56 | 57 | if sections_count == 0 { 58 | return Err(ModuleInfoError::NoCustomSection(section_name)); 59 | } 60 | 61 | Ok(§ions[0]) 62 | } 63 | -------------------------------------------------------------------------------- /examples/url-downloader/local_storage/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk::marine; 21 | use marine_rs_sdk::module_manifest; 22 | use marine_rs_sdk::WasmLoggerBuilder; 23 | 24 | use std::fs; 25 | use std::path::PathBuf; 26 | 27 | module_manifest!(); 28 | 29 | const SITES_DIR: &str = "/sites/"; 30 | 31 | /// Log level can be changed by `RUST_LOG` env as well. 32 | pub fn main() { 33 | WasmLoggerBuilder::new().build().unwrap(); 34 | } 35 | 36 | /// You can read or write files from the file system if there is permission to use directories described in `Config.toml`. 37 | #[marine] 38 | pub fn put(name: String, file_content: Vec) -> String { 39 | log::info!("put called with file name {}\n", name); 40 | let rpc_tmp_filepath = format!("{}{}", SITES_DIR, name); 41 | 42 | let result = fs::write(PathBuf::from(rpc_tmp_filepath), file_content); 43 | if let Err(e) = result { 44 | return format!("file can't be written: {}", e); 45 | } 46 | 47 | String::from("Ok") 48 | } 49 | 50 | #[marine] 51 | pub fn get(file_name: String) -> Vec { 52 | log::info!("get called with file name: {}\n", file_name); 53 | 54 | let tmp_filepath = format!("{}{}", SITES_DIR, file_name); 55 | 56 | fs::read(tmp_filepath).unwrap_or_else(|_| b"error while reading file".to_vec()) 57 | } 58 | -------------------------------------------------------------------------------- /crates/it-parser/src/deleter.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::errors::ITParserError; 21 | use super::custom::IT_SECTION_NAME; 22 | 23 | use walrus::ModuleConfig; 24 | 25 | use std::path::PathBuf; 26 | 27 | /// Delete all custom sections with IT from provided Wasm file. 28 | pub fn delete_it_section_from_file( 29 | in_wasm_path: PathBuf, 30 | out_wasm_path: PathBuf, 31 | ) -> Result<(), ITParserError> { 32 | let module = ModuleConfig::new() 33 | .parse_file(in_wasm_path) 34 | .map_err(ITParserError::CorruptedWasmFile)?; 35 | 36 | let mut module = delete_it_section(module); 37 | 38 | module 39 | .emit_wasm_file(&out_wasm_path) 40 | .map_err(ITParserError::WasmEmitError)?; 41 | 42 | Ok(()) 43 | } 44 | 45 | /// Delete all custom sections with IT from provided Wasm module. 46 | pub fn delete_it_section(mut wasm_module: walrus::Module) -> walrus::Module { 47 | let wit_section_ids = wasm_module 48 | .customs 49 | .iter() 50 | .filter_map(|(id, section)| { 51 | if section.name() == IT_SECTION_NAME { 52 | Some(id) 53 | } else { 54 | None 55 | } 56 | }) 57 | .collect::>(); 58 | 59 | for id in wit_section_ids { 60 | wasm_module.customs.delete(id); 61 | } 62 | 63 | wasm_module 64 | } 65 | -------------------------------------------------------------------------------- /crates/it-generator/src/instructions_generator/record_instructions.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::ITGenerator; 21 | use super::ITResolver; 22 | use crate::Result; 23 | 24 | use marine_macro_impl::RecordType; 25 | use marine_macro_impl::RecordFields; 26 | 27 | use wasmer_it::IRecordFieldType; 28 | use wasmer_it::NEVec; 29 | 30 | impl ITGenerator for RecordType { 31 | fn generate_it<'a>(&'a self, it_resolver: &mut ITResolver<'a>) -> Result<()> { 32 | let fields = match &self.fields { 33 | RecordFields::Named(fields) => fields, 34 | RecordFields::Unnamed(fields) => fields, 35 | RecordFields::Unit => return Ok(()), 36 | }; 37 | 38 | let fields = fields 39 | .iter() 40 | .map(|field| IRecordFieldType { 41 | name: field.name.clone().unwrap_or_default(), 42 | ty: super::utils::ptype_to_itype_unchecked(&field.ty, it_resolver), 43 | }) 44 | .collect::>(); 45 | 46 | let fields = NEVec::new(fields).map_err(|_| { 47 | crate::errors::ITGeneratorError::CorruptedRecord(format!( 48 | "serialized record with name '{}' contains no fields", 49 | self.name 50 | )) 51 | })?; 52 | 53 | it_resolver.add_record_type(self.name.clone(), fields); 54 | 55 | Ok(()) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/misc/version_checker.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::PrepareResult; 21 | use super::PrepareError; 22 | 23 | use marine_module_info_parser::sdk_version; 24 | use marine_min_it_version::min_sdk_version; 25 | use marine_min_it_version::min_it_version; 26 | use marine_wasm_backend_traits::WasmBackend; 27 | 28 | pub(crate) fn check_sdk_version( 29 | name: String, 30 | wasmer_module: &::Module, 31 | ) -> PrepareResult<()> { 32 | let module_version = sdk_version::extract_from_compiled_module::(wasmer_module)?; 33 | 34 | let required_version = min_sdk_version(); 35 | if module_version < *required_version { 36 | return Err(PrepareError::IncompatibleSDKVersions { 37 | module_name: name, 38 | required: required_version.clone(), 39 | provided: module_version, 40 | }); 41 | } 42 | 43 | Ok(()) 44 | } 45 | 46 | pub(crate) fn check_it_version( 47 | name: impl Into, 48 | it_version: &semver::Version, 49 | ) -> PrepareResult<()> { 50 | let required_version = min_it_version(); 51 | if it_version < required_version { 52 | return Err(PrepareError::IncompatibleITVersions { 53 | module_name: name.into(), 54 | required: required_version.clone(), 55 | provided: it_version.clone(), 56 | }); 57 | } 58 | 59 | Ok(()) 60 | } 61 | -------------------------------------------------------------------------------- /crates/it-parser/src/embedder.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::custom::ITCustomSection; 21 | use super::errors::ITParserError; 22 | use crate::ParserResult; 23 | 24 | use walrus::ModuleConfig; 25 | use wasmer_it::ast::Interfaces; 26 | use wasmer_it::decoders::wat::parse; 27 | use wasmer_it::decoders::wat::Buffer; 28 | use wasmer_it::ToBytes; 29 | 30 | use std::path::Path; 31 | 32 | /// Embed provided IT to a Wasm file by path. 33 | pub fn embed_text_it(in_wasm_path: I, out_wasm_path: O, it: &str) -> ParserResult<()> 34 | where 35 | I: AsRef, 36 | O: AsRef, 37 | { 38 | let module = ModuleConfig::new() 39 | .parse_file(in_wasm_path) 40 | .map_err(ITParserError::CorruptedWasmFile)?; 41 | 42 | let buffer = Buffer::new(it)?; 43 | let ast = parse(&buffer)?; 44 | 45 | let mut module = embed_it(module, &ast); 46 | module 47 | .emit_wasm_file(out_wasm_path) 48 | .map_err(ITParserError::WasmEmitError)?; 49 | 50 | Ok(()) 51 | } 52 | 53 | /// Embed provided IT to a Wasm module. 54 | pub fn embed_it(mut wasm_module: walrus::Module, interfaces: &Interfaces<'_>) -> walrus::Module { 55 | let mut bytes = vec![]; 56 | // TODO: think about possible errors here 57 | interfaces.to_bytes(&mut bytes).unwrap(); 58 | 59 | let custom = ITCustomSection(bytes); 60 | wasm_module.customs.add(custom); 61 | 62 | wasm_module 63 | } 64 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/macros.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /// Copypasted from Wasmtime. 21 | /// A helper macros for implementing anything for 0-16 generic parameters. 22 | /// The expected argument signature is this: 23 | /// ``` 24 | /// macro_rules! example_arg { 25 | /// ($num:tt $($args:ident)*) => (); 26 | /// } 27 | /// ``` 28 | /// https://github.com/bytecodealliance/wasmtime/blob/812b4b5229eac29b18b5c70a48536a514d73a8a6/crates/wasmtime/src/func.rs#LL242C14-L242C41 29 | #[macro_export] 30 | macro_rules! impl_for_each_function_signature { 31 | ($mac:ident) => { 32 | $mac!(0); 33 | $mac!(1 A1); 34 | $mac!(2 A1 A2); 35 | $mac!(3 A1 A2 A3); 36 | $mac!(4 A1 A2 A3 A4); 37 | $mac!(5 A1 A2 A3 A4 A5); 38 | $mac!(6 A1 A2 A3 A4 A5 A6); 39 | $mac!(7 A1 A2 A3 A4 A5 A6 A7); 40 | $mac!(8 A1 A2 A3 A4 A5 A6 A7 A8); 41 | $mac!(9 A1 A2 A3 A4 A5 A6 A7 A8 A9); 42 | $mac!(10 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10); 43 | $mac!(11 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11); 44 | $mac!(12 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12); 45 | $mac!(13 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13); 46 | $mac!(14 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14); 47 | $mac!(15 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15); 48 | $mac!(16 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16); 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /marine/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "marine-runtime" 3 | description = "The Fluence Wasm Runtime" 4 | version = "0.37.0" 5 | authors = ["Fluence DAO, Clouldless Labs"] 6 | repository = "https://github.com/fluencelabs/marine" 7 | license = "AGPL-3.0-only" 8 | edition = "2021" 9 | 10 | [lib] 11 | name = "marine" 12 | path = "src/lib.rs" 13 | 14 | [dependencies] 15 | marine-core = { path = "../core", version = "0.31.0", default-features = false} 16 | marine-module-interface = { path = "../crates/module-interface", version = "0.9.0" } 17 | marine-utils = { path = "../crates/utils", version = "0.5.1" } 18 | marine-rs-sdk-main = { version = "0.14.0", default-features = false, features = ["logger"] } 19 | marine-rs-sdk = { version = "0.14.0", default-features = false, features = ["logger"] } 20 | marine_call_parameters_v0 = { package = "marine-call-parameters", version = "=0.10.3", default-features = false } 21 | marine_call_parameters_v1 = { package = "marine-call-parameters", version = "=0.12.0", default-features = false } 22 | marine_call_parameters_v2 = { package = "marine-call-parameters", version = "=0.13.0", default-features = false } 23 | 24 | it-json-serde = { path = "../crates/it-json-serde", version = "0.6.0" } 25 | marine-wasm-backend-traits = { path = "../crates/wasm-backend-traits", version = "0.7.0" } 26 | marine-wasmtime-backend = { path = "../crates/wasmtime-backend", version = "0.7.0", optional = true} 27 | 28 | wasmer-it = { package = "wasmer-interface-types-fl", version = "0.28.0" } 29 | it-memory-traits = "0.5.0" 30 | 31 | toml = "0.5.9" 32 | serde = { version = "1.0.147", features = ["derive"] } 33 | serde_json = "1.0.107" 34 | serde_derive = "1.0.147" 35 | serde_with = "2.1.0" 36 | bytesize = {version = "1.2.0", features = ["serde"]} 37 | itertools = "0.10.5" 38 | log = "0.4.20" 39 | safe-transmute = "0.11.2" 40 | thiserror = "1.0.50" 41 | parking_lot = "0.12.1" 42 | 43 | [dev-dependencies] 44 | once_cell = "1.16.0" 45 | env_logger = "0.10.0" 46 | pretty_assertions = "1.3.0" 47 | tokio = {version = "1.33.0", features = ["rt", "macros"]} 48 | 49 | [features] 50 | raw-module-api = [] 51 | default = ["marine-core/default", "marine-wasmtime-backend"] 52 | -------------------------------------------------------------------------------- /crates/js-backend/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod store; 21 | mod module; 22 | mod imports; 23 | mod instance; 24 | mod caller; 25 | mod function; 26 | mod memory; 27 | mod wasi; 28 | mod module_info; 29 | mod js_conversions; 30 | 31 | mod single_shot_async_executor; 32 | 33 | use crate::store::JsContextMut; 34 | use crate::store::JsStore; 35 | use crate::module::JsModule; 36 | use crate::store::JsContext; 37 | use crate::imports::JsImports; 38 | use crate::instance::JsInstance; 39 | use crate::memory::JsMemory; 40 | use crate::wasi::JsWasi; 41 | use crate::caller::JsImportCallContext; 42 | use crate::function::HostImportFunction; 43 | use crate::function::WasmExportFunction; 44 | 45 | use marine_wasm_backend_traits::prelude::*; 46 | 47 | #[derive(Default, Clone)] 48 | pub struct JsWasmBackend {} 49 | 50 | impl WasmBackend for JsWasmBackend { 51 | type Store = JsStore; 52 | type Module = JsModule; 53 | type Imports = JsImports; 54 | type Instance = JsInstance; 55 | type Context<'c> = JsContext<'c>; 56 | type ContextMut<'c> = JsContextMut<'c>; 57 | type ImportCallContext<'c> = JsImportCallContext; 58 | type HostFunction = HostImportFunction; 59 | type ExportFunction = WasmExportFunction; 60 | type Memory = JsMemory; 61 | type MemoryView = JsMemory; 62 | type Wasi = JsWasi; 63 | 64 | fn new_async() -> WasmBackendResult { 65 | Ok(Self {}) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /crates/min-it-version/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #![warn(rust_2018_idioms)] 20 | #![deny( 21 | dead_code, 22 | nonstandard_style, 23 | unused_imports, 24 | unused_mut, 25 | unused_variables, 26 | unused_unsafe, 27 | unreachable_patterns 28 | )] 29 | 30 | use once_cell::sync::Lazy; 31 | 32 | use std::str::FromStr; 33 | 34 | static MINIMAL_SUPPORTED_SDK_VERSION: Lazy = Lazy::new(|| { 35 | semver::Version::from_str("0.6.0").expect("invalid minimal sdk version specified") 36 | }); 37 | static MINIMAL_SUPPORTED_IT_VERSION: Lazy = Lazy::new(|| { 38 | semver::Version::from_str("0.20.0").expect("invalid minimal sdk version specified") 39 | }); 40 | 41 | // These locals intended for check that set versions are correct at the start of an application. 42 | thread_local!(static MINIMAL_SUPPORTED_SDK_VERSION_CHECK: &'static semver::Version = Lazy::force(&MINIMAL_SUPPORTED_SDK_VERSION)); 43 | thread_local!(static MINIMAL_SUPPORTED_IT_VERSION_CHECK: &'static semver::Version = Lazy::force(&MINIMAL_SUPPORTED_IT_VERSION)); 44 | 45 | /// Return minimal support version of interface types. 46 | pub fn min_it_version() -> &'static semver::Version { 47 | Lazy::force(&MINIMAL_SUPPORTED_IT_VERSION) 48 | } 49 | 50 | /// Return minimal support version of SDK. 51 | pub fn min_sdk_version() -> &'static semver::Version { 52 | Lazy::force(&MINIMAL_SUPPORTED_SDK_VERSION) 53 | } 54 | -------------------------------------------------------------------------------- /tools/cli/src/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::cargo_manifest::ManifestError; 21 | 22 | use marine_module_info_parser::ModuleInfoError; 23 | use marine_it_generator::ITGeneratorError; 24 | use marine_it_parser::ITParserError; 25 | 26 | use thiserror::Error as ThisError; 27 | 28 | use std::path::PathBuf; 29 | 30 | #[derive(Debug, ThisError)] 31 | pub enum CLIError { 32 | /// Unknown command was entered by user. 33 | #[error("{0} is an unknown command")] 34 | NoSuchCommand(String), 35 | 36 | /// A error occurred while embedding rust sdk version. 37 | #[error(transparent)] 38 | VersionEmbeddingError(#[from] ModuleInfoError), 39 | 40 | /// An error occurred while generating interface types. 41 | #[error(transparent)] 42 | ITGeneratorError(#[from] ITGeneratorError), 43 | 44 | /// An error occurred while parsing interface types. 45 | #[error(transparent)] 46 | ITParserError(#[from] ITParserError), 47 | 48 | /// An error occurred when no Wasm file was compiled. 49 | #[error("{0}")] 50 | WasmCompilationError(String), 51 | 52 | /// Various errors related to I/O operations. 53 | #[error("{0:?}")] 54 | IOError(#[from] std::io::Error), 55 | 56 | #[error(transparent)] 57 | ManifestError(#[from] ManifestError), 58 | 59 | #[error("Error loading lockfile at {0}: {1}")] 60 | LockfileError(PathBuf, cargo_lock::Error), 61 | 62 | #[error(transparent)] 63 | MetadataError(#[from] cargo_metadata::Error), 64 | } 65 | -------------------------------------------------------------------------------- /crates/it-parser/src/extractor.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | mod it; 21 | 22 | pub use it::*; 23 | 24 | use crate::interface::ModuleInterface; 25 | use crate::it_interface::IModuleInterface; 26 | use crate::ParserResult; 27 | use crate::ITParserError; 28 | 29 | use marine_module_interface::it_interface; 30 | use marine_module_interface::interface; 31 | use marine_it_interfaces::MITInterfaces; 32 | use std::path::Path; 33 | 34 | pub fn module_interface

(module_path: P) -> ParserResult 35 | where 36 | P: AsRef, 37 | { 38 | create_mit_with(module_path, |it| interface::get_interface(&it)) 39 | } 40 | 41 | pub fn module_it_interface

(module_path: P) -> ParserResult 42 | where 43 | P: AsRef, 44 | { 45 | create_mit_with(module_path, |it| it_interface::get_interface(&it)) 46 | } 47 | 48 | fn create_mit_with( 49 | module_path: P, 50 | transformer: impl FnOnce(MITInterfaces<'_>) -> std::result::Result, 51 | ) -> ParserResult 52 | where 53 | P: AsRef, 54 | ITParserError: From, 55 | { 56 | let module = walrus::ModuleConfig::new() 57 | .parse_file(module_path) 58 | .map_err(ITParserError::CorruptedWasmFile)?; 59 | let raw_custom_section = extract_custom_section(&module)?; 60 | let custom_section_bytes = raw_custom_section.as_ref(); 61 | let it = extract_it_from_bytes(custom_section_bytes)?; 62 | 63 | let mit = MITInterfaces::new(it); 64 | 65 | transformer(mit).map_err(Into::into) 66 | } 67 | -------------------------------------------------------------------------------- /core/src/misc/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_module_info_parser::ModuleInfoError; 21 | 22 | use thiserror::Error as ThisError; 23 | 24 | #[derive(Debug, ThisError)] 25 | pub enum PrepareError { 26 | #[error("overflow was happened while summation globals size '{globals_pages_count}' and heap size '{max_heap_pages_count}'")] 27 | MemSizesOverflow { 28 | globals_pages_count: u32, 29 | max_heap_pages_count: u32, 30 | }, 31 | 32 | /// Error is encountered while parsing module version. 33 | #[error(transparent)] 34 | ModuleVersionParseError(#[from] ModuleInfoError), 35 | 36 | /// Provided module doesn't contain a sdk version that is necessary. 37 | #[error("module with name '{0}' doesn't contain a version of sdk, probably it's compiled with an old one")] 38 | ModuleWithoutVersion(String), 39 | 40 | /// Module sdk versions are incompatible. 41 | #[error("module with name '{module_name}' compiled with {provided} sdk version, but at least {required} required")] 42 | IncompatibleSDKVersions { 43 | module_name: String, 44 | required: semver::Version, 45 | provided: semver::Version, 46 | }, 47 | 48 | /// Module IT versions are incompatible. 49 | #[error("module with name '{module_name}' compiled with {provided} IT version, but at least {required} required")] 50 | IncompatibleITVersions { 51 | module_name: String, 52 | required: semver::Version, 53 | provided: semver::Version, 54 | }, 55 | } 56 | -------------------------------------------------------------------------------- /crates/module-interface/src/interface/itype_to_text.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::it_interface::IRecordTypes; 21 | 22 | use wasmer_it::IType; 23 | 24 | /// Converts the supplied IType to a Aqua0compatible text representation. 25 | /// 26 | /// SAFETY: 27 | /// It's assumed that arguments are well-formed and all records have a corresponded type in 28 | /// record_types. 29 | pub fn itype_text_view(arg_ty: &IType, record_types: &IRecordTypes) -> String { 30 | match arg_ty { 31 | IType::Record(record_type_id) => { 32 | // assumed that this functions called with well-formed args 33 | let record = record_types.get(record_type_id).unwrap(); 34 | record.name.clone() 35 | } 36 | IType::Array(array_ty) => format!("[]{}", itype_text_view(array_ty, record_types)), 37 | IType::Boolean => "bool".to_string(), 38 | IType::S8 => "i8".to_string(), 39 | IType::S16 => "i16".to_string(), 40 | IType::S32 => "i32".to_string(), 41 | IType::S64 => "i64".to_string(), 42 | IType::U8 => "u8".to_string(), 43 | IType::U16 => "u16".to_string(), 44 | IType::U32 => "u32".to_string(), 45 | IType::U64 => "u64".to_string(), 46 | IType::F32 => "f32".to_string(), 47 | IType::F64 => "f64".to_string(), 48 | IType::String => "string".to_string(), 49 | IType::ByteArray => "[]u8".to_string(), 50 | IType::I32 => "i32".to_string(), 51 | IType::I64 => "i64".to_string(), 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/store.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::WasmBackend; 21 | 22 | /// `Store` is an object that stores modules, instances, functions memories and so on. 23 | /// `Store` is grow-only: once something added, it will not be removed until Store is destroyed. 24 | /// Some of the implementations can limit allocated resources. 25 | /// For example, Wasmtime cannot have more than 10000 instances in one `Store`. 26 | /// 27 | /// Most of the functions in this crate require a handle to `Store` to work. 28 | pub trait Store: AsContextMut { 29 | fn new(backend: &WB) -> Self; 30 | 31 | // TODO: create general/backend-specific core config when new parameters are needed 32 | fn set_total_memory_limit(&mut self, total_memory_limit: u64); 33 | 34 | fn report_memory_allocation_stats(&self) -> Option; 35 | 36 | fn clear_allocation_stats(&mut self); 37 | } 38 | 39 | /// A temporary immutable handle to store 40 | pub trait Context: AsContext + Send {} 41 | 42 | /// A temporary mutable handle to store 43 | pub trait ContextMut: AsContextMut + Send {} 44 | 45 | pub trait AsContext: Send { 46 | fn as_context(&self) -> ::Context<'_>; 47 | } 48 | 49 | pub trait AsContextMut: AsContext { 50 | fn as_context_mut(&mut self) -> ::ContextMut<'_>; 51 | } 52 | 53 | #[derive(Default, Clone, Debug)] 54 | pub struct MemoryAllocationStats { 55 | pub allocation_rejects: u32, 56 | } 57 | -------------------------------------------------------------------------------- /core/tests/wasm_tests/lilo_after_2gb/src/pure.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | #![allow(clippy::all)] 22 | #![allow(unused_mut)] 23 | #![allow(dead_code)] 24 | 25 | use marine_rs_sdk::marine; 26 | static mut DATA: Option> = None; 27 | 28 | fn main() {} 29 | 30 | #[marine] 31 | pub struct TestRecord { 32 | field1: i32, 33 | field2: i32, 34 | field3: i32, 35 | field4: i32, 36 | field5: i32, 37 | } 38 | 39 | #[marine] 40 | pub fn fill_2gb_mem() { 41 | unsafe { 42 | DATA = Some(Vec::new()); 43 | let mut data = DATA.as_mut().unwrap(); 44 | data.reserve_exact(1); 45 | let data_offset = std::mem::transmute::<*const u8, usize>(data.as_ptr()); 46 | let size = 0x80000001 - data_offset; 47 | data.reserve_exact(size); 48 | } 49 | } 50 | 51 | #[marine] 52 | pub fn pass_record(_record: TestRecord) {} 53 | 54 | #[marine] 55 | pub fn pass_string(_record: String) {} 56 | 57 | #[marine] 58 | pub fn pass_byte_array(_record: Vec) {} 59 | 60 | #[marine] 61 | pub fn pass_array(_record: Vec) {} 62 | 63 | #[marine] 64 | pub fn return_record() -> TestRecord { 65 | TestRecord { 66 | field1: 0, 67 | field2: 1, 68 | field3: 2, 69 | field4: 3, 70 | field5: 4, 71 | } 72 | } 73 | 74 | #[marine] 75 | pub fn return_string() -> String { 76 | String::from("1234") 77 | } 78 | 79 | #[marine] 80 | pub fn return_byte_array() -> Vec { 81 | vec![0, 1, 2, 3] 82 | } 83 | 84 | #[marine] 85 | pub fn return_array() -> Vec { 86 | vec![0, 1, 2, 3] 87 | } 88 | -------------------------------------------------------------------------------- /crates/it-interfaces/src/errors.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use std::error::Error; 21 | 22 | #[derive(Debug)] 23 | pub enum MITInterfacesError { 24 | /// IT doesn't contain such type. 25 | NoSuchType(u32), 26 | 27 | /// IT doesn't contain such export. 28 | NoSuchExport(u32), 29 | 30 | /// IT doesn't contain such import. 31 | NoSuchImport(u32), 32 | 33 | /// IT doesn't contain such import. 34 | NoSuchAdapter(u32), 35 | } 36 | 37 | impl Error for MITInterfacesError {} 38 | 39 | impl std::fmt::Display for MITInterfacesError { 40 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { 41 | match self { 42 | MITInterfacesError::NoSuchType(type_id) => write!( 43 | f, 44 | "Loaded module doesn't contain type with idx = {}", 45 | type_id 46 | ), 47 | MITInterfacesError::NoSuchExport(export_type_id) => write!( 48 | f, 49 | "Loaded module doesn't contain export with type idx = {}", 50 | export_type_id 51 | ), 52 | MITInterfacesError::NoSuchImport(import_type_id) => write!( 53 | f, 54 | "Loaded module doesn't contain import with type idx = {}", 55 | import_type_id 56 | ), 57 | MITInterfacesError::NoSuchAdapter(adapter_type_id) => write!( 58 | f, 59 | "Loaded module doesn't contain adapter with type idx = {}", 60 | adapter_type_id 61 | ), 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /crates/it-parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #![warn(rust_2018_idioms)] 20 | #![deny( 21 | dead_code, 22 | nonstandard_style, 23 | unused_imports, 24 | unused_mut, 25 | unused_variables, 26 | unused_unsafe, 27 | unreachable_patterns 28 | )] 29 | 30 | mod custom; 31 | mod deleter; 32 | mod embedder; 33 | mod errors; 34 | mod extractor; 35 | 36 | pub use errors::ITParserError; 37 | 38 | pub use deleter::delete_it_section; 39 | pub use deleter::delete_it_section_from_file; 40 | 41 | pub use embedder::embed_it; 42 | pub use embedder::embed_text_it; 43 | 44 | pub use extractor::extract_it_from_module; 45 | pub use extractor::extract_version_from_module; 46 | pub use extractor::extract_text_it; 47 | pub use extractor::module_interface; 48 | pub use extractor::module_it_interface; 49 | 50 | pub mod interface { 51 | pub use marine_module_interface::interface::ModuleInterface; 52 | pub use marine_module_interface::interface::RecordType; 53 | pub use marine_module_interface::interface::RecordField; 54 | pub use marine_module_interface::interface::FunctionSignature; 55 | } 56 | 57 | pub mod it_interface { 58 | pub use marine_module_interface::it_interface::IModuleInterface; 59 | pub use marine_module_interface::it_interface::IRecordTypes; 60 | pub use marine_module_interface::it_interface::IFunctionSignature; 61 | 62 | pub mod it { 63 | pub use wasmer_it::IType; 64 | pub use wasmer_it::ast::FunctionArg as IFunctionArg; 65 | pub use wasmer_it::IRecordType; 66 | pub use wasmer_it::IRecordFieldType; 67 | } 68 | } 69 | 70 | pub(crate) type ParserResult = std::result::Result; 71 | -------------------------------------------------------------------------------- /crates/module-interface/src/interface/interface_transformer.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::ModuleInterface; 21 | use super::InterfaceResult; 22 | use super::FunctionSignature; 23 | use super::records_transformer::RecordsTransformer; 24 | use crate::it_interface::IModuleInterface; 25 | use crate::it_interface::IFunctionSignature; 26 | use crate::it_interface::IRecordTypes; 27 | 28 | pub fn it_to_module_interface(mm_interface: IModuleInterface) -> InterfaceResult { 29 | let record_types = mm_interface.export_record_types; 30 | 31 | let function_signatures = mm_interface 32 | .function_signatures 33 | .into_iter() 34 | .map(|sign| serialize_function_signature(sign, &record_types)) 35 | .collect(); 36 | 37 | let record_types = RecordsTransformer::transform(&record_types)?; 38 | 39 | let interface = ModuleInterface { 40 | function_signatures, 41 | record_types, 42 | }; 43 | 44 | Ok(interface) 45 | } 46 | 47 | fn serialize_function_signature( 48 | signature: IFunctionSignature, 49 | record_types: &IRecordTypes, 50 | ) -> FunctionSignature { 51 | use super::itype_text_view; 52 | 53 | let arguments = signature 54 | .arguments 55 | .iter() 56 | .map(|arg| (arg.name.clone(), itype_text_view(&arg.ty, record_types))) 57 | .collect(); 58 | 59 | let output_types = signature 60 | .outputs 61 | .iter() 62 | .map(|itype| itype_text_view(itype, record_types)) 63 | .collect(); 64 | 65 | FunctionSignature { 66 | name: signature.name.to_string(), 67 | arguments, 68 | output_types, 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /crates/wasmtime-backend/src/imports.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::StoreState; 21 | use crate::WasmtimeFunction; 22 | use crate::WasmtimeStore; 23 | use crate::WasmtimeWasmBackend; 24 | 25 | use marine_wasm_backend_traits::prelude::*; 26 | 27 | #[derive(Clone)] 28 | pub struct WasmtimeImports { 29 | pub(crate) linker: wasmtime::Linker, 30 | } 31 | 32 | impl Imports for WasmtimeImports { 33 | fn new(store: &mut WasmtimeStore) -> Self { 34 | Self { 35 | linker: wasmtime::Linker::new(store.inner.engine()), 36 | } 37 | } 38 | 39 | fn insert( 40 | &mut self, 41 | store: &impl AsContext, 42 | module: impl Into, 43 | name: impl Into, 44 | func: ::HostFunction, 45 | ) -> Result<(), ImportError> { 46 | let module = module.into(); 47 | let name = name.into(); 48 | self.linker 49 | .define(store.as_context(), &module, &name, func.inner) 50 | .map_err(|_| ImportError::DuplicateImport(module, name)) 51 | .map(|_| ()) 52 | } 53 | 54 | fn register( 55 | &mut self, 56 | store: &impl AsContext, 57 | name: S, 58 | namespace: I, 59 | ) -> Result<(), ImportError> 60 | where 61 | S: Into, 62 | I: IntoIterator, 63 | { 64 | let module: String = name.into(); 65 | for (name, func) in namespace { 66 | self.insert(store, &module, name, func)?; 67 | } 68 | 69 | Ok(()) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /examples/ipfs-node/pure/src/main.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | 22 | use marine_rs_sdk::marine; 23 | use marine_rs_sdk::module_manifest; 24 | use marine_rs_sdk::WasmLoggerBuilder; 25 | 26 | use std::fs; 27 | use std::path::PathBuf; 28 | 29 | const RPC_TMP_FILEPATH: &str = "/tmp/ipfs_rpc_file"; 30 | 31 | module_manifest!(); 32 | 33 | pub fn main() { 34 | WasmLoggerBuilder::new() 35 | .with_log_level(log::LevelFilter::Info) 36 | .build() 37 | .unwrap(); 38 | } 39 | 40 | #[marine] 41 | pub fn invoke() -> String { 42 | "IPFS_RPC wasm example, it allows to:\ninvoke\nput\nget".to_string() 43 | } 44 | 45 | #[marine] 46 | pub fn put(file_content: Vec) -> String { 47 | log::info!("put called with {:?}", file_content); 48 | 49 | let rpc_tmp_filepath = RPC_TMP_FILEPATH.to_string(); 50 | 51 | let r = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content); 52 | if let Err(e) = r { 53 | return format!("file can't be written: {}", e); 54 | } 55 | 56 | ipfs_put(rpc_tmp_filepath) 57 | } 58 | 59 | #[marine] 60 | pub fn get(hash: String) -> Vec { 61 | log::info!("get called with hash: {}", hash); 62 | 63 | let file_path = ipfs_get(hash); 64 | fs::read(file_path).unwrap_or_else(|_| b"error while reading file".to_vec()) 65 | } 66 | 67 | #[marine] 68 | #[module_import("ipfs_effector")] 69 | extern "C" { 70 | /// Put provided file to ipfs, return ipfs hash of the file. 71 | #[link_name = "put"] 72 | pub fn ipfs_put(file_path: String) -> String; 73 | 74 | /// Get file from ipfs by hash. 75 | #[link_name = "get"] 76 | pub fn ipfs_get(hash: String) -> String; 77 | } 78 | -------------------------------------------------------------------------------- /marine/tests/wasm_tests/memory_limiting/src/pure.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #![allow(improper_ctypes)] 21 | #![allow(clippy::all)] 22 | #![allow(non_snake_case)] 23 | 24 | use marine_rs_sdk::marine; 25 | 26 | pub fn main() {} 27 | 28 | #[marine] 29 | pub fn allocate_single_module_single_piece(size: i64) -> u32 { 30 | let addr = Vec::::with_capacity(size as usize).leak().as_ptr(); 31 | unsafe { std::mem::transmute::<*const u8, usize>(addr) as u32 } 32 | } 33 | 34 | #[marine] 35 | pub fn allocate_single_module_64KB_pieces(n_pieces: u32) -> u32 { 36 | let mut acc: u32 = 0; 37 | 38 | for _ in 0..n_pieces { 39 | unsafe { 40 | let addr = Box::leak(Box::new([0u8; 1024 * 64])); 41 | acc ^= std::mem::transmute::<*const u8, usize>(addr.as_ptr()) as u32; 42 | } 43 | } 44 | 45 | acc 46 | } 47 | 48 | #[marine] 49 | pub fn allocate_two_modules_single_piece(size: i64) -> u32 { 50 | let first = allocate_single_module_single_piece(size); 51 | let second = effector::allocate_single_module_single_piece(size); 52 | first ^ second 53 | } 54 | 55 | #[marine] 56 | pub fn allocate_two_modules_64KB_pieces(n_pieces: u32) -> u32 { 57 | let first = allocate_single_module_64KB_pieces(n_pieces); 58 | let second = effector::allocate_single_module_64KB_pieces(n_pieces); 59 | first ^ second 60 | } 61 | 62 | mod effector { 63 | use marine_rs_sdk::marine; 64 | 65 | #[marine] 66 | #[module_import("memory_limiting_effector")] 67 | extern "C" { 68 | pub fn allocate_single_module_single_piece(size: i64) -> u32; 69 | 70 | pub fn allocate_single_module_64KB_pieces(n_pieces: u32) -> u32; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tools/repl/src/logger.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use marine_rs_sdk_main::WASM_LOG_ENV_NAME; 21 | 22 | use std::io::Write; 23 | use std::env::var; 24 | 25 | const IT_MODULE_PATH: &str = "wasmer_interface_types_fl"; 26 | const RUST_LOG_ENV_NAME: &str = "RUST_LOG"; 27 | 28 | pub(super) fn init_logger() { 29 | use log::LevelFilter::Info; 30 | 31 | match (var(RUST_LOG_ENV_NAME), var(WASM_LOG_ENV_NAME)) { 32 | (Ok(_), _) => {} 33 | (Err(_), Ok(wasm_log_env)) if !wasm_log_env.starts_with("off") => { 34 | std::env::set_var(RUST_LOG_ENV_NAME, "trace") 35 | } 36 | _ => return, 37 | }; 38 | 39 | env_logger::builder() 40 | .format(|buf, record| { 41 | match record.module_path() { 42 | Some(module_path) if module_path.starts_with(IT_MODULE_PATH) => { 43 | writeln!(buf, "[host] {}", record.args()) 44 | } 45 | // due to the log_utf8_string implementation, 46 | // a log message from a Wasm module always has module path 47 | None => writeln!(buf, "[host] {}", record.args()), 48 | Some(module_path) => writeln!(buf, "[{}] {}", module_path, record.args()), 49 | } 50 | }) 51 | // set a default level Info for Wasmer components 52 | .filter(Some("cranelift_codegen"), Info) 53 | .filter(Some("wasmer_wasi"), Info) 54 | .filter(Some("wasmtime_wasi"), Info) 55 | //.filter(Some(WIT_MODULE_PATH), Info) 56 | // the same for rustyline and marine 57 | .filter(Some("rustyline"), Info) 58 | .filter(Some("marine"), Info) 59 | .init(); 60 | } 61 | -------------------------------------------------------------------------------- /crates/wasm-backend-traits/src/instance.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::AsContextMut; 21 | use crate::Export; 22 | use crate::ResolveResult; 23 | use crate::WasmBackend; 24 | 25 | /// A handle to an instantiated Wasm module. Cloning is cheap. 26 | pub trait Instance: Clone { 27 | /// Returns an `Iterator` to all exports of this instance. 28 | fn export_iter<'a>( 29 | &'a self, 30 | store: ::ContextMut<'a>, 31 | ) -> Box)> + 'a>; 32 | 33 | /// Returns nth exported memory, None if there is no nth memory. 34 | /// No guaranties is known for memory order, but almost always a module has only one memory, 35 | /// hence the only valid value for `memory_index` is 0. 36 | fn get_nth_memory( 37 | &self, 38 | store: &mut impl AsContextMut, 39 | memory_index: u32, // TODO: refactor memory indexing with enums 40 | ) -> Option<::Memory>; 41 | 42 | /// Returns a memory export with given name. 43 | /// # Errors: 44 | /// Returns an error if there is no export with such name, or it is not a memory. 45 | fn get_memory( 46 | &self, 47 | store: &mut impl AsContextMut, 48 | memory_name: &str, 49 | ) -> ResolveResult<::Memory>; 50 | 51 | /// Returns an exported function with the given name. 52 | /// # Errors: 53 | /// Returns an error if there is no export with such name, or it is not a function. 54 | fn get_function( 55 | &self, 56 | store: &mut impl AsContextMut, 57 | name: &str, 58 | ) -> ResolveResult<::ExportFunction>; 59 | } 60 | -------------------------------------------------------------------------------- /.github/workflows/snapshot-cargo.yml: -------------------------------------------------------------------------------- 1 | name: Publish crates snapshots 2 | 3 | on: 4 | workflow_call: 5 | inputs: 6 | ref: 7 | description: "git ref to checkout to" 8 | type: string 9 | default: "master" 10 | outputs: 11 | version: 12 | description: "crate snapshots version" 13 | value: ${{ jobs.publish.outputs.version }} 14 | 15 | jobs: 16 | publish: 17 | name: "Publish crates" 18 | runs-on: builder 19 | timeout-minutes: 60 20 | 21 | env: 22 | RUSTFLAGS: "-D warnings" 23 | RUSTC_WRAPPER: "sccache" 24 | 25 | outputs: 26 | version: "${{ steps.snapshot.outputs.version }}" 27 | 28 | permissions: 29 | contents: read 30 | id-token: write 31 | 32 | steps: 33 | - name: Checkout Marine 34 | uses: actions/checkout@v4 35 | with: 36 | repository: fluencelabs/marine 37 | ref: ${{ inputs.ref }} 38 | 39 | - name: Import secrets 40 | uses: hashicorp/vault-action@cb841f2c86fb6d07cff94fda240828c1abc5ba43 # v2.7.3 41 | with: 42 | url: https://vault.fluence.dev 43 | path: jwt/github 44 | role: ci 45 | method: jwt 46 | jwtGithubAudience: "https://github.com/fluencelabs" 47 | jwtTtl: 300 48 | exportToken: false 49 | secrets: | 50 | kv/cargo-registry/users/ci token | CARGO_REGISTRIES_FLUENCE_TOKEN 51 | 52 | - name: Setup Rust toolchain 53 | uses: dsherret/rust-toolchain-file@v1 54 | 55 | - name: Setup cache 56 | uses: Swatinem/rust-cache@v2 57 | with: 58 | cache-directories: ~/.cache/sccache 59 | shared-key: marine 60 | save-if: false 61 | 62 | - name: Setup sccache 63 | uses: mozilla-actions/sccache-action@v0.0.3 64 | 65 | - name: Generate snapshot version 66 | id: version 67 | uses: fluencelabs/github-actions/generate-snapshot-id@main 68 | 69 | - name: Publish crate snapshots 70 | id: snapshot 71 | uses: fluencelabs/github-actions/cargo-publish-snapshot@main 72 | with: 73 | id: ${{ steps.version.outputs.id }} 74 | 75 | - name: Build marine 76 | run: cargo build -p marine --release 77 | 78 | - name: Upload binary to checks 79 | uses: actions/upload-artifact@v3 80 | with: 81 | name: marine 82 | path: target/release/marine 83 | -------------------------------------------------------------------------------- /crates/fluence-app-service/src/raw_toml_config.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use crate::Result; 21 | use crate::AppServiceError; 22 | use crate::config::AppServiceConfig; 23 | 24 | use marine::TomlMarineConfig; 25 | use marine_wasm_backend_traits::WasmBackend; 26 | 27 | use serde_derive::Serialize; 28 | use serde_derive::Deserialize; 29 | 30 | use std::convert::TryInto; 31 | use std::path::PathBuf; 32 | 33 | #[derive(Deserialize, Serialize, Debug, Clone, Default)] 34 | pub struct TomlAppServiceConfig { 35 | pub service_working_dir: Option, 36 | 37 | #[serde(flatten)] 38 | pub toml_marine_config: TomlMarineConfig, 39 | } 40 | 41 | impl TomlAppServiceConfig { 42 | /// Load config from filesystem. 43 | pub fn load>(path: P) -> Result { 44 | let path = path.into(); 45 | let file_content = std::fs::read(&path)?; 46 | toml::from_slice(&file_content).map_err(|e| { 47 | AppServiceError::ConfigParseError(format!("Error parsing config {:?}: {:?}", path, e)) 48 | }) 49 | } 50 | } 51 | 52 | impl TryInto> for TomlAppServiceConfig { 53 | type Error = AppServiceError; 54 | 55 | fn try_into(self) -> Result> { 56 | let marine_config = self.toml_marine_config.try_into()?; 57 | let service_working_dir = match self.service_working_dir { 58 | Some(service_working_dir) => PathBuf::from(service_working_dir), 59 | // use current dir for service base dir if it isn't defined 60 | None => std::env::current_dir()?, 61 | }; 62 | 63 | Ok(AppServiceConfig { 64 | service_working_dir, 65 | marine_config, 66 | }) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /core/src/module/exports.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Marine WebAssembly runtime 3 | * 4 | * Copyright (C) 2024 Fluence DAO 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation version 3 of the 9 | * License. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | use super::IValue; 21 | use super::IType; 22 | use super::IFunctionArg; 23 | use wasmer_it::interpreter::wasm; 24 | 25 | use futures::future::BoxFuture; 26 | use futures::FutureExt; 27 | 28 | // In current implementation export simply does nothing, because there is no more 29 | // explicit instruction call-export in this version of wasmer-interface-types, 30 | // but explicit Exports is still required by wasmer-interface-types::Interpreter. 31 | #[derive(Clone)] 32 | pub(crate) struct ITExport { 33 | name: String, 34 | arguments: Vec, 35 | outputs: Vec, 36 | function: fn(arguments: &[IValue]) -> Result, anyhow::Error>, 37 | } 38 | 39 | impl ITExport { 40 | #[allow(unused)] 41 | pub(crate) fn new() -> Self { 42 | Self { 43 | name: String::new(), 44 | arguments: vec![], 45 | outputs: vec![], 46 | function: |_| -> _ { Ok(vec![]) }, 47 | } 48 | } 49 | } 50 | 51 | impl wasm::structures::Export for ITExport { 52 | fn name(&self) -> &str { 53 | self.name.as_str() 54 | } 55 | 56 | fn inputs_cardinality(&self) -> usize { 57 | self.arguments.len() 58 | } 59 | 60 | fn outputs_cardinality(&self) -> usize { 61 | self.outputs.len() 62 | } 63 | 64 | fn arguments(&self) -> &[IFunctionArg] { 65 | &self.arguments 66 | } 67 | 68 | fn outputs(&self) -> &[IType] { 69 | &self.outputs 70 | } 71 | 72 | fn call_async<'args>( 73 | &'args self, 74 | arguments: &'args [IValue], 75 | ) -> BoxFuture<'args, Result, anyhow::Error>> { 76 | async move { (self.function)(arguments) }.boxed() 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /marine-js/npm-package/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@fluencelabs/marine-js", 3 | "description": "Marine-js", 4 | "version": "0.14.0", 5 | "exports": { 6 | ".": "./dist/index.js", 7 | "./types": { 8 | "types": "./dist/types.d.ts", 9 | "import": "./dist/types.js" 10 | }, 11 | "./MarineService": { 12 | "types": "./dist/MarineService.d.ts", 13 | "import": "./dist/MarineService.js" 14 | }, 15 | "./config": { 16 | "types": "./dist/config.d.ts", 17 | "import": "./dist/config.js" 18 | }, 19 | "./marine-js.wasm": "./dist/marine-js.wasm", 20 | "./dist/types": { 21 | "types": "./dist/types.d.ts", 22 | "import": "./dist/types.js" 23 | }, 24 | "./dist/MarineService": { 25 | "types": "./dist/MarineService.d.ts", 26 | "import": "./dist/MarineService.js" 27 | }, 28 | "./dist/config": { 29 | "types": "./dist/config.d.ts", 30 | "import": "./dist/config.js" 31 | }, 32 | "./dist/marine-js.wasm": "./dist/marine-js.wasm" 33 | }, 34 | "typesVersions": { 35 | "*": { 36 | "types.d.ts": [ 37 | "./dist/types.d.ts" 38 | ], 39 | "MarineService.d.ts": [ 40 | "./dist/MarineService.d.ts" 41 | ], 42 | "config.d.ts": [ 43 | "./dist/config.d.ts" 44 | ] 45 | } 46 | }, 47 | "type": "module", 48 | "repository": "https://github.com/fluencelabs/marine", 49 | "author": "Fluence DAO, Clouldless Labs", 50 | "license": "AGPL-3.0-only", 51 | "files": [ 52 | "dist/*", 53 | "!lib/__test__/*" 54 | ], 55 | "scripts": { 56 | "build": "tsc -p tsconfig.build.json", 57 | "prebuild": "node update-imports.cjs && rm -rf ./src/snippets && cp -R ../marine-js-pkg/snippets ./src/", 58 | "postbuild": "cp ../marine-js-pkg/marine_js_bg.wasm ./dist/marine-js.wasm ", 59 | "test": "NODE_OPTIONS=--experimental-vm-modules jest" 60 | }, 61 | "private": false, 62 | "dependencies": { 63 | "@wasmer/wasi": "0.12.0", 64 | "@wasmer/wasmfs": "0.12.0", 65 | "default-import": "1.1.5" 66 | }, 67 | "devDependencies": { 68 | "@babel/parser": "7.22.7", 69 | "@babel/traverse": "7.22.8", 70 | "@fluencelabs/avm": "0.54.0", 71 | "@jest/globals": "29.6.2", 72 | "@types/download": "8.0.1", 73 | "@types/jest": "27.5.2", 74 | "@types/node": "16.11.59", 75 | "download": "8.0.0", 76 | "jest": "29.4.1", 77 | "recast": "0.23.1", 78 | "ts-jest": "29.0.5", 79 | "ts-loader": "9.4.2", 80 | "typescript": "4.8.3" 81 | } 82 | } 83 | --------------------------------------------------------------------------------