Skip to content

udpate asm script 0.21 #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 10.0.0
node-version: 16.17.0
- name: Publish if version has been updated
uses: pascalgn/npm-publish-action@4f4bf159e299f65d21cd1cbd96fc5d53228036df
with: # All of theses inputs are optional
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 10.0.0
node-version: 16.17.0
- run: npm install
- run: npm run asbuild
# make sure example filter builds:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ npx asinit .

add `--use abort=abort_proc_exit` to the `asc` in packages.json. for example:
```json
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm --use abort=abort_proc_exit -t build/untouched.wat --sourceMap http://127.0.0.1:8081/build/untouched.wasm.map --debug",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm --use abort=abort_proc_exit -t build/optimized.wat --sourceMap --optimize",
"asbuild:debug": "asc assembly/index.ts -b build/untouched.wasm --use abort=abort_proc_exit -t build/untouched.wat --sourceMap http://127.0.0.1:8081/build/untouched.wasm.map --debug",
"asbuild:release": "asc assembly/index.ts -b build/optimized.wasm --use abort=abort_proc_exit -t build/optimized.wat --sourceMap --optimize",
```

Add `"@solo-io/proxy-runtime": "file:/home/yuval/Projects/solo/proxy-assemblyscript"` to your dependencies.
Expand Down
23 changes: 23 additions & 0 deletions asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"targets": {
"debug": {
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat",
"sourceMap": "http://127.0.0.1:8081/build/untouched.wasm.map",
"debug": true
},
"release": {
"outFile": "build/release.wasm",
"textFile": "build/release.wat",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 0,
"converge": false,
"noAssert": false
}
},
"options": {
"bindings": "esm",
"use": "abort=abort_proc_exit"
}
}
2 changes: 1 addition & 1 deletion assembly/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./malloc";
export { malloc } from "./malloc";
export * from "./exports";
32 changes: 15 additions & 17 deletions assembly/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// import {LogLevel, WasmResult, MetricType, PeerType, HeaderMapType, BufferType, BufferFlags} from "./exports";
import * as imports from "./imports";
import { free } from "./malloc";
import { proc_exit } from "bindings/wasi_unstable";

import { proc_exit } from "./wasi_unstable";

// abort function.
// use with:
// --use abort=index/abort_proc_exit
// compiler flag
// @ts-ignore: decorator
@global
export function abort_proc_exit(message: string | null, fileName: string | null, lineNumber: u32, columnNumber: u32): void {
let logMessage = "";
export function abort_proc_exit(message: string | null, fileName: string | null, lineNumber: u32, columnNumber: u32): void {
let logMessage = "abort: ";
if (message !== null) {
logMessage += message.toString();
}
Expand Down Expand Up @@ -89,7 +87,7 @@ export class HeaderPair {
}
}

export function makeHeaderPair(key: string, value: string) : HeaderPair {
export function makeHeaderPair(key: string, value: string): HeaderPair {
let key_arr = String.UTF8.encode(key);
let value_arr = String.UTF8.encode(value);
return new HeaderPair(key_arr, value_arr);
Expand Down Expand Up @@ -355,25 +353,25 @@ export function send_local_response(response_code: u32, response_code_details: s

export function clear_route_cache(): WasmResultValues { return imports.proxy_clear_route_cache(); }
class GetSharedData {
value: ArrayBuffer|null;
value: ArrayBuffer | null;
result: WasmResultValues;
cas: u32;
cas: usize;
}

export function get_shared_data(key: string): GetSharedData {
const key_buffer = String.UTF8.encode(key);
let cas = globalUsizeRef;
let data = globalArrayBufferReference;
let result = new GetSharedData();
result.result = imports.proxy_get_shared_data(changetype<usize>(key_buffer), key_buffer.byteLength, data.bufferPtr(), data.sizePtr(), cas.ptr());
result.result = imports.proxy_get_shared_data(changetype<usize>(key_buffer), key_buffer.byteLength, data.bufferPtr(), data.sizePtr(), cas.ptr());
if (result.result == WasmResultValues.Ok) {
result.value = data.toArrayBuffer();
result.cas = cas.data;
}
return result;
}

export function set_shared_data(key: string, value: ArrayBuffer, cas : u32 = 0): WasmResultValues {
export function set_shared_data(key: string, value: ArrayBuffer, cas: u32 = 0): WasmResultValues {
const key_buffer = String.UTF8.encode(key);
return imports.proxy_set_shared_data(changetype<usize>(key_buffer), key_buffer.byteLength, changetype<usize>(value), value.byteLength, cas);
}
Expand Down Expand Up @@ -409,7 +407,7 @@ export function resolve_shared_queue(vm_id: string, queue_name: string): TokenSh

class DequeueSharedQueueResult {
result: WasmResultValues;
data: ArrayBuffer|null;
data: ArrayBuffer | null;
}
export function dequeue_shared_queue(token: u32): DequeueSharedQueueResult {
let result = new DequeueSharedQueueResult();
Expand Down Expand Up @@ -734,12 +732,12 @@ export function call_foreign_function(function_name: string, argument: string):
let argument_name_buffer = String.UTF8.encode(argument);

CHECK_RESULT(imports.proxy_call_foreign_function(
changetype<usize>(function_name_buffer),
function_name_buffer.byteLength,
changetype<usize>(argument_name_buffer),
argument_name_buffer.byteLength,
globalArrayBufferReference.bufferPtr(),
globalArrayBufferReference.sizePtr()));
changetype<usize>(function_name_buffer),
function_name_buffer.byteLength,
changetype<usize>(argument_name_buffer),
argument_name_buffer.byteLength,
globalArrayBufferReference.bufferPtr(),
globalArrayBufferReference.sizePtr()));
return globalArrayBufferReference.toArrayBuffer();
}
/////// runtime support
Expand Down
2 changes: 1 addition & 1 deletion assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
Expand Down
8 changes: 8 additions & 0 deletions assembly/wasi_unstable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/** Terminate the process normally. An exit code of 0 indicates successful termination of the program. The meanings of other values is dependent on the environment. */
// @ts-ignore: decorator
@unsafe
export declare function proc_exit(
/** Input: The exit code returned by the process. */
rval: u32
): void;
23 changes: 23 additions & 0 deletions examples/addheader/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"targets": {
"debug": {
"outFile": "build/debug.wasm",
"textFile": "build/debug.wat",
"sourceMap": true,
"debug": true
},
"release": {
"outFile": "build/release.wasm",
"textFile": "build/release.wat",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 0,
"converge": false,
"noAssert": false
}
},
"options": {
"bindings": "esm",
"use": "abort=abort_proc_exit"
}
}
4 changes: 2 additions & 2 deletions examples/addheader/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

export * from "@solo-io/proxy-runtime/proxy"; // this exports the required functions for the proxy to interact with us.
import { RootContext, Context, registerRootContext, FilterHeadersStatusValues, stream_context } from "@solo-io/proxy-runtime";
export * from "@solo-io/proxy-runtime/assembly/proxy"; // this exports the required functions for the proxy to interact with us.
import { RootContext, Context, registerRootContext, FilterHeadersStatusValues, stream_context } from "@solo-io/proxy-runtime/assembly";

class AddHeaderRoot extends RootContext {
createContext(context_id: u32): Context {
Expand Down
2 changes: 1 addition & 1 deletion examples/addheader/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"extends": "assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
Expand Down
111 changes: 28 additions & 83 deletions examples/addheader/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading