hello
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
|
||||
https://jsdw.me/posts/wasm-components/
|
||||
https://gertvv.nl/posts/wasm-component-raw.html
|
||||
|
||||
@@ -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"]
|
||||
|
||||
+15
-20
@@ -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
|
||||
|
||||
@@ -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<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