Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4557869
wip: module class for assemblyscript wrapper
Niraj-Kamdar Dec 20, 2022
9c0f92e
feat: e2e for bigint wasm-as wrapper working
Niraj-Kamdar Dec 21, 2022
51ea8d7
fix: add tests for wasm-as wrappers
Niraj-Kamdar Dec 21, 2022
e55af62
fix: wasm-as.spec.ts
Niraj-Kamdar Dec 21, 2022
e2224aa
debug
Niraj-Kamdar Dec 21, 2022
e09f4d8
debug: react
Niraj-Kamdar Dec 21, 2022
7214d3d
Merge branch 'origin-dev' into nk/module-class-wasm
Niraj-Kamdar Dec 21, 2022
65d7416
fix: react issue
Niraj-Kamdar Dec 21, 2022
53080d6
fix: e2e test issues
Niraj-Kamdar Dec 22, 2022
e4b3a3f
fix: wasm-wrapper tests
Niraj-Kamdar Dec 22, 2022
068f806
Merge remote-tracking branch 'upstream/origin-dev' into nk/module-cla…
Niraj-Kamdar Dec 22, 2022
d28dbb8
revert: react patch since merged
Niraj-Kamdar Dec 22, 2022
c34541e
fix: yarn.lock
Niraj-Kamdar Dec 22, 2022
fcf65b5
fix: issues
Niraj-Kamdar Dec 22, 2022
4ffbfe7
revert: test-env-js changes
Niraj-Kamdar Dec 22, 2022
b183636
fix: validate and plugins tests
Niraj-Kamdar Dec 22, 2022
6f19410
fix: cli tests
Niraj-Kamdar Dec 22, 2022
9659dcf
fix: entry point
Niraj-Kamdar Dec 22, 2022
1ded87b
feat: use transform to add hasEnv to moduleType
Niraj-Kamdar Dec 22, 2022
47e579c
feat: reserve dunder methods for polywrap binding usecases
Niraj-Kamdar Dec 24, 2022
8721c8d
feat: add env as reserved keyword for polywrap bindings
Niraj-Kamdar Dec 24, 2022
6197791
fix(wasm-as): bindings for env
Niraj-Kamdar Dec 24, 2022
ae2555e
fix(wasm-as): binding test cases
Niraj-Kamdar Dec 24, 2022
442dd22
Merge branch 'origin-dev' into nk/module-class-wasm
Niraj-Kamdar Jan 16, 2023
66839d7
fix: issues
Niraj-Kamdar Jan 16, 2023
93ffd62
fix: issues
Niraj-Kamdar Jan 16, 2023
ed8141c
fix: issues
Niraj-Kamdar Jan 16, 2023
7fa372e
Merge remote-tracking branch 'upstream/origin-dev' into nk/module-cla…
Niraj-Kamdar Feb 10, 2023
22842d9
feat: env should be available as function parameter when required
Niraj-Kamdar Feb 11, 2023
edc6374
WIP: Plugin env refactor
Niraj-Kamdar Feb 11, 2023
ad7662c
Merge remote-tracking branch 'upstream/origin-dev' into nk/module-cla…
Niraj-Kamdar Feb 11, 2023
d4fd225
fix: update template
Niraj-Kamdar Feb 11, 2023
2423c07
Update types.ts
Niraj-Kamdar Feb 14, 2023
410865a
merge origin-dev
dOrgJelli Mar 7, 2023
8416de4
chore: fix merge
dOrgJelli Mar 7, 2023
ad08c4f
chore: use wrap-test-harness branch
dOrgJelli Mar 7, 2023
482d4f9
chore: remove validate test cases
dOrgJelli Mar 7, 2023
3d8be87
chore: remove moduleHasEnv, not used
dOrgJelli Mar 7, 2023
570c45d
chore: trigger CI
dOrgJelli Mar 7, 2023
4683e6e
chore: fix env passing to wrap-test-harness CLI
dOrgJelli Mar 7, 2023
75555bd
chore: fix wrap-test-harness workflow
dOrgJelli Mar 7, 2023
4d52d38
chore: fix ci-wrap-test-harness toolchain checkout branch ref
dOrgJelli Mar 7, 2023
a9cd928
chore: disable .cargo registry index mount
dOrgJelli Mar 7, 2023
bf3bef2
chore: add back .cargo cache volume
dOrgJelli Mar 7, 2023
314621d
fix: mount entire ~/.cargo directory, fixing parallel builds
dOrgJelli Mar 8, 2023
6d6e220
chore: lint fix
dOrgJelli Mar 8, 2023
cd2bad9
chore: fix tests
dOrgJelli Mar 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .github/workflows/ci-wrap-test-harness.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.ref }}
path: toolchain
fetch-depth: 0

Expand Down Expand Up @@ -104,19 +103,16 @@ jobs:
cargo-${{ runner.os }}-${{ github.job }}

- name: Set environment variable
run: echo "POLYWRAP_CLI_PATH=${{ github.workspace }}/toolchain/packages/cli" >> $GITHUB_ENV
run: echo POLYWRAP_CLI_PATH=$(pwd)/toolchain/packages/cli >> $GITHUB_ENV

- name: Set environment variable
if: ${{ inputs.wasm-path }}
run: echo "POLYWRAP_WASM_PATH=${{ github.workspace }}/toolchain/packages/wasm" >> $GITHUB_ENV
run: echo POLYWRAP_WASM_PATH=$(pwd)/toolchain/packages/wasm >> $GITHUB_ENV

- uses: nick-fields/retry@v2
name: Run wrappers build
with:
command: cargo run -- -w
max_attempts: 3
retry_on: error
timeout_minutes: 60
- name: Run wrappers build
run: cargo run -- -w
env:
POLYWRAP_CLI_PATH: ${{env.POLYWRAP_CLI_PATH}}
POLYWRAP_WASM_PATH: ${{env.POLYWRAP_WASM_PATH}}

- uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion WRAP_TEST_HARNESS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master
module-class-wasm-as
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ export class DockerVMBuildStrategy extends BuildStrategy<void> {
});

// For rust, we want to also mount the cargo registry's cache directory
const localCargoCache = `${process.env.HOME}/.cargo/registry`;
let cacheVolume = "";
const localCargoCache = `${process.env.HOME}/.cargo`;
const cacheVolumes: string[] = [];
if (language === "wasm/rust" && fse.existsSync(localCargoCache)) {
cacheVolume = `-v ${localCargoCache}:/usr/local/cargo/registry`;
cacheVolumes.push(`-v ${localCargoCache}:/usr/local/cargo`);
// Ignore the bin folder, without this an exception is thrown upon exe exec
cacheVolumes.push(`-v /usr/local/cargo/bin/`);
}

let buildError: Error | undefined = undefined;
Expand All @@ -196,7 +198,7 @@ export class DockerVMBuildStrategy extends BuildStrategy<void> {
`${path.resolve(
this._volumePaths.linkedPackages
)}:/linked-packages`,
cacheVolume,
...cacheVolumes,
`${CONFIGS[language].baseImage}:${CONFIGS[language].version}`,
"/bin/bash",
"--verbose",
Expand Down
14 changes: 4 additions & 10 deletions packages/js/client/src/__tests__/core/error-structure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ describe("Error structure", () => {
).toBeTruthy();
expect(result.error?.method).toEqual("throwError");
expect(result.error?.args).toEqual('{\n "a": "Hey"\n}');
expect(result.error?.source).toEqual({
file: "~lib/@polywrap/wasm-as/containers/Result.ts",
row: 171,
col: 13,
});
expect(result.error?.source?.file).toEqual(
"~lib/@polywrap/wasm-as/containers/Result.ts"
);

expect(result.error?.innerError instanceof WrapError).toBeTruthy();
const prev = result.error?.innerError as WrapError;
Expand Down Expand Up @@ -409,11 +407,7 @@ describe("Error structure", () => {
).toBeTruthy();
expect(result.error?.method).toEqual("throwError");
expect(result.error?.args).toEqual('{\n "a": "Hey"\n}');
expect(result.error?.source).toEqual({
file: "src/lib.rs",
row: 10,
col: 117,
});
expect(result.error?.source?.file).toEqual("src/lib.rs");

expect(result.error?.innerError instanceof WrapError).toBeTruthy();
const prev = result.error?.innerError as WrapError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
wrap_invoke_args,
wrap_invoke,
wrap_invoke_result,
wrap_invoke_error,
wrap_abort,
InvokeArgs
} from "@polywrap/wasm-as";
Expand All @@ -15,22 +16,30 @@ import {
{{/methods.length}}
{{/moduleType}}

import { Module } from "../index";

export function _wrap_invoke(method_size: u32, args_size: u32, env_size: u32): bool {
const module = new Module();
const args: InvokeArgs = wrap_invoke_args(
method_size,
args_size
);

let result: ArrayBuffer;
{{#moduleType}}
{{#methods}}
{{^first}}else {{/first}}if (args.method == "{{name}}") {
return wrap_invoke(args, env_size, {{name}}Wrapped);
result = {{name}}Wrapped(module, args.args, env_size);
}
{{/methods}}
{{/moduleType}}
else {
return wrap_invoke(args, env_size, null);
wrap_invoke_error(
`Could not find invoke function "${args.method}"`
);
return false;
}
wrap_invoke_result(result);
return true;
}

export function wrapAbort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export {
};
{{/methods.length}}
{{/moduleType}}
{{#moduleType}}
export { ModuleBase } from "./Module";
{{/moduleType}}
{{#objectTypes}}
export { {{#detectKeyword}}{{type}}{{/detectKeyword}} } from "./{{type}}";
{{/objectTypes}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export {
Args_{{#detectKeyword}}{{name}}{{/detectKeyword}}{{^last}},{{/last}}
{{/methods}}
};
export { ModuleBase } from "./module";
{{/methods.length}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as Types from "..";

import {
BigInt,
BigNumber,
Box,
JSON,
} from "@polywrap/wasm-as";

export abstract class ModuleBase {
{{#methods}}
abstract {{#detectKeyword}}{{name}}{{/detectKeyword}}(
args: Types.Args_{{#detectKeyword}}{{name}}{{/detectKeyword}}{{#env}},
env: {{#required}}Types.Env{{/required}}{{^required}}Types.Env | null{{/required}}{{/env}}
): {{#return}}{{#toWasm}}{{toGraphQLType}}{{/toWasm}}{{/return}};
{{^last}}

{{/last}}
{{/methods}}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{{#methods.length}}
import { wrap_load_env } from "@polywrap/wasm-as";
import {
{{#methods}}
{{#detectKeyword}}{{name}}{{/detectKeyword}}{{^last}},{{/last}}
{{/methods}}
} from "../../index";
import {
{{#methods}}
deserialize{{name}}Args,
serialize{{name}}Result{{^last}},{{/last}}
{{/methods}}
} from "./serialization";
{{/methods.length}}
import { ModuleBase } from "./module";
import * as Types from "..";

{{#methods}}
export function {{name}}Wrapped(argsBuf: ArrayBuffer, env_size: u32): ArrayBuffer {
export function {{name}}Wrapped(module: ModuleBase, argsBuf: ArrayBuffer, env_size: u32): ArrayBuffer {
{{#env}}
{{#required}}
if (env_size == 0) {
Expand All @@ -37,7 +33,7 @@ export function {{name}}Wrapped(argsBuf: ArrayBuffer, env_size: u32): ArrayBuffe
const args = deserialize{{name}}Args(argsBuf);
{{/arguments.length}}

const result = {{#detectKeyword}}{{name}}{{/detectKeyword}}({{#arguments.length}}
const result = module.{{#detectKeyword}}{{name}}{{/detectKeyword}}({{#arguments.length}}
{
{{#arguments}}
{{#detectKeyword}}{{name}}{{/detectKeyword}}: args.{{#detectKeyword}}{{name}}{{/detectKeyword}}{{^last}},{{/last}}
Expand All @@ -50,4 +46,4 @@ export function {{name}}Wrapped(argsBuf: ArrayBuffer, env_size: u32): ArrayBuffe
{{^last}}

{{/last}}
{{/methods}}
{{/methods}}
53 changes: 53 additions & 0 deletions packages/schema/parse/src/__tests__/dunder-methods.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { parseSchema } from "..";

const ErrorSchemas = {
"__new__": `
type Module {
__new__: String!
}
`,
"__hello__": `
type Module {
__hello__: String!
}
`,
}

const ValidSchemas = {
"_new_": `
type Module {
_new_: String!
}
`,
"__new": `
type Module {
__new: String!
}
`,
"new__": `
type Module {
new__: String!
}
`,
"_hello__": `
type Module {
_hello__: String!
}
`
}

describe("Polywrap Schema shouldn't contain dunder method name", () => {

for (const [key, value] of Object.entries(ErrorSchemas)) {
it(`should throw error for ${key}`, () => {
expect(() => parseSchema(value)).toThrowError();
});
}

for (const [key, value] of Object.entries(ValidSchemas)) {
it(`shouldn't throw error for ${key}`, () => {
expect(() => parseSchema(value)).not.toThrowError();
});
}

})
5 changes: 5 additions & 0 deletions packages/schema/parse/src/abi/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ export function createObjectPropertyDefinition(
export function createMethodDefinition(
args: Omit<Omit<MethodDefinition, "kind">, "type">
): MethodDefinition {
if (args.name?.startsWith("__") && args.name?.endsWith("__")) {
throw new Error(
"Dunder methods (Methods starting and ending with __) are reserved methods"
);
}
return {
...args,
...createGenericDefinition({
Expand Down
12 changes: 7 additions & 5 deletions packages/templates/wasm/assemblyscript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Args_sampleMethod, SampleResult } from "./wrap";
import { Args_sampleMethod, SampleResult, ModuleBase } from "./wrap";

export function sampleMethod(args: Args_sampleMethod): SampleResult {
return {
result: args.arg,
};
export class Module extends ModuleBase {
sampleMethod(args: Args_sampleMethod): SampleResult {
return {
result: args.arg,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export {
Args_optionalEnvMethod,
Args__if
};
export { ModuleBase } from "./module";
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as Types from "..";

import {
BigInt,
BigNumber,
Box,
JSON,
} from "@polywrap/wasm-as";
Comment thread
Niraj-Kamdar marked this conversation as resolved.

export abstract class ModuleBase {
abstract moduleMethod(
args: Types.Args_moduleMethod
): i32;

abstract objectMethod(
args: Types.Args_objectMethod,
env: Types.Env
): Types.AnotherType | null;

abstract optionalEnvMethod(
args: Types.Args_optionalEnvMethod,
env: Types.Env | null
): Types.AnotherType | null;

abstract _if(
args: Types.Args__if
): Types._else;
}
Loading