Skip to content
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

Request Feature: Support direct WebAssembly import and run #6279

Closed
HKhademian opened this issue Jun 13, 2020 · 5 comments
Closed

Request Feature: Support direct WebAssembly import and run #6279

HKhademian opened this issue Jun 13, 2020 · 5 comments

Comments

@HKhademian
Copy link

It's good to directly run WebAssembly files in deno like .js and .ts files. If so then I can run:
deno run myTask.wasm
without any additional files and steps. (it exports a common function like main or start or ...)

Also it's good to directly import these files to project with simple and readable syntax:
import { task1 } from ".../myLib.wasm"

Like this code in dev.to, it writes a simple library function called square and import it in .ts file and run that .ts file with deno.

Example above can be very simpler:

const wasmCode = await Deno.readFile("./target/wasm32-unknown-unknown/debug/wasm_deno_example.wasm");
const wasmModule = new WebAssembly.Module(wasmCode);
const wasmInstance = new WebAssembly.Instance(wasmModule);
const {
    square,
} = wasmInstance.exports;

can write somthing like:

import { square } from "./target/wasm32-unknown-unknown/debug/wasm_deno_example.wasm";

It's much more readable, clean, easy to use, and also do not dirty the global context.

This simple feature enables more comfortable journey to publish libraries and write cross-platform deno apps.

@bartlomieju
Copy link
Member

Duplicate of #5609

@bartlomieju bartlomieju marked this as a duplicate of #5609 Jun 13, 2020
@HKhademian
Copy link
Author

this nested issues has not direct vision to every one how want to help.
this feature request has two parts:
1- deno run WASM files from command line to create portable deno apps
2- deno support clean import WASM files to create easy to use libraries

and yes it's better to use --unstable flag for such features.

@Spoonbender
Copy link
Contributor

From what I've gathered, wasm currently lacks the concept of an entry point ("main" function or top level code), so it is unclear how deno should execute the wasm module.
Perhaps we can provide a syntax for specifying the function name (also useful for ts/js), such as deno run mymodule.wasm;main or deno run --entrypoint main mymodule.wasm?

@bartlomieju
Copy link
Member

I'm gonna close this issue as a duplicate of #5609, let's continue there.

@ghost
Copy link

ghost commented Feb 10, 2021

@Spoonbender Sorry for the year late ping, but a WebAssembly module is allowed to choose a function that executes immediately upon compilation, reminiscence of Linux _start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants