From 18dd53f02a0c5aeb05700413ad3d1c568e640470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Mon, 22 Jun 2026 03:42:27 -0600 Subject: [PATCH] hello --- README.md | 1 + examples/hello/Shakefile.hs | 12 +++-------- examples/hello/hello.wat | 35 +++++++++++++----------------- examples/hello/hello.wit | 43 +++++++++++++++++++++++++++++++------ rustslop/.gitignore | 1 - rustslop/Cargo.lock | 7 ------ rustslop/Cargo.toml | 6 ------ rustslop/default.nix | 13 ----------- rustslop/src/main.rs | 3 --- 9 files changed, 56 insertions(+), 65 deletions(-) delete mode 100644 rustslop/.gitignore delete mode 100644 rustslop/Cargo.lock delete mode 100644 rustslop/Cargo.toml delete mode 100644 rustslop/default.nix delete mode 100644 rustslop/src/main.rs diff --git a/README.md b/README.md index c7b07bf..3941758 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ https://jsdw.me/posts/wasm-components/ +https://gertvv.nl/posts/wasm-component-raw.html diff --git a/examples/hello/Shakefile.hs b/examples/hello/Shakefile.hs index b21d88f..dc4a1c5 100644 --- a/examples/hello/Shakefile.hs +++ b/examples/hello/Shakefile.hs @@ -7,14 +7,8 @@ main = shakeArgs shakeOptions $ do -- action $ do -- sourceFiles <- getDirectoryFiles "" ["//*.luasm"] -- need $ (-<.> "luac") <$> sourceFiles - want ["complete.component.wasm"] + want ["hello.component.wasm"] alternatives $ do - "complete.component.wasm" %> \out -> do - need ["provider.component.wasm","importing.component.wasm"] - cmd_ - "wac plug --plug" - "provider.component.wasm" "importing.component.wasm" - "-o" "complete.component.wasm" "*.component.wasm" %> \out -> do let wasm = out `replaceExtensions` "wasm" need [wasm] @@ -30,8 +24,8 @@ main = shakeArgs shakeOptions $ do "wasm-tools component embed" [wit] [wat] "-o" [out] phony "run" $ do - need ["complete.component.wasm"] - cmd_ "wasmtime run --invoke add(1) complete.component.wasm" + need ["hello.component.wasm"] + cmd_ "wasmtime run --invoke hello() hello.component.wasm" phony "clean" $ do removeFilesAfter ".shake" ["//*"] liftIO $ removeFiles "." ["*.wasm"] diff --git a/examples/hello/hello.wat b/examples/hello/hello.wat index 1af4d0d..c4b9bf5 100644 --- a/examples/hello/hello.wat +++ b/examples/hello/hello.wat @@ -1,27 +1,22 @@ (module ;; Correct module name: stdio, not stdout - (import "wasi:cli/stdio@0.2.6" "get-stdout" - (func $get_stdout (result i32))) + (import "wasi:cli/stdout@0.2.6" "get-stdout" + (func $get-stdout (result i32))) ;; Write and flush a buffer. - (import "wasi:io/streams@0.2.0" "blocking-write-and-flush" - (func $bwrite (param i32 i32 i32) (result i32))) + (import + "wasi:io/streams@0.2.6" + "[method]output-stream.blocking-write-and-flush" + (func $print (param i32 i32 i32 i32))) - (memory (export "memory") 1) + (memory 1) + (export "memory" (memory 0)) - (data (i32.const 0) "Hello, World!\n") + (data (i32.const 16) "hello worms\n") - (func (export "main") - (local $stdout i32) - ;; Get the stdout stream handle - call $get_stdout - local.set $stdout - - ;; Write "Hello, World!\n" (14 bytes) to stdout - local.get $stdout - i32.const 0 - i32.const 14 - call $bwrite - drop ;; ignore the return value (0 = success) - ) -) + (func $hello (export "hello") + (call $print + (call $get-stdout) + (i32.const 16) ;; offset to print + (i32.const 12) ;; length to print + (i32.const 32)))) ;; offset for result diff --git a/examples/hello/hello.wit b/examples/hello/hello.wit index 4c52be0..e00606e 100644 --- a/examples/hello/hello.wit +++ b/examples/hello/hello.wit @@ -3,8 +3,10 @@ package root:component; world root { import wasi:cli/stdin@0.2.6; import wasi:cli/stdout@0.2.6; + import wasi:io/streams@0.2.6; - export wasi:cli/run@0.2.0; + // export wasi:cli/run@0.2.0; + export hello: func(); } package wasi:cli@0.2.6 { @@ -13,10 +15,39 @@ package wasi:cli@0.2.6 { get-stdout: func() -> output-stream; } -} - -package wasi:cli@0.2.0 { - interface run { - run: func() -> result; + interface stdin { } } + +// package wasi:cli@0.2.0 { +// interface run { +// run: func() -> result; +// } +// } + +package wasi:io@0.2.6 { + interface poll { + resource pollable { + block: func(); + } + } + interface error { + resource error; + } + interface streams { + use error.{error}; + use poll.{pollable}; + + resource input-stream; + + resource output-stream { + write: func(contents: list) -> result<_, stream-error>; + blocking-write-and-flush: func(contents: list) ->result<_,stream-error>; + } + + variant stream-error { + last-operation-failed(error), + closed, + } + } +} \ No newline at end of file diff --git a/rustslop/.gitignore b/rustslop/.gitignore deleted file mode 100644 index 1de5659..0000000 --- a/rustslop/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target \ No newline at end of file diff --git a/rustslop/Cargo.lock b/rustslop/Cargo.lock deleted file mode 100644 index b9d42e1..0000000 --- a/rustslop/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "rust" -version = "0.1.0" diff --git a/rustslop/Cargo.toml b/rustslop/Cargo.toml deleted file mode 100644 index 1c61e9e..0000000 --- a/rustslop/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "rust" -version = "0.1.0" -edition = "2024" - -[dependencies] diff --git a/rustslop/default.nix b/rustslop/default.nix deleted file mode 100644 index d9d6e4f..0000000 --- a/rustslop/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ lib -, rustPlatform -}: - -rustPlatform.buildRustPackage (finalAttrs: { - pname = "rustslop"; - version = "0.0.1"; - src = ./.; - cargoLock = { - lockFile = ./Cargo.lock; - }; - CARGO_BUILD_TARGET = "wasm32-wasip2"; -}) diff --git a/rustslop/src/main.rs b/rustslop/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/rustslop/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -}