WebAssembly n’est pas qu’une affaire de frontend
Benjamin Coenen
@bnj25
2
Benjamin Coenen
bnj25
bnjjj
https://www.apollographql.com/blog/announcement/backend/announcing-apollo-router-v1-0/
Summary
Historique
WebAssembly
WebAssembly: langage à pile
Exemple opération: 5 + 2
WebAssembly: langage à pile
WebAssembly: langage à pile
WebAssembly: langage à pile
WebAssembly: langage à pile
WebAssembly: langage à pile
Credit to Laetitia Langlois
WebAssembly: 5 types
WebAssembly: formats
WebAssembly
Frontend side
Frontend side: communication entre JavaScript et Wasm
Frontend side
Backend side: cas d’usage
Backend side: projets existants
Backend side: projets existants
HIPPO
Deislab
Backend side: projets existants
Tools and libraries: runtimes (liste non-exhaustive)
Wasmtime
Environnement sandboxé
X
X
Environnement sandboxé
V
V
Environnement sandboxé: exemple
Bindings
Cas d’usage: utilisation dans un autre langage
(func $concat (type $t10) (param $p0 i32) (param $p1 i32) (param $p2 i32) (param $p3 i32) (param $p4 i32) (param $p5 i32) (param $p6 i32)
#[no_mangle]
pub extern "C" fn concat(mut first: String, second: String) -> String {
first.push_str(&second);
first
}
ptr, len0 = _encode_utf8(first, realloc, memory, caller)
ptr1, len2 = _encode_utf8(second, realloc, memory, caller)
ret = self._concat(caller, ptr, len0, ptr1, len2)
assert(isinstance(ret, int))
load = _load(ctypes.c_int32, memory, caller, ret, 0)
load3 = _load(ctypes.c_int32, memory, caller, ret, 8)
ptr4 = load
len5 = load3
list = _decode_utf8(memory, caller, ptr4, len5)
Bindings générés via wit-bindgen
wit-bindgen, exemple de fichier .wit
Fichier bindings.py généré
+
#[no_mangle]
pub extern "C" fn concat(mut first: String, second: String) -> String {
first.push_str(&second);
first
}
concat: function(first: string, second: string) -> string
input = bindings.Input(store, linker, my_module)
print(input.concat(store, "hello", "world"))
Exécution au niveau de python
Runtime WASM
Lecture dans la mémoire du runtime via pointeur
Fichier wit auto généré grâce à witgen
Fichier .wit généré avec witgen
#[no_mangle]
#[witgen]
pub extern "C" fn concat(mut first: String, second: String) -> String {
first.push_str(&second);
first
}
concat: function(first: string, second: string) -> string
Fichier bindings.py généré
+
input = bindings.Input(store, linker, my_module)
print(input.concat(store, "hello", "world"))
Exemple wit-bindgen et witgen
Toolings
Merci
bnj25
bnjjj