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

Generate typescript #6192

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e76aa6e
progress
ericvergnaud Dec 7, 2023
16cae25
has complete i32, i64, f32 and f64
ericvergnaud Dec 7, 2023
19378e6
document API changes
ericvergnaud Dec 7, 2023
b1be833
generates v128
ericvergnaud Dec 7, 2023
76846ff
support i8x16
ericvergnaud Dec 10, 2023
96add7c
support i16x8
ericvergnaud Dec 10, 2023
b69507a
support i32x4
ericvergnaud Dec 10, 2023
6d99060
support i64x2
ericvergnaud Dec 10, 2023
6e6d209
support f32x4
ericvergnaud Dec 11, 2023
f5866e6
support f64x2
ericvergnaud Dec 11, 2023
255b56f
more stuff
ericvergnaud Dec 11, 2023
cc49c4c
more stuff
ericvergnaud Dec 11, 2023
3a2b2a2
progress
ericvergnaud Dec 11, 2023
a52dfe3
support ExpressionInfo
ericvergnaud Dec 11, 2023
4b4460e
migration of index.d.ts from binaryen.js complete
ericvergnaud Dec 11, 2023
0520e32
reinstate deprecated methods
ericvergnaud Dec 12, 2023
e370f1c
fix return types
ericvergnaud Dec 12, 2023
839b665
a base version i.e. symbols are exported, but not tested yet
ericvergnaud Dec 13, 2023
76a0e7c
Works for all existing tests in my project
ericvergnaud Dec 13, 2023
ec80d01
rename for consistency
ericvergnaud Dec 13, 2023
898cb2d
Fix typos
ericvergnaud Dec 13, 2023
36c0747
Fix Feature API
ericvergnaud Dec 13, 2023
4036ade
implements a new approach
ericvergnaud Dec 21, 2023
95f3df3
need to await on the imported function, not the import
ericvergnaud Dec 21, 2023
b0c24cd
house keeping
ericvergnaud Dec 21, 2023
67b9213
fix memory leak and add support for get array item
ericvergnaud Jan 6, 2024
cbb6c00
more arrays API
ericvergnaud Jan 9, 2024
b779e22
add support for structs, unify GC field type
ericvergnaud Jan 13, 2024
d1b34d2
use powershell commands on windows
ericvergnaud Jan 13, 2024
deea92d
rely on built-in exports mechanism
ericvergnaud Jan 14, 2024
76d7f08
more GC methods
ericvergnaud Jan 23, 2024
4199884
add support for BinaryenArrayNewData
ericvergnaud Jan 24, 2024
59a05f0
add entry point for BinaryenArrayNewData
ericvergnaud Jan 24, 2024
34b692f
fix missing semicolon
ericvergnaud Jan 24, 2024
8efbe18
simplify
ericvergnaud Jan 30, 2024
3596b41
Merge branch 'main' into generate-typescript
ericvergnaud Feb 1, 2024
f2019de
update memory API
ericvergnaud Feb 1, 2024
9be8b9c
make name optional in SegmentInfo
ericvergnaud Feb 1, 2024
e6bbbc1
make it possible to capture the validator error stream
ericvergnaud Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ test/lit/lit.site.cfg.py

# files related to clangd cache
.cache/*

# files related to tsc compilation
/src/ts/binaryen_post.js
/src/ts/binaryen_post.d.ts
/src/ts/binaryen.d.ts
/src/ts/binaryen.js
/*.map
50 changes: 44 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_BUILD_TYPE "Debug")
endif()

# We default to assertions enabled, even in release builds so that we get
Expand Down Expand Up @@ -352,7 +352,7 @@ if(EMSCRIPTEN)
add_link_flag("-sMODULARIZE")
add_link_flag("-sEXPORT_ES6")
add_link_flag("-sFILESYSTEM")
add_link_flag("-sFORCE_FILESYSTEM")
add_link_flag("-sFORCE_FILESYSTEM")
else()
# On Node.js, make the tools immediately usable.
add_link_flag("-sNODERAWFS")
Expand Down Expand Up @@ -455,18 +455,39 @@ if(EMSCRIPTEN)
)

# binaryen.js WebAssembly variant
# compile the TypeScript file injected in the generated js
add_custom_target(binaryen_post_js
COMMAND tsc --target ES2020 --module ES2022 --outDir ${CMAKE_BINARY_DIR}/bin ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_post.ts)
# compile the TypeScript file that wraps the generated js
if(WIN32) # not tested!
add_custom_target(binaryen_wasm_wrapper
COMMAND (Get-content ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen.ts) | Foreach-Object {$_ -replace "TARGET", "wasm"} | Set-Content ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_wasm.ts &&
tsc --target ES2020 --module ES2022 --declaration --declarationMap --outDir ${CMAKE_BINARY_DIR}/bin ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_wasm.ts &&
rm ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_wasm.ts)
else()
add_custom_target(binaryen_wasm_wrapper
COMMAND sed -e 's/TARGET/wasm/g' ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen.ts >> ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_wasm.ts &&
tsc --target ES2020 --module ES2022 --declaration --declarationMap --outDir ${CMAKE_BINARY_DIR}/bin ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_wasm.ts &&
rm ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_wasm.ts)
endif()
add_executable(binaryen_wasm
${binaryen_emscripten_SOURCES})
add_dependencies(binaryen_wasm binaryen_post_js binaryen_wasm_wrapper)
set_target_properties(binaryen_wasm PROPERTIES OUTPUT_NAME "binaryen_raw_wasm")
target_link_libraries(binaryen_wasm wasm asmjs emscripten-optimizer passes ir cfg support analysis parser wasm)
target_link_libraries(binaryen_wasm "-sFILESYSTEM")
target_link_libraries(binaryen_wasm "-sEXPORT_NAME=Binaryen")
target_link_libraries(binaryen_wasm "-sNODERAWFS=0")
target_link_libraries(binaryen_wasm "-sEXPORT_ES6")
target_link_libraries(binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=allocateUTF8OnStack,stringToAscii")
target_link_libraries(binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=allocateUTF8OnStack,stringToAscii,stackSave,stackAlloc,stackRestore,UTF8ToString")
target_link_libraries(binaryen_wasm "-sEXPORTED_FUNCTIONS=_malloc,_free")
target_link_libraries(binaryen_wasm "--post-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
# useful when working on --post-js file
target_link_libraries(binaryen_wasm "--minify=0")
target_link_libraries(binaryen_wasm "--post-js=${CMAKE_BINARY_DIR}/bin/binaryen_post.js")
target_link_libraries(binaryen_wasm "-msign-ext")
target_link_libraries(binaryen_wasm "-mbulk-memory")
target_link_libraries(binaryen_wasm optimized "--closure=0")
target_link_libraries(binaryen_wasm optimized "--closure-args=\"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\"")
target_link_libraries(binaryen_wasm optimized "--closure=1")
# TODO: Fix closure warnings! (#5062)
target_link_libraries(binaryen_wasm optimized "-Wno-error=closure")
Expand All @@ -475,8 +496,22 @@ if(EMSCRIPTEN)
install(TARGETS binaryen_wasm DESTINATION ${CMAKE_INSTALL_BINDIR})

# binaryen.js JavaScript variant
# compile the TypeScript file that wraps the generated js
if(WIN32) # not tested!
add_custom_target(binaryen_js_wrapper
COMMAND (Get-content ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen.ts) | Foreach-Object {$_ -replace "TARGET", "js"} | Set-Content ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_js.ts &&
tsc --target ES2020 --module ES2022 --declaration --declarationMap --outDir ${CMAKE_BINARY_DIR}/bin ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_js.ts &&
rm ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_js.ts)
else()
add_custom_target(binaryen_js_wrapper
COMMAND sed -e 's/TARGET/js/g' ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen.ts >> ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_js.ts &&
tsc --target ES2020 --module ES2022 --declaration --declarationMap --outDir ${CMAKE_BINARY_DIR}/bin ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_js.ts &&
rm ${CMAKE_CURRENT_SOURCE_DIR}/src/ts/binaryen_js.ts)
endif()
add_executable(binaryen_js
${binaryen_emscripten_SOURCES})
add_dependencies(binaryen_js binaryen_post_js binaryen_js_wrapper)
set_target_properties(binaryen_js PROPERTIES OUTPUT_NAME "binaryen_raw_js")
target_link_libraries(binaryen_js wasm asmjs emscripten-optimizer passes ir cfg support analysis parser wasm)
target_link_libraries(binaryen_js "-sWASM=0")
target_link_libraries(binaryen_js "-sWASM_ASYNC_COMPILATION=0")
Expand All @@ -500,9 +535,11 @@ if(EMSCRIPTEN)
else()
target_link_libraries(binaryen_js "-sEXPORT_ES6=1")
endif()
target_link_libraries(binaryen_js "-sEXPORTED_RUNTIME_METHODS=allocateUTF8OnStack,stringToAscii")
target_link_libraries(binaryen_js "-sEXPORTED_RUNTIME_METHODS=allocateUTF8OnStack,stringToAscii,stackSave,stackAlloc,stackRestore,UTF8ToString")
target_link_libraries(binaryen_js "-sEXPORTED_FUNCTIONS=_malloc,_free")
target_link_libraries(binaryen_js "--post-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
# useful when working on --post-js file
# target_link_libraries(binaryen_js "--minify=0")
target_link_libraries(binaryen_js "--post-js=${CMAKE_BINARY_DIR}/bin/binaryen_post.js")
# js_of_ocaml needs a specified variable with special comment to provide the library to consumers
if(JS_OF_OCAML)
target_link_libraries(binaryen_js "--extern-pre-js=${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.jsoo-extern-pre.js")
Expand All @@ -518,6 +555,7 @@ if(EMSCRIPTEN)
target_link_libraries(binaryen_js debug "--profiling")
target_link_libraries(binaryen_js debug "-sASSERTIONS")
install(TARGETS binaryen_js DESTINATION ${CMAKE_INSTALL_BINDIR})

endif()

configure_file(scripts/binaryen-lit.in ${CMAKE_BINARY_DIR}/bin/binaryen-lit @ONLY)