web-devkits / wasmnizer-ts Goto Github PK
View Code? Open in Web Editor NEWToolchain for compiling TypeScript to WasmGC
License: Apache License 2.0
Toolchain for compiling TypeScript to WasmGC
License: Apache License 2.0
I just started learning webassembly, and I feel that AssemblyScript and this project seem to be doing the same things. What's the difference?
Hi,
As an initial experiment I moved the tests from Mocha to Node.js Test Runner.
https://github.com/AaronNGray/Wasmnizer-ts/tree/nodejs-test-runner
Thought you might want to take a look !
Following the instructions in https://github.com/intel/Wasmnizer-ts/blob/main/doc/getting_started.md
/opt/wasm/Wasmnizer-ts/ npm install
up to date in 277ms
/opt/wasm/Wasmnizer-ts/ npm run build
> [email protected] build
> npx tsc && npm run build:lib
cli/ts2wasm.ts:6:22 - error TS2307: Cannot find module 'minimist' or its corresponding type declarations.
6 import minimist from 'minimist';
~~~~~~~~~~
cli/ts2wasm.ts:7:16 - error TS2307: Cannot find module 'child_process' or its corresponding type declarations.
7 import cp from 'child_process';
~~~~~~~~~~~~~~~
cli/ts2wasm.ts:8:16 - error TS2307: Cannot find module 'fs' or its corresponding type declarations.
8 import fs from 'fs';
~~~~
brew upgrade (Mac Sonoma)
typescript 5.2.2 already installed
Are there any other prerequisites?
Under Windows:
cd wasmnizer-ts\build
node .\cli\ts2wasm.js ..\tests\benchmark\mandelbrot.ts -o mandelbrot.wasm --opt=3 => success
cd tools\validate\run_module_on_node
node --experimental-wasm-gc --experimental-wasm-stringref --experimental-wasm-modules --experimental-repl-await run_module.js -f main ......\build\mandelbrot.wasm
Error:
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
[CompileError: WebAssembly.instantiate(): invalid value type 0x78 @+12]
Node.js v20.10.0
Run binarytrees_class benchmark by WAMR aot:
LLVM ERROR: Only small, tiny and large code models are allowed on AArch64
./run.sh: line 46: 43945 Abort trap: 6 $wamrc --enable-gc -o $prefix.aot $prefix.wasm > tmp.txt
Read file to buffer failed: open file binarytrees_class.aot failed.
sys: macos 14.2 arm64
The following command in Windows command prompt: node cli/ts2wasm.js --opt=3 mandelbrot.ts -o out.wasm =>
Error: Error: Error: Cannot find the idenentifier "DataView"
at buildExpression (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/expression_builder.js:1940:15)
at buildIfStatement (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/statement_builder.js:194:21)
at buildStatement (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/statement_builder.js:346:23)
at buildStatements (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:46:23)
at generateFunctionScopeNodes (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:360:24)
at generateScopeNodes (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:382:13)
at foreachScopeChildren (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:289:9)
at generateClassScopeNodes (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:367:5)
at generateScopeNodes (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:385:13)
at foreachScopeChildren (file:///C:/Users/louis/projecten/wasmnizer-ts/build/src/semantics/index.js:289:9)
The sample from run_module_on_node results in the following error:
Import #144 module="libdyntype" function="dyntype_get_keys" error: function import requires a callable]
dyntype_get_keys is not defined in import_object.js. Maybe that causes the error.
I am not sure if it is the intention, but I believe that the function initArr will generate an array filled with the same number.
Add some more detail to the CONTRIBUTING.md to describe how people can contribute, eg. file issues, create PRs, etc.
Unable to install iwasm_gc under Windows.
Is the end goal support for the full TypeScript language? What about JavaScript?
Code:
export function indexGenerator(alpha: i32): i32[] {
let results: i32[] = new Array(alpha);
for (let counter: i32 = 0; counter < alpha; counter++) {
results[counter] = counter;
}
return results;
};
Error:
Aborted(Assertion failed: Type::isSubType(newType, oldType), at: /home/runner/work/binaryen.js/binaryen.js/binaryen/src/passes/LocalSubtyping.cpp,148,doWalkFunction)
[2024-01-07T22:46:19.148] [ERROR] console - Aborted(Assertion failed: Type::isSubType(newType, oldType), at: /home/runner/work/binaryen.js/binaryen.js/binaryen/src/passes/LocalSubtyping.cpp,148,doWalkFunction). Build with -sASSERTIONS for more info.
Error details is in 'C:\Users\louis\AppData\Local\Temp\ts2wasm-log-r6GkvW\error.log'
Log details is in 'C:\Users\louis\AppData\Local\Temp\ts2wasm-log-r6GkvW\trace.log'
However the following code will generate the wasm-file:
New Code:
type i32_ = i32;
export function indexGenerator(alpha: i32_): i32_[] {
let results: i32_[] = new Array(alpha);
for (let counter: i32_ = 0; counter < alpha; counter++) {
results[counter] = counter;
}
return results;
};
I met a exception when execute aot file on Android platform. Who can help me? Thanks a lot.
Exception:
12-22 17:33:09.956 9534 9534 I wasm_jni::: wasm_runtime_full_init
12-22 17:33:09.956 9534 9534 I wasm_jni::: use an internal test file, gona to output Hello World in logcat
12-22 17:33:09.956 9534 9534 I wasm_jni::: wasm_runtime_load file buf_size= 7876 4
12-22 17:33:09.956 9534 9534 I wasm_jni::: wasm_runtime_instantiate
12-22 17:33:09.957 9534 9534 I wasm_runtime::: [13:32:42:470 - EB61C470]:
12-22 17:33:09.957 9534 9534 I wasm_runtime::: warning: failed to link import function (libdyntype, dyntype_get_context)
12-22 17:33:09.957 9534 9534 I wasm_runtime:::
12-22 17:33:09.957 9534 9534 I wasm_runtime::: [13:32:42:544 - EB61C470]:
12-22 17:33:09.957 9534 9534 I wasm_runtime::: warning: failed to link import function (libdyntype, dyntype_new_number)
12-22 17:33:09.957 9534 9534 I wasm_runtime:::
12-22 17:33:09.957 9534 9534 I wasm_runtime::: [13:32:42:606 - EB61C470]:
12-22 17:33:09.957 9534 9534 I wasm_runtime::: warning: failed to link import function (libdyntype, dyntype_new_string)
12-22 17:33:09.957 9534 9534 I wasm_runtime:::
12-22 17:33:09.957 9534 9534 I wasm_runtime::: [13:32:42:667 - EB61C470]:
12-22 17:33:09.957 9534 9534 I wasm_runtime::: warning: failed to link import function (env, Console_log)
12-22 17:33:09.957 9534 9534 I wasm_runtime:::
12-22 17:33:09.957 9534 9534 I wasm_jni::: run main() of the application
12-22 17:33:09.957 9534 9534 I wasm_jni::: wasm_runtime app_instance_main
12-22 17:33:09.957 9534 9534 I wasm_jni::: Exception: failed to call unlinked import function (libdyntype, dyntype_get_context)
12-22 17:33:09.957 9534 9534 I wasm_jni::: wasm_runtime_deinstantiate
12-22 17:33:09.957 9534 9534 I wasm_jni::: wasm_runtime_unload
12-22 17:33:09.957 9534 9534 I wasm_jni::: wasm_runtime_destroy
android cmake I changed:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/product-mini/platforms/android/CMakeLists.txt
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.4.1)
set (CMAKE_VERBOSE_MAKEFILE on)
set (CMAKE_BUILD_TYPE Release)
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#environment-variables-3
set (CMAKE_TOOLCHAIN_FILE "/home/mi/Android/Sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake")
set (ANDROID_SDK "/home/mi/Android/Sdk")
set (ANDROID_NDK "/home/mi/Android/Sdk/ndk/23.1.7779620")
set (ANDROID_ABI "armeabi-v7a")
set (ANDROID_LD lld)
if (NOT DEFINED ANDROID_PLATFORM)
set (ANDROID_PLATFORM 24)
endif ()
project (iwasm)
set (WAMR_BUILD_PLATFORM "android")
set (WAMR_BUILD_TARGET "ARMV7")
set (WAMR_BUILD_TYPE Release)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 1)
set (WAMR_BUILD_GC_BINARYEN 1)
set (WAMR_BUILD_FAST_INTERP 1)
set (WAMR_BUILD_GC 1)
#set (WAMR_BUILD_STRINGREF 1)
add_definitions(-DWASM_TABLE_MAX_SIZE=10240)
if (NOT DEFINED WAMR_BUILD_SIMD)
# Enable SIMD by default
set (WAMR_BUILD_SIMD 1)
endif ()
# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
endif ()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()
if (NOT DEFINED WAMR_BUILD_AOT)
# Enable AOT by default.
set (WAMR_BUILD_AOT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()
if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Enable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 1)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../deps/wamr-gc)
#include_directories(${WAMR_ROOT_DIR}/core/iwasm/include)
#include_directories(${WAMR_ROOT_DIR}/core/iwasm/common/gc)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
endif ()
endif ()
# The following flags are to enhance security, but it may impact performance,
# we disable them by default.
#if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
#endif ()
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
if (USE_SANITIZER EQUAL 1)
message("Sanitizer enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=signed-integer-overflow \
-fsanitize=undefined -fsanitize=address \
-fno-sanitize=bounds,bounds-strict,alignment \
-fno-sanitize-recover -Wall -Werror -Wformat")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=signed-integer-overflow \
-fsanitize=undefined -fsanitize=address \
-fno-sanitize=bounds,bounds-strict,alignment \
-fno-sanitize-recover -Wall -Werror -Wformat")
endif ()
## WAMR
include(${CMAKE_CURRENT_LIST_DIR}/../../../../../wamr_config.cmake)
## quickjs
set(QUICKJS_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../deps/quickjs)
include_directories(${QUICKJS_SRC_DIR})
set(QUICKJS_SOURCE
${QUICKJS_SRC_DIR}/cutils.c
${QUICKJS_SRC_DIR}/libregexp.c
${QUICKJS_SRC_DIR}/libunicode.c
${QUICKJS_SRC_DIR}/quickjs.c)
## libdyntype
set(LIBDYNTYPE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../libdyntype)
include (${LIBDYNTYPE_DIR}/libdyntype.cmake)
## stdlib
set(STDLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../stdlib)
include_directories(${STDLIB_DIR})
set(STDLIB_SOURCE
${STDLIB_DIR}/lib_console.c
${STDLIB_DIR}/lib_array.c
${STDLIB_DIR}/lib_timer.c
)
## struct-indirect
set(STRUCT_INDIRECT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../struct-indirect)
include_directories(${STRUCT_INDIRECT_DIR})
set(STRUCT_INDIRECT_SOURCE
${STRUCT_INDIRECT_DIR}/lib_struct_indirect.c
)
## utils
set(UTILS_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../utils)
include_directories(${UTILS_DIR})
set(TYPE_UTILS_SOURCE
${UTILS_DIR}/type_utils.c
)
set(OBJECT_UTILS_SOURCE
${UTILS_DIR}/object_utils.c
)
set(WAMR_UTILS_SOURCE
${UTILS_DIR}/wamr_utils.c
)
# Ignore warnings of QuickJS
set_source_files_properties(
${QUICKJS_SOURCE}
PROPERTIES
COMPILE_FLAGS "-w"
)
set(STRINGREF_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../stringref)
set(WAMR_STRINGREF_IMPL_SOURCE
${STRINGREF_DIR}/stringref_qjs.c
)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
find_library(
log-lib
log)
find_library(android-lib android)
add_library (iwasm SHARED
${WAMR_RUNTIME_LIB_SOURCE}
${UNCOMMON_SHARED_SOURCE}
${QUICKJS_SOURCE}
${LIBDYNTYPE_SRC}
${STDLIB_SOURCE}
${STRUCT_INDIRECT_SOURCE}
${TYPE_UTILS_SOURCE}
${OBJECT_UTILS_SOURCE}
${WAMR_STRINGREF_IMPL_SOURCE}
${WAMR_UTILS_SOURCE}
"${CMAKE_CURRENT_LIST_DIR}/wasm-jni.cpp")
target_link_libraries(
iwasm
${log-lib}
${android-lib})
if (CMAKE_BUILD_TYPE STREQUAL Release)
target_link_libraries (iwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -landroid -llog -s)
else()
target_link_libraries (iwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -landroid -llog)
endif()
set (distribution_DIR ${CMAKE_BINARY_DIR}/distribution)
set_target_properties (iwasm PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${distribution_DIR}/wasm/lib")
cd wamr-compiler
./build_llvm.sh
[notice] A new release of pip is available: 23.3.1 -> 23.3.2
[notice] To update, run: python3.11 -m pip install --upgrade pip
To use ssh for git clone, run: export USE_GIT_SSH=true
Use the gcc toolchain
CMake Deprecation Warning at CMakeLists.txt:8 (cmake_policy):
The OLD behavior for policy CMP0114 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_ASM_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
sys: macos 14.2 arm64
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.