From 17a98478fb2e2cef2ad0e428c6353543db82d64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Mon, 9 Dec 2024 06:54:44 +0100 Subject: [PATCH 1/3] app manifest for js, ts, python --- examples/go/go-default/golem.yaml | 26 ++ examples/js/INSTRUCTIONS-app | 9 + examples/js/js-default/.gitignore | 1 + examples/js/js-default/golem.yaml | 31 ++ examples/js/js-default/metadata.json | 4 +- examples/js/js-default/package.json | 5 - examples/python/.gitignore | 1 + examples/python/INSTRUCTIONS-app | 6 + examples/python/python-default/.gitignore | 4 + examples/python/python-default/golem.yaml | 26 ++ examples/python/python-default/metadata.json | 2 + examples/ts/INSTRUCTIONS-app | 9 + examples/ts/INSTRUCTIONS-buildts | 7 +- examples/ts/ts-default/.gitignore | 1 + examples/ts/ts-default/golem.yaml | 36 ++ examples/ts/ts-default/metadata.json | 1 + examples/ts/ts-multi-rpc/.gitignore | 6 +- examples/ts/ts-multi-rpc/README.md | 205 --------- examples/ts/ts-multi-rpc/build-config.ts | 7 - examples/ts/ts-multi-rpc/build.ts | 426 +++++------------- .../component-template/component/golem.yaml | 8 + .../component/wit/main.wit.template | 7 - examples/ts/ts-multi-rpc/golem.yaml | 42 ++ examples/ts/ts-multi-rpc/metadata.json | 11 +- examples/ts/ts-multi-rpc/package.json | 7 +- .../src/build-tools/build-tools.ts | 101 +---- .../src/components/component-one/golem.yaml | 14 + .../src/components/component-one/main.ts | 2 +- .../pack-ns_component-three-stub/_stub.wit | 23 - .../wit/deps/pack-ns_component-three/main.wit | 39 -- .../deps/pack-ns_component-two-stub/_stub.wit | 23 - .../wit/deps/pack-ns_component-two/main.wit | 39 -- .../src/components/component-one/wit/main.wit | 5 - .../src/components/component-three/golem.yaml | 8 + .../src/components/component-three/main.ts | 2 +- .../components/component-three/wit/main.wit | 4 - .../src/components/component-two/golem.yaml | 12 + .../src/components/component-two/main.ts | 2 +- .../pack-ns_component-three-stub/_stub.wit | 23 - .../wit/deps/pack-ns_component-three/main.wit | 39 -- .../src/components/component-two/wit/main.wit | 4 - .../ts/ts-multi-rpc/test/integration.test.ts | 4 +- examples/ts/ts-multi-rpc/wit-deps/README.md | 1 + 43 files changed, 383 insertions(+), 850 deletions(-) create mode 100644 examples/go/go-default/golem.yaml create mode 100644 examples/js/INSTRUCTIONS-app create mode 100644 examples/js/js-default/golem.yaml create mode 100644 examples/python/INSTRUCTIONS-app create mode 100644 examples/python/python-default/.gitignore create mode 100644 examples/python/python-default/golem.yaml create mode 100644 examples/ts/INSTRUCTIONS-app create mode 100644 examples/ts/ts-default/golem.yaml delete mode 100644 examples/ts/ts-multi-rpc/README.md create mode 100644 examples/ts/ts-multi-rpc/component-template/component/golem.yaml create mode 100644 examples/ts/ts-multi-rpc/golem.yaml create mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three-stub/_stub.wit delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two-stub/_stub.wit delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit create mode 100644 examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml create mode 100644 examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three-stub/_stub.wit delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit create mode 100644 examples/ts/ts-multi-rpc/wit-deps/README.md diff --git a/examples/go/go-default/golem.yaml b/examples/go/go-default/golem.yaml new file mode 100644 index 0000000..def9c78 --- /dev/null +++ b/examples/go/go-default/golem.yaml @@ -0,0 +1,26 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +tempDir: build/golem-temp +components: + pack:name: + sourceWit: wit + generatedWit: wit-generated + componentWasm: build/components/component_name.wasm + linkedWasm: build/linked-components/component_name_linked.wasm + build: + - command: componentize-py bindings bindings + sources: + - wit-generated + targets: + - bindings + - command: componentize-py componentize main -o build/components/component_name.wasm + mkdirs: + - build/components + sources: + - bindings + - main.py + targets: + - build/components/component_name.wasm diff --git a/examples/js/INSTRUCTIONS-app b/examples/js/INSTRUCTIONS-app new file mode 100644 index 0000000..c68efb5 --- /dev/null +++ b/examples/js/INSTRUCTIONS-app @@ -0,0 +1,9 @@ +See the documentation about installing tooling: https://learn.golem.cloud/docs/experimental-languages/js-language-guide/setup + +First time node package install: + golem-cli app install + +Generate wit and bindings, build and link component: + golem-cli app build + +The `out/linked-components/component_name.wasm` file is ready to be uploaded to Golem Cloud! diff --git a/examples/js/js-default/.gitignore b/examples/js/js-default/.gitignore index 72aae85..bcc7cae 100644 --- a/examples/js/js-default/.gitignore +++ b/examples/js/js-default/.gitignore @@ -1,2 +1,3 @@ node_modules/ out/ +wit-generated/ \ No newline at end of file diff --git a/examples/js/js-default/golem.yaml b/examples/js/js-default/golem.yaml new file mode 100644 index 0000000..0c914a9 --- /dev/null +++ b/examples/js/js-default/golem.yaml @@ -0,0 +1,31 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +tempDir: out/golem-temp +components: + pack:name: + sourceWit: wit + generatedWit: wit-generated + componentWasm: out/components/component_name.wasm + linkedWasm: out/linked-components/component_name_linked.wasm + build: + - command: npx rollup --config + sources: + - src + - wit-generated + targets: + - out/main.js + - command: npx jco componentize -w wit-generated -o out/components/component_name.wasm out/main.js + mkdirs: + - out/components + sources: + - out/main.js + targets: + - out/components/component_name.wasm + clean: + - src/generated + customCommands: + install: + - command: npm install diff --git a/examples/js/js-default/metadata.json b/examples/js/js-default/metadata.json index 22274c0..8c29d5a 100644 --- a/examples/js/js-default/metadata.json +++ b/examples/js/js-default/metadata.json @@ -3,8 +3,10 @@ "requiresAdapter": false, "requiresGolemHostWIT": true, "requiresWASI": true, + "instructions": "INSTRUCTIONS-app", "exclude": [ "node_modules", - "out" + "out", + "wit-generated" ] } \ No newline at end of file diff --git a/examples/js/js-default/package.json b/examples/js/js-default/package.json index e6ba274..71cc5fb 100644 --- a/examples/js/js-default/package.json +++ b/examples/js/js-default/package.json @@ -1,9 +1,4 @@ { - "scripts": { - "build": "rollup --config", - "componentize": "npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js", - "clean": "rm -rf out src/generated" - }, "devDependencies": { "@golemcloud/componentize-js": "0.10.5-golem.3", "@golemcloud/golem-ts": "1.1.0", diff --git a/examples/python/.gitignore b/examples/python/.gitignore index 4629a5c..775da38 100644 --- a/examples/python/.gitignore +++ b/examples/python/.gitignore @@ -1,3 +1,4 @@ bindings component_name.wasm +wit-generated __pycache__ diff --git a/examples/python/INSTRUCTIONS-app b/examples/python/INSTRUCTIONS-app new file mode 100644 index 0000000..c2a69f1 --- /dev/null +++ b/examples/python/INSTRUCTIONS-app @@ -0,0 +1,6 @@ +See the documentation about installing tooling: https://learn.golem.cloud/docs/python-language-guide/setup + +Generate wit and bindings, build and link component: + golem-cli app build + +The `build/linked-components/component_name_linked.wasm` file is ready to be uploaded to Golem Cloud! diff --git a/examples/python/python-default/.gitignore b/examples/python/python-default/.gitignore new file mode 100644 index 0000000..775da38 --- /dev/null +++ b/examples/python/python-default/.gitignore @@ -0,0 +1,4 @@ +bindings +component_name.wasm +wit-generated +__pycache__ diff --git a/examples/python/python-default/golem.yaml b/examples/python/python-default/golem.yaml new file mode 100644 index 0000000..def9c78 --- /dev/null +++ b/examples/python/python-default/golem.yaml @@ -0,0 +1,26 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +tempDir: build/golem-temp +components: + pack:name: + sourceWit: wit + generatedWit: wit-generated + componentWasm: build/components/component_name.wasm + linkedWasm: build/linked-components/component_name_linked.wasm + build: + - command: componentize-py bindings bindings + sources: + - wit-generated + targets: + - bindings + - command: componentize-py componentize main -o build/components/component_name.wasm + mkdirs: + - build/components + sources: + - bindings + - main.py + targets: + - build/components/component_name.wasm diff --git a/examples/python/python-default/metadata.json b/examples/python/python-default/metadata.json index 107e387..4227516 100644 --- a/examples/python/python-default/metadata.json +++ b/examples/python/python-default/metadata.json @@ -3,9 +3,11 @@ "requiresAdapter": false, "requiresGolemHostWIT": true, "requiresWASI": true, + "instructions": "INSTRUCTIONS-app", "exclude": [ "component_name.wasm", "bindings", + "wit-generated ", "__pycache__" ] } \ No newline at end of file diff --git a/examples/ts/INSTRUCTIONS-app b/examples/ts/INSTRUCTIONS-app new file mode 100644 index 0000000..0215fa4 --- /dev/null +++ b/examples/ts/INSTRUCTIONS-app @@ -0,0 +1,9 @@ +See the documentation about installing tooling: https://learn.golem.cloud/docs/experimental-languages/ts-language-guide/setup + +First time node package install: + golem-cli app install + +Generate wit and bindings, build and link component: + golem-cli app build + +The `out/linked-components/component_name.wasm` file is ready to be uploaded to Golem Cloud! diff --git a/examples/ts/INSTRUCTIONS-buildts b/examples/ts/INSTRUCTIONS-buildts index 7f1f771..6ed073d 100644 --- a/examples/ts/INSTRUCTIONS-buildts +++ b/examples/ts/INSTRUCTIONS-buildts @@ -1,12 +1,11 @@ -See the documentation about installing tooling: https://learn.golem.cloud/docs/go-language-guide/setup +See the documentation about installing tooling: https://learn.golem.cloud/docs/experimental-languages/ts-language-guide/setup and see more details in the README.md file about other commands. -Before first time build, install dependencies and generate RPC stubs: +Before first time build, install dependencies: npm install - npm run updateRpcStubs Generate bindings, compile and compose components: - npm run build + golem-cli app build Deploy components to default profile: npm run deploy diff --git a/examples/ts/ts-default/.gitignore b/examples/ts/ts-default/.gitignore index 4bded1c..7d01259 100644 --- a/examples/ts/ts-default/.gitignore +++ b/examples/ts/ts-default/.gitignore @@ -1,3 +1,4 @@ node_modules/ out/ src/generated/ +wit-generated/ diff --git a/examples/ts/ts-default/golem.yaml b/examples/ts/ts-default/golem.yaml new file mode 100644 index 0000000..f12fa66 --- /dev/null +++ b/examples/ts/ts-default/golem.yaml @@ -0,0 +1,36 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +tempDir: out/golem-temp +components: + pack:name: + sourceWit: wit + generatedWit: wit-generated + componentWasm: out/components/component_name.wasm + linkedWasm: out/linked-components/component_name_linked.wasm + build: + - command: npx jco stubgen wit-generated -o src/generated + sources: + - wit-generated + targets: + - src/generated + - command: npx rollup --config + sources: + - src + - wit-generated + targets: + - out/main.js + - command: npx jco componentize -w wit-generated -o out/components/component_name.wasm out/main.js + mkdirs: + - out/components + sources: + - out/main.js + targets: + - out/components/component_name.wasm + clean: + - src/generated + customCommands: + install: + - command: npm install diff --git a/examples/ts/ts-default/metadata.json b/examples/ts/ts-default/metadata.json index 3da9b1a..a7acde3 100644 --- a/examples/ts/ts-default/metadata.json +++ b/examples/ts/ts-default/metadata.json @@ -3,6 +3,7 @@ "requiresAdapter": false, "requiresGolemHostWIT": true, "requiresWASI": true, + "instructions": "INSTRUCTIONS-ap", "exclude": [ "node_modules", "out", diff --git a/examples/ts/ts-multi-rpc/.gitignore b/examples/ts/ts-multi-rpc/.gitignore index 4d9022f..49c372f 100644 --- a/examples/ts/ts-multi-rpc/.gitignore +++ b/examples/ts/ts-multi-rpc/.gitignore @@ -1,3 +1,5 @@ -node_modules/ -out/ +binding generated +node_modules +out +wit-generated \ No newline at end of file diff --git a/examples/ts/ts-multi-rpc/README.md b/examples/ts/ts-multi-rpc/README.md deleted file mode 100644 index ac8dbe7..0000000 --- a/examples/ts/ts-multi-rpc/README.md +++ /dev/null @@ -1,205 +0,0 @@ -# Golem TypeScript Example with Multiple Components and Worker to Worker RPC Communication - -## Building - -The project uses a custom Typescript build file: [build.ts](build.ts), ran through [tsx](https://nodejs.org/en/learn/getting-started/nodejs-with-typescript#running-typescript-code-with-tsx). The `build.ts` file handles **generating stubs**, **building**, **deploying** and **testing**; and also handles _"up to date" checks_ based on _modification times_. Build commands can be run using `npx tsx build.ts ` (or without _npx_, if _tsx_ is available globally), but all commands have `npm run ` wrappers, in the examples we will use the latter. - -To see the available commands use: - -```shell -npm run help - -> help -> npx tsx build.ts - -Available commands: - fmt: format using prettier - lint: lint project using eslint - fix: format, lint and fix project using prettier and eslint - build: build all components - updateRpcStubs: update stubs based on componentDependencies - generateNewComponent: generates new component from template, expects - deploy: deploy (create or update) all components - deployComponent: deploy (create or update) the specified component, expects - test: run tests - clean: clean outputs and generated code -``` - -For building the project for the first time (or after `clean`) use the following commands: - -```shell -npm install -npm run updateRpcStubs -npm run build -``` - -After this, using the `build` command is enough, unless there are changes in the RPC dependencies, -in that case `updateRpcStubs` is needed again. - -Note that multiple commands can be used in one invocation (if they do not have parameters), e.g.: - -```shell -npm run updateRpcStubs build -``` - -The final components that are usable by golem are placed in the `out/components` folder. - -## Deploying and testing the example - -In the example 3 simple counter components are defined, which can be familiar from the smaller examples. To showcase the remote calls, the counters `add` functions are connected, apart from increasing their own counter: - -- **component one** delegates the add call to **component two** and **three** too, -- and **component two** delegates to **component three**. - -In both cases the _current worker name_ will be used as _target worker name_ too. - -Apart from _worker name_, remote calls also require the **target components' deployed ID**. For this the example uses environment variables, and uses the `lib/cfg` subpackage (which is shared between the components) to extract it. - -The examples assume a configured default `golem-cli` profile, and will use that. - -To test, first we have to build the project as seen in the above: - -```shell -npm run updateRpcStubs build -``` - -Then we can deploy our components with `golem-cli`, for which a wrapper command is provided: - -```shell -npm run deploy -``` - -Note that `npm run deployComponent ` can be used to deploy (or update) only one component. - -Once the components are deployed, a simple example integration test suite can be used to test the components. - -Note that after deploy it might still take some time for the components to be prepared inside golem, which for TypeScript can take about 30-50 seconds, so invoking workers or running the tests immediately after deploy might have to wait for this preparation. - -Once the components are deployed, a simple example integration test suite can be used to test the components. -The tests are in the [/test/integration.test.ts](/test/integration.test.ts) test file, and can be run with: - -```shell -npm run test -``` - -The first test simply tests if our components metadata is available through `golem-cli component get`. - -The second test will: - -- get the _component URNs_ with `golem-cli component get` -- generates a _random worker name_, so our tests are starting from a clean state -- adds 1 - 1 worker for component one and component two with the required _environment variables_ containing the other workers' _component ids_ -- then makes various component invocations with `golem-cli worker invoke-and-await` and tests if the counters - after increments - are holding the right value according to the delegated `add` function calls. - -## Adding Components - -Use the `generateNewComponent` command to add new components to the project: - -```shell -npm run generateNewComponent component-four -``` - -The above will create a new component in the `src/components/component-four` directory based on the template at [/component-template/component](/component-template/component). - -After adding a new component the `build` command will also include it. - -## Using Worker to Worker RPC calls - -### Under the hood - -Under the hood the `build.ts` commands below use generic `golem-cli stubgen` subcommands: - -- `golem-cli stubgen build` for creating remote call _stub WIT_ definitions and _WASM components_ for the stubs -- `golem-cli stubgen add-stub-dependency` for adding the _stub WIT_ definitions to a _component's WIT_ dependencies -- `golem-cli stubgen compose` for _composing_ components with the stub components - -### Commands and required manual steps - -The dependencies between components are defined in the [build-config.ts](build-config.ts) build script: - -```typescript -// Defines worker to worker RPC dependencies -const componentDependencies: Dependencies = { - "component-one": ["component-two", "component-three"], - "component-two": ["component-three"], -}; -``` - -After changing dependencies the `updateRpcStubs` command can be used to create the necessary stubs: - -```shell -npm run updateRpcStubs -``` - -The command will create stubs for the dependency projects in the `/out/stub` directory and will also place the required stub _WIT_ interfaces on the dependant component's `wit/deps` directory. - -To actually use the dependencies in a project it also has to be manually imported in the component's world. - -E.g. with the above definitions the following import has to be **manually** added to `/components/component-one/wit/component-one.wit`: - -```wit -import pack-ns:component-two-stub; -import pack-ns:component-three-stub; -``` - -So the component definition should like similar to this: - -```wit -package pack-ns:component-one; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-one-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-one { - // Golem dependencies - import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - // . - // . - // . - // other dependencies - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - import pack-ns:component-two-stub; - import pack-ns:component-three-stub; - - export component-one-api; -} -``` - -After this `build` command can be used to update bindings, which now should include the -required functions for calling other components. - -Here's an example that delegates the `Add` call to another component and waits for the result: - -```go -import {ComponentTwoApi} from "./generated/component-two"; -import {ComponentThreeApi} from "golem:component-three-stub/stub-component-three"; - -let state = BigInt(0); - -export const componentTwoApi: ComponentTwoApi = { - add(value: bigint) { - console.log(`Adding ${value} to the counter`); - - console.log("Calling component three"); - const componentThree = new ComponentThreeApi({value: "urn"}); - componentThree.blockingAdd(value); - - state += value; - }, - get() { - return state; - } -}; -``` - -Once a remote call is in place, the `build` command will also compose the stub components into the caller component. diff --git a/examples/ts/ts-multi-rpc/build-config.ts b/examples/ts/ts-multi-rpc/build-config.ts index c99f0d7..88657bb 100644 --- a/examples/ts/ts-multi-rpc/build-config.ts +++ b/examples/ts/ts-multi-rpc/build-config.ts @@ -1,5 +1,4 @@ import * as path from "node:path"; -import { Dependencies } from "./src/build-tools/build-tools"; export const pckNs = "pack-ns"; export const outDir = "out"; @@ -7,9 +6,3 @@ export const componentsDir = path.join("src", "components"); export const libDir = path.join("src", "lib"); export const generatedDir = "generated"; export const componentTemplateDir = path.join("component-template", "component"); - -// Defines worker to worker RPC dependencies -export const componentDependencies: Dependencies = { - "component-one": ["component-two", "component-three"], - "component-two": ["component-three"], -}; diff --git a/examples/ts/ts-multi-rpc/build.ts b/examples/ts/ts-multi-rpc/build.ts index 7b0ba81..1d4eff1 100644 --- a/examples/ts/ts-multi-rpc/build.ts +++ b/examples/ts/ts-multi-rpc/build.ts @@ -1,385 +1,177 @@ import * as path from "node:path"; import fs from "node:fs"; -import { InputOptions, OutputOptions, rollup } from "rollup"; +import {InputOptions, OutputOptions, rollup} from "rollup"; import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"; -import rollupPluginTypeScript, { RollupTypescriptOptions } from "@rollup/plugin-typescript"; +import rollupPluginTypeScript, {RollupTypescriptOptions} from "@rollup/plugin-typescript"; -import { allDepsSorted, cmd, cmdArg, Commands, fsMatch, main, runTask } from "./src/build-tools/build-tools"; -import { run, runCapture } from "./src/lib/process"; +import {cmd, cmdArg, Commands, fsMatch, getComponentNameFromArgs, main} from "./src/build-tools/build-tools"; +import {run, runCapture} from "./src/lib/process"; import * as cfg from "./build-config"; const commands: Commands = { - fmt: cmd(prettierWrite, "format using prettier"), - lint: cmd(() => eslint(false), "lint project using eslint"), - fix: cmd(fix, "format, lint and fix project using prettier and eslint"), - build: cmd(build, "build all components"), - updateRpcStubs: cmd(updateRpcStubs, "update stubs based on componentDependencies"), - generateNewComponent: cmdArg( - generateNewComponents, - "generates new component from template, expects ", - ), - deploy: cmd(deploy, "deploy (create or update) all components"), - deployComponent: cmdArg( - deployComponentCmd, - "deploy (create or update) the specified component, expects ", - ), - test: cmd(test, "run tests"), - clean: cmd(clean, "clean outputs and generated code"), + fmt: cmd(prettierWrite, "format using prettier"), + lint: cmd(() => eslint(false), "lint project using eslint"), + fix: cmd(fix, "format, lint and fix project using prettier and eslint"), + generateNewComponent: cmdArg( + generateNewComponents, + "generates new component from template, expects ", + ), + rollupComponent: cmdArg( + rollupComponentCmd, + "Runs rollup for the specified component, expects ", + ), + deploy: cmd(deploy, "deploy (create or update) all components"), + deployComponent: cmdArg( + deployComponentCmd, + "deploy (create or update) the specified component, expects ", + ), + test: cmd(test, "run tests"), }; const componentNames: string[] = fs - .readdirSync(cfg.componentsDir, { withFileTypes: true }) - .filter((entry) => entry.isDirectory()) - .map((entry) => entry.name); - -async function build() { - for (const componentName of componentNames) { - await buildComponent(componentName); - } -} - -async function buildComponent(componentName: string) { - console.log(`Build component: ${componentName}`); - - await generateBinding(componentName); - await rollupComponent(componentName); - await componentize(componentName); - await stubCompose(componentName); -} - -async function generateBinding(componentName: string) { - const componentDir = path.join(cfg.componentsDir, componentName); - const witDir = path.join(componentDir, "wit"); - const bindingDir = path.join(componentDir, cfg.generatedDir); - - return runTask({ - runMessage: `Generating bindings from ${witDir} into ${bindingDir}`, - skipMessage: "binding generation", - targets: [bindingDir], - sources: [witDir], - run: async () => { - return run("npx", ["jco", "stubgen", witDir, "-o", bindingDir]); - }, - }); -} + .readdirSync(cfg.componentsDir, {withFileTypes: true}) + .filter((entry) => entry.isDirectory()) + .map((entry) => entry.name); async function prettierWrite() { - return run("npx", ["prettier", ".", "--write"]); + return run("npx", ["prettier", ".", "--write"]); } async function eslint(fix: boolean) { - const args = ["eslint", "--color"]; - if (fix) args.push("--fix"); - return run("npx", args); + const args = ["eslint", "--color"]; + if (fix) args.push("--fix"); + return run("npx", args); } async function fix() { - await prettierWrite(); - await eslint(true); + await prettierWrite(); + await eslint(true); +} + +async function rollupComponentCmd(args: string[]) { + return rollupComponent(getComponentNameFromArgs(args)); } async function rollupComponent(componentName: string) { - const componentDir = path.join(cfg.componentsDir, componentName); - const mainTs = path.join(cfg.componentsDir, componentName, "main.ts"); - const componentBuildDir = path.join(cfg.outDir, "build", componentName); - const mainJs = path.join(componentBuildDir, "main.js"); - const generatedInterfacesDir = path.join(componentDir, cfg.generatedDir, "interfaces"); - - return runTask({ - runMessage: `Rollup component: ${componentName}`, - skipMessage: "component rollup", - targets: [mainJs], - sources: [componentDir, cfg.libDir, "build.ts", "package.json", "tsconfig.json"], - run: async () => { - const moduleRegex = /declare\s+module\s+"([^"]+)"/g; - const externalInterfaces: string[] = fsMatch({ + const componentDir = path.join(cfg.componentsDir, componentName); + const mainTs = path.join(cfg.componentsDir, componentName, "main.ts"); + const componentBuildDir = path.join(cfg.outDir, "build", componentName); + const mainJs = path.join(componentBuildDir, "main.js"); + const generatedInterfacesDir = path.join(componentDir, cfg.generatedDir, "interfaces"); + + const moduleRegex = /declare\s+module\s+"([^"]+)"/g; + const externalInterfaces: string[] = fsMatch({ includePaths: [generatedInterfacesDir], picoPattern: "**/*.d.ts", - }).flatMap((path) => + }).flatMap((path) => [...fs.readFileSync(path).toString().matchAll(moduleRegex)].map((match) => { - const moduleName = match[1]; - if (moduleName === undefined) { - throw new Error(`Missing match for module name`); - } - return moduleName; + const moduleName = match[1]; + if (moduleName === undefined) { + throw new Error(`Missing match for module name`); + } + return moduleName; }), - ); + ); - const tsOptions: RollupTypescriptOptions = { + const tsOptions: RollupTypescriptOptions = { include: ["src/lib/**/*.ts", componentDir + "/**/*.ts"], - }; + }; - const input: InputOptions = { + const input: InputOptions = { input: mainTs, external: externalInterfaces, plugins: [rollupPluginNodeResolve(), rollupPluginTypeScript(tsOptions)], - }; + }; - const output: OutputOptions = { + const output: OutputOptions = { file: mainJs, format: "esm", - }; - - const bundle = await rollup(input); - await bundle.write(output); - await bundle.close(); - }, - }); -} - -async function componentize(componentName: string) { - const componentDir = path.join(cfg.componentsDir, componentName); - const witDir = path.join(componentDir, "wit"); - const componentBuildDir = path.join(cfg.outDir, "build", componentName); - const mainJs = path.join(componentBuildDir, "main.js"); - const componentWasm = path.join(componentBuildDir, "component.wasm"); - - return runTask({ - runMessage: `Componentizing component: ${componentName}`, - skipMessage: "componentize", - targets: [componentWasm], - sources: [mainJs], - run: async () => { - await run("npx", ["jco", "componentize", "-w", witDir, "-o", componentWasm, mainJs]); - }, - }); -} - -async function stubCompose(componentName: string) { - const componentBuildDir = path.join(cfg.outDir, "build", componentName); - const componentWasm = path.join(componentBuildDir, "component.wasm"); - const componentsBuildDir = path.join(cfg.outDir, "components"); - const targetWasm = path.join(cfg.outDir, "components", componentName + ".wasm"); - - const stubWasms: string[] = []; - const deps = cfg.componentDependencies[componentName]; - if (deps !== undefined) { - for (const componentName of deps) { - stubWasms.push(path.join(cfg.outDir, "stub", componentName, "stub.wasm")); - } - } - - return runTask({ - runMessage: `Composing stubs [${stubWasms.join(", ")}] into component: ${componentName}`, - skipMessage: "stub compose", - targets: [targetWasm], - sources: [componentWasm, ...stubWasms], - run: async () => { - let composeWasm = componentWasm; - if (stubWasms.length > 0) { - let srcWasm = componentWasm; - let i = 0; - for (const stubWasm of stubWasms) { - i++; - const prevComposeWasm = composeWasm; - composeWasm = path.join(componentBuildDir, `compose-${i}-${path.basename(path.dirname(stubWasm))}.wasm`); - const result = await runCapture("golem-cli", [ - "stubgen", - "compose", - "--source-wasm", - srcWasm, - "--stub-wasm", - stubWasm, - "--dest-wasm", - composeWasm, - ]); - if (result.code !== 0) { - if (result.stderr.includes("Error: no dependencies of component") && result.stderr.includes("were found")) { - console.log(`Skipping composing ${stubWasm}, not used`); - composeWasm = prevComposeWasm; - continue; - } - - if (result.stdout) { - process.stderr.write(result.stdout); - } - if (result.stderr) { - process.stderr.write(result.stderr); - } - - throw new Error(`Command [${result.cmd}] failed with code: ${result.code}`); - } - srcWasm = composeWasm; - } - } + }; - fs.mkdirSync(componentsBuildDir, { recursive: true }); - fs.copyFileSync(composeWasm, targetWasm); - }, - }); + const bundle = await rollup(input); + await bundle.write(output); + await bundle.close(); } -async function updateRpcStubs() { - const stubs = allDepsSorted(cfg.componentDependencies); - for (const stub of stubs) { - await buildStubComponent(stub); - } +async function generateNewComponents(args: string[]) { + const componentName = getComponentNameFromArgs(args); + const componentDir = path.join(cfg.componentsDir, componentName); - for (const [comp, deps] of Object.entries(cfg.componentDependencies)) { - for (const dep of deps) { - await addStubDependency(comp, dep); + if (fs.existsSync(componentDir)) { + throw new Error(`${componentDir} already exists!`); } - } -} - -async function buildStubComponent(componentName: string) { - const componentDir = path.join(cfg.componentsDir, componentName); - const srcWitDir = path.join(componentDir, "wit"); - const stubTargetDir = path.join(cfg.outDir, "stub", componentName); - const destWasm = path.join(stubTargetDir, "stub.wasm"); - const destWitDir = path.join(stubTargetDir, "wit"); - - return runTask({ - runMessage: `Building stub component for: ${componentName}`, - skipMessage: "stub component build", - targets: [destWasm, destWitDir], - sources: [srcWitDir], - run: async () => { - return run("golem-cli", [ - "stubgen", - "build", - "--source-wit-root", - srcWitDir, - "--dest-wasm", - destWasm, - "--dest-wit-root", - destWitDir, - ]); - }, - }); -} - -async function addStubDependency(componentName: string, depComponentName: string) { - const stubTargetDir = path.join(cfg.outDir, "stub", depComponentName); - const srcWitDir = path.join(stubTargetDir, "wit"); - const dstComponentDir = path.join(cfg.componentsDir, componentName); - const dstWitDir = path.join(dstComponentDir, "wit"); - const dstWitDepDir = path.join(dstComponentDir, dstWitDir, "deps", `${cfg.pckNs}_${componentName}`); - const dstWitDepStubDir = path.join(dstComponentDir, dstWitDir, "deps", `${cfg.pckNs}_${componentName}-stub`); - - return runTask({ - runMessage: `Adding stub dependency for ${depComponentName} to ${componentName}`, - skipMessage: "add stub dependency", - targets: [dstWitDepDir, dstWitDepStubDir], - sources: [srcWitDir], - run: async () => { - return run("golem-cli", [ - "stubgen", - "add-stub-dependency", - "--overwrite", - "--stub-wit-root", - srcWitDir, - "--dest-wit-root", - dstWitDir, - ]); - }, - }); -} - -async function generateNewComponents(args: string[]) { - const componentName = getComponentNameFromArgs(args); - const componentDir = path.join(cfg.componentsDir, componentName); - if (fs.existsSync(componentDir)) { - throw new Error(`${componentDir} already exists!`); - } + console.log(`Creating directory ${componentDir}`); + fs.mkdirSync(componentDir, {recursive: true}); - console.log(`Creating directory ${componentDir}`); - fs.mkdirSync(componentDir, { recursive: true }); + const entries = fs.readdirSync(cfg.componentTemplateDir, { + recursive: true, + withFileTypes: true, + }); - const entries = fs.readdirSync(cfg.componentTemplateDir, { - recursive: true, - withFileTypes: true, - }); + for (const entry of entries) { + const relEntryPath = path.relative(cfg.componentTemplateDir, entry.parentPath); + if (entry.isDirectory()) { + const targetPath = path.join(componentDir, relEntryPath, entry.name); + console.log(`Creating directory ${targetPath}`); + fs.mkdirSync(targetPath); - for (const entry of entries) { - const relEntryPath = path.relative(cfg.componentTemplateDir, entry.parentPath); - if (entry.isDirectory()) { - const targetPath = path.join(componentDir, relEntryPath, entry.name); - console.log(`Creating directory ${targetPath}`); - fs.mkdirSync(targetPath); + continue; + } - continue; - } + if (entry.name.endsWith(".template")) { + const sourcePath = path.join(entry.parentPath, entry.name); + const targetPath = path.join(componentDir, relEntryPath, entry.name.replaceAll(".template", "")); + console.log(`Generating ${targetPath} from ${sourcePath}`); - if (entry.name.endsWith(".template")) { - const sourcePath = path.join(entry.parentPath, entry.name); - const targetPath = path.join(componentDir, relEntryPath, entry.name.replaceAll(".template", "")); - console.log(`Generating ${targetPath} from ${sourcePath}`); + const dashToPascal = (str: string): string => + str + .split("-") + .map((s) => s.substring(0, 1).toUpperCase() + s.substring(1)) + .join(""); + const componentNamePascal = dashToPascal(componentName); + const componentNameCamel = componentNamePascal.substring(0, 1).toLowerCase() + componentNamePascal.substring(1); - const dashToPascal = (str: string): string => - str - .split("-") - .map((s) => s.substring(0, 1).toUpperCase() + s.substring(1)) - .join(""); - const componentNamePascal = dashToPascal(componentName); - const componentNameCamel = componentNamePascal.substring(0, 1).toLowerCase() + componentNamePascal.substring(1); + let template = fs.readFileSync(sourcePath).toString(); + template = template.replaceAll("pck-ns", cfg.pckNs); + template = template.replaceAll("comp-name", componentName); + template = template.replaceAll("componentName", componentNameCamel); + template = template.replaceAll("CompName", componentNamePascal); - let template = fs.readFileSync(sourcePath).toString(); - template = template.replaceAll("pck-ns", cfg.pckNs); - template = template.replaceAll("comp-name", componentName); - template = template.replaceAll("componentName", componentNameCamel); - template = template.replaceAll("CompName", componentNamePascal); + fs.writeFileSync(targetPath, new Uint8Array(Buffer.from(template))); - fs.writeFileSync(targetPath, new Uint8Array(Buffer.from(template))); + continue; + } - continue; + const sourcePath = path.join(entry.parentPath, entry.name); + const targetPath = path.join(componentDir, relEntryPath, entry.name); + console.log(`Copying ${sourcePath} to ${targetPath}`); + fs.copyFileSync(sourcePath, targetPath); } - - const sourcePath = path.join(entry.parentPath, entry.name); - const targetPath = path.join(componentDir, relEntryPath, entry.name); - console.log(`Copying ${sourcePath} to ${targetPath}`); - fs.copyFileSync(sourcePath, targetPath); - } } async function deploy() { - for (const componentName of componentNames) { - await deployComponent(componentName); - } + for (const componentName of componentNames) { + await deployComponent(componentName); + } } async function deployComponentCmd(args: string[]) { - return deployComponent(getComponentNameFromArgs(args)); + return deployComponent(getComponentNameFromArgs(args)); } async function deployComponent(componentName: string) { - console.log(`Deploying ${componentName}`); - const componentsTargetDir = path.join(cfg.outDir, "components"); - const wasm = path.join(componentsTargetDir, componentName + ".wasm"); - return run("golem-cli", ["component", "add", "--non-interactive", "--component-name", componentName, wasm]); + console.log(`Deploying ${componentName}`); + const linkedComponentsDir = path.join(cfg.outDir, "linked-components"); + const wasm = path.join(linkedComponentsDir, componentName + "-linked.wasm"); + return run("golem-cli", ["component", "add", "--non-interactive", "--component-name", componentName, wasm]); } async function test() { - return run("npx", ["tsx", ...fsMatch({ includePaths: ["test"], picoPattern: "test/**.test.ts" })]); -} - -async function clean() { - const paths = ["out"]; - for (const componentName of componentNames) { - paths.push(path.join(cfg.componentsDir, componentName, cfg.generatedDir)); - } - - for (const path of paths) { - console.log(`Deleting ${path}`); - fs.rmSync(path, { recursive: true, force: true }); - } -} - -function getComponentNameFromArgs(args: string[]) { - if (args.length != 1) { - throw new Error(`generateNewComponents expected exactly one argument (component-name), got: [${args.join(", ")}]`); - } - - const componentName = args[0]; - if (componentName === undefined) { - throw new Error("Undefined component name"); - } - - return componentName; + return run("npx", ["tsx", ...fsMatch({includePaths: ["test"], picoPattern: "test/**.test.ts"})]); } await main(commands); diff --git a/examples/ts/ts-multi-rpc/component-template/component/golem.yaml b/examples/ts/ts-multi-rpc/component-template/component/golem.yaml new file mode 100644 index 0000000..1b20950 --- /dev/null +++ b/examples/ts/ts-multi-rpc/component-template/component/golem.yaml @@ -0,0 +1,8 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +components: + comp-name: + template: ts diff --git a/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template b/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template index e07e294..a1c84f4 100644 --- a/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template +++ b/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template @@ -8,10 +8,6 @@ interface comp-name-api { } world comp-name { - // Golem dependencies - import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; - // WASI dependencies import wasi:blobstore/blobstore; import wasi:blobstore/container; @@ -32,8 +28,5 @@ world comp-name { import wasi:sockets/ip-name-lookup@0.2.0; import wasi:sockets/instance-network@0.2.0; - // Project Component dependencies - // import pck-ns:name-stub/stub-name; - export comp-name-api; } diff --git a/examples/ts/ts-multi-rpc/golem.yaml b/examples/ts/ts-multi-rpc/golem.yaml new file mode 100644 index 0000000..67f4c2d --- /dev/null +++ b/examples/ts/ts-multi-rpc/golem.yaml @@ -0,0 +1,42 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +tempDir: out/golem-temp +includes: +- src/components/*/golem.yaml +witDeps: +- wit-deps +templates: + ts: + sourceWit: wit + generatedWit: wit-generated + componentWasm: ../../../out/components/{{ componentName }}.wasm + linkedWasm: ../../../out/linked-components/{{ componentName }}-linked.wasm + build: + - command: npx jco stubgen src/components/{{ componentName }}/wit-generated -o src/components/{{ componentName }}/binding + dir: ../../.. + sources: + - src/components/{{ componentName }}/wit-generated + targets: + - src/components/{{ componentName }}/binding + - command: npx tsx build.ts rollupComponent {{ componentName }} + dir: ../../.. + sources: + - src/components/{{ componentName }} + targets: + - out/build/{{ componentName }}/main.js + - command: npx jco componentize -w src/components/{{ componentName }}/wit-generated -o out/components/{{ componentName }}.wasm out/build/{{ componentName }}/main.js + dir: ../../.. + mkdirs: + - out/components/{{ componentName }} + sources: + - out/build/{{ componentName }}/main.js + targets: + - out/components/{{ componentName }}.wasm + clean: + - src/generated + customCommands: + install: + - command: npm install diff --git a/examples/ts/ts-multi-rpc/metadata.json b/examples/ts/ts-multi-rpc/metadata.json index dee6e03..c6cbd21 100644 --- a/examples/ts/ts-multi-rpc/metadata.json +++ b/examples/ts/ts-multi-rpc/metadata.json @@ -4,18 +4,19 @@ "requiresGolemHostWIT": true, "requiresWASI": true, "witDepsPaths": [ - "component-template/component/wit/deps", - "src/components/component-one/wit/deps", - "src/components/component-two/wit/deps", - "src/components/component-three/wit/deps" + "wit-deps" ], "exclude": [ + "binding", "generated", + "wit-generated", "out" ], "transformExclude": [ "build.ts", - "integration.test.ts" + "build-tools.ts", + "integration.test.ts", + "golem.yaml" ], "instructions": "INSTRUCTIONS-buildts" } \ No newline at end of file diff --git a/examples/ts/ts-multi-rpc/package.json b/examples/ts/ts-multi-rpc/package.json index eae3533..ade0d35 100644 --- a/examples/ts/ts-multi-rpc/package.json +++ b/examples/ts/ts-multi-rpc/package.json @@ -4,13 +4,10 @@ "fmt": "npx tsx build.ts fmt", "lint": "npx tsx build.ts lint", "fix": "npx tsx build.ts fix", - "build": "npx tsx build.ts build", - "updateRpcStubs": "npx tsx build.ts updateRpcStubs", - "generateNewComponent": "npx tsx build.ts generateNewComponent", + "rollupComponent": "npx tsx build.ts rollupComponent", "deploy": "npx tsx build.ts deploy", "deployComponent": "npx tsx build.ts deployComponent", "test": "npx tsx build.ts test", - "clean": "npx tsx build.ts clean", "help": "npx tsx build.ts" }, "dependencies": { @@ -29,7 +26,7 @@ "globals": "^15.9.0", "picomatch": "^4.0.2", "prettier": "3.3.3", - "rollup": "^4.21.2", + "rollup": "^4.28.1", "tslib": "^2.7.0", "tsx": "^4.19.0", "typescript-eslint": "^8.3.0" diff --git a/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts b/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts index 91e21d0..d8cd6e5 100644 --- a/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts +++ b/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts @@ -31,6 +31,19 @@ export const cmdArg = Command.cmdArgs; export type Commands = { [key: string]: Command }; +export function getComponentNameFromArgs(args: string[]) { + if (args.length != 1) { + throw new Error(`generateNewComponents expected exactly one argument (component-name), got: [${args.join(", ")}]`); + } + + const componentName = args[0]; + if (componentName === undefined) { + throw new Error("Undefined component name"); + } + + return componentName; +} + export async function main(commands: Commands) { const args = process.argv.splice(2); @@ -61,94 +74,6 @@ export async function main(commands: Commands) { } } -export interface Task { - runMessage: string; - skipMessage: string; - targets: string[]; - sources: string[]; - run: () => Promise; -} - -export async function runTask(task: Task) { - let run = task.targets.length == 0; - - upToDateCheck: for (const target of task.targets) { - let targetInfo; - try { - targetInfo = fs.statSync(target); - } catch (error) { - if (error instanceof Error && "code" in error && error.code == "ENOENT") { - run = true; - break; - } - throw error; - } - - let targetModifiedMs = Number.MAX_SAFE_INTEGER; - - if (targetInfo.isDirectory()) { - const targets = fs.readdirSync(target, { - recursive: true, - withFileTypes: true, - }); - for (const target of targets) { - if (target.isDirectory()) continue; - const targetInfo = fs.statSync(path.join(target.parentPath, target.name)); - if (targetModifiedMs > targetInfo.mtimeMs) { - targetModifiedMs = targetInfo.mtimeMs; - } - } - } else { - targetModifiedMs = targetInfo.mtimeMs; - } - - for (const source of task.sources) { - const sourceInfo = fs.statSync(source); - - if (!sourceInfo.isDirectory()) { - if (sourceInfo.mtimeMs > targetModifiedMs) { - run = true; - break upToDateCheck; - } - continue; - } - - const sources = fs.readdirSync(source, { - recursive: true, - withFileTypes: true, - }); - for (const source of sources) { - if (source.isDirectory()) continue; - const sourceInfo = fs.statSync(path.join(source.parentPath, source.name)); - if (sourceInfo.mtimeMs > targetModifiedMs) { - run = true; - break upToDateCheck; - } - } - } - } - - if (!run) { - console.log(`${task.targets.join(",")} is up to date, skipping ${task.skipMessage}`); - return; - } - - console.log(task.runMessage); - await task.run(); -} - -export type Dependencies = { [key: string]: string[] }; - -export function allDepsSorted(dependencies: Dependencies): string[] { - const allDepsSet = new Set(); - for (const deps of Object.values(dependencies).values()) { - for (const dep of deps) { - allDepsSet.add(dep); - } - } - return Array.from(allDepsSet).sort(); -} - interface FsMatchOptions { includePaths?: string[]; picoPattern?: string; diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml b/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml new file mode 100644 index 0000000..6550863 --- /dev/null +++ b/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml @@ -0,0 +1,14 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +components: + component-one: + template: ts +dependencies: + component-one: + - target: component-two + type: wasm-rpc + - target: component-three + type: wasm-rpc \ No newline at end of file diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/main.ts b/examples/ts/ts-multi-rpc/src/components/component-one/main.ts index e3a3eee..a42ab97 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-one/main.ts +++ b/examples/ts/ts-multi-rpc/src/components/component-one/main.ts @@ -1,4 +1,4 @@ -import { ComponentOneApi } from "./generated/component-one"; +import { ComponentOneApi } from "./binding/component-one"; import { ComponentTwoApi } from "pack-ns:component-two-stub/stub-component-two"; import { ComponentThreeApi } from "pack-ns:component-three-stub/stub-component-three"; import * as cfg from "../../lib/cfg"; diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three-stub/_stub.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three-stub/_stub.wit deleted file mode 100644 index ab3de6b..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three-stub/_stub.wit +++ /dev/null @@ -1,23 +0,0 @@ -package pack-ns:component-three-stub; - -interface stub-component-three { - use golem:rpc/types@0.1.0.{uri as golem-rpc-uri}; - use wasi:io/poll@0.2.0.{pollable as wasi-io-pollable}; - - resource future-get-result { - subscribe: func() -> wasi-io-pollable; - get: func() -> option; - } - resource component-three-api { - constructor(location: golem-rpc-uri); - blocking-add: func(value: u64); - add: func(value: u64); - blocking-get: func() -> u64; - get: func() -> future-get-result; - } - -} - -world wasm-rpc-stub-component-three { - export stub-component-three; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit deleted file mode 100644 index f0f45ad..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit +++ /dev/null @@ -1,39 +0,0 @@ -package pack-ns:component-three; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-three-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-three { - // Golem dependencies - import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - import wasi:blobstore/container; - import wasi:cli/environment@0.2.0; - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:logging/logging; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - // import pack-ns:name-stub/stub-name; - - export component-three-api; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two-stub/_stub.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two-stub/_stub.wit deleted file mode 100644 index f83aa85..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two-stub/_stub.wit +++ /dev/null @@ -1,23 +0,0 @@ -package pack-ns:component-two-stub; - -interface stub-component-two { - use golem:rpc/types@0.1.0.{uri as golem-rpc-uri}; - use wasi:io/poll@0.2.0.{pollable as wasi-io-pollable}; - - resource future-get-result { - subscribe: func() -> wasi-io-pollable; - get: func() -> option; - } - resource component-two-api { - constructor(location: golem-rpc-uri); - blocking-add: func(value: u64); - add: func(value: u64); - blocking-get: func() -> u64; - get: func() -> future-get-result; - } - -} - -world wasm-rpc-stub-component-two { - export stub-component-two; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit deleted file mode 100644 index f708ae6..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit +++ /dev/null @@ -1,39 +0,0 @@ -package pack-ns:component-two; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-two-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-two { - // Golem dependencies - import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - import wasi:blobstore/container; - import wasi:cli/environment@0.2.0; - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:logging/logging; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - import pack-ns:component-three-stub/stub-component-three; - - export component-two-api; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit index 97b0271..09b9345 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit +++ b/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit @@ -10,7 +10,6 @@ interface component-one-api { world component-one { // Golem dependencies import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; // WASI dependencies import wasi:blobstore/blobstore; @@ -32,9 +31,5 @@ world component-one { import wasi:sockets/ip-name-lookup@0.2.0; import wasi:sockets/instance-network@0.2.0; - // Project Component dependencies - import pack-ns:component-two-stub/stub-component-two; - import pack-ns:component-three-stub/stub-component-three; - export component-one-api; } diff --git a/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml b/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml new file mode 100644 index 0000000..28a4e79 --- /dev/null +++ b/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml @@ -0,0 +1,8 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +components: + component-three: + template: ts diff --git a/examples/ts/ts-multi-rpc/src/components/component-three/main.ts b/examples/ts/ts-multi-rpc/src/components/component-three/main.ts index 30039b4..55e456e 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-three/main.ts +++ b/examples/ts/ts-multi-rpc/src/components/component-three/main.ts @@ -1,4 +1,4 @@ -import { ComponentThreeApi } from "./generated/component-three"; +import { ComponentThreeApi } from "./binding/component-three"; let state = BigInt(0); diff --git a/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit b/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit index f0f45ad..9f9016e 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit +++ b/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit @@ -10,7 +10,6 @@ interface component-three-api { world component-three { // Golem dependencies import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; // WASI dependencies import wasi:blobstore/blobstore; @@ -32,8 +31,5 @@ world component-three { import wasi:sockets/ip-name-lookup@0.2.0; import wasi:sockets/instance-network@0.2.0; - // Project Component dependencies - // import pack-ns:name-stub/stub-name; - export component-three-api; } diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml b/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml new file mode 100644 index 0000000..37aba91 --- /dev/null +++ b/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml @@ -0,0 +1,12 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json + +components: + component-two: + template: ts +dependencies: + component-two: + - target: component-three + type: wasm-rpc diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/main.ts b/examples/ts/ts-multi-rpc/src/components/component-two/main.ts index 1ca535e..381c5fd 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-two/main.ts +++ b/examples/ts/ts-multi-rpc/src/components/component-two/main.ts @@ -1,4 +1,4 @@ -import { ComponentTwoApi } from "./generated/component-two"; +import { ComponentTwoApi } from "./binding/component-two"; import { ComponentThreeApi } from "pack-ns:component-three-stub/stub-component-three"; import * as cfg from "../../lib/cfg"; import { getSelfMetadata } from "golem:api/host@0.2.0"; diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three-stub/_stub.wit b/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three-stub/_stub.wit deleted file mode 100644 index ab3de6b..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three-stub/_stub.wit +++ /dev/null @@ -1,23 +0,0 @@ -package pack-ns:component-three-stub; - -interface stub-component-three { - use golem:rpc/types@0.1.0.{uri as golem-rpc-uri}; - use wasi:io/poll@0.2.0.{pollable as wasi-io-pollable}; - - resource future-get-result { - subscribe: func() -> wasi-io-pollable; - get: func() -> option; - } - resource component-three-api { - constructor(location: golem-rpc-uri); - blocking-add: func(value: u64); - add: func(value: u64); - blocking-get: func() -> u64; - get: func() -> future-get-result; - } - -} - -world wasm-rpc-stub-component-three { - export stub-component-three; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit b/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit deleted file mode 100644 index f0f45ad..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit +++ /dev/null @@ -1,39 +0,0 @@ -package pack-ns:component-three; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-three-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-three { - // Golem dependencies - import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - import wasi:blobstore/container; - import wasi:cli/environment@0.2.0; - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:logging/logging; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - // import pack-ns:name-stub/stub-name; - - export component-three-api; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit b/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit index f708ae6..0eacc11 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit +++ b/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit @@ -10,7 +10,6 @@ interface component-two-api { world component-two { // Golem dependencies import golem:api/host@0.2.0; - import golem:rpc/types@0.1.0; // WASI dependencies import wasi:blobstore/blobstore; @@ -32,8 +31,5 @@ world component-two { import wasi:sockets/ip-name-lookup@0.2.0; import wasi:sockets/instance-network@0.2.0; - // Project Component dependencies - import pack-ns:component-three-stub/stub-component-three; - export component-two-api; } diff --git a/examples/ts/ts-multi-rpc/test/integration.test.ts b/examples/ts/ts-multi-rpc/test/integration.test.ts index 41f0d45..0363cc0 100644 --- a/examples/ts/ts-multi-rpc/test/integration.test.ts +++ b/examples/ts/ts-multi-rpc/test/integration.test.ts @@ -156,7 +156,7 @@ async function invokeWorkerGet(componentName: string, workerName: string) { const result = await invokeAndAwaitWorker( componentName, workerName, - `${buildCfg.pckNs}:${componentName}/${componentName}-api.{get}`, + `${buildCfg.pckNs}:${componentName}-interface/${componentName}-api.{get}`, [], ); return result["value"][0] as number; @@ -166,7 +166,7 @@ async function invokeWorkerAdd(componentName: string, workerName: string, value: await invokeAndAwaitWorker( componentName, workerName, - `${buildCfg.pckNs}:${componentName}/${componentName}-api.{add}`, + `${buildCfg.pckNs}:${componentName}-interface/${componentName}-api.{add}`, [value.toString()], ); } diff --git a/examples/ts/ts-multi-rpc/wit-deps/README.md b/examples/ts/ts-multi-rpc/wit-deps/README.md new file mode 100644 index 0000000..dabb173 --- /dev/null +++ b/examples/ts/ts-multi-rpc/wit-deps/README.md @@ -0,0 +1 @@ +Place your wit dependencies here. \ No newline at end of file From e899e530091b56e3873eddc618f6c53109e4b99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Mon, 9 Dec 2024 09:56:58 +0100 Subject: [PATCH 2/3] fixes --- examples/go/INSTRUCTIONS-app | 6 +++ examples/go/go-default/Makefile | 15 ------- examples/go/go-default/golem.yaml | 35 +++++++++++++---- examples/go/go-default/main.go | 4 +- examples/go/go-default/metadata.json | 4 +- examples/js/js-default/golem.yaml | 4 +- examples/python/python-default/golem.yaml | 4 +- examples/ts/ts-default/golem.yaml | 11 +++--- examples/ts/ts-default/metadata.json | 4 +- examples/ts/ts-default/package.json | 6 --- examples/ts/ts-default/src/main.ts | 2 +- examples/ts/ts-multi-rpc/build.ts | 2 +- .../{golem.yaml => golem.yaml.template} | 4 +- .../component/main.ts.template | 2 +- .../component/wit/main.wit.template | 5 --- examples/ts/ts-multi-rpc/golem.yaml | 7 ++-- examples/ts/ts-multi-rpc/package.json | 1 + .../src/build-tools/build-tools.ts | 2 +- .../src/components/component-one/golem.yaml | 4 +- .../wit/deps/pack-ns_component-three/main.wit | 39 ------------------- .../wit/deps/pack-ns_component-two/main.wit | 39 ------------------- .../src/components/component-one/wit/main.wit | 5 --- .../src/components/component-three/golem.yaml | 4 +- .../components/component-three/wit/main.wit | 5 --- .../src/components/component-two/golem.yaml | 4 +- .../wit/deps/pack-ns_component-three/main.wit | 39 ------------------- .../src/components/component-two/wit/main.wit | 5 --- 27 files changed, 67 insertions(+), 195 deletions(-) create mode 100644 examples/go/INSTRUCTIONS-app delete mode 100644 examples/go/go-default/Makefile rename examples/ts/ts-multi-rpc/component-template/component/{golem.yaml => golem.yaml.template} (58%) delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit delete mode 100644 examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit diff --git a/examples/go/INSTRUCTIONS-app b/examples/go/INSTRUCTIONS-app new file mode 100644 index 0000000..8a6af6f --- /dev/null +++ b/examples/go/INSTRUCTIONS-app @@ -0,0 +1,6 @@ +See the documentation about installing tooling: https://learn.golem.cloud/docs/go-language-guide/setup + +Generate wit and bindings, build and link component: + golem-cli app build + +The `out/linked-components/component_name.wasm` file is ready to be uploaded to Golem Cloud! diff --git a/examples/go/go-default/Makefile b/examples/go/go-default/Makefile deleted file mode 100644 index 8d67d7a..0000000 --- a/examples/go/go-default/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -.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 - -bindings: - wit-bindgen tiny-go --world component-name --out-dir component_name ./wit - -compile: bindings - tinygo build -target=wasi -tags=purego -o component_name.module.wasm main.go - -clean: - rm -rf component_name - rm *.wasm diff --git a/examples/go/go-default/golem.yaml b/examples/go/go-default/golem.yaml index def9c78..b196193 100644 --- a/examples/go/go-default/golem.yaml +++ b/examples/go/go-default/golem.yaml @@ -1,26 +1,45 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json tempDir: build/golem-temp components: pack:name: sourceWit: wit generatedWit: wit-generated - componentWasm: build/components/component_name.wasm + componentWasm: build/adapted-components/component_name.wasm linkedWasm: build/linked-components/component_name_linked.wasm build: - - command: componentize-py bindings bindings + - command: wit-bindgen tiny-go --rename-package binding --out-dir binding ./wit-generated sources: - wit-generated targets: - - bindings - - command: componentize-py componentize main -o build/components/component_name.wasm + - binding + - command: tinygo build -target=wasi -tags=purego -o build/components/component_name.wasm main.go mkdirs: - build/components sources: - - bindings - - main.py + - component_name + - main.go targets: - build/components/component_name.wasm + - command: wasm-tools component embed wit-generated build/components/component_name.wasm --output build/embedded-components/component_name.wasm + mkdirs: + - build/embedded-components + sources: + - wit-generated + - build/components/component_name.wasm + targets: + - build/embedded-components/component_name.wasm + - command: wasm-tools component new build/embedded-components/component_name.wasm -o build/adapted-components/component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm + mkdirs: + - build/adapted-components + sources: + - adapters/tier1/wasi_snapshot_preview1.wasm + - build/embedded-components/component_name.wasm + targets: + - build/adapted-components/component_name.wasm + clean: + - build + - binding diff --git a/examples/go/go-default/main.go b/examples/go/go-default/main.go index cefebac..6ec990b 100644 --- a/examples/go/go-default/main.go +++ b/examples/go/go-default/main.go @@ -3,7 +3,7 @@ package main import ( "github.com/golemcloud/golem-go/std" - "pack/name/component_name" + "pack/name/binding" ) type RequestBody struct { @@ -15,7 +15,7 @@ type ResponseBody struct { } func init() { - component_name.SetExportsPackNameApi(&ComponentNameImpl{}) + binding.SetExportsPackNameInterfaceApi(&ComponentNameImpl{}) } // total State can be stored in global variables diff --git a/examples/go/go-default/metadata.json b/examples/go/go-default/metadata.json index 576a055..8c433c1 100644 --- a/examples/go/go-default/metadata.json +++ b/examples/go/go-default/metadata.json @@ -3,8 +3,10 @@ "requiresAdapter": true, "requiresGolemHostWIT": true, "requiresWASI": true, + "instructions": "INSTRUCTIONS-app", "exclude": [ - "component_name", + "wit-generated", + "build", "main.wasm" ] } \ No newline at end of file diff --git a/examples/js/js-default/golem.yaml b/examples/js/js-default/golem.yaml index 0c914a9..7c34a74 100644 --- a/examples/js/js-default/golem.yaml +++ b/examples/js/js-default/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json tempDir: out/golem-temp components: diff --git a/examples/python/python-default/golem.yaml b/examples/python/python-default/golem.yaml index def9c78..83ca484 100644 --- a/examples/python/python-default/golem.yaml +++ b/examples/python/python-default/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json tempDir: build/golem-temp components: diff --git a/examples/ts/ts-default/golem.yaml b/examples/ts/ts-default/golem.yaml index f12fa66..3bdb08b 100644 --- a/examples/ts/ts-default/golem.yaml +++ b/examples/ts/ts-default/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json tempDir: out/golem-temp components: @@ -11,11 +11,11 @@ components: componentWasm: out/components/component_name.wasm linkedWasm: out/linked-components/component_name_linked.wasm build: - - command: npx jco stubgen wit-generated -o src/generated + - command: npx jco stubgen wit-generated -o src/binding sources: - wit-generated targets: - - src/generated + - src/binding - command: npx rollup --config sources: - src @@ -30,7 +30,8 @@ components: targets: - out/components/component_name.wasm clean: - - src/generated + - src/binding + - wit-generated customCommands: install: - command: npm install diff --git a/examples/ts/ts-default/metadata.json b/examples/ts/ts-default/metadata.json index a7acde3..cfce515 100644 --- a/examples/ts/ts-default/metadata.json +++ b/examples/ts/ts-default/metadata.json @@ -3,10 +3,10 @@ "requiresAdapter": false, "requiresGolemHostWIT": true, "requiresWASI": true, - "instructions": "INSTRUCTIONS-ap", + "instructions": "INSTRUCTIONS-app", "exclude": [ "node_modules", "out", - "src/generated" + "src/binding" ] } \ No newline at end of file diff --git a/examples/ts/ts-default/package.json b/examples/ts/ts-default/package.json index 59547a3..04336de 100644 --- a/examples/ts/ts-default/package.json +++ b/examples/ts/ts-default/package.json @@ -1,10 +1,4 @@ { - "scripts": { - "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/generated" - }, "devDependencies": { "@golemcloud/componentize-js": "0.10.5-golem.3", "@golemcloud/golem-ts": "1.1.0", diff --git a/examples/ts/ts-default/src/main.ts b/examples/ts/ts-default/src/main.ts index 50ebba8..ce9c8cf 100644 --- a/examples/ts/ts-default/src/main.ts +++ b/examples/ts/ts-default/src/main.ts @@ -1,4 +1,4 @@ -import { Api } from './generated/component-name.js'; +import { Api } from './binding/component-name.js'; let state = BigInt(0); diff --git a/examples/ts/ts-multi-rpc/build.ts b/examples/ts/ts-multi-rpc/build.ts index 1d4eff1..7bbd0ee 100644 --- a/examples/ts/ts-multi-rpc/build.ts +++ b/examples/ts/ts-multi-rpc/build.ts @@ -138,7 +138,7 @@ async function generateNewComponents(args: string[]) { let template = fs.readFileSync(sourcePath).toString(); template = template.replaceAll("pck-ns", cfg.pckNs); template = template.replaceAll("comp-name", componentName); - template = template.replaceAll("componentName", componentNameCamel); + template = template.replaceAll("compName", componentNameCamel); template = template.replaceAll("CompName", componentNamePascal); fs.writeFileSync(targetPath, new Uint8Array(Buffer.from(template))); diff --git a/examples/ts/ts-multi-rpc/component-template/component/golem.yaml b/examples/ts/ts-multi-rpc/component-template/component/golem.yaml.template similarity index 58% rename from examples/ts/ts-multi-rpc/component-template/component/golem.yaml rename to examples/ts/ts-multi-rpc/component-template/component/golem.yaml.template index 1b20950..b542fd7 100644 --- a/examples/ts/ts-multi-rpc/component-template/component/golem.yaml +++ b/examples/ts/ts-multi-rpc/component-template/component/golem.yaml.template @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json components: comp-name: diff --git a/examples/ts/ts-multi-rpc/component-template/component/main.ts.template b/examples/ts/ts-multi-rpc/component-template/component/main.ts.template index 084501c..4db024b 100644 --- a/examples/ts/ts-multi-rpc/component-template/component/main.ts.template +++ b/examples/ts/ts-multi-rpc/component-template/component/main.ts.template @@ -1,4 +1,4 @@ -import {CompNameApi} from "./generated/comp-name"; +import {CompNameApi} from "./binding/comp-name"; let state = BigInt(0); diff --git a/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template b/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template index d815e99..65888dd 100644 --- a/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template +++ b/examples/ts/ts-multi-rpc/component-template/component/wit/main.wit.template @@ -8,13 +8,8 @@ interface comp-name-api { } world comp-name { -<<<<<<< HEAD -======= - // Golem dependencies import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; ->>>>>>> main // WASI dependencies import wasi:blobstore/blobstore; import wasi:blobstore/container; diff --git a/examples/ts/ts-multi-rpc/golem.yaml b/examples/ts/ts-multi-rpc/golem.yaml index 67f4c2d..4951861 100644 --- a/examples/ts/ts-multi-rpc/golem.yaml +++ b/examples/ts/ts-multi-rpc/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json tempDir: out/golem-temp includes: @@ -36,7 +36,8 @@ templates: targets: - out/components/{{ componentName }}.wasm clean: - - src/generated + - binding + - wit-generated customCommands: install: - command: npm install diff --git a/examples/ts/ts-multi-rpc/package.json b/examples/ts/ts-multi-rpc/package.json index ade0d35..ff6e72c 100644 --- a/examples/ts/ts-multi-rpc/package.json +++ b/examples/ts/ts-multi-rpc/package.json @@ -4,6 +4,7 @@ "fmt": "npx tsx build.ts fmt", "lint": "npx tsx build.ts lint", "fix": "npx tsx build.ts fix", + "generateNewComponent": "npx tsx build.ts generateNewComponent", "rollupComponent": "npx tsx build.ts rollupComponent", "deploy": "npx tsx build.ts deploy", "deployComponent": "npx tsx build.ts deployComponent", diff --git a/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts b/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts index d8cd6e5..e020726 100644 --- a/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts +++ b/examples/ts/ts-multi-rpc/src/build-tools/build-tools.ts @@ -33,7 +33,7 @@ export type Commands = { [key: string]: Command }; export function getComponentNameFromArgs(args: string[]) { if (args.length != 1) { - throw new Error(`generateNewComponents expected exactly one argument (component-name), got: [${args.join(", ")}]`); + throw new Error(`expected exactly one argument (component-name), got: [${args.join(", ")}]`); } const componentName = args[0]; diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml b/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml index 6550863..fbe9d9c 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml +++ b/examples/ts/ts-multi-rpc/src/components/component-one/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json components: component-one: diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit deleted file mode 100644 index f6183b8..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-three/main.wit +++ /dev/null @@ -1,39 +0,0 @@ -package pack-ns:component-three; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-three-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-three { - // Golem dependencies - import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - import wasi:blobstore/container; - import wasi:cli/environment@0.2.0; - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:logging/logging; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - // import pack-ns:name-stub/stub-name; - - export component-three-api; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit deleted file mode 100644 index dd8b3ac..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/deps/pack-ns_component-two/main.wit +++ /dev/null @@ -1,39 +0,0 @@ -package pack-ns:component-two; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-two-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-two { - // Golem dependencies - import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - import wasi:blobstore/container; - import wasi:cli/environment@0.2.0; - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:logging/logging; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - import pack-ns:component-three-stub/stub-component-three; - - export component-two-api; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit b/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit index 401549c..65c30a8 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit +++ b/examples/ts/ts-multi-rpc/src/components/component-one/wit/main.wit @@ -9,12 +9,7 @@ interface component-one-api { world component-one { // Golem dependencies -<<<<<<< HEAD - import golem:api/host@0.2.0; -======= import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; ->>>>>>> main // WASI dependencies import wasi:blobstore/blobstore; diff --git a/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml b/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml index 28a4e79..2e6835d 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml +++ b/examples/ts/ts-multi-rpc/src/components/component-three/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json components: component-three: diff --git a/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit b/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit index 60e1695..9f9016e 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit +++ b/examples/ts/ts-multi-rpc/src/components/component-three/wit/main.wit @@ -9,12 +9,7 @@ interface component-three-api { world component-three { // Golem dependencies -<<<<<<< HEAD import golem:api/host@0.2.0; -======= - import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; ->>>>>>> main // WASI dependencies import wasi:blobstore/blobstore; diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml b/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml index 37aba91..70186b7 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml +++ b/examples/ts/ts-multi-rpc/src/components/component-two/golem.yaml @@ -1,7 +1,7 @@ # Schema for IDEA: -# $schema: https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json # Schema for vscode-yaml -# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0-rc3/golem.schema.json +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json components: component-two: diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit b/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit deleted file mode 100644 index f6183b8..0000000 --- a/examples/ts/ts-multi-rpc/src/components/component-two/wit/deps/pack-ns_component-three/main.wit +++ /dev/null @@ -1,39 +0,0 @@ -package pack-ns:component-three; - -// See https://component-model.bytecodealliance.org/design/wit.html for more details about the WIT syntax - -interface component-three-api { - add: func(value: u64); - get: func() -> u64; -} - -world component-three { - // Golem dependencies - import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; - - // WASI dependencies - import wasi:blobstore/blobstore; - import wasi:blobstore/container; - import wasi:cli/environment@0.2.0; - import wasi:clocks/wall-clock@0.2.0; - import wasi:clocks/monotonic-clock@0.2.0; - import wasi:filesystem/preopens@0.2.0; - import wasi:filesystem/types@0.2.0; - import wasi:http/types@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import wasi:io/error@0.2.0; - import wasi:io/poll@0.2.0; - import wasi:io/streams@0.2.0; - import wasi:logging/logging; - import wasi:random/random@0.2.0; - import wasi:random/insecure@0.2.0; - import wasi:random/insecure-seed@0.2.0; - import wasi:sockets/ip-name-lookup@0.2.0; - import wasi:sockets/instance-network@0.2.0; - - // Project Component dependencies - // import pack-ns:name-stub/stub-name; - - export component-three-api; -} diff --git a/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit b/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit index 25c050e..512b7ec 100644 --- a/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit +++ b/examples/ts/ts-multi-rpc/src/components/component-two/wit/main.wit @@ -9,12 +9,7 @@ interface component-two-api { world component-two { // Golem dependencies -<<<<<<< HEAD - import golem:api/host@0.2.0; -======= import golem:api/host@1.1.0; - import golem:rpc/types@0.1.0; ->>>>>>> main // WASI dependencies import wasi:blobstore/blobstore; From 0882254a7ec15274f87957dc13061d12ae1a6bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Istv=C3=A1n=20B=C3=ADr=C3=B3?= Date: Mon, 9 Dec 2024 10:18:05 +0100 Subject: [PATCH 3/3] update rust-default to use app manifest --- examples/rust/INSTRUCTIONS-app | 11 +++++++ examples/rust/rust-default/golem.yaml | 38 ++++++++++++++++++++++++ examples/rust/rust-default/metadata.json | 3 +- examples/rust/rust-default/src/lib.rs | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 examples/rust/INSTRUCTIONS-app create mode 100644 examples/rust/rust-default/golem.yaml diff --git a/examples/rust/INSTRUCTIONS-app b/examples/rust/INSTRUCTIONS-app new file mode 100644 index 0000000..c37ba1d --- /dev/null +++ b/examples/rust/INSTRUCTIONS-app @@ -0,0 +1,11 @@ +See the documentation about installing common tooling: https://learn.golem.cloud/docs/rust-language-guide/setup + +Compile the Rust component with golem-cli: + golem-cli app build + +The result component in target/golem-components/debug/component_name.wasm is ready to be used with Golem! + +For compiling with the release build profile, use: + golem-cli app -b release build + +The result release component in target/golem-components/debug/component_name.wasm is ready to be used with Golem! diff --git a/examples/rust/rust-default/golem.yaml b/examples/rust/rust-default/golem.yaml new file mode 100644 index 0000000..5a762cb --- /dev/null +++ b/examples/rust/rust-default/golem.yaml @@ -0,0 +1,38 @@ +# Schema for IDEA: +# $schema: https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json +# Schema for vscode-yaml +# yaml-language-server: $schema=https://schema.golem.cloud/app/golem/1.1.0/golem.schema.json + +tempDir: target/golem-temp +components: + pack:name: + profiles: + debug: + build: + - command: cargo component build + sources: + - src + - wit + targets: + - target/wasm32-wasi/debug/component_name.wasm + sourceWit: wit + generatedWit: wit-generated + componentWasm: target/wasm32-wasi/debug/component_name.wasm + linkedWasm: target/golem-components/debug/component_name.wasm + clean: + - src/bindings.rs + release: + build: + - command: cargo component build --release + sources: + - src + - wit + targets: + - target/wasm32-wasi/release/component_name.wasm + sourceWit: wit + generatedWit: wit-generated + componentWasm: target/wasm32-wasi/release/component_name.wasm + linkedWasm: target/golem-components/release/component_name.wasm + clean: + - src/bindings.rs + defaultProfile: debug diff --git a/examples/rust/rust-default/metadata.json b/examples/rust/rust-default/metadata.json index 94d40d0..0670e84 100644 --- a/examples/rust/rust-default/metadata.json +++ b/examples/rust/rust-default/metadata.json @@ -3,5 +3,6 @@ "requiresAdapter": false, "requiresGolemHostWIT": false, "requiresWASI": false, - "exclude": ["target"] + "instructions": "INSTRUCTIONS-app", + "exclude": ["target", "src/binding"] } diff --git a/examples/rust/rust-default/src/lib.rs b/examples/rust/rust-default/src/lib.rs index a2352d7..9b93cbb 100644 --- a/examples/rust/rust-default/src/lib.rs +++ b/examples/rust/rust-default/src/lib.rs @@ -1,6 +1,6 @@ mod bindings; -use crate::bindings::exports::pack::name::api::*; +use crate::bindings::exports::golemx::componentx_interface::api::*; use std::cell::RefCell; /// This is one of any number of data types that our application