GithubHelp home page GithubHelp logo

web-devkits / wasmnizer-ts Goto Github PK

View Code? Open in Web Editor NEW
286.0 286.0 23.0 2.91 MB

Toolchain for compiling TypeScript to WasmGC

License: Apache License 2.0

Dockerfile 0.06% TypeScript 76.58% CMake 0.56% Shell 0.28% C 14.40% C++ 2.23% Python 1.25% JavaScript 3.35% WebAssembly 0.13% HTML 1.16%

wasmnizer-ts's People

Contributors

beautiful-boyyy avatar brucehuke avatar dependabot[bot] avatar kylo5aby avatar levelca avatar pgc avatar rdower avatar shanks0224 avatar wenly1 avatar xujuntwt95329 avatar yviansu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasmnizer-ts's Issues

Exception: failed to call unlinked import function (libdyntype, dyntype_get_context) on Android platform.

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")

Run benchmark error

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

run module on node error

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.

wasm file generation error

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;
};

FAQ

I'm going to try to summarize and collate the questions and answers from #13 #14 #152 into a simple faq.md in the documentation folder. I think once we've captured the key points of the discussion we can close those bugs. We then have a destination for as other questions come up in future.

Error running mandelbrot.wasm using nodejs

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

build wamr-compiler error

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

Unable to build

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?

Update CONTRIBUTING.md

Add some more detail to the CONTRIBUTING.md to describe how people can contribute, eg. file issues, create PRs, etc.

DataView error when using windows

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)

how to use iwasm_gc?

I got iwasm by homebrew because i can't build runtime library on my computer. Can you give a more detailed example?
Screenshot 2023-12-25 at 19 44 06
sys: arm64 macos 14.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.