Skip to content
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: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/base/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ where
deno_fetch::Options {
user_agent: deno::versions::user_agent().to_string(),
root_cert_store_provider: Some(root_cert_store_provider.clone()),
file_fetch_handler: Rc::new(deno_fetch::FsFetchHandler),
..Default::default()
},
),
Expand Down
10 changes: 10 additions & 0 deletions crates/base/test_cases/fetch-local-npm-file/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as _meow from "npm:@imagemagick/magick-wasm@0.0.30";

const url = import.meta.resolve("npm:@imagemagick/magick-wasm@0.0.30");

export default {
async fetch() {
const text = await (await fetch(url)).text();
return new Response(text);
},
};
1 change: 1 addition & 0 deletions crates/base/test_cases/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Deno.serve(async (req: Request) => {
noNpm,
envVars,
context,
staticPatterns: ["**/*.wasm"],
});
};

Expand Down
4 changes: 4 additions & 0 deletions crates/base/test_cases/wasm-module/add-wasm/pkg/add_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* tslint:disable */
/* eslint-disable */

export function add(a: number, b: number): number;
38 changes: 38 additions & 0 deletions crates/base/test_cases/wasm-module/add-wasm/pkg/add_wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* @ts-self-types="./add_wasm.d.ts" */

/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
export function add(a, b) {
const ret = wasm.add(a, b);
return ret >>> 0;
}

function __wbg_get_imports() {
const import0 = {
__proto__: null,
__wbindgen_init_externref_table: function () {
const table = wasm.__wbindgen_externrefs;
const offset = table.grow(4);
table.set(0, undefined);
table.set(offset + 0, undefined);
table.set(offset + 1, null);
table.set(offset + 2, true);
table.set(offset + 3, false);
},
};
return {
__proto__: null,
"./add_wasm_bg.js": import0,
};
}

const wasmUrl = new URL("add_wasm_bg.wasm", import.meta.url);
const wasmInstantiated = await WebAssembly.instantiateStreaming(
fetch(wasmUrl),
__wbg_get_imports(),
);
const wasm = wasmInstantiated.instance.exports;
wasm.__wbindgen_start();
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export const add: (a: number, b: number) => number;
export const __wbindgen_externrefs: WebAssembly.Table;
export const __wbindgen_start: () => void;
7 changes: 7 additions & 0 deletions crates/base/test_cases/wasm-module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { add } from "./add-wasm/pkg/add_wasm.js";

Deno.serve(async (req) => {
const result = add(1, 2);

return new Response(`${result}`, { status: 200 }); // result: 3
});
57 changes: 57 additions & 0 deletions crates/base/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,63 @@ async fn test_declarative_style_fetch_handler() {
);
}

#[tokio::test]
#[serial]
async fn test_fetch_local_file_handler() {
let (tx, mut rx) = mpsc::unbounded_channel();
let tb = TestBedBuilder::new("./test_cases/main")
.with_per_worker_policy(None)
.with_worker_event_sender(Some(tx))
.build()
.await;

let mut resp = tb
.request(|b| {
b.uri("/fetch-local-npm-file")
.body(Body::empty())
.context("can't make request")
})
.await
.unwrap();

let status = resp.status().as_u16();
let body = to_bytes(resp.body_mut()).await.unwrap();
let body = String::from_utf8_lossy(&body).to_string();

if status != 200 || body.is_empty() {
rx.close();
tb.exit(Duration::from_secs(TESTBED_DEADLINE_SEC)).await;

while let Some(ev) = rx.recv().await {
if let WorkerEvents::Log(ev) = ev.event {
eprintln!("[worker-log] {}", ev.msg);
}
}
}

assert_eq!(status, 200);
assert!(!body.is_empty());
}

// https://github.com/supabase/edge-runtime/issues/640
#[tokio::test]
#[serial]
async fn test_wasm_module() {
integration_test!(
"./test_cases/main",
NON_SECURE_PORT,
"wasm-module",
None,
None,
None,
(|resp| async {
// Testing mod add(1, 2) === 3;
assert_eq!(resp.unwrap().text().await.unwrap(), "3");
}),
TerminationToken::new()
);
}

#[tokio::test]
#[serial]
async fn test_issue_208() {
Expand Down
1 change: 1 addition & 0 deletions examples/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Deno.serve(async (req: Request) => {
const cpuTimeHardLimitMs = 20000;
const staticPatterns = [
"./examples/**/*.html",
"./examples/**/*.wasm",
];

return await EdgeRuntime.userWorkers.create({
Expand Down
114 changes: 114 additions & 0 deletions examples/wasm-module/add-wasm/Cargo.lock

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

12 changes: 12 additions & 0 deletions examples/wasm-module/add-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "add-wasm"
version = "0.1.0"
edition = "2021"
license = "MIT/Apache-2.0"
description = "A simple wasm module that adds two numbers"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"
4 changes: 4 additions & 0 deletions examples/wasm-module/add-wasm/pkg/add_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* tslint:disable */
/* eslint-disable */

export function add(a: number, b: number): number;
38 changes: 38 additions & 0 deletions examples/wasm-module/add-wasm/pkg/add_wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* @ts-self-types="./add_wasm.d.ts" */

/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
export function add(a, b) {
const ret = wasm.add(a, b);
return ret >>> 0;
}

function __wbg_get_imports() {
const import0 = {
__proto__: null,
__wbindgen_init_externref_table: function () {
const table = wasm.__wbindgen_externrefs;
const offset = table.grow(4);
table.set(0, undefined);
table.set(offset + 0, undefined);
table.set(offset + 1, null);
table.set(offset + 2, true);
table.set(offset + 3, false);
},
};
return {
__proto__: null,
"./add_wasm_bg.js": import0,
};
}

const wasmUrl = new URL("add_wasm_bg.wasm", import.meta.url);
const wasmInstantiated = await WebAssembly.instantiateStreaming(
fetch(wasmUrl),
__wbg_get_imports(),
);
const wasm = wasmInstantiated.instance.exports;
wasm.__wbindgen_start();
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/wasm-module/add-wasm/pkg/add_wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export const add: (a: number, b: number) => number;
export const __wbindgen_externrefs: WebAssembly.Table;
export const __wbindgen_start: () => void;
5 changes: 5 additions & 0 deletions examples/wasm-module/add-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn add(a: u32, b: u32) -> u32 {
a + b
}
Binary file added examples/wasm-module/add_wasm_bg.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions examples/wasm-module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { add } from "./add-wasm/pkg/add_wasm.js";

Deno.serve(async (req) => {
const { a, b } = await req.json();
const result = add(a, b);

return Response.json({ result });
});
2 changes: 1 addition & 1 deletion types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ declare namespace Supabase {
}

export class Session {
init: Promise<void>
init: Promise<void>;
/**
* Create a new model session using given model
*/
Expand Down
2 changes: 2 additions & 0 deletions vendor/deno_fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ base64.workspace = true
bytes.workspace = true
data-url.workspace = true
deno_core.workspace = true
deno_fs.workspace = true
deno_io.workspace = true
deno_path_util.workspace = true
deno_permissions.workspace = true
deno_tls.workspace = true
Expand Down
Loading
Loading