-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to emit TypeScript definitions for Wasm module exports.
The new flag `--emit-tsd <filename>` will generate a TypeScript defintion file for any Wasm module exports. If embind is also used the definitions for those types will also be included in the same file. This still doesn't give the full picture of Wasm module e.g. missing HEAP<N> and the various helper functions defined in JS.
- Loading branch information
1 parent
4aefde3
commit 2b75c93
Showing
13 changed files
with
327 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export interface MainModule { | ||
interface WasmModule { | ||
} | ||
|
||
interface EmbindModule { | ||
bigintFn(_0: bigint): bigint; | ||
} | ||
export type MainModule = WasmModule & EmbindModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time. | ||
interface WasmModule { | ||
_pthread_self(): number; | ||
_main(_0: number, _1: number): number; | ||
__emscripten_tls_init(): number; | ||
__emscripten_proxy_main(_0: number, _1: number): number; | ||
__embind_initialize_bindings(): void; | ||
__emscripten_thread_init(_0: number, _1: number, _2: number, _3: number, _4: number, _5: number): void; | ||
__emscripten_thread_crashed(): void; | ||
__emscripten_thread_exit(_0: number): void; | ||
} | ||
|
||
export interface Test { | ||
x: number; | ||
readonly y: number; | ||
functionOne(_0: number, _1: number): number; | ||
functionTwo(_0: number, _1: number): number; | ||
functionFour(_0: boolean): number; | ||
functionFive(x: number, y: number): number; | ||
constFn(): number; | ||
longFn(_0: number): number; | ||
functionThree(_0: ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string): number; | ||
functionSix(str: ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string): number; | ||
delete(): void; | ||
} | ||
|
||
export interface BarValue<T extends number> { | ||
value: T; | ||
} | ||
export type Bar = BarValue<0>|BarValue<1>|BarValue<2>; | ||
|
||
export interface EmptyEnumValue<T extends number> { | ||
value: T; | ||
} | ||
export type EmptyEnum = never/* Empty Enumerator */; | ||
|
||
export type ValArrIx = [ Bar, Bar, Bar, Bar ]; | ||
|
||
export interface IntVec { | ||
push_back(_0: number): void; | ||
resize(_0: number, _1: number): void; | ||
size(): number; | ||
set(_0: number, _1: number): boolean; | ||
get(_0: number): any; | ||
delete(): void; | ||
} | ||
|
||
export interface Foo { | ||
process(_0: Test): void; | ||
delete(): void; | ||
} | ||
|
||
export type ValObj = { | ||
foo: Foo, | ||
bar: Bar | ||
}; | ||
|
||
export interface ClassWithConstructor { | ||
fn(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export interface ClassWithTwoConstructors { | ||
delete(): void; | ||
} | ||
|
||
export interface ClassWithSmartPtrConstructor { | ||
fn(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export interface BaseClass { | ||
fn(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export interface DerivedClass extends BaseClass { | ||
fn2(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export type ValArr = [ number, number, number ]; | ||
|
||
interface EmbindModule { | ||
Test: {staticFunction(_0: number): number; staticFunctionWithParam(x: number): number; staticProperty: number}; | ||
class_returning_fn(): Test; | ||
class_unique_ptr_returning_fn(): Test; | ||
a_class_instance: Test; | ||
an_enum: Bar; | ||
Bar: {valueOne: BarValue<0>, valueTwo: BarValue<1>, valueThree: BarValue<2>}; | ||
EmptyEnum: {}; | ||
enum_returning_fn(): Bar; | ||
IntVec: {new(): IntVec}; | ||
Foo: {}; | ||
ClassWithConstructor: {new(_0: number, _1: ValArr): ClassWithConstructor}; | ||
ClassWithTwoConstructors: {new(): ClassWithTwoConstructors; new(_0: number): ClassWithTwoConstructors}; | ||
ClassWithSmartPtrConstructor: {new(_0: number, _1: ValArr): ClassWithSmartPtrConstructor}; | ||
BaseClass: {}; | ||
DerivedClass: {}; | ||
a_bool: boolean; | ||
an_int: number; | ||
global_fn(_0: number, _1: number): number; | ||
optional_test(_0: Foo | undefined): number | undefined; | ||
smart_ptr_function(_0: ClassWithSmartPtrConstructor): number; | ||
smart_ptr_function_with_params(foo: ClassWithSmartPtrConstructor): number; | ||
function_with_callback_param(_0: (message: string) => void): number; | ||
string_test(_0: ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string): string; | ||
wstring_test(_0: string): string; | ||
} | ||
export type MainModule = WasmModule & EmbindModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time. | ||
interface WasmModule { | ||
} | ||
|
||
export interface Test { | ||
x: number; | ||
readonly y: number; | ||
functionOne(_0: number, _1: number): number; | ||
functionTwo(_0: number, _1: number): number; | ||
functionFour(_0: boolean): number; | ||
functionFive(x: number, y: number): number; | ||
constFn(): number; | ||
longFn(_0: number): number; | ||
functionThree(_0: ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string): number; | ||
functionSix(str: ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string): number; | ||
delete(): void; | ||
} | ||
|
||
export interface BarValue<T extends number> { | ||
value: T; | ||
} | ||
export type Bar = BarValue<0>|BarValue<1>|BarValue<2>; | ||
|
||
export interface EmptyEnumValue<T extends number> { | ||
value: T; | ||
} | ||
export type EmptyEnum = never/* Empty Enumerator */; | ||
|
||
export type ValArrIx = [ Bar, Bar, Bar, Bar ]; | ||
|
||
export interface IntVec { | ||
push_back(_0: number): void; | ||
resize(_0: number, _1: number): void; | ||
size(): number; | ||
set(_0: number, _1: number): boolean; | ||
get(_0: number): any; | ||
delete(): void; | ||
} | ||
|
||
export interface Foo { | ||
process(_0: Test): void; | ||
delete(): void; | ||
} | ||
|
||
export type ValObj = { | ||
foo: Foo, | ||
bar: Bar | ||
}; | ||
|
||
export interface ClassWithConstructor { | ||
fn(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export interface ClassWithTwoConstructors { | ||
delete(): void; | ||
} | ||
|
||
export interface ClassWithSmartPtrConstructor { | ||
fn(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export interface BaseClass { | ||
fn(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export interface DerivedClass extends BaseClass { | ||
fn2(_0: number): number; | ||
delete(): void; | ||
} | ||
|
||
export type ValArr = [ number, number, number ]; | ||
|
||
interface EmbindModule { | ||
Test: {staticFunction(_0: number): number; staticFunctionWithParam(x: number): number; staticProperty: number}; | ||
class_returning_fn(): Test; | ||
class_unique_ptr_returning_fn(): Test; | ||
a_class_instance: Test; | ||
an_enum: Bar; | ||
Bar: {valueOne: BarValue<0>, valueTwo: BarValue<1>, valueThree: BarValue<2>}; | ||
EmptyEnum: {}; | ||
enum_returning_fn(): Bar; | ||
IntVec: {new(): IntVec}; | ||
Foo: {}; | ||
ClassWithConstructor: {new(_0: number, _1: ValArr): ClassWithConstructor}; | ||
ClassWithTwoConstructors: {new(): ClassWithTwoConstructors; new(_0: number): ClassWithTwoConstructors}; | ||
ClassWithSmartPtrConstructor: {new(_0: number, _1: ValArr): ClassWithSmartPtrConstructor}; | ||
BaseClass: {}; | ||
DerivedClass: {}; | ||
a_bool: boolean; | ||
an_int: number; | ||
global_fn(_0: number, _1: number): number; | ||
optional_test(_0: Foo | undefined): number | undefined; | ||
smart_ptr_function(_0: ClassWithSmartPtrConstructor): number; | ||
smart_ptr_function_with_params(foo: ClassWithSmartPtrConstructor): number; | ||
function_with_callback_param(_0: (message: string) => void): number; | ||
string_test(_0: ArrayBuffer|Uint8Array|Uint8ClampedArray|Int8Array|string): string; | ||
wstring_test(_0: string): string; | ||
} | ||
export type MainModule = WasmModule & EmbindModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export interface MainModule { | ||
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time. | ||
interface WasmModule { | ||
} | ||
|
||
interface EmbindModule { | ||
longFn(_0: bigint): bigint; | ||
} | ||
export type MainModule = WasmModule & EmbindModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <emscripten.h> | ||
|
||
EMSCRIPTEN_KEEPALIVE void fooVoid() {} | ||
EMSCRIPTEN_KEEPALIVE int fooInt(int a, int b) { | ||
return 42; | ||
} | ||
|
||
int main() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// TypeScript bindings for emscripten-generated code. Automatically generated at compile time. | ||
interface WasmModule { | ||
_fooVoid(): void; | ||
_fooInt(_0: number, _1: number): number; | ||
_main(_0: number, _1: number): number; | ||
} | ||
|
||
export type MainModule = WasmModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.