From 56d83c1a713758ce2c53e771176ac42fb9fdeae3 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 20 Sep 2024 22:18:37 +0200 Subject: [PATCH] fix: link `wasi:logging` Signed-off-by: Roman Volosatovs --- Cargo.lock | 4 +- Cargo.toml | 2 +- bindings/wasi/logging/imports/imports.wit.go | 4 + bindings/wasi/logging/logging/empty.s | 3 + bindings/wasi/logging/logging/logging.wit.go | 86 ++++++++++++++++++++ crates/sys/Cargo.toml | 2 +- src/lib.rs | 5 +- 7 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 bindings/wasi/logging/imports/imports.wit.go create mode 100644 bindings/wasi/logging/logging/empty.s create mode 100644 bindings/wasi/logging/logging/logging.wit.go diff --git a/Cargo.lock b/Cargo.lock index ee6946a..924fbea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2045,7 +2045,7 @@ dependencies = [ [[package]] name = "west" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "http", @@ -2068,7 +2068,7 @@ dependencies = [ [[package]] name = "west-sys" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 977460f..11c3407 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "west" -version = "0.1.2" +version = "0.1.3" description = "WebAssembly component test runtime" authors.workspace = true diff --git a/bindings/wasi/logging/imports/imports.wit.go b/bindings/wasi/logging/imports/imports.wit.go new file mode 100644 index 0000000..033fb88 --- /dev/null +++ b/bindings/wasi/logging/imports/imports.wit.go @@ -0,0 +1,4 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package imports represents the world "wasi:logging/imports". +package imports diff --git a/bindings/wasi/logging/logging/empty.s b/bindings/wasi/logging/logging/empty.s new file mode 100644 index 0000000..5444f20 --- /dev/null +++ b/bindings/wasi/logging/logging/empty.s @@ -0,0 +1,3 @@ +// This file exists for testing this package without WebAssembly, +// allowing empty function bodies with a //go:wasmimport directive. +// See https://pkg.go.dev/cmd/compile for more information. diff --git a/bindings/wasi/logging/logging/logging.wit.go b/bindings/wasi/logging/logging/logging.wit.go new file mode 100644 index 0000000..15b6e95 --- /dev/null +++ b/bindings/wasi/logging/logging/logging.wit.go @@ -0,0 +1,86 @@ +// Code generated by wit-bindgen-go. DO NOT EDIT. + +// Package logging represents the imported interface "wasi:logging/logging". +// +// WASI Logging is a logging API intended to let users emit log messages with +// simple priority levels and context values. +package logging + +import ( + "github.com/bytecodealliance/wasm-tools-go/cm" +) + +// Level represents the enum "wasi:logging/logging#level". +// +// A log level, describing a kind of message. +// +// enum level { +// trace, +// debug, +// info, +// warn, +// error, +// critical +// } +type Level uint8 + +const ( + // Describes messages about the values of variables and the flow of + // control within a program. + LevelTrace Level = iota + + // Describes messages likely to be of interest to someone debugging a + // program. + LevelDebug + + // Describes messages likely to be of interest to someone monitoring a + // program. + LevelInfo + + // Describes messages indicating hazardous situations. + LevelWarn + + // Describes messages indicating serious errors. + LevelError + + // Describes messages indicating fatal errors. + LevelCritical +) + +var stringsLevel = [6]string{ + "trace", + "debug", + "info", + "warn", + "error", + "critical", +} + +// String implements [fmt.Stringer], returning the enum case name of e. +func (e Level) String() string { + return stringsLevel[e] +} + +// Log represents the imported function "log". +// +// Emit a log message. +// +// A log message has a `level` describing what kind of message is being +// sent, a context, which is an uninterpreted string meant to help +// consumers group similar messages, and a string containing the message +// text. +// +// log: func(level: level, context: string, message: string) +// +//go:nosplit +func Log(level Level, context string, message string) { + level0 := (uint32)(level) + context0, context1 := cm.LowerString(context) + message0, message1 := cm.LowerString(message) + wasmimport_Log((uint32)(level0), (*uint8)(context0), (uint32)(context1), (*uint8)(message0), (uint32)(message1)) + return +} + +//go:wasmimport wasi:logging/logging log +//go:noescape +func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) diff --git a/crates/sys/Cargo.toml b/crates/sys/Cargo.toml index 4a3f45d..d28628d 100644 --- a/crates/sys/Cargo.toml +++ b/crates/sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "west-sys" -version = "0.1.2" +version = "0.1.3" description = "WebAssembly component test runtime C bindings" authors.workspace = true diff --git a/src/lib.rs b/src/lib.rs index 729ef76..411b206 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -302,7 +302,10 @@ pub fn instantiate(Config { engine, wasm }: Config) -> anyhow::Result wasmtime_wasi::add_to_linker_sync(&mut linker).context("failed to link WASI")?; wasmtime_wasi_http::add_only_http_to_linker_sync(&mut linker) .context("failed to link `wasi:http`")?; - bindings::wasiext::http::ext::add_to_linker(&mut linker, |cx| cx)?; + bindings::wasiext::http::ext::add_to_linker(&mut linker, |cx| cx) + .context("failed to link `wasiext:http/ext`")?; + bindings::wasi::logging::logging::add_to_linker(&mut linker, |cx| cx) + .context("failed to link `wasi:logging/logging`")?; let wasi = WasiCtxBuilder::new() .inherit_env()