aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2023-03-28 13:39:12 -0400
committerXe Iaso <me@xeiaso.net>2023-03-28 13:39:12 -0400
commit12c1d317138d124c2e54cb94da045bdb832d22f3 (patch)
treef7d1849ed4da847c4f6f4bc96a6a188f8d1fb353
parentfda27095a9098b3b536d1e6ab9aa11a47ab3523c (diff)
downloadx-12c1d317138d124c2e54cb94da045bdb832d22f3.tar.xz
x-12c1d317138d124c2e54cb94da045bdb832d22f3.zip
add wasip1 experiments
Signed-off-by: Xe Iaso <me@xeiaso.net>
-rw-r--r--flake.lock18
-rw-r--r--flake.nix34
-rw-r--r--wasm/wasip1/.gitignore1
-rw-r--r--wasm/wasip1/Makefile12
-rw-r--r--wasm/wasip1/cat.go31
-rw-r--r--wasm/wasip1/envdump.go16
-rw-r--r--wasm/wasip1/hello.go7
7 files changed, 116 insertions, 3 deletions
diff --git a/flake.lock b/flake.lock
index 6785a68..4cf5d57 100644
--- a/flake.lock
+++ b/flake.lock
@@ -100,6 +100,7 @@
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay",
"utils": "utils_2",
+ "wasigo": "wasigo",
"xess": "xess"
}
},
@@ -156,6 +157,23 @@
"type": "github"
}
},
+ "wasigo": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1680023486,
+ "narHash": "sha256-LRCzxbowBykYSJnaffPqwVpckPRmFcHG6UsWxjfPxQ4=",
+ "owner": "Xe",
+ "repo": "go",
+ "rev": "b558380c7a1c8976c8eeacde716be3d4ccd409f2",
+ "type": "github"
+ },
+ "original": {
+ "owner": "Xe",
+ "ref": "wasip1-wasm",
+ "repo": "go",
+ "type": "github"
+ }
+ },
"xess": {
"inputs": {
"nixpkgs": [
diff --git a/flake.nix b/flake.nix
index 1c02d1a..3317105 100644
--- a/flake.nix
+++ b/flake.nix
@@ -29,9 +29,18 @@
};
iaso-fonts.url = "github:Xe/iosevka";
+
+ ## other things
+ # go + wasip1
+ wasigo = {
+ # https://github.com/Pryz/go/archive/refs/heads/wasip1-wasm.zip
+ url = "github:Xe/go/wasip1-wasm";
+ flake = false;
+ };
};
- outputs = { self, nixpkgs, utils, gomod2nix, rust-overlay, naersk, xess, iaso-fonts }@inputs:
+ outputs = { self, nixpkgs, utils, gomod2nix, rust-overlay, naersk, xess
+ , iaso-fonts, wasigo }@inputs:
utils.lib.eachSystem [
"x86_64-linux"
"aarch64-linux"
@@ -90,7 +99,9 @@
buildPhase = ''
mkdir -p $out/static/css/iosevka
- ln -s ${xess.packages.${system}.aoi}/static/css/xess.css $out/static/css/xess.css
+ ln -s ${
+ xess.packages.${system}.aoi
+ }/static/css/xess.css $out/static/css/xess.css
for file in ${iaso-fonts.packages.${system}.default}/*; do
ln -s $file $out/static/css/iosevka
done
@@ -116,6 +127,20 @@
cp $src/bin/$pname $out/bin/$path
'';
};
+
+ wasigo' = pkgs.go_1_20.overrideAttrs (old: {
+ src = pkgs.runCommand "gowasi-version-hack" { } ''
+ mkdir -p $out
+ echo "go-wasip1-dev-${wasigo.shortRev}" > $out/VERSION
+ cp -vrf ${wasigo}/* $out
+ '';
+ });
+
+ gowasi = pkgs.writeShellScriptBin "gowasi" ''
+ export GOOS=wasip1
+ export GOARCH=wasm
+ exec ${wasigo'}/bin/go $*
+ '';
in {
overlays.default = final: prev:
let
@@ -126,6 +151,8 @@
packages = rec {
default = everything;
+ wasigo = wasigo';
+
mastosan-wasm = naersk'.buildPackage {
src = ./web/mastosan;
targets = [ "wasm32-wasi" ];
@@ -181,7 +208,7 @@
};
};
portable = {
- xedn = let
+ xedn = let
service = pkgs.substituteAll {
name = "xedn.service";
src = ./run/xedn.service.in;
@@ -212,6 +239,7 @@
strace
hey
boltbrowser
+ gowasi
pkg-config
libaom
diff --git a/wasm/wasip1/.gitignore b/wasm/wasip1/.gitignore
new file mode 100644
index 0000000..19e1bce
--- /dev/null
+++ b/wasm/wasip1/.gitignore
@@ -0,0 +1 @@
+*.wasm
diff --git a/wasm/wasip1/Makefile b/wasm/wasip1/Makefile
new file mode 100644
index 0000000..c5cc92d
--- /dev/null
+++ b/wasm/wasip1/Makefile
@@ -0,0 +1,12 @@
+GOBIN = gowasi
+
+export GOARCH = wasm
+export GOOS = wasip1
+
+SOURCES := $(wildcard *.go)
+OBJECTS := $(patsubst %.go, %.wasm, $(SOURCES))
+
+%.wasm: %.go
+ $(GOBIN) build -o $@ $^
+
+all: $(OBJECTS)
diff --git a/wasm/wasip1/cat.go b/wasm/wasip1/cat.go
new file mode 100644
index 0000000..a327d9d
--- /dev/null
+++ b/wasm/wasip1/cat.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "io"
+ "log"
+ "os"
+)
+
+func main() {
+ flag.Usage = func() {
+ fmt.Printf("%s <file>\n\nprints file to standard out\n", os.Args[0])
+ }
+ flag.Parse()
+
+ if flag.NArg() != 1 {
+ log.Fatalf("wanted 1 arg, got %#v", os.Args)
+ }
+
+ fin, err := os.Open(flag.Arg(0))
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer fin.Close()
+
+ _, err = io.Copy(os.Stdout, fin)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/wasm/wasip1/envdump.go b/wasm/wasip1/envdump.go
new file mode 100644
index 0000000..79dedc5
--- /dev/null
+++ b/wasm/wasip1/envdump.go
@@ -0,0 +1,16 @@
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+func main() {
+ if len(os.Environ()) == 0 {
+ fmt.Println("No environment variables found")
+ return
+ }
+ for _, kv := range os.Environ() {
+ fmt.Println(kv)
+ }
+}
diff --git a/wasm/wasip1/hello.go b/wasm/wasip1/hello.go
new file mode 100644
index 0000000..db5bdb6
--- /dev/null
+++ b/wasm/wasip1/hello.go
@@ -0,0 +1,7 @@
+package main
+
+import "log"
+
+func main() {
+ log.Println("Hello, world!")
+}