-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CUE and WebAssembly (Wasm) #2035
Comments
If you'd like to provide use cases and/or feedback on potential use of Wasm with CUE, please post to the discussion at #2045. |
Add a new package, cuelang.org/go/cue/interpreter/wasm that enables Wasm support in CUE as an external interpreter. Code wishing to use Wasm must use an `@extern("wasm")` package attribute. Individual functions are imported from Wasm modules like so: add: _ @extern("foo.wasm", abi=c, sig="func(int64, int64): int64") mul: _ @extern("foo.wasm", abi=c, sig="func(float64, float64): float64") not: _ @extern("foo.wasm", abi=c, sig="func(bool): bool") Where "foo.wasm" is a compiled Wasm module, and sig is the type signature of the imported function. So far, only the C ABI is supported, and only relatively few data types can be exchanged with the Wasm module. Basically only fixed-sized integers of any signness, fixed-sized floats, and booleans. The Wasm module is instantiated in a sandbox, with no access to the outside world. Users must ensure the functions exposed by the Wasm modules are pure, that is, they always returns the same answer for the same arguments. Functions may make use of global state for memoization and other optimizations as long as purity is preserved as viewed from the outside. Be aware that functions from the standard libraries of many languages are often not pure. Wasm is only enabled if the user explicitly imports cuelang.org/go/cue/wasm, otherwise it is not available. The Go cue package does not impart upon the user a dependency on the Wasm runtime if Wasm is not explicitly requested. Wasm is enabled and available in the command line tool. Updates #2035. Updates #2281. Updates #2282. Updates #2007. Change-Id: I844ec1229ea465dfeca45bc54006e87ed8ef0460 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/551738 Unity-Result: CUEcueckoo <cueckoo+gerrithub@cuelang.org> TryBot-Result: CUEcueckoo <cueckoo+gerrithub@cuelang.org> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com> Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
For folks following along here, apologies we forgot to add notice of the CUE + Web Assembly Focus Session Call. It was well advertised elsewhere, but we failed to join the dots here. |
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro>
…turn structs Add support for structs in Wasm functions. A function declares that is uses or returns a struct by referring to a CUE struct (defined elsewhere) in its type signature. The CUE struct is a straightforward translation of the native struct type with native scalars replaced by their CUE counterpats (e.g. u32 in Rust becomes uint32 in CUE, int16_t in C becomes int16 in CUE, etc). The order of fields in the CUE struct must match that of the target language. Only structs that contain scalars or other supported structs are currently supported. Struct fields that are pointers in the target language are not currently supported. This may change. In order to support structs CUE needs access to the memory allocator of the guest program. For this, the guest must export two Wasm functions with the following C type signatures: void* allocate(int n); void deallocate(void *ptr, int n); Allocate returns a Wasm pointer to a buffer of size n. Deallocate takes a Wasm pointer and the size of the buffer it points to and frees it. Updates #2035. Updates #2281. Change-Id: Ic509448226b22d2a54b70d565db6c702b801a839 Signed-off-by: Aram Hăvărneanu <aram@mgk.ro> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1173964 TryBot-Result: CUEcueckoo <cueckoo@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Roger Peppe <rogpeppe@gmail.com> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
As we discussed in several community calls, we're pausing Wasm developement until the Wasm ecosystem matures, in particular, we're waiting for the Component Model. |
Will there be an alternate way to do custom functions? |
We are open to the idea, although we don't have a concrete design in mind yet. Care to share an experience report, or a simple feature request? |
Would using an abstraction layer like extism help for integration of wasm? Then cue using wasm/wasi/wasipx wouldn't depend too much on their versions but more on the implementation in extism. https://github.com/extism/go-sdk |
This is an umbrella tracking issue for WebAssembly support in CUE.
Details to follow, but initial exploration is linked to #2007.
The text was updated successfully, but these errors were encountered: