wip: rustslop
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import Development.Shake
|
||||
import Development.Shake.Command
|
||||
import Development.Shake.FilePath
|
||||
import Development.Shake.Util
|
||||
|
||||
main = shakeArgs shakeOptions $ do
|
||||
-- action $ do
|
||||
-- sourceFiles <- getDirectoryFiles "" ["//*.luasm"]
|
||||
-- need $ (-<.> "luac") <$> sourceFiles
|
||||
want ["complete.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]
|
||||
cmd_
|
||||
"wasm-tools component new"
|
||||
[wasm]
|
||||
"-o" [out]
|
||||
"*.wasm" %> \out -> do
|
||||
let wit = out -<.> "wit"
|
||||
let wat = out -<.> "wat"
|
||||
need [wit,wat]
|
||||
cmd_
|
||||
"wasm-tools component embed"
|
||||
[wit] [wat] "-o" [out]
|
||||
phony "run" $ do
|
||||
need ["complete.component.wasm"]
|
||||
cmd_ "wasmtime run --invoke add(1) complete.component.wasm"
|
||||
phony "clean" $ do
|
||||
removeFilesAfter ".shake" ["//*"]
|
||||
liftIO $ removeFiles "." ["*.wasm"]
|
||||
@@ -0,0 +1,27 @@
|
||||
(module
|
||||
;; Correct module name: stdio, not stdout
|
||||
(import "wasi:cli/stdio@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)))
|
||||
|
||||
(memory (export "memory") 1)
|
||||
|
||||
(data (i32.const 0) "Hello, World!\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)
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
package root:component;
|
||||
|
||||
world root {
|
||||
import wasi:cli/stdin@0.2.6;
|
||||
import wasi:cli/stdout@0.2.6;
|
||||
|
||||
export wasi:cli/run@0.2.0;
|
||||
}
|
||||
|
||||
package wasi:cli@0.2.6 {
|
||||
interface stdout {
|
||||
use wasi:io/streams@0.2.6.{output-stream};
|
||||
|
||||
get-stdout: func() -> output-stream;
|
||||
}
|
||||
}
|
||||
|
||||
package wasi:cli@0.2.0 {
|
||||
interface run {
|
||||
run: func() -> result;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
inherit system;
|
||||
};
|
||||
shake = pkgs.callPackage ./shake-wrapper.nix {};
|
||||
rustslop = pkgs.callPackage ./rustslop {};
|
||||
in {
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
packages = [
|
||||
@@ -20,6 +21,10 @@
|
||||
pkgs.wasm-tools
|
||||
pkgs.wac-cli
|
||||
];
|
||||
inputsFrom = [
|
||||
rustslop
|
||||
];
|
||||
inherit (rustslop) CARGO_BUILD_TARGET;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
target
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,13 @@
|
||||
{ lib
|
||||
, rustPlatform
|
||||
}:
|
||||
|
||||
rustPlatform.buildRustPackage (finalAttrs: {
|
||||
pname = "rustslop";
|
||||
version = "0.0.1";
|
||||
src = ./.;
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
};
|
||||
CARGO_BUILD_TARGET = "wasm32-wasip2";
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
Reference in New Issue
Block a user