From bbb00b58dc2b08bfb630048c3be1328104263f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Fri, 16 Aug 2024 17:15:29 +0200 Subject: [PATCH] ts and go cleanups --- Cargo.lock | 11 +++++++++++ Cargo.toml | 4 ++-- examples/go/go-default-minimal/Makefile | 2 ++ examples/go/go-default-minimal/go.mod | 2 ++ examples/go/go-default-minimal/go.sum | 2 ++ examples/go/go-default-minimal/main.go | 8 +++----- examples/go/go-default/Makefile | 4 +++- examples/go/go-default/go.mod | 2 +- examples/go/go-default/go.sum | 4 ++-- examples/go/go-default/main.go | 17 +++++++++-------- examples/go/go-default/wit/component-name.wit | 6 +----- examples/ts/ts-default-minimal/package.json | 2 +- examples/ts/ts-default/package.json | 2 +- examples/ts/ts-example-fetch/package.json | 2 +- src/main.rs | 3 +-- 15 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 examples/go/go-default-minimal/go.sum diff --git a/Cargo.lock b/Cargo.lock index b8ad997..66b36ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,6 +162,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -217,6 +227,7 @@ dependencies = [ "Inflector", "cargo_metadata", "clap", + "colored", "copy_dir", "derive_more", "dir-diff", diff --git a/Cargo.toml b/Cargo.toml index c44e302..606ab1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,8 @@ repository = "https://github.com/golemcloud/golem-examples" description = "Golem example templates" [dependencies] +clap = { version = "4.4.17", features = ["derive"], optional = true } +colored = "2.1.0" derive_more = "0.99.17" golem-wit = { version = "0.4.0" } include_dir = { version = "0.7.3" } @@ -19,8 +21,6 @@ serde_json = { version = "1.0.111" } strum = "0.26.1" strum_macros = "0.26.1" -clap = { version = "4.4.17", features = ["derive"], optional = true } - [build-dependencies] cargo_metadata = "0.18.1" copy_dir = "0.1.3" diff --git a/examples/go/go-default-minimal/Makefile b/examples/go/go-default-minimal/Makefile index c6b2a50..240729a 100644 --- a/examples/go/go-default-minimal/Makefile +++ b/examples/go/go-default-minimal/Makefile @@ -1,3 +1,5 @@ +.PHONY: build bindings compile clean + build: compile wasm-tools component embed ./wit component_name.module.wasm --output component_name.embed.wasm wasm-tools component new component_name.embed.wasm -o component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm diff --git a/examples/go/go-default-minimal/go.mod b/examples/go/go-default-minimal/go.mod index 02fe01c..ee1c6af 100644 --- a/examples/go/go-default-minimal/go.mod +++ b/examples/go/go-default-minimal/go.mod @@ -1,3 +1,5 @@ module pack/name go 1.20 + +require github.com/golemcloud/golem-go v0.6.0 // indirect \ No newline at end of file diff --git a/examples/go/go-default-minimal/go.sum b/examples/go/go-default-minimal/go.sum new file mode 100644 index 0000000..550467a --- /dev/null +++ b/examples/go/go-default-minimal/go.sum @@ -0,0 +1,2 @@ +github.com/golemcloud/golem-go v0.6.0 h1:JkeHRrqqs+k6PTFASwknJVjcLBAvizqonhMO9M5B648= +github.com/golemcloud/golem-go v0.6.0/go.mod h1:VLL22qVo5R2+jGLO43tLPpPjf2WrA6B7GQoqXKnSODo= diff --git a/examples/go/go-default-minimal/main.go b/examples/go/go-default-minimal/main.go index 430dd0c..98f35d2 100644 --- a/examples/go/go-default-minimal/main.go +++ b/examples/go/go-default-minimal/main.go @@ -5,8 +5,7 @@ import ( ) func init() { - a := ComponentNameImpl{} - component_name.SetExportsPackNameApi(a) + component_name.SetExportsPackNameApi(&ComponentNameImpl{}) } // total State can be stored in global variables @@ -17,12 +16,11 @@ type ComponentNameImpl struct { // Implementation of the exported interface - -func (e ComponentNameImpl) Add(value uint64) { +func (e *ComponentNameImpl) Add(value uint64) { total += value } -func (e ComponentNameImpl) Get() uint64 { +func (e *ComponentNameImpl) Get() uint64 { return total } diff --git a/examples/go/go-default/Makefile b/examples/go/go-default/Makefile index f1452f8..8d67d7a 100644 --- a/examples/go/go-default/Makefile +++ b/examples/go/go-default/Makefile @@ -1,5 +1,7 @@ +.PHONY: build bindings compile clean + build: compile - wasm-tools component embed ./wit component_name.module.wasm --world component-name-imports --output component_name.embed.wasm + wasm-tools component embed ./wit component_name.module.wasm --output component_name.embed.wasm wasm-tools component new component_name.embed.wasm -o component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm bindings: diff --git a/examples/go/go-default/go.mod b/examples/go/go-default/go.mod index 5dba3c3..5513ff3 100644 --- a/examples/go/go-default/go.mod +++ b/examples/go/go-default/go.mod @@ -2,4 +2,4 @@ module pack/name go 1.20 -require github.com/golemcloud/golem-go v0.4.4 // indirect +require github.com/golemcloud/golem-go v0.6.0 diff --git a/examples/go/go-default/go.sum b/examples/go/go-default/go.sum index 4fc2cf0..550467a 100644 --- a/examples/go/go-default/go.sum +++ b/examples/go/go-default/go.sum @@ -1,2 +1,2 @@ -github.com/golemcloud/golem-go v0.4.4 h1:MAxS+jPsJZTdhm/cegzLbPanpLGi1jnfDBq4d1LeEw0= -github.com/golemcloud/golem-go v0.4.4/go.mod h1:O3l4YC7os4nGPWbJc02wPDxsgRelcS5v1L2xxzhNro4= +github.com/golemcloud/golem-go v0.6.0 h1:JkeHRrqqs+k6PTFASwknJVjcLBAvizqonhMO9M5B648= +github.com/golemcloud/golem-go v0.6.0/go.mod h1:VLL22qVo5R2+jGLO43tLPpPjf2WrA6B7GQoqXKnSODo= diff --git a/examples/go/go-default/main.go b/examples/go/go-default/main.go index de22ee2..cefebac 100644 --- a/examples/go/go-default/main.go +++ b/examples/go/go-default/main.go @@ -1,10 +1,9 @@ package main import ( - "github.com/golemcloud/golem-go/roundtrip" - "pack/name/component_name" + "github.com/golemcloud/golem-go/std" - "net/http" + "pack/name/component_name" ) type RequestBody struct { @@ -16,9 +15,7 @@ type ResponseBody struct { } func init() { - a := ComponentNameImpl{} - component_name.SetExportsPackNameApi(a) - http.DefaultClient.Transport = roundtrip.WasiHttpTransport{} + component_name.SetExportsPackNameApi(&ComponentNameImpl{}) } // total State can be stored in global variables @@ -29,11 +26,15 @@ type ComponentNameImpl struct { // Implementation of the exported interface -func (e ComponentNameImpl) Add(value uint64) { +func (e *ComponentNameImpl) Add(value uint64) { + std.Init(std.Packages{Os: true, NetHttp: true}) + total += value } -func (e ComponentNameImpl) Get() uint64 { +func (e *ComponentNameImpl) Get() uint64 { + std.Init(std.Packages{Os: true, NetHttp: true}) + return total } diff --git a/examples/go/go-default/wit/component-name.wit b/examples/go/go-default/wit/component-name.wit index 8720793..9c5377c 100644 --- a/examples/go/go-default/wit/component-name.wit +++ b/examples/go/go-default/wit/component-name.wit @@ -8,10 +8,6 @@ interface api { } world component-name { - export api; -} - -world component-name-imports { import golem:api/host@0.2.0; import golem:rpc/types@0.1.0; @@ -36,5 +32,5 @@ world component-name-imports { import wasi:sockets/ip-name-lookup@0.2.0; import wasi:sockets/instance-network@0.2.0; - include component-name; + export api; } diff --git a/examples/ts/ts-default-minimal/package.json b/examples/ts/ts-default-minimal/package.json index 4f9cf38..9c11bc5 100644 --- a/examples/ts/ts-default-minimal/package.json +++ b/examples/ts/ts-default-minimal/package.json @@ -3,7 +3,7 @@ "stub": "jco stubgen wit -o src/generated", "build": "rollup --config", "componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js", - "clean": "rm -rf out src/interfaces src/main.d.ts" + "clean": "rm -rf out src/generated" }, "devDependencies": { "@golemcloud/componentize-js": "0.10.2-golem.1", diff --git a/examples/ts/ts-default/package.json b/examples/ts/ts-default/package.json index 3fe29eb..60b7fe0 100644 --- a/examples/ts/ts-default/package.json +++ b/examples/ts/ts-default/package.json @@ -3,7 +3,7 @@ "stub": "jco stubgen wit -o src/generated", "build": "rollup --config", "componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js", - "clean": "rm -rf out src/interfaces src/main.d.ts" + "clean": "rm -rf out src/generated" }, "devDependencies": { "@golemcloud/componentize-js": "0.10.2-golem.1", diff --git a/examples/ts/ts-example-fetch/package.json b/examples/ts/ts-example-fetch/package.json index 3fe29eb..60b7fe0 100644 --- a/examples/ts/ts-example-fetch/package.json +++ b/examples/ts/ts-example-fetch/package.json @@ -3,7 +3,7 @@ "stub": "jco stubgen wit -o src/generated", "build": "rollup --config", "componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js", - "clean": "rm -rf out src/interfaces src/main.d.ts" + "clean": "rm -rf out src/generated" }, "devDependencies": { "@golemcloud/componentize-js": "0.10.2-golem.1", diff --git a/src/main.rs b/src/main.rs index e7bb492..06f71bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,8 +103,7 @@ fn test_example(example: &Example) -> Result<(), String> { let target_path = PathBuf::from("examples-test"); let component_name = ComponentName::new(example.name.as_string().to_string() + "-comp"); let package_name = - PackageName::from_string(example.name.as_string().to_string() + ":test-example") - .ok_or("failed to create package name")?; + PackageName::from_string("golem:component").ok_or("failed to create package name")?; let component_path = target_path.join(component_name.as_string()); println!("Target path: {}", target_path.display().to_string().blue());