Package org.apache.ignite.compute.wasm
Enum Class WasmCallingConvention
- All Implemented Interfaces:
Serializable,Comparable<WasmCallingConvention>,Constable
WebAssembly calling conventions.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionClang-specific calling convention that works with modules built using--target=wasm32-wasi.Generic calling convention.Generic command calling convention.Go-specific calling convention that works with modules built usingGOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared.Rust-specific calling convention that works with modules built usingwasm-packandwasm-bindgen. -
Method Summary
Modifier and TypeMethodDescriptionstatic WasmCallingConventionReturns the enum constant of this class with the specified name.static WasmCallingConvention[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
GENERIC
Generic calling convention. Aims to be language-agnostic.- Calls
_startand/or__wasm_call_ctorsfor module initialization (if present). - Requires
allocanddeallocexports for memory management.
- Calls
-
RUST_WASM_BINDGEN
Rust-specific calling convention that works with modules built usingwasm-packandwasm-bindgen.To build a compatible module:
cargo install wasm-packcargo new --lib hello-wasm- Add the following to
Cargo.toml:[lib] crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2"
- Add the following to
src/lib.rs:use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn hello(arg: String) -> String { format!("Hello from Rust, {}!", arg) } - Build the module:
wasm-pack build - Use the generated
pkg/hello_wasm_bg.wasmfile as the compute module.
-
GO_WASI_REACTOR
Go-specific calling convention that works with modules built usingGOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared.To build a compatible module:
- In Go code, use
//go:wasmexportto mark functions for export:package main func main() { } //go:wasmexport addOne func addOne(x int32) int32 { return x + 1 } - Build the module:
GOOS=wasip1 GOARCH=wasm go build -o addone.wasm -buildmode=c-shared - Use the generated
addone.wasmfile as the compute module.
- In Go code, use
-
CLANG_WASI
Clang-specific calling convention that works with modules built using--target=wasm32-wasi.To build a compatible module:
- Install LLVM packages for WASM:
wasi-libc libc++abi-dev-wasm32 libc++-dev-wasm32 libclang-rt-dev-wasm32 - Add the following to
clang_min/add.c:#include <stdint.h> int32_t addOne(int32_t arg) { return arg + 1; } - Build and link your module:
--target=wasm32-wasi --no-standard-libraries -nostartfiles -Wl,--no-entry -Wl,--export-all -fvisibility=hidden
C:clang --target=wasm32-wasi --no-standard-libraries -nostartfiles -Wl,--no-entry -Wl,--export-all -fvisibility=hidden -o c_wasi.wasm add.c -l:libc.a
C++:clang++ --target=wasm32-wasi --no-standard-libraries -nostartfiles -Wl,--no-entry -Wl,--export-all -fvisibility=hidden -o cpp_wasi.wasm add.cpp -fno-exceptions -l:libc.a -l:libc++abi.a -l:libc++.a -l:libm.a $FULL_PATH_TO_BUILTINS_WASM32/libclang_rt.builtins-wasm32.a
Issue with the libclang_rt.builtins-wasm32.a - Use the generated
c_wasi.wasmorcpp_wasi.wasmfile as the compiled module.
- Install LLVM packages for WASM:
-
GENERIC_COMMAND
Generic command calling convention. Unlike "reactor" conventions which require an exported function to call ("library" mode), here we run the module as a command (program), passing the job argument to standard input and reading the result from the standard output.NOTE: Only string arguments and results are supported in this mode.
py2wasm example:
- Install py2wasm:
pip install py2wasm - Create a Python file
hello.py:import sys def main(): name = sys.stdin.read() print(f"Hello, {name}!") if __name__ == "__main__": main() - Build the module:
py2wasm --output hello.wasm hello.py - Use the generated
hello.wasmfile as the compute module. - Use
WasmJobDescriptor.commandBuilder(String)to build the job descriptor.
- Install py2wasm:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-