hello
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
|
|
||||||
https://jsdw.me/posts/wasm-components/
|
https://jsdw.me/posts/wasm-components/
|
||||||
|
https://gertvv.nl/posts/wasm-component-raw.html
|
||||||
|
|||||||
@@ -7,14 +7,8 @@ main = shakeArgs shakeOptions $ do
|
|||||||
-- action $ do
|
-- action $ do
|
||||||
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
||||||
-- need $ (-<.> "luac") <$> sourceFiles
|
-- need $ (-<.> "luac") <$> sourceFiles
|
||||||
want ["complete.component.wasm"]
|
want ["hello.component.wasm"]
|
||||||
alternatives $ do
|
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
|
"*.component.wasm" %> \out -> do
|
||||||
let wasm = out `replaceExtensions` "wasm"
|
let wasm = out `replaceExtensions` "wasm"
|
||||||
need [wasm]
|
need [wasm]
|
||||||
@@ -30,8 +24,8 @@ main = shakeArgs shakeOptions $ do
|
|||||||
"wasm-tools component embed"
|
"wasm-tools component embed"
|
||||||
[wit] [wat] "-o" [out]
|
[wit] [wat] "-o" [out]
|
||||||
phony "run" $ do
|
phony "run" $ do
|
||||||
need ["complete.component.wasm"]
|
need ["hello.component.wasm"]
|
||||||
cmd_ "wasmtime run --invoke add(1) complete.component.wasm"
|
cmd_ "wasmtime run --invoke hello() hello.component.wasm"
|
||||||
phony "clean" $ do
|
phony "clean" $ do
|
||||||
removeFilesAfter ".shake" ["//*"]
|
removeFilesAfter ".shake" ["//*"]
|
||||||
liftIO $ removeFiles "." ["*.wasm"]
|
liftIO $ removeFiles "." ["*.wasm"]
|
||||||
|
|||||||
+15
-20
@@ -1,27 +1,22 @@
|
|||||||
(module
|
(module
|
||||||
;; Correct module name: stdio, not stdout
|
;; Correct module name: stdio, not stdout
|
||||||
(import "wasi:cli/stdio@0.2.6" "get-stdout"
|
(import "wasi:cli/stdout@0.2.6" "get-stdout"
|
||||||
(func $get_stdout (result i32)))
|
(func $get-stdout (result i32)))
|
||||||
|
|
||||||
;; Write and flush a buffer.
|
;; Write and flush a buffer.
|
||||||
(import "wasi:io/streams@0.2.0" "blocking-write-and-flush"
|
(import
|
||||||
(func $bwrite (param i32 i32 i32) (result i32)))
|
"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")
|
(func $hello (export "hello")
|
||||||
(local $stdout i32)
|
(call $print
|
||||||
;; Get the stdout stream handle
|
(call $get-stdout)
|
||||||
call $get_stdout
|
(i32.const 16) ;; offset to print
|
||||||
local.set $stdout
|
(i32.const 12) ;; length to print
|
||||||
|
(i32.const 32)))) ;; offset for result
|
||||||
;; 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)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package root:component;
|
|||||||
world root {
|
world root {
|
||||||
import wasi:cli/stdin@0.2.6;
|
import wasi:cli/stdin@0.2.6;
|
||||||
import wasi:cli/stdout@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 {
|
package wasi:cli@0.2.6 {
|
||||||
@@ -13,10 +15,39 @@ package wasi:cli@0.2.6 {
|
|||||||
|
|
||||||
get-stdout: func() -> output-stream;
|
get-stdout: func() -> output-stream;
|
||||||
}
|
}
|
||||||
|
interface stdin {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
package wasi:cli@0.2.0 {
|
// package wasi:cli@0.2.0 {
|
||||||
interface run {
|
// interface run {
|
||||||
run: func() -> result;
|
// 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<u8>) -> result<_, stream-error>;
|
||||||
|
blocking-write-and-flush: func(contents: list<u8>) ->result<_,stream-error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
variant stream-error {
|
||||||
|
last-operation-failed(error),
|
||||||
|
closed,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
target
|
|
||||||
Generated
-7
@@ -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"
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "rust"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
@@ -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";
|
|
||||||
})
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user