Compare commits

..

10 Commits

Author SHA1 Message Date
Wenyong Huang
3f5e2bd23b
release/1.3.x: Update version number to 1.3.3 and update release notes (#3371) 2024-04-29 11:30:53 +08:00
Wenyong Huang
190571feae
release/1.3.x: Cumulative fixes for release/1.3.x (#3342)
Apply patches which were fixed in branch main to branch `release/1.3.x`:
- aot debug: Fix a few NULL dereferences on errors (#3273)
- aot debug: Fix a NULL dereference (#3274)
- aot debug: Process lldb_function_to_function_dbi only for C (#3278)
- Revert "lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)" (#3281)
- Fix warnings/issues reported in Windows and by CodeQL/Coverity (#3275)
- thread mgr: Free aux stack only when it was allocated (#3282)
- interp: Restore context from prev_frame after tail calling a native f
unction (#3283)
- Sync simd opcode definitions spec (#3290)
- Add more checks in wasm loader (#3300)
- Fix posix_fadvise error handling (#3323)
- Fix readdir for posix (#3339)
- wasm loader: Fix checks for opcode ref.func and opcode else (#3340)
- Enhance wasm loader checks for opcode br_table (#3352)
- CI: Use macos-13 instead of macos-latest (#3366)
2024-04-28 15:38:09 +08:00
dongheng
2735192a8d
Fix ESP32-S3 compiling error (#3360)
1. when enable SPIRAM
2. when using esp-idf v5.3
2024-04-25 20:43:14 +08:00
dongheng
6f18fe9bac
Add WASI support for esp-idf platform in release/1.3.x (#3334)
Add WASI support for esp-idf platform in release/1.3.x:

1. add Kconfig and cmake scripts
2. add API "openat" when using littlefs
3. add clock/rwlock/file/socket OS adapter
2024-04-23 11:52:01 +08:00
dongheng
9e37892cd8
Update esp-idf platform support in release/v1.3.x (#3296)
1. Fix API "futimens" and "utimensat" compiling error in different esp-idf version
2. Update component registry description file
2024-04-09 17:08:12 +08:00
TianlongLiang
12affeaf41
Update release CI (#3294)
In the release CI and related scripts, when comparing and printing to the CI,
use the most recent **ancestor** tag(s) for the release branch rather than
the most recent one(s).
2024-04-09 16:49:08 +08:00
dongheng
e885a072d3
Fix ESP-IDF platform mmap data size error (#3288) 2024-04-07 20:23:28 +08:00
dongheng
4109fcee57
Add wamr to esp-idf components registry (#3264)
Espressif has [ESP-IDF component registry](https://components.espressif.com/) to
manage external components, and developers can use this directly and easily.
2024-04-07 18:37:19 +08:00
Wenyong Huang
9e07aa6f9f
Cumulative fixes for release/1.3.x (#3268)
Apply patches which were fixed branch main to branch `release/1.3.x`:
- zephyr: Use zephyr sys_cache instead of CMSIS (#3162)
- Fix llvm jit push funcref/externref result type issue (#3169)
- Fix inconsistent coding convention (#3171)
- VSCode IDE enhancement and readme update (#3172)
- zephyr: include math only with minimal libc (#3177)
- Fix wasm loader handling opcode br_table (#3176)
- Specify language in the wasi socket ext project (#3183)
- lldb_function_to_function_dbi: Fix a null dereference (#3189)
- Fix LLVM assertion failure and update CONTRIBUTING.md (#3197)
- lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)
- Fix compilation errors on MinGW (#3217)
- Fix compilation errors on esp-idf platform (#3224)
- Fix aot relocation symbols not found on windows 32-bit (#3231)
- Fix nightly run tsan ASLR issue (#3233)
- Go binding: Change C.long to C.int64_t when call wasm_runtime_set_wasi_args_ex (#3235)
- posix_file.c: Correct the dirfd argument that passes to fstatat (#3244)
- Fix compilation errors on zephyr platform (#3255)
- Fix dynamic offset not updated in op_br for block with ret type (#3269)
- Fix CI error when install packages for macos-14 (#3270)
2024-04-03 12:28:20 +08:00
Wenyong Huang
add9547324
Cumulative fixes for release/1.3.x (#3155)
Apply patches in branch main for branch `release/1.3.x`:
- Fix loader check_wasi_abi_compatibility (#3126)
- Zero the memory mapped from os_mmap in NuttX (#3132)
- Fix possible integer overflow in loader target block check (#3133)
- Fix locel.set in polymorphic stack (#3135)
- Fix threads opcodes' boundary check in classic-interp and fast-interp (#3136)
- aot_compile_op_call: Stop setting calling convention explicitly (#3140)
- aot compiler: Place precheck wrapper before the corresponding wrapped function (#3141)
- fast-interp: Fix copy_stack_top_i64 overlap issue (#3146)
- fast-interp: Fix frame_offset overflow issue (#3149)
- Fix null pointer access in fast-interp when configurable soft bound check is enabled (#3150)
2024-02-17 13:48:55 +08:00
1489 changed files with 53526 additions and 111995 deletions

View File

@ -1,12 +0,0 @@
# for now, it is used to speed up wasi-nn tests only.
# you shall adapt below rules to incoming requirements
**/build
**/tmp.*
.*
**/*.gguf
/core/deps/
!/core/deps/tensorflow-src
/samples
/tests

View File

@ -1,5 +0,0 @@
---
name: Blank Issue
about: Create a blank issue.
title: ''
---

View File

@ -1,28 +0,0 @@
---
name: Improvement
about: A feature request or code improvement.
title: ''
labels: ''
assignees: ''
---
Thanks for filing a feature request! Please fill out the TODOs below.
#### Feature
TODO: Brief description of the feature/improvement you'd like to see in WAMR
#### Benefit
TODO: What is the value of adding this in WAMR? What problems does it solve?
#### Implementation
TODO: Do you have an implementation plan, and/or ideas for data structures or
algorithms to use?
#### Alternatives
TODO: What are the alternative implementation approaches or alternative ways to
solve the problem that this feature would solve? How do these alternatives
compare to this proposal?

View File

@ -1,36 +0,0 @@
---
name: WAMR bug or defect report
about: Report a bug or defect in WAMR
title: ''
---
Thanks for filing a bug or defect report! Please fill out the TODOs below.
### Subject of the issue
Describe the bug or defect here.
### Test case
Upload the related wasm file, wast file or the source files if you can.
### Your environment
* Host OS
* WAMR version, platform, cpu architecture, running mode, etc.
### Steps to reproduce
Tell us how to reproduce this bug or defect.
### Expected behavior
Tell us what should happen
### Actual behavior
Tell us what happens instead
### Extra Info
Anything else you'd like to add?

View File

@ -1,47 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Always follow https://download.01.org/intel-sgx/latest/linux-latest/docs/
name: "Install Intel SGX SDK"
description: "Installs the Intel SGX SDK and necessary libraries for Ubuntu."
author: "Intel Corporation"
inputs:
os:
description: "Operating system to install on (ubuntu-22.04)"
required: true
runs:
using: "composite"
steps:
- name: Check Runner OS
if: ${{ inputs.os != 'ubuntu-22.04' }}
shell: bash
run: |
echo "::error title=⛔ error hint::Only support ubuntu-22.04 for now"
exit 1
- name: Create installation directory
shell: bash
run: sudo mkdir -p /opt/intel
- name: Download and install SGX SDK on ubuntu-22.04
if: ${{ inputs.os == 'ubuntu-22.04' }}
shell: bash
run: |
sudo wget -O sgx_linux_x64_sdk.bin https://download.01.org/intel-sgx/sgx-linux/2.25/distro/ubuntu22.04-server/sgx_linux_x64_sdk_2.25.100.3.bin
sudo chmod +x sgx_linux_x64_sdk.bin
echo 'yes' | sudo ./sgx_linux_x64_sdk.bin
working-directory: /opt/intel
- name: Add SGX repository and install libraries
shell: bash
run: |
echo "deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/intel-sgx.list
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
sudo apt update
sudo apt install -y libsgx-launch libsgx-urts
- name: Source SGX SDK environment
shell: bash
run: source /opt/intel/sgxsdk/environment

View File

@ -1,80 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Get URLs from:
# - https://github.com/WebAssembly/wasi-sdk/releases
# - https://github.com/WebAssembly/wabt/releases
# Install WASI-SDK and WABT at /opt
# /opt is the assumed location widely used in the project
name: Install WASI-SDK and WABT
description: A composite action to download and install wasi-sdk and wabt on Ubuntu, macOS.
inputs:
os:
description: "Operating system to install on (ubuntu, macos)"
required: true
runs:
using: "composite"
steps:
- name: Check Runner OS
if: ${{ !startsWith(inputs.os, 'ubuntu') && !startsWith(inputs.os, 'windows') && !startsWith(inputs.os, 'macos') }}
shell: bash
run: |
echo "::error title=⛔ error hint::Support Ubuntu, Windows, and macOS Only"
exit 1
- name: Set up wasi-sdk and wabt on Ubuntu
if: ${{ startsWith(inputs.os, 'ubuntu') }}
shell: bash
run: |
sudo wget -O wasi-sdk.tar.gz --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz
sudo tar -xf wasi-sdk.tar.gz
sudo ln -sf wasi-sdk-25.0-x86_64-linux/ wasi-sdk
sudo wget -O wabt.tar.gz --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/1.0.37/wabt-1.0.37-ubuntu-20.04.tar.gz
sudo tar -xf wabt.tar.gz
sudo ln -sf wabt-1.0.37 wabt
/opt/wasi-sdk/bin/clang --version
/opt/wabt/bin/wasm-interp --version
echo "::notice::wasi-sdk-25 and wabt-1.0.37 installed on ubuntu"
working-directory: /opt
- name: Set up wasi-sdk and wabt on macOS-13 (intel)
if: ${{ inputs.os == 'macos-13' }}
shell: bash
run: |
sudo wget -O wasi-sdk.tar.gz --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-macos.tar.gz
sudo tar -xf wasi-sdk.tar.gz
sudo ln -sf wasi-sdk-25.0-x86_64-macos wasi-sdk
sudo wget -O wabt.tar.gz --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/1.0.36/wabt-1.0.36-macos-12.tar.gz
sudo tar -xf wabt.tar.gz
sudo ln -sf wabt-1.0.36 wabt
/opt/wasi-sdk/bin/clang --version
/opt/wabt/bin/wasm-interp --version
echo "::notice::wasi-sdk-25 and wabt-1.0.36 installed on macos-13"
working-directory: /opt
- name: Set up wasi-sdk and wabt on macOS-14 (arm64)
if: ${{ inputs.os == 'macos-14' }}
shell: bash
run: |
sudo wget -O wasi-sdk.tar.gz --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-arm64-macos.tar.gz
sudo tar -xf wasi-sdk.tar.gz
sudo ln -sf wasi-sdk-25.0-arm64-macos wasi-sdk
sudo wget -O wabt.tar.gz --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/1.0.37/wabt-1.0.37-macos-14.tar.gz
sudo tar -xf wabt.tar.gz
sudo ln -sf wabt-1.0.37 wabt
/opt/wasi-sdk/bin/clang --version
/opt/wabt/bin/wasm-interp --version
echo "::notice::wasi-sdk-25 and wabt-1.0.37 installed on macos-14"
working-directory: /opt
#TODO: Add support for Windows
- name: Set up wasi-sdk and wabt on Windows
if: ${{ startsWith(inputs.os, 'windows') }}
shell: powershell
run: |
echo "::notice::Support for Windows is not implemented yet"
exit 1

View File

@ -1,35 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "docker"
directory: "/.devcontainer"
schedule:
interval: "weekly"
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/build-scripts"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/language-bindings/python/wasm-c-api"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/language-bindings/python/wamr-api"
schedule:
interval: "weekly"

View File

@ -1,312 +0,0 @@
#!/usr/bin/env bash
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
sudo apt update
sudo apt install -y build-essential cmake g++-multilib libgcc-12-dev lib32gcc-12-dev ccache ninja-build
WAMR_DIR=${PWD}
# TODO: use pre-built llvm binary to build wamrc to
# avoid static code analysing for llvm
: '
# build wamrc
cd ${WAMR_DIR}/wamr-compiler
./build_llvm.sh
rm -fr build && mkdir build && cd build
cmake ..
make -j
if [[ $? != 0 ]]; then
echo "Failed to build wamrc!"
exit 1;
fi
'
# build iwasm with default features enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -fr build && mkdir build && cd build
cmake ..
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with default features enabled!"
exit 1;
fi
# build iwasm with default features enabled on x86_32
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -fr build && mkdir build && cd build
cmake .. -DWAMR_BUILD_TARGET=X86_32
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with default features enabled on x86_32!"
exit 1;
fi
# build iwasm with classic interpreter enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_FAST_INTERP=0
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with classic interpreter enabled!"
exit 1;
fi
# build iwasm with extra features enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -fr build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug \
-DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \
-DWAMR_BUILD_MULTI_MODULE=1 -DWAMR_BUILD_SIMD=1 \
-DWAMR_BUILD_TAIL_CALL=1 -DWAMR_BUILD_REF_TYPES=1 \
-DWAMR_BUILD_CUSTOM_NAME_SECTION=1 -DWAMR_BUILD_MEMORY_PROFILING=1 \
-DWAMR_BUILD_PERF_PROFILING=1 -DWAMR_BUILD_DUMP_CALL_STACK=1 \
-DWAMR_BUILD_LOAD_CUSTOM_SECTION=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build wamrc iwasm with extra features enabled!"
exit 1;
fi
# build iwasm with global heap pool enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -fr build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug \
-DWAMR_BUILD_ALLOC_WITH_USER_DATA=1 \
-DWAMR_DISABLE_STACK_HW_BOUND_CHECK=1 \
-DWAMR_BUILD_GLOBAL_HEAP_POOL=1 \
-DWAMR_BUILD_GLOBAL_HEAP_SIZE=131072
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with global heap pool enabled!"
exit 1;
fi
# build iwasm with wasi-threads enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -fr build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_LIB_WASI_THREADS=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with wasi-threads enabled!"
exit 1;
fi
# build iwasm with GC enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_GC=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with GC enabled!"
exit 1;
fi
# build iwasm with exception handling enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_EXCE_HANDLING=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with exception handling enabled!"
exit 1;
fi
# build iwasm with memory64 enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_MEMORY64=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with memory64 enabled!"
exit 1;
fi
# build iwasm with multi-memory enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_MULTI_MEMORY=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with multi-memory enabled!"
exit 1;
fi
# build iwasm with hardware boundary check disabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_DISABLE_HW_BOUND_CHECK=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with hardware boundary check disabled!"
exit 1;
fi
# build iwasm with quick AOT entry disabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_QUICK_AOT_ENTRY=0
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with quick AOT entry disabled!"
exit 1;
fi
# build iwasm with wakeup of blocking operations disabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_DISABLE_WAKEUP_BLOCKING_OP=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with wakeup of blocking operations disabled!"
exit 1;
fi
# build iwasm with module instance context disabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_MODULE_INST_CONTEXT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=0 -DWAMR_BUILD_LIBC_WASI=0
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with module instance context disabled!"
exit 1;
fi
# build iwasm with libc-uvwasi enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -fr build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_LIBC_UVWASI=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with libc-uvwasi enabled!"
exit 1;
fi
# build iwasm with fast jit lazy mode enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_FAST_JIT_DUMP=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with fast jit lazy mode enabled!"
exit 1;
fi
# build iwasm with fast jit eager mode enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_FAST_JIT_DUMP=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with fast jit eager mode enabled!"
exit 1;
fi
# TODO: use pre-built llvm binary to build llvm-jit and multi-tier-jit
: '
# build iwasm with llvm jit lazy mode enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_JIT=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build llvm jit lazy mode enabled!"
exit 1;
fi
# build iwasm with llvm jit eager mode enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0
make -j
if [[ $? != 0 ]]; then
echo "Failed to build llvm jit eager mode enabled!"
exit 1;
fi
# build iwasm with multi-tier jit enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \
-DWAMR_BUILD_FAST_JIT_DUMP=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with multi-tier jit enabled!"
exit 1;
fi
'
# build iwasm with wasm mini-loader enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_MINI_LOADER=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build with wasm mini-loader enabled!"
exit 1;
fi
# build iwasm with source debugging enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_DEBUG_INTERP=1 -DWAMR_BUILD_DEBUG_AOT=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with source debugging enabled!"
exit 1;
fi
# build iwasm with AOT static PGO enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_STATIC_PGO=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with AOT static PGO enabled!"
exit 1;
fi
# build iwasm with configurable bounds checks enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_CONFIGURABLE_BOUNDS_CHECKS=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with configurable bounds checks enabled!"
exit 1;
fi
# build iwasm with linux perf support enabled
cd ${WAMR_DIR}/product-mini/platforms/linux/
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_LINUX_PERF=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with linux perf support enabled!"
exit 1;
fi
# build iwasm with shared heap enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_SHARED_HEAP=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm with shared heap enabled!"
exit 1;
fi
# build iwasm with dynamic aot debug enabled
cd ${WAMR_DIR}/product-mini/platforms/linux
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_DYNAMIC_AOT_DEBUG=1
make -j
if [[ $? != 0 ]]; then
echo "Failed to build iwasm dynamic aot debug enabled!"
exit 1;
fi

View File

@ -1,124 +0,0 @@
#!/usr/bin/env python3
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
import json
import sys
import os
import requests
def fetch_dismissed_alerts(repo_name, github_token):
headers = {
"Authorization": f"token {github_token}",
"Accept": "application/vnd.github.v3+json",
}
url = (
f"https://api.github.com/repos/{repo_name}/code-scanning/alerts?state=dismissed"
)
response = requests.get(url, headers=headers)
return response.json() # This assumes a successful API call
def parse_location(location):
path = location.get("physicalLocation", {}).get("artifactLocation", {}).get("uri")
start_line = location.get("physicalLocation", {}).get("region", {}).get("startLine")
column_range = (
location.get("physicalLocation", {}).get("region", {}).get("startColumn"),
location.get("physicalLocation", {}).get("region", {}).get("endColumn"),
)
return (path, start_line, column_range)
def is_dismissed(rule_id, path, start_line, column_range, dismissed_alerts):
for alert in dismissed_alerts:
alert_rule_id = alert.get("rule", {}).get("id")
alert_path = alert.get("location", {}).get("path")
alert_start_line = alert.get("location", {}).get("start_line")
alert_column_range = (
alert.get("location", {}).get("start_column"),
alert.get("location", {}).get("end_column"),
)
if (
rule_id == alert_rule_id
and path == alert_path
and start_line == alert_start_line
and column_range == alert_column_range
):
return True
return False
# Return whether SARIF file contains error-level results
def codeql_sarif_contain_error(filename, dismissed_alerts):
has_error = False
with open(filename, "r") as f:
s = json.load(f)
for run in s.get("runs", []):
rules_metadata = run["tool"]["driver"]["rules"]
if not rules_metadata:
rules_metadata = run["tool"]["extensions"][0]["rules"]
for res in run.get("results", []):
if "ruleIndex" in res:
rule_index = res["ruleIndex"]
elif "rule" in res and "index" in res["rule"]:
rule_index = res["rule"]["index"]
else:
continue
# check whether it's dismissed before
rule_id = res["ruleId"]
path, start_line, column_range = parse_location(res["locations"][0])
# the source code is from dependencies
if "_deps" in path:
continue
if is_dismissed(rule_id, path, start_line, column_range, dismissed_alerts):
print(
f"====== Finding a dismissed entry: {rule_id} at {path}:{start_line} is dismissed.======"
)
print(res)
continue
try:
rule_level = rules_metadata[rule_index]["defaultConfiguration"]["level"]
except IndexError as e:
print(e, rule_index, len(rules_metadata))
else:
if rule_level == "error":
# very likely to be an actual error
if rules_metadata[rule_index]["properties"].get("precision") in [
"high",
"very-high",
]:
# the security severity is above medium(Common Vulnerability Scoring System (CVSS) >= 4.0)
if "security-severity" in rules_metadata[rule_index][
"properties"
] and (
float(
rules_metadata[rule_index]["properties"][
"security-severity"
]
)
> 4.0
):
print("====== Finding a likely error. ======")
print(res)
has_error = True
return has_error
if __name__ == "__main__":
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY")
dismissed_alerts = fetch_dismissed_alerts(GITHUB_REPOSITORY, GITHUB_TOKEN)
if codeql_sarif_contain_error(sys.argv[1], dismissed_alerts):
sys.exit(1)

View File

@ -1,10 +0,0 @@
#! /bin/sh
set -e
URL=https://github.com/espressif/qemu/releases/download/esp-develop-9.0.0-20240606/qemu-xtensa-softmmu-esp_develop_9.0.0_20240606-x86_64-linux-gnu.tar.xz
DIR=$(mktemp -d)
cd ${DIR}
curl -fLsS "${URL}" | xzcat | tar -x
ln -s ${DIR}/qemu/bin/qemu-system-xtensa /usr/local/bin/qemu-system-xtensa

View File

@ -15,14 +15,9 @@ on:
type: string
required: true
permissions:
contents: read
jobs:
build-and-push-images:
runs-on: ubuntu-22.04
permissions:
contents: write # for uploading release artifacts
steps:
- name: Checkout repository

View File

@ -11,7 +11,7 @@ on:
required: false
default: x86_64
cwd:
description: working directory
description: workfing directory
type: string
required: true
llvm_cache_key:
@ -31,78 +31,9 @@ on:
type: string
required: false
env:
DEFAULT_BUILD_OPTIONS:
"-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \
-DWAMR_BUILD_CUSTOM_NAME_SECTION=0 \
-DWAMR_BUILD_DEBUG_INTERP=0 \
-DWAMR_BUILD_DEBUG_AOT=0 \
-DWAMR_BUILD_DUMP_CALL_STACK=0 \
-DWAMR_BUILD_LIBC_UVWASI=0 \
-DWAMR_BUILD_LIBC_EMCC=0 \
-DWAMR_BUILD_LIB_RATS=0 \
-DWAMR_BUILD_LOAD_CUSTOM_SECTION=0 \
-DWAMR_BUILD_MEMORY_PROFILING=0 \
-DWAMR_BUILD_MINI_LOADER=0 \
-DWAMR_BUILD_MULTI_MODULE=0 \
-DWAMR_BUILD_PERF_PROFILING=0 \
-DWAMR_BUILD_SPEC_TEST=0 \
-DWAMR_BUILD_BULK_MEMORY=1 \
-DWAMR_BUILD_LIB_PTHREAD=1 \
-DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \
-DWAMR_BUILD_LIB_WASI_THREADS=1 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=1 \
-DWAMR_BUILD_REF_TYPES=1 \
-DWAMR_BUILD_SIMD=1 \
-DWAMR_BUILD_SHARED_MEMORY=1 \
-DWAMR_BUILD_TAIL_CALL=1 \
-DWAMR_BUILD_THREAD_MGR=1"
GC_EH_BUILD_OPTIONS:
"-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_CUSTOM_NAME_SECTION=0 \
-DWAMR_BUILD_DEBUG_INTERP=0 \
-DWAMR_BUILD_DEBUG_AOT=0 \
-DWAMR_BUILD_DUMP_CALL_STACK=0 \
-DWAMR_BUILD_LIBC_UVWASI=0 \
-DWAMR_BUILD_LIBC_EMCC=0 \
-DWAMR_BUILD_LIB_RATS=0 \
-DWAMR_BUILD_LOAD_CUSTOM_SECTION=0 \
-DWAMR_BUILD_MEMORY_PROFILING=0 \
-DWAMR_BUILD_MINI_LOADER=0 \
-DWAMR_BUILD_MULTI_MODULE=0 \
-DWAMR_BUILD_PERF_PROFILING=0 \
-DWAMR_BUILD_SPEC_TEST=0 \
-DWAMR_BUILD_BULK_MEMORY=1 \
-DWAMR_BUILD_LIB_PTHREAD=1 \
-DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \
-DWAMR_BUILD_LIB_WASI_THREADS=1 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=1 \
-DWAMR_BUILD_REF_TYPES=1 \
-DWAMR_BUILD_SIMD=1 \
-DWAMR_BUILD_SHARED_MEMORY=1 \
-DWAMR_BUILD_TAIL_CALL=1 \
-DWAMR_BUILD_THREAD_MGR=1 \
-DWAMR_BUILD_EXCE_HANDLING=1 \
-DWAMR_BUILD_GC=1"
permissions:
contents: read
jobs:
build:
runs-on: ${{ inputs.runner }}
strategy:
matrix:
include:
- build_options: $DEFAULT_BUILD_OPTIONS
suffix: ''
- build_options: $GC_EH_BUILD_OPTIONS
suffix: '-gc-eh'
permissions:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
@ -120,25 +51,40 @@ jobs:
fail-on-cache-miss: true
- name: generate iwasm binary release
shell: bash
run: |
cmake -S . -B build ${{ matrix.build_options }}
cmake -S . -B build \
-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \
-DWAMR_BUILD_CUSTOM_NAME_SECTION=0 \
-DWAMR_BUILD_DEBUG_INTERP=0 \
-DWAMR_BUILD_DEBUG_AOT=0 \
-DWAMR_BUILD_DUMP_CALL_STACK=0 \
-DWAMR_BUILD_LIBC_UVWASI=0 \
-DWAMR_BUILD_LIBC_EMCC=0 \
-DWAMR_BUILD_LIB_RATS=0 \
-DWAMR_BUILD_LOAD_CUSTOM_SECTION=0 \
-DWAMR_BUILD_MEMORY_PROFILING=0 \
-DWAMR_BUILD_MINI_LOADER=0 \
-DWAMR_BUILD_MULTI_MODULE=0 \
-DWAMR_BUILD_PERF_PROFILING=0 \
-DWAMR_BUILD_SPEC_TEST=0 \
-DWAMR_BUILD_BULK_MEMORY=1 \
-DWAMR_BUILD_LIB_PTHREAD=1 \
-DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1 \
-DWAMR_BUILD_LIB_WASI_THREADS=1 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=1 \
-DWAMR_BUILD_REF_TYPES=1 \
-DWAMR_BUILD_SIMD=1 \
-DWAMR_BUILD_SHARED_MEMORY=1 \
-DWAMR_BUILD_TAIL_CALL=1 \
-DWAMR_BUILD_THREAD_MGR=1
cmake --build build --config Release --parallel 4
working-directory: ${{ inputs.cwd }}
- name: Compress the binary on Windows
if: inputs.runner == 'windows-latest'
- name: compress the binary
run: |
tar -czf iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm.exe
Compress-Archive -Path iwasm.exe -DestinationPath iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
mv iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
working-directory: ${{ inputs.cwd }}/build/Release
- name: compress the binary on non-Windows
if: inputs.runner != 'windows-latest'
run: |
tar czf iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm
zip iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm
tar czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm
zip iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm
working-directory: ${{ inputs.cwd }}/build
- name: upload release tar.gz
@ -147,8 +93,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: ${{ inputs.cwd }}/build/iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_path: ${{ inputs.cwd }}/build/iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: iwasm-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_content_type: application/x-gzip
- name: upload release zip
@ -157,6 +103,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: ${{ inputs.cwd }}/build/iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: iwasm${{ matrix.suffix }}-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_path: ${{ inputs.cwd }}/build/iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: iwasm-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_content_type: application/zip

View File

@ -14,22 +14,11 @@ on:
container_image:
required: false
type: string
extra_build_llvm_options:
required: false
type: string
default: ""
cache_key_suffix:
required: false
type: string
default: ""
outputs:
cache_key:
description: "A cached key of LLVM libraries"
value: ${{ jobs.build_llvm_libraries.outputs.key}}
permissions:
contents: read
jobs:
build_llvm_libraries:
runs-on: ${{ inputs.os }}
@ -39,9 +28,6 @@ jobs:
image: ${{ inputs.container_image }}
outputs:
key: ${{ steps.create_lib_cache_key.outputs.key}}
permissions:
contents: read
actions: write # for uploading cached artifact
steps:
- name: checkout
@ -49,7 +35,6 @@ jobs:
- name: install dependencies for non macos-14
if: inputs.os != 'macos-14'
shell: bash
run: /usr/bin/env python3 -m pip install -r requirements.txt
working-directory: build-scripts
@ -58,13 +43,9 @@ jobs:
run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
working-directory: build-scripts
- name: Retrieve the last commit ID
- name: retrive the last commit ID
id: get_last_commit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT
run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py --llvm-ver)" >> $GITHUB_OUTPUT
working-directory: build-scripts
# Bump the prefix number to evict all previous caches and
@ -73,9 +54,7 @@ jobs:
# suspect.
- name: form the cache key of libraries
id: create_lib_cache_key
shell: bash
run: |
echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
run: echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}" >> $GITHUB_OUTPUT
- name: Cache LLVM libraries
id: retrieve_llvm_libs
@ -89,6 +68,14 @@ jobs:
./core/deps/llvm/build/share
key: ${{ steps.create_lib_cache_key.outputs.key}}
- uses: actions/cache@v4
with:
path: ~/.ccache
key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
restore-keys: |
0-ccache-${{ inputs.os }}
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'ubuntu-20.04'
- uses: actions/cache@v4
with:
path: ~/.cache/ccache
@ -112,20 +99,7 @@ jobs:
- run: brew install ccache ninja
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
- uses: actions/cache@v4
with:
path: ~/.cache/ccache
key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
restore-keys: |
0-ccache-${{ inputs.os }}
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
# Install tools on Windows
- run: choco install -y ccache ninja
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
- name: Build LLVM libraries
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
shell: bash
run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
run: /usr/bin/env python3 ./build_llvm.py --arch ${{ inputs.arch }}
working-directory: build-scripts

View File

@ -28,13 +28,8 @@ on:
required: false
default: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz"
permissions:
contents: read
jobs:
try_reuse:
permissions:
contents: write # for uploading release artifacts
uses: ./.github/workflows/reuse_latest_release_binaries.yml
with:
binary_name_stem: "wamr-lldb-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}"
@ -51,9 +46,6 @@ jobs:
PYTHON_VERSION: '3.10'
PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz
PYTHON_MACOS_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-apple-darwin-install_only.tar.gz
permissions:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
@ -172,12 +164,6 @@ jobs:
python3 ci/validate_lldb.py --port 1239 --lldb core/deps/wamr-lldb/bin/lldb --wamr wamr-debug/iwasm --verbose
working-directory: .
# Define CMAKE_OSX_SYSROOT to avoid the error:
# no such file or directory: 'llvm-project/build/tools/lldb/tools/debugserver/source/mach_excServer.c'
# no such file or directory: 'llvm-project/build/tools/lldb/tools/debugserver/source/mach_excUser.c'
#
# This workaround should be removed when the issue is fixed in llvm-project:
# - https://github.com/llvm/llvm-project/pull/138020/
- name: build lldb macos
if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos')
run: |
@ -185,7 +171,6 @@ jobs:
mkdir -p wamr-lldb
cmake -S ./llvm -B build \
-G Ninja \
-DCMAKE_OSX_SYSROOT=$(xcrun --show-sdk-path) \
-DCMAKE_INSTALL_PREFIX=../wamr-lldb \
-DCMAKE_BUILD_TYPE:STRING="Release" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \

View File

@ -30,31 +30,13 @@ on:
description: download WASI_SDK from this URL
type: string
required: true
wamr_app_framework_url:
description: download WAMR app framework to get wamr_sdk
type: string
required: true
permissions:
contents: read
jobs:
build:
runs-on: ${{ inputs.runner }}
permissions:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- name: download wamr-app-framework
run: |
git clone ${{ inputs.wamr_app_framework_url }}
cd wamr-app-framework
git submodule init
git submodule update
working-directory: wamr-sdk
- name: download and install wasi-sdk
run: |
cd /opt
@ -64,24 +46,16 @@ jobs:
sudo rm ${basename}
sudo mv wasi-sdk-* wasi-sdk
- name: download dependencies
run: |
cd ./wamr-app-framework/deps
./download.sh
working-directory: wamr-sdk
- name: generate wamr-sdk release
run: |
cd ./wamr-app-framework/wamr-sdk
./build_sdk.sh -n wamr-sdk -x $(pwd)/${{ inputs.config_file }}
working-directory: wamr-sdk
- name: compress the binary
run: |
cd wamr-app-framework/wamr-sdk/out
tar czf wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamr-sdk
zip -r wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamr-sdk
working-directory: wamr-sdk
working-directory: wamr-sdk/out
- name: upload release tar.gz
uses: actions/upload-release-asset@v1
@ -89,7 +63,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: wamr-sdk/wamr-app-framework/wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_path: wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz
asset_name: wamr-sdk-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.tar.gz
asset_content_type: application/x-gzip
@ -99,11 +73,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ inputs.upload_url }}
asset_path: wamr-sdk/wamr-app-framework/wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_path: wamr-sdk/out/wamr-sdk-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
asset_name: wamr-sdk-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}.zip
asset_content_type: application/zip
- name: delete wamr-app-framework
run: |
rm -rf wamr-app-framework
working-directory: wamr-sdk

View File

@ -14,22 +14,16 @@ on:
type: string
required: true
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 16.x
- name: set vscode extension to correct version
run: |
@ -39,7 +33,7 @@ jobs:
- name: generate wamr ide vscode extension
run: |
npm install -g @vscode/vsce
npm install -g vsce
rm -rf node_modules
npm install
vsce package

View File

@ -31,15 +31,9 @@ on:
type: string
required: false
permissions:
contents: read
jobs:
build:
runs-on: ${{ inputs.runner }}
permissions:
contents: write # for uploading release artifacts
steps:
- uses: actions/checkout@v4
@ -62,16 +56,8 @@ jobs:
cmake --build build --config Release --parallel 4
working-directory: wamr-compiler
- name: Compress the binary on Windows
if: inputs.runner == 'windows-latest' && inputs.release
run: |
tar -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
Compress-Archive -Path wamrc.exe -DestinationPath wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
mv wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
working-directory: wamr-compiler/build/Release
- name: compress the binary on non-Windows
if: inputs.runner != 'windows-latest' && inputs.release
- name: compress the binary
if: inputs.release
run: |
tar czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc

View File

@ -1,29 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
name: confirm version.h stay in sync
on:
workflow_call:
permissions:
contents: read
jobs:
confirm_version:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: cmake execute to generate version.h
run: cmake -B build_version -S .
- name: confirm version.h
run: |
if [ -z "$(git status --porcelain | grep version.h)" ]; then
echo "version.h is in sync"
else
echo "version.h is not in sync"
exit 1
fi

View File

@ -1,121 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
name: "CodeQL"
on:
#pull_request:
# types:
# - opened
# branches: '*'
#push:
# branches: [ "main" ]
# midnight UTC
schedule:
- cron: '0 0 * * *'
# allow to be triggered manually
workflow_dispatch:
permissions:
contents: read
jobs:
analyze:
if: github.repository == 'bytecodealliance/wasm-micro-runtime'
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-13') || 'ubuntu-22.04' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
permissions:
contents: read
actions: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3.28.18
with:
languages: ${{ matrix.language }}
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
queries: security-and-quality
# Command-line programs to run using the OS shell.
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
- run: |
./.github/scripts/codeql_buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3.28.18
with:
category: "/language:${{matrix.language}}"
upload: false
id: step1
# Filter out rules with low severity or high false positve rate
# Also filter out warnings in third-party code
- name: Filter out unwanted errors and warnings
uses: advanced-security/filter-sarif@v1
with:
patterns: |
-**:cpp/path-injection
-**:cpp/world-writable-file-creation
-**:cpp/poorly-documented-function
-**:cpp/potentially-dangerous-function
-**:cpp/use-of-goto
-**:cpp/integer-multiplication-cast-to-long
-**:cpp/comparison-with-wider-type
-**:cpp/leap-year/*
-**:cpp/ambiguously-signed-bit-field
-**:cpp/suspicious-pointer-scaling
-**:cpp/suspicious-pointer-scaling-void
-**:cpp/unsigned-comparison-zero
-**/cmake*/Modules/**
input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
- name: Upload CodeQL results to code scanning
uses: github/codeql-action/upload-sarif@v3.28.18
with:
sarif_file: ${{ steps.step1.outputs.sarif-output }}
category: "/language:${{matrix.language}}"
- name: Upload CodeQL results as an artifact
if: success() || failure()
uses: actions/upload-artifact@v4.6.2
with:
name: codeql-results
path: ${{ steps.step1.outputs.sarif-output }}
retention-days: 10
- name: Fail if an error is found
run: |
./.github/scripts/codeql_fail_on_error.py \
${{ steps.step1.outputs.sarif-output }}/cpp.sarif
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}

View File

@ -14,12 +14,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
compliance_job:
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v4

View File

@ -19,8 +19,8 @@ on:
- "samples/**"
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "tests/unit/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
- "test-tools/wamr-ide/**"
# will be triggered on push events
push:
@ -37,8 +37,8 @@ on:
- "samples/**"
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "tests/unit/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
- "test-tools/wamr-ide/**"
# allow to be triggered manually
workflow_dispatch:
@ -65,25 +65,10 @@ env:
THREADS_TEST_OPTIONS: "-s spec -b -p -P"
X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
WASI_TEST_OPTIONS: "-s wasi_certification -w"
WAMR_COMPILER_TEST_OPTIONS: "-s wamr_compiler -S -b -P"
GC_TEST_OPTIONS: "-s spec -G -b -P"
MEMORY64_TEST_OPTIONS: "-s spec -W -b -P"
MULTI_MEMORY_TEST_OPTIONS: "-s spec -E -b -P"
permissions:
contents: read
WAMR_COMPILER_TEST_OPTIONS: "-s wamr_compiler -b -P"
jobs:
check_version_h:
permissions:
contents: read
actions: write
uses: ./.github/workflows/check_version_h.yml
build_llvm_libraries_on_ubuntu_2204:
permissions:
contents: read
actions: write
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
@ -158,18 +143,15 @@ jobs:
"-DWAMR_BUILD_PERF_PROFILING=1",
"-DWAMR_BUILD_REF_TYPES=1",
"-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_LIB_SIMDE=1",
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
"-DWAMR_BUILD_MEMORY64=1",
"-DWAMR_BUILD_MULTI_MEMORY=1",
"-DWAMR_BUILD_SHARED=1",
"-DWAMR_ENABLE_SHARED_MEMORY_MMAP=1",
]
os: [ubuntu-22.04]
platform: [android, linux]
exclude:
# incompatible feature and platform
# incompatible mode and feature
# uncompatiable feature and platform
# uncompatiable mode and feature
# MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
@ -179,9 +161,11 @@ jobs:
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
# SIMD only on JIT/AOT/fast interpreter mode
# SIMD only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
# DEBUG_INTERP only on CLASSIC INTERP mode
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
@ -220,48 +204,11 @@ jobs:
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
# Memory64 only on CLASSIC INTERP and AOT mode, and only on 64-bit platform
- make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
platform: android
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
# Multi memory only on CLASSIC INTERP mode, and only on 64-bit platform
- make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
platform: android
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
# Fast-JIT and Multi-Tier-JIT mode don't support android
# Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32)
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
platform: android
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
platform: android
# LLVM JIT pre-built binary wasn't compiled by Android NDK
# and isn't available for android
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
platform: android
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
platform: android
# android does not support WAMR_BUILD_SHARED in its CMakeLists.txt.
- make_options_feature: "-DWAMR_BUILD_SHARED=1"
platform: android
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
@ -287,84 +234,17 @@ jobs:
if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: Build iwasm for linux
if: matrix.platform == 'linux'
- name: Build iwasm
run: |
mkdir build && cd build
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
cmake --build . --config Release --parallel 4
working-directory: product-mini/platforms/${{ matrix.platform }}
- name: Build iwasm for android
if: matrix.platform == 'android'
run: |
mkdir build && cd build
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
-DWAMR_BUILD_TARGET=X86_64
cmake --build . --config Release --parallel 4
working-directory: product-mini/platforms/${{ matrix.platform }}
build_unit_tests:
needs:
[
build_llvm_libraries_on_ubuntu_2204,
build_wamrc
]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
build_target: [
"X86_64",
"X86_32",
]
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Get LLVM libraries
id: retrieve_llvm_libs
uses: actions/cache@v4
with:
path: |
./core/deps/llvm/build/bin
./core/deps/llvm/build/include
./core/deps/llvm/build/lib
./core/deps/llvm/build/libexec
./core/deps/llvm/build/share
key: ${{ matrix.llvm_cache_key }}
- name: Quit if cache miss
if: (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: Build wamrc
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
- name: Install dependencies for X86_32
if: matrix.build_target == 'X86_32'
run: |
sudo apt-get update
sudo apt-get install -y g++-multilib
- name: Build and run unit tests
run: |
mkdir build && cd build
cmake .. -DWAMR_BUILD_TARGET=${{ matrix.build_target }}
mkdir build-unittests && cd build-unittests
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
cmake --build . --config Release --parallel 4
ctest
working-directory: tests/unit
@ -391,6 +271,14 @@ jobs:
$MULTI_TIER_JIT_BUILD_OPTIONS,
]
os: [ubuntu-22.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
@ -416,10 +304,12 @@ jobs:
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: download and install wabt
run: |
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: Build wamrc
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
@ -437,11 +327,6 @@ jobs:
ctest --test-dir build --output-on-failure
working-directory: samples/wasm-c-api
- name: Build Sample [printversion]
run: |
./test.sh
working-directory: samples/printversion
build_samples_others:
needs:
[
@ -453,14 +338,34 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: download and install wasi-sdk
run: |
cd /opt
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
- name: download and install wabt
run: |
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: Get LLVM libraries
id: retrieve_llvm_libs
uses: actions/cache@v4
@ -472,19 +377,12 @@ jobs:
./core/deps/llvm/build/libexec
./core/deps/llvm/build/share
key: ${{ matrix.llvm_cache_key }}
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: Build wamrc
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
- name: Build Sample [basic]
run: |
cd samples/basic
@ -532,6 +430,13 @@ jobs:
cmake --build . --config Debug --parallel 4
./hello
- name: Build Sample [simple]
run: |
./build.sh -p host-interp
python3 ./sample_test_run.py $(pwd)/out
exit $?
working-directory: ./samples/simple
- name: Build Sample [wasi-threads]
run: |
cd samples/wasi-threads
@ -552,32 +457,6 @@ jobs:
./build.sh
./run.sh
- name: Build Sample [debug-tools]
run: |
cd samples/debug-tools
mkdir build && cd build
cmake ..
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/trap.wasm | grep "#" > call_stack.txt
./iwasm wasm-apps/trap.aot | grep "#" > call_stack_aot.txt
bash -x ../symbolicate.sh
- name: Build Sample [native-stack-overflow]
run: |
cd samples/native-stack-overflow
./build.sh
./run.sh test1
./run.sh test2
- name: Build Sample [shared-heap]
run: |
cd samples/shared-heap
mkdir build && cd build
cmake ..
cmake --build . --config Debug --parallel 4
./shared_heap_test
./shared_heap_test --aot
test:
needs:
[
@ -606,9 +485,10 @@ jobs:
$SIMD_TEST_OPTIONS,
$THREADS_TEST_OPTIONS,
$WASI_TEST_OPTIONS,
$GC_TEST_OPTIONS,
$MEMORY64_TEST_OPTIONS,
$MULTI_MEMORY_TEST_OPTIONS,
]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
]
include:
- os: ubuntu-22.04
@ -619,10 +499,12 @@ jobs:
running_mode: aot
test_option: $WAMR_COMPILER_TEST_OPTIONS
exclude:
# incompatible modes and features
# classic-interp doesn't support simd
# uncompatiable modes and features
# classic-interp and fast-interp don't support simd
- running_mode: "classic-interp"
test_option: $SIMD_TEST_OPTIONS
- running_mode: "fast-interp"
test_option: $SIMD_TEST_OPTIONS
# llvm jit doesn't support multi module
- running_mode: "jit"
test_option: $MULTI_MODULES_TEST_OPTIONS
@ -636,51 +518,17 @@ jobs:
test_option: $MULTI_MODULES_TEST_OPTIONS
- running_mode: "multi-tier-jit"
test_option: $SIMD_TEST_OPTIONS
# fast-jit and multi-tier-jit don't support GC
- running_mode: "fast-jit"
test_option: $GC_TEST_OPTIONS
- running_mode: "multi-tier-jit"
test_option: $GC_TEST_OPTIONS
# fast-interp, fast-jit, llvm-jit, multi-tier-jit don't support Memory64
- running_mode: "fast-interp"
test_option: $MEMORY64_TEST_OPTIONS
- running_mode: "fast-jit"
test_option: $MEMORY64_TEST_OPTIONS
- running_mode: "jit"
test_option: $MEMORY64_TEST_OPTIONS
- running_mode: "multi-tier-jit"
test_option: $MEMORY64_TEST_OPTIONS
# aot, fast-interp, fast-jit, llvm-jit, multi-tier-jit don't support Multi Memory
- running_mode: "aot"
test_option: $MULTI_MEMORY_TEST_OPTIONS
- running_mode: "fast-interp"
test_option: $MULTI_MEMORY_TEST_OPTIONS
- running_mode: "fast-jit"
test_option: $MULTI_MEMORY_TEST_OPTIONS
- running_mode: "jit"
test_option: $MULTI_MEMORY_TEST_OPTIONS
- running_mode: "multi-tier-jit"
test_option: $MULTI_MEMORY_TEST_OPTIONS
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set-up OCaml
uses: ocaml/setup-ocaml@v3
if: matrix.test_option == '$GC_TEST_OPTIONS'
with:
ocaml-compiler: 4.13
- name: Set-up Ocamlbuild
if: matrix.test_option == '$GC_TEST_OPTIONS'
run: opam install ocamlbuild dune menhir
- name: download and install wasi-sdk
if: matrix.test_option == '$WASI_TEST_OPTIONS'
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
run: |
cd /opt
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
# It is a temporary solution until new wasi-sdk that includes bug fixes is released
- name: build wasi-libc from source
@ -691,16 +539,16 @@ jobs:
make -j AR=/opt/wasi-sdk/bin/llvm-ar NM=/opt/wasi-sdk/bin/llvm-nm CC=/opt/wasi-sdk/bin/clang THREAD_MODEL=posix
echo "SYSROOT_PATH=$PWD/sysroot" >> $GITHUB_ENV
- name: set env variable(if llvm are used)
if: matrix.running_mode == 'aot' || matrix.running_mode == 'jit' || matrix.running_mode == 'multi-tier-jit'
run: echo "USE_LLVM=true" >> $GITHUB_ENV
- name: set env variable(if x86_32 test needed)
if: >
((matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS'
|| matrix.test_option == '$WASI_TEST_OPTIONS' || matrix.test_option == '$GC_TEST_OPTIONS')
&& matrix.test_option != '$MEMORY64_TEST_OPTIONS'
&& matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit')
(matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS'
|| matrix.test_option == '$WASI_TEST_OPTIONS')
&& matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit'
run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV
#only download llvm libraries in jit and aot mode
@ -737,18 +585,9 @@ jobs:
- name: run tests
timeout-minutes: 30
if: matrix.test_option != '$GC_TEST_OPTIONS'
run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
working-directory: ./tests/wamr-test-suites
- name: run gc tests
timeout-minutes: 20
if: matrix.test_option == '$GC_TEST_OPTIONS'
run: |
eval $(opam env)
./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
working-directory: ./tests/wamr-test-suites
#only install x32 support libraries when to run x86_32 cases
- name: install x32 support libraries
if: env.TEST_ON_X86_32 == 'true'
@ -762,18 +601,10 @@ jobs:
- name: run tests x86_32
timeout-minutes: 30
if: env.TEST_ON_X86_32 == 'true' && matrix.test_option != '$GC_TEST_OPTIONS'
if: env.TEST_ON_X86_32 == 'true'
run: ./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
working-directory: ./tests/wamr-test-suites
- name: run gc tests x86_32
timeout-minutes: 20
if: env.TEST_ON_X86_32 == 'true' && matrix.test_option == '$GC_TEST_OPTIONS'
run: |
eval $(opam env)
./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
working-directory: ./tests/wamr-test-suites
test-wamr-ide:
needs:
[
@ -790,7 +621,7 @@ jobs:
- name: install dependencies
run: |
rustup target add wasm32-wasip1
rustup target add wasm32-wasi
sudo apt update && sudo apt-get install -y lld ninja-build
npm install
working-directory: test-tools/wamr-ide/VSCode-Extension
@ -805,7 +636,7 @@ jobs:
run: |
mkdir build
cd build
cmake .. -DWAMR_BUILD_DEBUG_INTERP=1 -DWAMR_BUILD_REF_TYPES=1
cmake .. -DWAMR_BUILD_DEBUG_INTERP=1
make
working-directory: product-mini/platforms/linux

View File

@ -20,6 +20,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# will be triggered on push events
push:
branches:
@ -36,6 +37,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# allow to be triggered manually
workflow_dispatch:
@ -46,44 +48,27 @@ concurrency:
cancel-in-progress: true
env:
# For BUILD
AOT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_INTERP_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
LLVM_LAZY_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
permissions:
contents: read
AOT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
jobs:
build_llvm_libraries_on_intel_macos:
permissions:
contents: read
actions: write
build_llvm_libraries:
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "macos-13"
arch: "X86"
build_llvm_libraries_on_arm_macos:
permissions:
contents: read
actions: write
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "macos-14"
arch: "AArch64 ARM"
build_wamrc:
needs: [build_llvm_libraries_on_intel_macos]
needs: [build_llvm_libraries]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-13
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
@ -112,7 +97,7 @@ jobs:
working-directory: wamr-compiler
build_iwasm:
needs: [build_llvm_libraries_on_intel_macos]
needs: [build_llvm_libraries]
runs-on: ${{ matrix.os }}
strategy:
matrix:
@ -146,8 +131,8 @@ jobs:
os: [macos-13]
platform: [darwin]
exclude:
# incompatible feature and platform
# incompatible mode and feature
# uncompatiable feature and platform
# uncompatiable mode and feature
# MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
@ -186,7 +171,7 @@ jobs:
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
include:
- os: macos-13
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
@ -217,95 +202,77 @@ jobs:
working-directory: product-mini/platforms/${{ matrix.platform }}
build_samples_wasm_c_api:
needs:
[
build_iwasm,
build_llvm_libraries_on_intel_macos,
build_wamrc,
]
needs: [build_iwasm]
runs-on: ${{ matrix.os }}
strategy:
matrix:
make_options: [
$AOT_BUILD_OPTIONS,
# Running modes supported
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
$FAST_JIT_BUILD_OPTIONS,
$LLVM_LAZY_JIT_BUILD_OPTIONS,
$LLVM_EAGER_JIT_BUILD_OPTIONS,
$MULTI_TIER_JIT_BUILD_OPTIONS,
# Running modes unsupported
#$LLVM_LAZY_JIT_BUILD_OPTIONS,
#$LLVM_EAGER_JIT_BUILD_OPTIONS,
#$AOT_BUILD_OPTIONS,
]
os: [macos-13]
include:
- os: macos-13
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-macos-12.tar.gz",
]
steps:
- name: checkout
uses: actions/checkout@v4
- name: Get LLVM libraries
id: retrieve_llvm_libs
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
uses: actions/cache@v4
with:
path: |
./core/deps/llvm/build/bin
./core/deps/llvm/build/include
./core/deps/llvm/build/lib
./core/deps/llvm/build/libexec
./core/deps/llvm/build/share
key: ${{ matrix.llvm_cache_key }}
- name: Quit if cache miss
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: Build wamrc
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
- name: download and install wabt
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: Build Sample [wasm-c-api]
run: |
VERBOSE=1
cmake -S . -B build ${{ matrix.make_options }}
cmake --build build --config Debug --parallel 4
ctest --test-dir build --output-on-failure
cmake --build build --config Release --parallel 4
ctest --test-dir build
working-directory: samples/wasm-c-api
- name: Build Sample [printversion]
run: |
./test.sh
working-directory: samples/printversion
build_samples_others:
needs: [build_iwasm, build_wamrc, build_llvm_libraries_on_intel_macos, build_llvm_libraries_on_arm_macos]
needs: [build_iwasm, build_wamrc]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13, macos-14]
include:
- os: macos-13
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
- os: macos-14
llvm_cache_key: ${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}
os: [macos-13]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-macos-12.tar.gz",
]
steps:
- name: checkout
uses: actions/checkout@v4
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: download and install wasi-sdk
run: |
cd /opt
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
- name: download and install wabt
run: |
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: Build Sample [basic]
run: |
@ -353,37 +320,14 @@ jobs:
cmake --build . --config Debug --parallel 4
./hello
- name: Get LLVM libraries
id: retrieve_llvm_libs
uses: actions/cache@v4
with:
path: |
./core/deps/llvm/build/bin
./core/deps/llvm/build/include
./core/deps/llvm/build/lib
./core/deps/llvm/build/libexec
./core/deps/llvm/build/share
key: ${{ matrix.llvm_cache_key }}
- name: Build wamrc
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
working-directory: wamr-compiler
# cmake --build . --config Debug --parallel 4
- name: Build Sample [wasi-threads]
run: |
cd samples/wasi-threads
mkdir build && cd build
cmake ..
cmake --build . --config Debug --verbose
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/no_pthread.wasm
../../../wamr-compiler/build/wamrc --size-level=0 --enable-multi-thread -o wasm-apps/no_pthread.aot wasm-apps/no_pthread.wasm
./iwasm wasm-apps/no_pthread.aot
- name: Build Sample [shared-module]
run: |
cd samples/shared-module
@ -395,29 +339,3 @@ jobs:
cd samples/terminate
./build.sh
./run.sh
- name: Build Sample [debug-tools]
run: |
cd samples/debug-tools
mkdir build && cd build
cmake ..
cmake --build . --config Debug --parallel 4
./iwasm wasm-apps/trap.wasm | grep "#" > call_stack.txt
./iwasm wasm-apps/trap.aot | grep "#" > call_stack_aot.txt
bash -x ../symbolicate.sh
- name: Build Sample [native-stack-overflow]
run: |
cd samples/native-stack-overflow
./build.sh
./run.sh test1
./run.sh test2
- name: Build Sample [shared-heap]
run: |
cd samples/shared-heap
mkdir build && cd build
cmake ..
cmake --build . --config Debug --parallel 4
./shared_heap_test
./shared_heap_test --aot

View File

@ -19,6 +19,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# will be triggered on push events
push:
branches:
@ -34,6 +35,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# allow to be triggered manually
workflow_dispatch:
@ -46,9 +48,6 @@ concurrency:
env:
WASI_SDK_PATH: "/opt/wasi-sdk"
permissions:
contents: read
jobs:
build_iwasm_on_nuttx:
runs-on: ubuntu-latest
@ -64,6 +63,8 @@ jobs:
"boards/arm/rp2040/raspberrypi-pico/configs/nsh",
# cortex-m7
"boards/arm/stm32h7/nucleo-h743zi/configs/nsh",
# riscv32imc
"boards/risc-v/espressif/esp32c3-generic/configs/nsh",
# riscv32gc
"boards/risc-v/qemu-rv/rv-virt/configs/nsh",
# riscv64gc
@ -71,31 +72,32 @@ jobs:
# arm64
"boards/arm64/qemu/qemu-armv8a/configs/nsh",
]
wamr_config_option:
- "CONFIG_INTERPRETERS_WAMR_AOT"
- "CONFIG_INTERPRETERS_WAMR_FAST"
- "CONFIG_INTERPRETERS_WAMR_CLASSIC"
- "CONFIG_INTERPRETERS_WAMR_AOT CONFIG_INTERPRETERS_WAMR_FAST"
- "CONFIG_INTERPRETERS_WAMR_AOT CONFIG_INTERPRETERS_WAMR_FAST CONFIG_INTERPRETERS_WAMR_LIBC_WASI"
- "CONFIG_INTERPRETERS_WAMR_AOT CONFIG_INTERPRETERS_WAMR_FAST CONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN"
- "CONFIG_INTERPRETERS_WAMR_AOT CONFIG_INTERPRETERS_WAMR_CLASSIC"
- "CONFIG_INTERPRETERS_WAMR_AOT CONFIG_INTERPRETERS_WAMR_CLASSIC CONFIG_INTERPRETERS_WAMR_LIBC_WASI"
- "CONFIG_INTERPRETERS_WAMR_AOT CONFIG_INTERPRETERS_WAMR_CLASSIC CONFIG_INTERPRETERS_WAMR_LIBC_WASI"
wamr_config_option: [
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_WASI=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_WASI=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_AOT=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_FAST=y\\n",
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_CLASSIC=y\\n",
]
steps:
- name: Checkout NuttX
uses: actions/checkout@v4
with:
repository: apache/nuttx
ref: releases/12.9
repository: apache/incubator-nuttx
ref: releases/12.4
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v4
with:
repository: apache/nuttx-apps
ref: releases/12.9
repository: apache/incubator-nuttx-apps
ref: releases/12.4
path: apps
- name: Checkout WAMR
@ -104,43 +106,13 @@ jobs:
repository: ${{ github.repository }}
path: apps/interpreters/wamr/wamr
- name: Configure WAMR
working-directory: nuttx
- name: Enable WAMR for NuttX
run: |
tools/configure.sh ${{ matrix.nuttx_board_config }}
kconfig-tweak --enable CONFIG_PSEUDOFS_SOFTLINKS
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR
kconfig-tweak --enable CONFIG_INTERPRETERS_IWASM_TASK
kconfig-tweak --set-val CONFIG_INTERPRETERS_WAMR_PRIORITY 100
kconfig-tweak --set-val CONFIG_INTERPRETERS_WAMR_STACKSIZE 8192
for x in ${{ matrix.wamr_config_option }}; do
kconfig-tweak --enable $x
done
find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\n${{ matrix.wamr_config_option }}'
find nuttx/boards/sim -name defconfig | xargs sed -i '$a\CONFIG_LIBM=y\n'
- name: Build
working-directory: nuttx
run: make -j$(nproc) EXTRAFLAGS=-Werror
- name: Checkout Bloaty
uses: actions/checkout@v4
with:
repository: google/bloaty
submodules: recursive
path: bloaty
ref: 34f4a66559ad4938c1e629e9b5f54630b2b4d7b0
- name: Build Bloaty
run: |
cmake -Bbuild -GNinja bloaty
cmake --build build
- name: Size Report
run: |
echo "Build target: ${{ matrix.nuttx_board_config }}"
echo "WAMR build config: ${{ matrix.wamr_config_option }}"
echo "WAMR size:"
build/bloaty -d compileunits --source-filter wamr nuttx/nuttx
echo "libc-builtin size (if enabled):"
build/bloaty -d compileunits --source-filter libc-builtin nuttx/nuttx
echo "libc-wasi size (if enabled):"
build/bloaty -d compileunits --source-filter libc-wasi nuttx/nuttx
cd nuttx
tools/configure.sh ${{ matrix.nuttx_board_config }}
make -j$(nproc) EXTRAFLAGS=-Werror

View File

@ -20,6 +20,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# will be triggered on push events
push:
branches:
@ -36,6 +37,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# allow to be triggered manually
workflow_dispatch:
@ -46,29 +48,18 @@ concurrency:
cancel-in-progress: true
env:
# ref types enabled in wamrc by default, so we need to enable it for iwasm in AOT mode
AOT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0 -DWAMR_BUILD_REF_TYPES=1"
AOT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0 -DWAMR_BUILD_SIMD=0"
FAST_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
# For Spec Test
DEFAULT_TEST_OPTIONS: "-s spec -x -p -b"
SIMD_TEST_OPTIONS: "-s spec -x -p -b -S"
XIP_TEST_OPTIONS: "-s spec -x -p -b -X"
permissions:
contents: read
jobs:
build_llvm_libraries:
permissions:
contents: read
actions: write
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: ubuntu-22.04
os: "ubuntu-20.04"
arch: "X86"
build_iwasm:
@ -101,27 +92,35 @@ jobs:
"-DWAMR_BUILD_PERF_PROFILING=1",
"-DWAMR_BUILD_REF_TYPES=1",
# doesn't support
"-DWAMR_BUILD_SIMD=0",
# "-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
"-DWAMR_BUILD_SGX_IPFS=1",
]
os: [ubuntu-22.04]
os: [ubuntu-20.04]
platform: [linux-sgx]
exclude:
# incompatible mode and feature
# uncompatiable mode and feature
# MINI_LOADER only on INTERP mode
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
steps:
- name: install SGX SDK and necessary libraries
run: |
mkdir -p /opt/intel
cd /opt/intel
wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin
chmod +x sgx_linux_x64_sdk_2.15.100.3.bin
echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin
echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
sudo apt update
sudo apt install -y libsgx-launch libsgx-urts
source /opt/intel/sgxsdk/environment
- name: checkout
uses: actions/checkout@v4
- name: install SGX SDK and necessary libraries
uses: ./.github/actions/install-linux-sgx
with:
os: ${{ matrix.os }}
- name: Build iwasm
run: |
mkdir build && cd build
@ -146,29 +145,69 @@ jobs:
#$LLVM_LAZY_JIT_BUILD_OPTIONS,
#$LLVM_EAGER_JIT_BUILD_OPTIONS,
]
os: [ubuntu-22.04]
os: [ubuntu-20.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
iwasm_make_options_feature: [
# Features to be tested: IPFS
"-DWAMR_BUILD_SGX_IPFS=1",
]
platform: [linux-sgx]
include:
- os: ubuntu-22.04
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: download and install wasi-sdk
run: |
cd /opt
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-19.0 wasi-sdk
- name: download and install wabt
run: |
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: build wasi-libc (needed for wasi-threads)
run: |
mkdir wasi-libc
cd wasi-libc
git init
# "Fix a_store operation in atomic.h" commit on main branch
git fetch https://github.com/WebAssembly/wasi-libc \
1dfe5c302d1c5ab621f7abf04620fae92700fd22
git checkout FETCH_HEAD
make \
AR=/opt/wasi-sdk/bin/llvm-ar \
NM=/opt/wasi-sdk/bin/llvm-nm \
CC=/opt/wasi-sdk/bin/clang \
THREAD_MODEL=posix
working-directory: core/deps
- name: install SGX SDK and necessary libraries
uses: ./.github/actions/install-linux-sgx
with:
os: ${{ matrix.os }}
run: |
mkdir -p /opt/intel
cd /opt/intel
wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin
chmod +x sgx_linux_x64_sdk_2.15.100.3.bin
echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin
echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
sudo apt update
sudo apt install -y libsgx-launch libsgx-urts
- name: Build iwasm for testing samples
run: |
@ -196,61 +235,58 @@ jobs:
- name: Build wamrc only for testing samples in aot mode
if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS'
run: |
cmake -S . -B build
cmake --build build --config Release --parallel 4
cp build/wamrc ../product-mini/platforms/${{ matrix.platform }}/enclave-sample
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
cp wamrc `pwd`/../../product-mini/platforms/${{ matrix.platform }}/enclave-sample
working-directory: wamr-compiler
- name: Build Sample [file]
run: |
cmake -S . -B build
cmake --build build --config Debug --parallel 4
cp build/wasm-app/file.wasm ../../product-mini/platforms/${{ matrix.platform }}/enclave-sample
working-directory: samples/file
cd samples/file
mkdir build && cd build
cmake ..
cmake --build . --config Debug --parallel 4
cp wasm-app/file.wasm `pwd`/../../../product-mini/platforms/${{ matrix.platform }}/enclave-sample
- name: Test Sample [file] in non-aot mode
if: matrix.iwasm_make_options_run_mode != '$AOT_BUILD_OPTIONS'
run: |
source /opt/intel/sgxsdk/environment
./iwasm --dir=. ./file.wasm
./iwasm --dir=. file.wasm
working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample
- name: Test Sample [file] in aot mode
if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS'
run: |
source /opt/intel/sgxsdk/environment
./wamrc -sgx -o ./file.aot ./file.wasm
./iwasm --dir=. ./file.aot
./wamrc -sgx -o file.aot file.wasm
./iwasm --dir=. file.aot
working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample
spec_test_default:
needs: [build_iwasm, build_llvm_libraries]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-20.04
strategy:
matrix:
#(workaround) disable "fast-interp" because of SIMDE
running_mode: ["classic-interp", "aot", "fast-jit"]
test_option:
[$DEFAULT_TEST_OPTIONS, $SIMD_TEST_OPTIONS, $XIP_TEST_OPTIONS]
os: [ubuntu-22.04]
running_mode: ["classic-interp", "fast-interp", "aot", "fast-jit"]
test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P", "-x -p -s spec -X -b -P"]
llvm_cache_key: ["${{ needs.build_llvm_libraries.outputs.cache_key }}"]
exclude:
# classic-interp, fast-interp and fast-jit don't support simd
- running_mode: "classic-interp"
test_option: $SIMD_TEST_OPTIONS
test_option: "-x -p -s spec -S -b -P"
- running_mode: "fast-interp"
test_option: $SIMD_TEST_OPTIONS
test_option: "-x -p -s spec -S -b -P"
- running_mode: "fast-jit"
test_option: $SIMD_TEST_OPTIONS
test_option: "-x -p -s spec -S -b -P"
# classic-interp, fast-interp and fast jit don't support XIP
- running_mode: "classic-interp"
test_option: $XIP_TEST_OPTIONS
test_option: "-x -p -s spec -X -b -P"
- running_mode: "fast-interp"
test_option: $XIP_TEST_OPTIONS
test_option: "-x -p -s spec -X -b -P"
- running_mode: "fast-jit"
test_option: $XIP_TEST_OPTIONS
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
test_option: "-x -p -s spec -X -b -P"
steps:
- name: checkout
@ -274,44 +310,19 @@ jobs:
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: install SGX SDK and necessary libraries
uses: ./.github/actions/install-linux-sgx
with:
os: ${{ matrix.os }}
#workaround about a https://github.com/actions/runner-images/issues/6680#issuecomment-2640923706
- name: Increase swapfile
run: |
sudo swapoff -a
sudo fallocate -l 15G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
mkdir -p /opt/intel
cd /opt/intel
wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin
chmod +x sgx_linux_x64_sdk_2.15.100.3.bin
echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin
echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list
wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add -
sudo apt update
sudo apt install -y libsgx-launch libsgx-urts
- name: run spec tests
run: |
set +e
source /opt/intel/sgxsdk/environment
attempts=0
max_attempts=3
while [ $attempts -lt $max_attempts ]; do
./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
exitcode="$?"
if [ $exitcode -eq 0 ]; then
echo "Spec test passed"
exit 0
elif [ $exitcode -ne 143 ]; then
echo "Spec test failed with error code $exitcode"
exit 1
fi
echo "$exitcode is a known GitHub-hosted runner issue"
echo "::notice::Re-running the spec test due to error code 143"
attempts=$((attempts + 1))
done
echo "::notice::Report an error with code 143 in SGX CI after $max_attempts attempts"
exit 143
working-directory: ./tests/wamr-test-suites

View File

@ -19,6 +19,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# will be triggered on push events
push:
branches:
@ -34,6 +35,7 @@ on:
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
# allow to be triggered manually
workflow_dispatch:
@ -53,9 +55,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build:
runs-on: windows-latest

View File

@ -15,9 +15,6 @@ on:
description: "the new tag just created"
value: ${{ jobs.create_tag.outputs.new_tag}}
permissions:
contents: read
jobs:
create_tag:
runs-on: ubuntu-latest
@ -25,8 +22,6 @@ jobs:
minor_version: ${{ steps.preparation.outputs.minor_version }}
new_ver: ${{ steps.preparation.outputs.new_ver }}
new_tag: ${{ steps.preparation.outputs.new_tag }}
permissions:
contents: write # create and push tags
steps:
- uses: actions/checkout@v4

View File

@ -28,9 +28,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
run-hadolint-on-dockerfiles:
runs-on: ubuntu-22.04

View File

@ -36,35 +36,36 @@ env:
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
# For Spec Test
# FIXME: use binary release(adding -b) instead of building from source after upgrading to 22.04
DEFAULT_TEST_OPTIONS: "-s spec -P"
MULTI_MODULES_TEST_OPTIONS: "-s spec -M -P"
SIMD_TEST_OPTIONS: "-s spec -S -P"
THREADS_TEST_OPTIONS: "-s spec -p -P"
DEFAULT_TEST_OPTIONS: "-s spec -b -P"
MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M -P"
SIMD_TEST_OPTIONS: "-s spec -b -S -P"
THREADS_TEST_OPTIONS: "-s spec -b -p -P"
X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
WASI_TEST_OPTIONS: "-s wasi_certification -w"
permissions:
contents: read
jobs:
build_llvm_libraries_on_ubuntu:
permissions:
contents: read
actions: write
build_llvm_libraries_on_ubuntu_2004:
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-20.04"
arch: "X86"
build_llvm_libraries_on_ubuntu_2204:
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
arch: "X86"
build_wamrc:
needs: build_llvm_libraries_on_ubuntu
needs:
[
build_llvm_libraries_on_ubuntu_2004,
]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
@ -95,7 +96,10 @@ jobs:
working-directory: wamr-compiler
build_iwasm:
needs: build_llvm_libraries_on_ubuntu
needs:
[
build_llvm_libraries_on_ubuntu_2004,
]
runs-on: ${{ matrix.os }}
strategy:
matrix:
@ -126,15 +130,12 @@ jobs:
"-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
"-DWAMR_BUILD_MEMORY64=1",
"-DWAMR_BUILD_MULTI_MEMORY=1",
"-DWAMR_BUILD_SHARED=1",
]
os: [ubuntu-22.04]
os: [ubuntu-20.04]
platform: [android, linux]
exclude:
# incompatible feature and platform
# incompatible mode and feature
# uncompatiable feature and platform
# uncompatiable mode and feature
# MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
@ -187,48 +188,14 @@ jobs:
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
# Memory64 only on CLASSIC INTERP and AOT mode, and only on 64-bit platform
- make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
platform: android
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
# Multi memory only on CLASSIC INTERP mode, and only on 64-bit platform
- make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
platform: android
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
# Fast-JIT and Multi-Tier-JIT mode don't support android
# Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32)
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
platform: android
- make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS
platform: android
# LLVM JIT pre-built binary wasn't compiled by Android NDK
# and isn't available for android
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
platform: android
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
platform: android
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
steps:
- name: checkout
@ -252,23 +219,13 @@ jobs:
if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: Build iwasm for linux
if: matrix.platform == 'linux'
- name: Build iwasm
run: |
mkdir build && cd build
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }}
cmake --build . --config Release --parallel 4
working-directory: product-mini/platforms/${{ matrix.platform }}
- name: Build iwasm for android
if: matrix.platform == 'android'
run: |
mkdir build && cd build
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} \
-DWAMR_BUILD_TARGET=X86_64
cmake --build . --config Release --parallel 4
working-directory: product-mini/platforms/${{ matrix.platform }}
build_iwasm_linux_gcc4_8:
runs-on: ubuntu-latest
container:
@ -298,12 +255,10 @@ jobs:
"-DWAMR_BUILD_SIMD=1",
"-DWAMR_BUILD_TAIL_CALL=1",
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
"-DWAMR_BUILD_MEMORY64=1",
"-DWAMR_BUILD_MULTI_MEMORY=1",
]
exclude:
# incompatible feature and platform
# incompatible mode and feature
# uncompatiable feature and platform
# uncompatiable mode and feature
# MULTI_MODULE only on INTERP mode and AOT mode
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
@ -328,24 +283,17 @@ jobs:
# MINI_LOADER only on INTERP mode
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
# Memory64 only on CLASSIC INTERP mode
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MEMORY64=1"
# Memory64 only on CLASSIC INTERP mode
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MEMORY=1"
steps:
- name: Install dependencies
run: |
apt update && apt install -y make g++-4.8 gcc-4.8 wget git
- name: checkout
run: |
git clone https://github.com/${{ github.repository }} wamr
uses: actions/checkout@v3
- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: apt update && apt install -y make g++-4.8 gcc-4.8 wget git
on_retry_command: sudo rm -r /var/lib/apt/lists/*
- name: Install cmake
run: |
@ -358,10 +306,15 @@ jobs:
mkdir build && cd build
cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8
cmake --build . --config Release --parallel 4
working-directory: wamr/product-mini/platforms/linux
working-directory: product-mini/platforms/linux
build_samples_wasm_c_api:
needs: [build_iwasm, build_llvm_libraries_on_ubuntu, build_wamrc]
needs:
[
build_iwasm,
build_llvm_libraries_on_ubuntu_2004,
build_wamrc,
]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
@ -377,10 +330,18 @@ jobs:
$LLVM_EAGER_JIT_BUILD_OPTIONS,
$MULTI_TIER_JIT_BUILD_OPTIONS,
]
os: [ubuntu-22.04]
os: [ubuntu-20.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
exclude:
- make_options: $MULTI_TIER_JIT_BUILD_OPTIONS
sanitizer: asan
@ -405,11 +366,12 @@ jobs:
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true')
run: echo "::error::can not get prebuilt llvm libraries" && exit 1
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: download and install wabt
run: |
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: Build wamrc
if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS'))
run: |
@ -429,22 +391,43 @@ jobs:
working-directory: samples/wasm-c-api
build_samples_others:
needs: [build_iwasm, build_llvm_libraries_on_ubuntu, build_wamrc]
needs:
[
build_iwasm,
build_llvm_libraries_on_ubuntu_2004,
build_wamrc,
]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
os: [ubuntu-20.04]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
]
wabt_release:
[
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz",
]
include:
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: download and install wasi-sdk
run: |
cd /opt
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
- name: download and install wabt
run: |
cd /opt
sudo wget ${{ matrix.wabt_release }}
sudo tar -xzf wabt-1.0.31-*.tar.gz
sudo mv wabt-1.0.31 wabt
- name: Get LLVM libraries
id: retrieve_llvm_libs
@ -506,6 +489,12 @@ jobs:
cmake ..
cmake --build . --config Release --parallel 4
./hello
- name: Build Sample [simple]
run: |
./build.sh -p host-interp
python3 ./sample_test_run.py $(pwd)/out
exit $?
working-directory: ./samples/simple
- name: Build Sample [wasi-threads]
run: |
@ -526,54 +515,19 @@ jobs:
cd samples/terminate
./build.sh
./run.sh
- name: Build Sample [native-stack-overflow]
run: |
cd samples/native-stack-overflow
./build.sh
./run.sh test1
./run.sh test2
- name: Build Sample [native-lib]
run: |
mkdir build && cd build
cmake ..
cmake --build . --config Release --parallel 4
./iwasm --native-lib=./libtest_add.so --native-lib=./libtest_sqrt.so --native-lib=./libtest_hello.so --native-lib=./libtest_hello2.so wasm-app/test.wasm
working-directory: ./samples/native-lib
# FIXME: un-comment me after fix cmake minimum issue
# https://github.com/bytecodealliance/wamr-app-framework/pull/11
# - name: checkout wamr-app-framework
# run: git clone https://github.com/bytecodealliance/wamr-app-framework.git
# - name: download wamr-app-framework dependencies
# run: LVGL=0 LV_DRIVERS=0 ./download.sh
# working-directory: ./wamr-app-framework/deps
# - name: Build Sample [simple]
# run: |
# ./build.sh -p host-interp
# python3 ./sample_test_run.py $(pwd)/out
# exit $?
# working-directory: ./wamr-app-framework/samples/simple
- name: Build Sample [shared-heap]
run: |
cd samples/shared-heap
mkdir build && cd build
cmake ..
cmake --build . --config Debug --parallel 4
./shared_heap_test
./shared_heap_test --aot
test:
needs: [build_iwasm, build_llvm_libraries_on_ubuntu, build_wamrc]
needs:
[
build_iwasm,
build_llvm_libraries_on_ubuntu_2004,
build_llvm_libraries_on_ubuntu_2204,
build_wamrc,
]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-20.04, ubuntu-22.04]
sanitizer: ["", "ubsan", "asan", "tsan"]
running_mode:
[
@ -592,12 +546,22 @@ jobs:
$THREADS_TEST_OPTIONS,
$WASI_TEST_OPTIONS,
]
wasi_sdk_release:
[
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz",
]
include:
- os: ubuntu-20.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
ubuntu_version: "20.04"
- os: ubuntu-22.04
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }}
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }}
ubuntu_version: "22.04"
exclude:
# uncompatiable modes and features
- os: ubuntu-20.04
sanitizer: tsan
# asan works only for aot now
- running_mode: "classic-interp"
sanitizer: asan
@ -639,10 +603,13 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- name: install-wasi-sdk-wabt
uses: ./.github/actions/install-wasi-sdk-wabt
with:
os: ${{ matrix.os }}
- name: download and install wasi-sdk
if: matrix.test_option == '$WASI_TEST_OPTIONS'
run: |
cd /opt
sudo wget ${{ matrix.wasi_sdk_release }}
sudo tar -xzf wasi-sdk-*.tar.gz
sudo mv wasi-sdk-20.0 wasi-sdk
# It is a temporary solution until new wasi-sdk that includes bug fixes is released
- name: build wasi-libc from source
@ -692,9 +659,6 @@ jobs:
if: matrix.running_mode == 'aot' && matrix.test_option == '$WASI_TEST_OPTIONS'
run: sudo apt-get update && sudo apt install -y jq
- name: install for wabt compilation
run: sudo apt update && sudo apt install -y ninja-build
- name: Build WASI thread tests
if: matrix.test_option == '$WASI_TEST_OPTIONS'
run: bash build.sh --sysroot "$SYSROOT_PATH"

View File

@ -18,18 +18,11 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
create_tag:
permissions:
contents: write # create and push tags
uses: ./.github/workflows/create_tag.yml
create_release:
permissions:
contents: write # create release
needs: [create_tag]
runs-on: ubuntu-latest
outputs:
@ -58,10 +51,14 @@ jobs:
#
# LLVM_LIBRARIES
build_llvm_libraries_on_ubuntu_2004:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-20.04"
arch: "AArch64 ARM Mips RISCV X86"
build_llvm_libraries_on_ubuntu_2204:
permissions:
contents: read
actions: write
needs: [create_tag, create_release]
uses: ./.github/workflows/build_llvm_libraries.yml
with:
@ -69,30 +66,25 @@ jobs:
arch: "AArch64 ARM Mips RISCV X86"
build_llvm_libraries_on_macos:
permissions:
contents: read
actions: write
needs: [create_tag, create_release]
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "macos-13"
arch: "AArch64 ARM Mips RISCV X86"
build_llvm_libraries_on_windows:
permissions:
contents: read
actions: write
needs: [create_tag, create_release]
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "windows-latest"
arch: "AArch64 ARM Mips RISCV X86"
#
# WAMRC
release_wamrc_on_ubuntu_2004:
needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2004]
uses: ./.github/workflows/build_wamrc.yml
with:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
release: true
runner: ubuntu-20.04
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
release_wamrc_on_ubuntu_2204:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2204 ]
uses: ./.github/workflows/build_wamrc.yml
with:
@ -103,8 +95,6 @@ jobs:
ver_num: ${{ needs.create_tag.outputs.new_ver }}
release_wamrc_on_ubuntu_macos:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release, build_llvm_libraries_on_macos]
uses: ./.github/workflows/build_wamrc.yml
with:
@ -114,23 +104,19 @@ jobs:
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver }}
release_wamrc_on_windows:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release, build_llvm_libraries_on_windows]
uses: ./.github/workflows/build_wamrc.yml
#
# IWASM
release_iwasm_on_ubuntu_2004:
needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2004]
uses: ./.github/workflows/build_iwasm_release.yml
with:
llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}
release: true
runner: windows-latest
cwd: product-mini/platforms/linux
llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }}
runner: ubuntu-20.04
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
#
# IWASM
release_iwasm_on_ubuntu_2204:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release, build_llvm_libraries_on_ubuntu_2204]
uses: ./.github/workflows/build_iwasm_release.yml
with:
@ -141,8 +127,6 @@ jobs:
ver_num: ${{ needs.create_tag.outputs.new_ver}}
release_iwasm_on_macos:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release, build_llvm_libraries_on_macos]
uses: ./.github/workflows/build_iwasm_release.yml
with:
@ -152,23 +136,19 @@ jobs:
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
release_iwasm_on_windows:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release, build_llvm_libraries_on_windows]
uses: ./.github/workflows/build_iwasm_release.yml
with:
cwd: product-mini/platforms/windows
llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}
runner: windows-latest
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
#
# WAMR_SDK
release_wamr_sdk_on_ubuntu_2004:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_sdk.yml
with:
config_file: wamr_config_ubuntu_release.cmake
runner: ubuntu-20.04
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
wasi_sdk_url: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz
release_wamr_sdk_on_ubuntu_2204:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_sdk.yml
with:
@ -177,11 +157,8 @@ jobs:
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
wasi_sdk_url: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz
wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git
release_wamr_sdk_on_macos:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_sdk.yml
with:
@ -190,38 +167,37 @@ jobs:
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
wasi_sdk_url: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-macos.tar.gz
wamr_app_framework_url: https://github.com/bytecodealliance/wamr-app-framework.git
# Let's disable it for now and reopen it when the actual requirement arises.
# Please ensure all dependencies have been updated before reopening.
#
# # vscode extension cross-platform
# release_wamr_ide_vscode_ext:
# permissions:
# contents: write # upload release artifact
# needs: [create_tag, create_release]
# uses: ./.github/workflows/build_wamr_vscode_ext.yml
# secrets: inherit
# with:
# upload_url: ${{ needs.create_release.outputs.upload_url }}
# ver_num: ${{ needs.create_tag.outputs.new_ver }}
# vscode extension cross-platform
release_wamr_ide_vscode_ext:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_vscode_ext.yml
secrets: inherit
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver }}
# #
# # vscode extension docker images package
# release_wamr_ide_docker_images_package:
# permissions:
# contents: write # upload release artifact
# needs: [create_tag, create_release]
# uses: ./.github/workflows/build_docker_images.yml
# with:
# upload_url: ${{ needs.create_release.outputs.upload_url }}
# ver_num: ${{ needs.create_tag.outputs.new_ver }}
#
# vscode extension docker images package
release_wamr_ide_docker_images_package:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_docker_images.yml
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver }}
#
# WAMR_LLDB
release_wamr_lldb_on_ubuntu_2004:
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_lldb.yml
with:
runner: ubuntu-20.04
upload_url: ${{ needs.create_release.outputs.upload_url }}
ver_num: ${{ needs.create_tag.outputs.new_ver}}
release_wamr_lldb_on_ubuntu_2204:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_lldb.yml
with:
@ -230,8 +206,6 @@ jobs:
ver_num: ${{ needs.create_tag.outputs.new_ver}}
release_wamr_lldb_on_macos_universal:
permissions:
contents: write # upload release artifact
needs: [create_tag, create_release]
uses: ./.github/workflows/build_wamr_lldb.yml
with:

View File

@ -22,17 +22,11 @@ on:
result:
value: ${{ jobs.build.outputs.result }}
permissions:
contents: read
jobs:
reuse:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.try_reuse.outputs.result }}
permissions:
contents: write # for creating realease and uploading release artifacts
steps:
- uses: actions/checkout@v4
# Full git history is needed to get a proper list of commits and tags

View File

@ -10,56 +10,31 @@ on:
- synchronize
paths:
- ".github/workflows/spec_test_on_nuttx.yml"
- "core/**"
- "!core/deps/**"
- "product-mini/**"
- "!samples/workload/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
# Note on INTERPRETERS_WAMR_STACK_GUARD_SIZE:
# https://github.com/apache/nuttx-apps/pull/2241 is not included in
# releases/12.4 branch as of writing this.
env:
LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex"
WASI_SDK_PATH: "/opt/wasi-sdk"
permissions:
contents: read
WAMR_COMMON_OPTION:
"CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_STACKSIZE=32768\\nCONFIG_INTERPRETERS_WAMR_LOG=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\nCONFIG_INTERPRETERS_WAMR_REF_TYPES=y\\nCONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST=y\\nCONFIG_INTERPRETERS_WAMR_SHARED_MEMORY=y\\nCONFIG_INTERPRETERS_WAMR_BULK_MEMORY=y\\nCONFIG_EOL_IS_LF=y\\nCONFIG_ARM_SEMIHOSTING_HOSTFS=y\\nCONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y\\nCONFIG_RISCV_SEMIHOSTING_HOSTFS=y\\nCONFIG_FS_HOSTFS=y\\nCONFIG_LIBC_FLOATINGPOINT=y\\n"
jobs:
build_llvm_libraries:
permissions:
contents: read
actions: write
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
arch: "ARM RISCV AArch64"
container_image: ghcr.io/no1wudi/nuttx/apache-nuttx-ci-linux@sha256:8c4e00b607d4d6d66ba8f51c4544819a616eac69d3a2ac669e2af2150e2eb0f9
build_llvm_libraries_xtensa:
permissions:
contents: read
actions: write
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
arch: "Xtensa"
extra_build_llvm_options: "--platform xtensa"
cache_key_suffix: "-xtensa"
container_image: ghcr.io/no1wudi/nuttx/apache-nuttx-ci-linux@sha256:8c4e00b607d4d6d66ba8f51c4544819a616eac69d3a2ac669e2af2150e2eb0f9
container_image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:d9261eacf6c6ebe656c571757751c803e8f04c3ae9b820320a5ea5dd57b7205a
spec_test_on_qemu:
runs-on: ubuntu-latest
needs: [build_llvm_libraries, build_llvm_libraries_xtensa]
needs: [build_llvm_libraries]
container:
image: ghcr.io/no1wudi/nuttx/apache-nuttx-ci-linux@sha256:8c4e00b607d4d6d66ba8f51c4544819a616eac69d3a2ac669e2af2150e2eb0f9
image: ghcr.io/apache/nuttx/apache-nuttx-ci-linux@sha256:d9261eacf6c6ebe656c571757751c803e8f04c3ae9b820320a5ea5dd57b7205a
strategy:
matrix:
target_config: [
@ -85,11 +60,6 @@ jobs:
},
# {
# config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
# target: "riscv32_ilp32f",
# fpu_type: "fp"
#},
# {
# config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh",
# target: "riscv32_ilp32d",
# fpu_type: "dp"
# },
@ -98,62 +68,45 @@ jobs:
target: "riscv64",
fpu_type: "none"
},
{
config: "boards/xtensa/esp32s3/esp32s3-devkit/configs/qemu_debug",
target: "xtensa",
fpu_type: "none"
},
]
wamr_test_option: [
{
mode: "-t aot",
option: "CONFIG_INTERPRETERS_WAMR_AOT"
option: "CONFIG_INTERPRETERS_WAMR_AOT=y\\n"
},
{
mode: "-t aot -X",
option: "CONFIG_INTERPRETERS_WAMR_AOT"
option: "CONFIG_INTERPRETERS_WAMR_AOT=y\\n"
},
{
mode: "-t classic-interp",
option: "CONFIG_INTERPRETERS_WAMR_CLASSIC=y\\n"
},
{
mode: "-t fast-interp",
option: "CONFIG_INTERPRETERS_WAMR_FAST=y\\n"
},
# {
# mode: "-t classic-interp",
# option: "CONFIG_INTERPRETERS_WAMR_CLASSIC"
# },
# {
# mode: "-t fast-interp",
# option: "CONFIG_INTERPRETERS_WAMR_FAST"
# },
]
wamr_feature_option:
# Empty option for default
- { option: "", mode: "" }
# need to install menhir
# - { option: "CONFIG_INTERPRETERS_WAMR_GC CONFIG_INTERPRETERS_WAMR_AOT_STACK_FRAME", mode: "-G" }
exclude:
# XIP is not fully supported yet on RISCV64, some relocations can not be resolved
- target_config: { config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64" }
wamr_test_option: { mode: "-t aot -X" }
# Our xtensa environment doesn't have enough memory
- target_config: { target: "xtensa" }
wamr_feature_option: { mode: "-G" }
steps:
# Note: we use an unreleased version nuttx for xtensa because
# 12.4 doesn't contain necessary esp32s3 changes.
- name: Checkout NuttX
uses: actions/checkout@v4
with:
repository: apache/nuttx
ref: ${{ matrix.target_config.target == 'xtensa' && '985d395b025cf2012b22f6bb4461959fa6d87645' || 'releases/12.9' }}
repository: apache/incubator-nuttx
ref: releases/12.4
path: nuttx
- name: Checkout NuttX Apps
uses: actions/checkout@v4
with:
repository: apache/nuttx-apps
ref: ${{ matrix.target_config.target == 'xtensa' && '2ef3eb25c0cec944b13792185f7e5d5a05990d5f' || 'releases/12.9' }}
repository: apache/incubator-nuttx-apps
ref: releases/12.4
path: apps
- name: Checkout WAMR
@ -173,7 +126,7 @@ jobs:
./core/deps/llvm/build/lib
./core/deps/llvm/build/libexec
./core/deps/llvm/build/share
key: ${{ matrix.target_config.target == 'xtensa' && needs.build_llvm_libraries_xtensa.outputs.cache_key || needs.build_llvm_libraries.outputs.cache_key }}
key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
- name: Quit if cache miss
if: contains(matrix.wamr_test_option.mode, 'aot') && steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
@ -183,153 +136,40 @@ jobs:
if: contains(matrix.wamr_test_option.mode, 'aot')
run: cp -r core/deps/llvm apps/interpreters/wamr/wamr/core/deps/llvm
- name: Build wamrc
if: contains(matrix.wamr_test_option.mode, 'aot')
working-directory: apps/interpreters/wamr/wamr/wamr-compiler
run: |
cmake -B build -DWAMR_BUILD_SHRUNK_MEMORY=0 -S .
cmake --build build
# the nuttx version we use for xtensa requires esptool.py newer than
# what we have in our version of the apache-nuttx-ci-linux image.
- name: Install the latest esptool.py (xtensa)
if: matrix.target_config.target == 'xtensa'
run: |
pip3 install esptool==4.7.0
esptool.py version
- name: Configure NuttX
run: |
tools/configure.sh ${{ matrix.target_config.config }}
working-directory: nuttx
# depending on configurations, the iwasm command line generated
# by spec-test-script can be longer than the default NSH_LINELEN,
# which is 64 or 80.
- name: Enable WAMR for NuttX
run: |
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_LOG
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_REF_TYPES
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_SHARED_MEMORY
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_BULK_MEMORY
kconfig-tweak --set-val CONFIG_INTERPRETERS_WAMR_STACK_GUARD_SIZE 1024
kconfig-tweak --enable CONFIG_FS_HOSTFS
kconfig-tweak --enable CONFIG_ARM_SEMIHOSTING_HOSTFS
kconfig-tweak --enable CONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
kconfig-tweak --enable CONFIG_RISCV_SEMIHOSTING_HOSTFS
kconfig-tweak --enable CONFIG_RISCV_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
kconfig-tweak --enable CONFIG_XTENSA_SEMIHOSTING_HOSTFS
kconfig-tweak --enable CONFIG_XTENSA_SEMIHOSTING_HOSTFS_CACHE_COHERENCE
kconfig-tweak --enable CONFIG_LIBC_FLOATINGPOINT
kconfig-tweak --set-val CONFIG_NSH_LINELEN 255
working-directory: nuttx
find nuttx/boards -name defconfig | xargs sed -i '$a\${{ env.WAMR_COMMON_OPTION }}'
- name: Set WAMR stack size for NuttX
if: matrix.target_config.target != 'xtensa'
- name: Enable WAMR Interpreter for NuttX
run: |
kconfig-tweak --set-val CONFIG_INTERPRETERS_WAMR_STACKSIZE 327680
working-directory: nuttx
# because qemu doesn't have a proper emulation of esp32s3 psram,
# we are limited to the internal ram, which is about 400KB.
- name: Set WAMR stack size for NuttX (xtensa)
if: matrix.target_config.target == 'xtensa'
run: |
kconfig-tweak --set-val CONFIG_INTERPRETERS_WAMR_STACKSIZE 25600
working-directory: nuttx
- name: Enable WAMR interpreter/aot runtime for NuttX
if: matrix.wamr_test_option.option != ''
run: |
for x in ${{ matrix.wamr_test_option.option }}; do
kconfig-tweak --enable $x
done
working-directory: nuttx
- name: Enable WAMR Features for NuttX
if: matrix.wamr_feature_option.option != ''
run: |
for x in ${{ matrix.wamr_feature_option.option }}; do
kconfig-tweak --enable $x
done
working-directory: nuttx
find nuttx/boards -name defconfig | xargs sed -i '$a\${{ matrix.wamr_test_option.option }}'
- name: Disable FPU for NuttX
if: matrix.target_config.fpu_type == 'none'
run: |
kconfig-tweak --disable CONFIG_ARCH_FPU
working-directory: nuttx
find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_FPU is not set\n'
- name: Disable DPFPU for NuttX
if: matrix.target_config.fpu_type == 'fp'
run: |
kconfig-tweak --disable CONFIG_ARCH_DPFPU
working-directory: nuttx
find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_DPFPU is not set\n'
# Note: while a real hardware would need
# INTERPRETERS_WAMR_MEM_DUAL_BUS_MIRROR=y,
# it doesn't work with xtensa qemu which we use on the CI because it
# doesn't have a proper emulation of I/D separate mappings.
# we work it around by using INTERPRETERS_WAMR_MEM_DUAL_BUS_MIRROR=n.
# this configuration won't work on a real hardware.
- name: Tweak NuttX config (xtensa)
if: matrix.target_config.target == 'xtensa'
- name: Build wamrc
if: contains(matrix.wamr_test_option.mode, 'aot')
working-directory: apps/interpreters/wamr/wamr/wamr-compiler
run: |
kconfig-tweak --enable CONFIG_INTERPRETERS_WAMR_AOT_WORD_ALIGN_READ
kconfig-tweak --disable CONFIG_INTERPRETERS_WAMR_MEM_DUAL_BUS_MIRROR
working-directory: nuttx
cmake -Bbuild .
cmake --build build
- name: Build NuttX
run: |
make olddefconfig
make -j$(nproc)
working-directory: nuttx
# for xtensa, build a 8MB firmware image.
# simple boot is assumed. (thus the nuttx.bin offset in the image is 0)
# qemu will infer the flash size from the file size.
- name: Post build processing (xtensa)
if: matrix.target_config.target == 'xtensa'
- name: Build
id: build_firmware
run: |
cd nuttx
dd if=/dev/zero of=flash.img bs=1024 count=8192
dd if=nuttx.bin of=flash.img conv=notrunc
mv flash.img nuttx
- name: Build firmware path
id: build_firmware_path
run: |
echo "firmware=$PWD/nuttx/nuttx" >> $GITHUB_OUTPUT
# for xtensa, use the espressif fork of qemu, which has esp32s3 support.
- name: Install QEMU (xtensa)
if: matrix.target_config.target == 'xtensa'
run: |
apt-get remove -y qemu-system-misc
apt-get update && apt-get install -y libsdl2-2.0-0
./.github/scripts/install_qemu_xtensa.sh
qemu-system-xtensa --version
working-directory: apps/interpreters/wamr/wamr
tools/configure.sh ${{ matrix.target_config.config }}
make -j$(nproc)
echo "firmware=$PWD/nuttx" >> $GITHUB_OUTPUT
- name: Test
run: |
cd apps/interpreters/wamr/wamr/tests/wamr-test-suites
./test_wamr.sh -s spec ${{ matrix.wamr_test_option.mode }} -m ${{ matrix.target_config.target }} -b -Q -F ${{ steps.build_firmware_path.outputs.firmware }} ${{ matrix.wamr_feature_option.mode}}
- name: pack the log
if: always()
run: |
mkdir log
cp $PWD/nuttx/.config log/dot-config
cp ${{ steps.build_firmware_path.outputs.firmware }} log
tar -C apps/interpreters/wamr/wamr/tests/wamr-test-suites/workspace -cvzf log/report.tgz report
- name: upload the log
if: always()
uses: actions/upload-artifact@v4.6.2
with:
name: spec-test-log-${{ github.run_id }}-${{ strategy.job-index }}-${{ matrix.target_config.target }}
path: log
./test_wamr.sh -s spec ${{ matrix.wamr_test_option.mode }} -m ${{ matrix.target_config.target }} -b -Q -P -F ${{ steps.build_firmware.outputs.firmware }}

View File

@ -1,65 +0,0 @@
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.
# Check current WASM Micro Runtime results here: https://securityscorecards.dev/viewer/?uri=github.com/bytecodealliance/wasm-micro-runtime
name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
# midnight UTC
schedule:
- cron: "0 0 * * *"
# allow to be triggered manually
workflow_dispatch:
# Declare default permissions as read only.
permissions:
contents: read
jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
if: github.repository == 'bytecodealliance/wasm-micro-runtime'
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
persist-credentials: false
- name: "Run analysis"
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1
with:
results_file: results.sarif
results_format: sarif
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
publish_results: true
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v3.1.0
with:
name: SARIF file
path: results.sarif
retention-days: 5
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@57eebf61a2246ab60a0c2f5a85766db783ad3553
with:
sarif_file: results.sarif

10
.gitignore vendored
View File

@ -5,21 +5,21 @@
.venv
/.idea
**/cmake-build-*/
**/*build*/
!/build-scripts
**/*build/
*.obj
*.a
*.so
.clangd
.DS_Store
*.o
.aider*
core/deps/**
core/shared/mem-alloc/tlsf
core/app-framework/wgl
core/iwasm/libraries/lib-wasi-threads/test/*.wasm
core/iwasm/libraries/lib-socket/test/*.wasm
wamr-sdk/out/
wamr-sdk/runtime/build_runtime_sdk/
test-tools/host-tool/bin/
product-mini/app-samples/hello-world/test.wasm
product-mini/platforms/linux-sgx/enclave-sample/App/
product-mini/platforms/linux-sgx/enclave-sample/Enclave/

View File

@ -1,36 +0,0 @@
# WAMR adopters
_If you are using WAMR in production/pre-production at your organization, please add your company name to this list.
The list is in alphabetical order._
| Organization | Contact | Status | Description of Use |
| -------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
| [Alibaba](https://www.alibaba.com) | [@johnlanni](https://github.com/johnlanni) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | Higress is a next-generation cloud-native gateway built on the core of open-source Istio + Envoy based on Alibaba's internal Envoy Gateway practice. |
| [Amazon](https://www.amazon.com) | [@loganek](https://github.com/loganek) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | Prime Video is a global streaming service by Amazon that provides on-demand access to a vast library of movies, TV shows, and original programming, as well as live content. |
| [Ant Group](https://www.antgroup.com) | [@wei-tang](https://github.com/wei-tang) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | AntChain is a blockchain technology platform owned by Ant Group, a Chinese tech conglomerate that also runs Alipay, China's largest digital payment system. |
| [Bosch](https://www.bosch.com) | emily.ruppel@us.bosch.com | ![Undisclosed](https://img.shields.io/badge/-Undisclosed-orange?style=flat) | Silverline Cloud-Edge platform |
| [Disney](https://www.disney.com) | | ![production](https://img.shields.io/badge/-production-blue?style=flat) | Disney+ Streaming |
| [Intel](https://www.intel.com) | [@wenyongh](https://github.com/wenyongh) | ![Undisclosed](https://img.shields.io/badge/-Undisclosed-orange?style=flat) | Edge and the embedded environments |
| [Moonbit](https://www.moonbitlang.com) | [@peter-jerry-ye](https://github.com/peter-jerry-ye) | ![Undisclosed](https://img.shields.io/badge/-Undisclosed-orange?style=flat) | MoonBit is an end-to-end programming language toolchain for cloud and edge computing using WebAssembly. |
| [Microsoft](https://www.microsoft.com) | [@Mossaka](https://github.com/Mossaka) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | Hyperlight runs Wasm workloads in VMs without OS and kernel, it is a solution for improving the management and security of Wasm workloads on Azure. |
| [Midokura](https://www.midokura.com) | [@yamt](https://github.com/yamt) | ![Undisclosed](https://img.shields.io/badge/-Undisclosed-orange?style=flat) | The next-generation Edge AI sensing platform |
| [Siemens](https://www.siemens.com) | [@ttrenner](https://github.com/ttrenner) | ![Undisclosed](https://img.shields.io/badge/-Undisclosed-orange?style=flat) | Industrial, IoT |
| [Sony Semiconductor Solutions](https://www.sony-semicon.com) | [@dongsheng28849455](https://github.com/dongsheng28849455) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | AI digital camera |
| [Xiaomi](https://www.mi.com) | [@no1wudi](https://github.com/no1wudi) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | Xiaomi Vela is Xiaomi's IoT embedded software platform based on the open-source, real-time operating system NuttX. |
| [Xiaomi](https://www.mi.com) | [@no1wudi](https://github.com/no1wudi) | ![production](https://img.shields.io/badge/-production-blue?style=flat) | TEE (trusted execution environment) app engine. |
# Adopted in open-source projects
_The list is in alphabetical order._
| Project | Reference |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [Apache Teaclave](https://github.com/apache/incubator-teaclave) | https://github.com/apache/incubator-teaclave/blob/master/docs/executing-wasm.md |
| [Envoy](https://github.com/envoyproxy/envoy) | https://github.com/envoyproxy/envoy/blob/main/docs/root/configuration/other_features/wasm.rst |
| [faasm](https://github.com/faasm/faasm) | https://github.com/faasm/faasm/blob/main/docs/source/wamr.md |
| [fluent-bit](https://github.com/fluent/fluent-bit) | https://github.com/fluent/fluent-bit/tree/master/lib/wasm-micro-runtime-WAMR-1.3.0 |
| [harfbuzz](https://github.com/harfbuzz/harfbuzz) | https://github.com/harfbuzz/harfbuzz/blob/main/docs/wasm-shaper.md#enabling-the-wasm-shaper-when-building-harfbuzz |
| [inclave-containers](https://github.com/inclavare-containers/inclavare-containers) | https://github.com/inclavare-containers/inclavare-containers |
| [private-data-objects](https://github.com/hyperledger-labs/private-data-objects) | https://github.com/hyperledger-labs/private-data-objects/blob/main/common/interpreter/wawaka_wasm/README.md |
| [runwasi](https://github.com/containerd/runwasi) | https://github.com/containerd/runwasi/pull/508 (WIP) |
| [Wasmnizer-ts](https://github.com/web-devkits/Wasmnizer-ts) | https://github.com/web-devkits/Wasmnizer-ts |

View File

@ -2,10 +2,10 @@ WebAssembly Micro Runtime Attributions
======================================
WAMR project reused some components from other open source project:
- **cJson**: in the repository [wamr-app-framework](https://github.com/bytecodealliance/wamr-app-framework/), used in the host_tool for remotely managing wasm applications
- **cJson**: used in the host_tool for remotely managing wasm applications
- **contiki-ng**: for the coap protocol implementation
- **freebsd libm**: used in core/shared/platform/alios/bh_math.c
- **LVGL**: in the repository [wamr-app-framework](https://github.com/bytecodealliance/wamr-app-framework/), for the gui samples and wrapped the wasm graphic layer
- **LVGL**: for the gui samples and wrapped the wasm graphic layer
- **llvm**: for the AOT/JIT compilation
- **wasm-c-api**: to implement the C-APIs of wasm. using headers and sameples
- **wasmtime**: for the wasi libc implementation
@ -16,9 +16,9 @@ WAMR project reused some components from other open source project:
- **asmjit**: for the Fast JIT x86-64 codegen implementation
- **zydis**: for the Fast JIT x86-64 codegen implementation
- **NuttX ELF headers**: used in core/iwasm/aot/debug/elf_parser.c
- **Dhrystone**: for the test benchmark dhrystone
- **Dhrystone**: for the test benchmakr dhrystone
The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated operand stack location.
The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.
| third party components | version number | latest release | vendor pages | CVE details |
| --- | --- | --- | --- | --- |
@ -35,14 +35,14 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
| uvwasi | unspecified | v0.0.12 | https://github.com/nodejs/uvwasi | |
| asmjit | unspecified | unspecified | https://github.com/asmjit/asmjit | |
| zydis | unspecified | e14a07895136182a5b53e181eec3b1c6e0b434de | https://github.com/zyantific/zydis | |
| NuttX ELF headers | 72313301e23f9c2de969fb64b9a0f67bb4c284df | 10.3.0 | https://github.com/apache/nuttx | |
| NuttX ELF headers | 72313301e23f9c2de969fb64b9a0f67bb4c284df | 10.3.0 | https://github.com/apache/incubator-nuttx | |
| Dhrystone | 2.1 | 2.1 | https://fossies.org/linux/privat/old/ | |
## Licenses
### cJson
[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/test-tools/host-tool/external/cJSON/LICENSE)
[LICENSE](./test-tools/host-tool/external/cJSON/LICENSE)
### contiki-ng
@ -54,13 +54,13 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
### LVGL
[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/samples/littlevgl/LICENCE.txt)
[LICENSE](./samples/littlevgl/LICENCE.txt)
[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt)
[LICENSE](./core/app-framework/wgl/app/wa-inc/lvgl/LICENCE.txt)
### llvm
[LICENSE](./LICENSE)
[LICENSE](./core/deps/llvm/llvm/LICENCE.txt)
### wasm-c-api
@ -76,7 +76,11 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
### zephyr
[LICENSE](https://github.com/bytecodealliance/wamr-app-framework/blob/main/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE)
[LICENSE](./samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE)
### wac
[LICENSE](./tests/wamr-test-suites/spec-test-script/LICENSE)
### libuv

View File

@ -1,18 +1,14 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required (VERSION 3.14)
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
cmake_minimum_required (VERSION 3.0)
if(ESP_PLATFORM)
include (${COMPONENT_DIR}/build-scripts/esp-idf/wamr/CMakeLists.txt)
return()
endif()
project (iwasm LANGUAGES C)
set(CMAKE_CXX_STANDARD 17)
project (iwasm)
set (CMAKE_VERBOSE_MAKEFILE OFF)
@ -99,11 +95,6 @@ if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS)
set (WAMR_BUILD_LIB_WASI_THREADS 0)
endif ()
if (NOT DEFINED WAMR_ENABLE_COPY_CALLSTACK)
# Disable copy callstack by default
set (WAMR_ENABLE_COPY_CALLSTACK 0)
endif()
if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
# Disable wasm mini loader by default
set (WAMR_BUILD_MINI_LOADER 0)
@ -115,23 +106,18 @@ if (NOT DEFINED WAMR_BUILD_SIMD)
endif ()
if (NOT DEFINED WAMR_BUILD_REF_TYPES)
# Enable reference types by default
set (WAMR_BUILD_REF_TYPES 1)
# Disable reference types by default
set (WAMR_BUILD_REF_TYPES 0)
endif ()
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
if (NOT WIN32)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security \
-ffunction-sections -fdata-sections \
-Wno-unused-parameter -Wno-pedantic \
-fvisibility=hidden")
# Remove the extra spaces for better make log
string (REGEX REPLACE " *" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
endif()
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"))
@ -149,47 +135,35 @@ endif ()
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if (MSVC)
add_definitions(-DCOMPILING_WASM_RUNTIME_API=1)
# STATIC LIBRARY
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
endif ()
add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (vmlib PROPERTIES OUTPUT_NAME iwasm)
target_include_directories(vmlib INTERFACE
$<BUILD_INTERFACE:${WAMR_ROOT_DIR}/core/iwasm/include>
$<INSTALL_INTERFACE:include/iwasm>
)
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
target_link_libraries (vmlib PUBLIC ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT})
# SHARED LIBRARY
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
target_link_libraries(vmlib INTERFACE boringssl_crypto)
target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
endif ()
if (MINGW)
target_link_libraries(vmlib INTERFACE -lWs2_32 -lwsock32)
target_link_libraries(vmlib PRIVATE ws2_32)
target_link_libraries (iwasm_shared INTERFACE -lWs2_32 -lwsock32)
endif ()
if (WIN32)
target_link_libraries(vmlib PRIVATE ntdll)
endif()
install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
set (WAMR_PUBLIC_HEADERS
# HEADERS
install (FILES
${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h
${WAMR_ROOT_DIR}/core/iwasm/include/wasm_export.h
${WAMR_ROOT_DIR}/core/iwasm/include/lib_export.h
)
set_target_properties (vmlib PROPERTIES PUBLIC_HEADER "${WAMR_PUBLIC_HEADERS}")
set_version_info (vmlib)
install (TARGETS vmlib
EXPORT iwasmTargets
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/iwasm
)
install_iwasm_package ()
DESTINATION include)

View File

@ -1,29 +0,0 @@
# In this project, we use CODEOWNERS to identify people who are likely to know
# who should review a pull request.
#
# People listed in this file are committing to respond in a timely fashion to
# PRs in the selected areas. However, that response doesn't have to be a full
# code review; it could also take any of these forms:
#
# - "I intend to review this but I can't yet. Please leave me a message if I
# haven't responded by (a specific date in the near future)."
#
# - "I think (a specific other contributor) should review this." (Note that the
# best reviewer for a PR may not necessarily be listed in this file.)
#
# People must only be added to this file if they've agreed to provide one of
# the above responses in a reasonable amount of time for every PR to which
# they're assigned.
#
# We only ask for this commitment from people who are employed full-time to
# work on this project. We gratefully welcome reviews from other contributors,
# but we don't believe it's fair to ask volunteers to respond quickly.
# If none of the later patterns match, assign to anyone. This team is the
# parent of all the other teams and automatically includes everyone on those
# teams.
* @loganek @lum1n0us @no1wudi @TianlongLiang @wenyongh @xujuntwt95329 @yamt
# Some parts of the project require more specialized knowledge. In those areas
# we designate smaller groups who are more likely to be aware of who's working
# in specific areas.

View File

@ -19,7 +19,7 @@ Code changes
We Use Github Flow, So All Code Changes Happen Through Pull Requests. Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests:
- If you've added code that should be tested, add tests. Ensure the test suite passes.
- Avoid use macros for different platforms. Use separate folder of source files to host different platform logic.
- Avoid use macros for different platforms. Use seperate folder of source files to host diffeent platform logic.
- Put macro definitions inside share_lib/include/config.h if you have to use macro.
- Make sure your code lints and compliant to our coding style.
- Extend the application library is highly welcome.

View File

@ -10,23 +10,18 @@
[Build WAMR](./doc/build_wamr.md) | [Build AOT Compiler](./wamr-compiler/README.md) | [Embed WAMR](./doc/embed_wamr.md) | [Export Native API](./doc/export_native_api.md) | [Build Wasm Apps](./doc/build_wasm_app.md) | [Samples](./samples/README.md)
WebAssembly Micro Runtime (WAMR) is a lightweight standalone WebAssembly (Wasm) runtime with small footprint, high performance and highly configurable features for applications cross from embedded, IoT, edge to Trusted Execution Environment (TEE), smart contract, cloud native and so on. It includes a few parts as below:
- [**VMcore**](./core/iwasm/): A set of runtime libraries for loading and running Wasm modules. It supports rich running modes including interpreter, Ahead-of-Time compilation(AoT) and Just-in-Time compilation (JIT). WAMR supports two JIT tiers - Fast JIT, LLVM JIT, and dynamic tier-up from Fast JIT to LLVM JIT.
- [**iwasm**](./product-mini/): The executable binary built with WAMR VMcore which supports WASI and command line interface.
- [**VMcore**](./core/iwasm/): A set of runtime libraries for loading and running Wasm modules. It supports several execution modes including interpreter, Ahead-of-Time compilation(AoT) and Just-in-Time compilation (JIT). The WAMR supports two JIT tiers - Fast JIT, LLVM JIT, and dynamic tier-up from Fast JIT to LLVM JIT.
- [**iwasm**](./product-mini/): The executable binary built with WAMR VMcore supports WASI and command line interface.
- [**wamrc**](./wamr-compiler/): The AOT compiler to compile Wasm file into AOT file
- Useful components and tools for building real solutions with WAMR vmcore:
- [App-framework](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-framework/README.md): A framework for supporting APIs for the Wasm applications
- [App-manager](https://github.com/bytecodealliance/wamr-app-framework/blob/main/app-mgr/README.md): A framework for dynamical loading the Wasm module remotely
- [App-framework](./core/app-framework/README.md): A framework for supporting APIs for the Wasm applications
- [App-manager](./core/app-mgr/README.md): a framework for dynamical loading the Wasm module remotely
- [WAMR-IDE](./test-tools/wamr-ide): An experimental VSCode extension for developping WebAssembly applications with C/C++
### Key features
- Full compliant to the W3C Wasm MVP
- Small runtime binary size (core vmlib on cortex-m4f with tail-call/bulk memroy/shared memroy support, text size from bloaty)
* ~58.9K for fast interpreter
* ~56.3K for classic interpreter
* ~29.4K for aot runtime
* ~21.4K for libc-wasi library
* ~3.7K for libc-builtin library
- Small runtime binary size (~85K for interpreter and ~50K for AOT) and low memory usage
- Near to native speed by AOT and JIT
- Self-implemented AOT module loader to enable AOT working on Linux, Windows, MacOS, Android, SGX and MCU systems
- Choices of Wasm application libc support: the built-in libc subset for the embedded environment or [WASI](https://github.com/WebAssembly/WASI) for the standard libc
@ -40,14 +35,15 @@ WebAssembly Micro Runtime (WAMR) is a lightweight standalone WebAssembly (Wasm)
- [XIP (Execution In Place) support](./doc/xip.md), ref to [document](./doc/xip.md)
- [Berkeley/Posix Socket support](./doc/socket_api.md), ref to [document](./doc/socket_api.md) and [sample](./samples/socket-api)
- [Multi-tier JIT](./product-mini#linux) and [Running mode control](https://bytecodealliance.github.io/wamr.dev/blog/introduction-to-wamr-running-modes/)
- Language bindings: [Go](./language-bindings/go/README.md), [Python](./language-bindings/python/README.md), [Rust](./language-bindings/rust/README.md)
- Language bindings: [Go](./language-bindings/go/README.md), [Python](./language-bindings/python/README.md)
### Wasm post-MVP features
- [wasm-c-api](https://github.com/WebAssembly/wasm-c-api), ref to [document](doc/wasm_c_api.md) and [sample](samples/wasm-c-api)
- [128-bit SIMD](https://github.com/WebAssembly/simd), ref to [samples/workload](samples/workload)
- [Reference Types](https://github.com/WebAssembly/reference-types), ref to [document](doc/ref_types.md) and [sample](samples/ref-types)
- [Bulk memory operations](https://github.com/WebAssembly/bulk-memory-operations), [Shared memory](https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md#shared-linear-memory), [Memory64](https://github.com/WebAssembly/memory64)
- [Tail-call](https://github.com/WebAssembly/tail-call), [Garbage Collection](https://github.com/WebAssembly/gc), [Exception Handling](https://github.com/WebAssembly/exception-handling)
- [Non-trapping float-to-int conversions](https://github.com/WebAssembly/nontrapping-float-to-int-conversions)
- [Sign-extension operators](https://github.com/WebAssembly/sign-extension-ops), [Bulk memory operations](https://github.com/WebAssembly/bulk-memory-operations)
- [Multi-value](https://github.com/WebAssembly/multi-value), [Tail-call](https://github.com/WebAssembly/tail-call), [Shared memory](https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md#shared-linear-memory)
### Supported architectures and platforms
The WAMR VMcore supports the following architectures:
@ -58,21 +54,21 @@ The WAMR VMcore supports the following architectures:
- XTENSA, MIPS, ARC
The following platforms are supported, click each link below for how to build iwasm on that platform. Refer to [WAMR porting guide](./doc/port_wamr.md) for how to port WAMR to a new platform.
- [Linux](./product-mini/README.md#linux), [Linux SGX (Intel Software Guard Extension)](./doc/linux_sgx.md), [MacOS](./product-mini/README.md#macos), [Android](./product-mini/README.md#android), [Windows](./product-mini/README.md#windows), [Windows (MinGW, MSVC)](./product-mini/README.md#mingw)
- [Zephyr](./product-mini/README.md#zephyr), [AliOS-Things](./product-mini/README.md#alios-things), [VxWorks](./product-mini/README.md#vxworks), [NuttX](./product-mini/README.md#nuttx), [RT-Thread](./product-mini/README.md#RT-Thread), [ESP-IDF(FreeRTOS)](./product-mini/README.md#esp-idf)
- [Linux](./product-mini/README.md#linux), [Linux SGX (Intel Software Guard Extension)](./doc/linux_sgx.md), [MacOS](./product-mini/README.md#macos), [Android](./product-mini/README.md#android), [Windows](./product-mini/README.md#windows), [Windows (MinGW)](./product-mini/README.md#mingw)
- [Zephyr](./product-mini/README.md#zephyr), [AliOS-Things](./product-mini/README.md#alios-things), [VxWorks](./product-mini/README.md#vxworks), [NuttX](./product-mini/README.md#nuttx), [RT-Thread](./product-mini/README.md#RT-Thread), [ESP-IDF](./product-mini/README.md#esp-idf)
## Getting started
- [Build VM core](./doc/build_wamr.md) and [Build wamrc AOT compiler](./wamr-compiler/README.md)
- [Build iwasm (mini product)](./product-mini/README.md): [Linux](./product-mini/README.md#linux), [SGX](./doc/linux_sgx.md), [MacOS](./product-mini/README.md#macos) and [Windows](./product-mini/README.md#windows)
- [Embed into C/C++](./doc/embed_wamr.md), [Embed into Python](./language-bindings/python), [Embed into Go](./language-bindings/go), [Embed in Rust](./language-bindings/rust)
- [Embed into C/C++](./doc/embed_wamr.md), [Embed into Python](./language-bindings/python), [Embed into Go](./language-bindings/go)
- [Register native APIs for Wasm applications](./doc/export_native_api.md)
- [Build wamrc AOT compiler](./wamr-compiler/README.md)
- [Build Wasm applications](./doc/build_wasm_app.md)
- [Port WAMR to a new platform](./doc/port_wamr.md)
- [VS Code development container](./doc/devcontainer.md)
- [Samples](./samples) and [Benchmarks](./tests/benchmarks)
- [End-user APIs documentation](https://bytecodealliance.github.io/wamr.dev/apis/)
### Performance and memory
@ -86,6 +82,7 @@ The following platforms are supported, click each link below for how to build iw
- [Performance and footprint data](https://github.com/bytecodealliance/wasm-micro-runtime/wiki/Performance): the performance and footprint data
Project Technical Steering Committee
====================================
The [WAMR PTSC Charter](./TSC_Charter.md) governs the operations of the project TSC.

View File

@ -1,637 +1,69 @@
## WAMR-2.3.0
### Breaking changes
### New features
- simd for fast-interp (#4131)
- copy call-stack (#4033)
### Bug fixes
- fix(ios): Remove `float-abi` flag (#3889)
- Fix out of bounds issues after memory.grow on non-aot non-threads builds (#3872)
- Fix out of bounds issue in is_native_addr_in_shared_heap function (#3886)
- Fix mmap flags for AOT loader on non-Linux SGX platforms (#3890)
- fix(uwp): Gate NTSTATUS definition behind WINAPI_PARTITION_DESKTOP for UWP builds (#3897)
- Fix linked global initialization in multimodule (#3905)
- Correct the table index calculation in aot_instantiation (#3903)
- Fix a leak in wasm_loader_emit_br_info (#3900)
- Check possible integer overflow in aot memory boundary check (#3920)
- Fix CI wamr-ide error (#3913)
- Fix WASI Path Mapping Processing (#3923)
- Use plain assignment rather than bh_memcpy_s (#3924)
- Fix loader small bug (#3928)
- don't return an uninitialized trap if argv_to_results fails (#3935)
- support WASM_FUNCREF return type in argv_to_results (#3936)
- Fix incorrect assignment in win_file.c (#3939)
- Fix aot table instantiate (#3946)
- set alignment 4 when loading multi return value (#3955)
- Only access Zephyr thread stats info when it's available (#3962)
- top-level cmakefile: fix macOS build (#3968)
- Handle a new scenario where an item is both exported and imported. (#3984)
- platform/nuttx: Flush icache/dcache properly (#4147)
- fix(runtest.py): A workaround to bypass errors that occur when deleting temporary files (#4093)
- Fix build issues when compiling WAMRC as a cross-compiler (#4112)
- include bh_platform.h (#4135)
- Fix iwasm build error when WAMR_BUILD_WASI_NN enabled (#4138)
- avoid Windows perform newline translation (#4128)
- fix: correct typos and improve comments across multiple files by codespell (#4116)
- fix: fix load aarch64 aot failed (#4114)
- wasm_loader allocates more spaces for elements (#4099)
- fix: add dispose of the debug information builder when destroying compilation context (#4105)
- prevent mmap size overflow on 32 bit platform for memory.grow (#4071)
- fix: when load aot init expr,no type_idx set. (#4094)
- fix(aot_emit_aot_file): prevent buffer emission for zero byte_count (#4095)
- fix(build_llvm_libraries.yml): Correct script path for build_llvm.py (#4089)
- fix(unit-test): libc_builtin_test issues (#4073)
- [gc] Subtyping fix (#4075)
- fix(build_llvm.py): clean up whitespace and formatting in build script (#4087)
- Unit test:type matching issue and code redundancy (#4079)
- fix(aot): ensure value_cmp does not exceed br_count in branch table compilation (#4065)
- In wasm32, fix potential conversion overflow when enlarging 65536 pages (#4064)
- Use wasm32-wasip1 instead of wasm32-wasi target for rust code (#4057)
- Update Rust target from 'wasm32-wasi' to 'wasm32-wasip1' in CI (#4050)
- Fix wasm loader check data segment count (#4039)
- Fix table index calculations in wasm_loader and wasm_mini_loader (#4004)
- Ensure **heap_base and **data_end global indices are validated against import count (#3996)
- fix format specifier warning on 32bit builds (#4177)
- Remove indirect-load for constants on Xtensa Target to improve performance (#4162)
- cmake: Enhance target selection for ARM architectures with FPU (#4185)
- Add import memory/table flag assert check for miniloader (#4179)
- Fix few integer overflowing (#4161)
- prevent frame_offset underflow in wasm_loader (#4165)
- fix: Remove unused variables in SIMD_v128_const case (#4197)
- fix false native stack overflow detections with HW_BOUND_CHECK (#4196)
- Keep fix the CMake compatibility issue (#4180)
- Fix the error of AOT mode on the "i386-windows-msvc" platform (#4183)
- debug-engine: fix a few type mismatches (#4189)
- Replace CMAKE_CURRENT_FUNCTION_LIST_DIR (#4200)
- fix potential memory leak (#4205)
- Add missing V128 handling in WASM_OP_BR (#4203)
- fix print_help when libc wasi is enabled (#4218)
- LLVM: don't verify instcombine fixpoint (#4219)
- LLVMCreateTargetMachineWithOpts: disable large data (#4220)
- set default value of `WAMR_BUILD_REF_TYPES` to 1 in standalone cases (#4227)
- platform/nuttx: Fix dcache operation in os_dcache_flush (#4225)
- fix return types of our 64-bit clz/ctz/popcount intrinsics (#4238)
- riscv: avoid llvm.cttz.i32/i64 for xip (#4248)
- Add overflow check for preserved local offset in preserve_referenced_local (#4211)
- aot_resolve_object_relocation_group: adapt to LLVM 16 (#4250)
- initialize WASI stdio handles to invalid for better error handling (#4092)
- Modifying build flags to ensure libiwasm.so is built (#4255)
- Stop pretending to support extended-const proposal (#4258)
- Improve readlinkat_dup() to handle symlink size correctly (#4229)
- fix: improve error handling of snprintf() in send_thread_stop_status() (#4234)
- Don't call os_thread_get_stack_boundary unless we actually use it (#4264)
- avoid access null pointer (#4262)
- disable compiler to prevent get_current_target() crash (#4251)
- product-mini/platforms/windows: set C++17 explicitly (#4269)
- fix buf checking in load_table_section (#4276)
- Set CMAKE_OSX_SYSROOT when building lldb (#4274)
- Add select 128 (#4236)
### Enhancements
- Refine looking up aot function with index (#3882)
- Wasm loader enhancement: check code size in code entry (#3892)
- Refactor AOT loader to support compatible versions (#3891)
- GlobalValueSet was moved to IRPartitionLayer recently, but we have a local definition anyway (#3899)
- Support external toolchain on Windows for aot compiler (#3911)
- Drop declarative elements on module instantiation (#3922)
- add testcases for shared heap and fix POP_MEM_OFFSET of memory64 (#3916)
- Enable ref types by default (#3894)
- Update README.md to clarify Windows toolchain support and ESP-IDF reference (#3917)
- add thread cpu time for zephyr (#3937)
- Improvements for platform thread APIs on Windows and Zephyr (#3941)
- Refactor SConscript and add file checks in iwasm.c (#3945)
- Consume the placeholders that were put when emitting table info (#3940)
- wasm_export.h: Use "default" visibility for gcc and clang (#3957)
- [fuzzing] Enable instantiation (#3958)
- use a random secret key (#3971)
- CMakeLists.txt: Do not require C++ (#3956)
- add reference type support by default for darwin to support WASI-SDK-25 (#3978)
- top-level cmake: link llvm libraries to our shared library (#3973)
- Set thread information earlier in exec_env creation (#3967)
- Break aot_create_comp_data into small functions (#3987)
- Optimize memory initialization handling in AOT loader (#3983)
- nuttx: remove the up_x API for kernel build (#4154)
- Expose WAMR_BUILD_GC_HEAP_SIZE_DEFAULT as a CMake option (#4124)
- Use log instead of using assertion in aot loader (#4119)
- feat: use C linkage in aot_comp_option.h for C++ embeding (#4106)
- Cmake improvements (#4076)
- feat: add support for EXTERNREF value type and enable AOT validator in fuzz tests (#4083)
- build_llvm.py: Allow to build xtensa target on non-xtensa host (#4086)
- Add a conditional check for the macro **STDC_VERSION** (#4080)
- [fuzzing] execute every exported function (#3959)
- Update memory allocation functions to use allocator user data (#4043)
- Add versioning support and update CMake configuration (#3933)
- Show wasm proposals status during compilation and execution (#3989)
- add a validator for aot module (#3995)
- Synchronize the GC spec tests to the commit from December 9. 2024. (#4022)
- Refine getting const offsets in wasm loader of fast-interp (#4012)
- fixes for compiling on windows (#4026)
- .github: Add shared lib builds (#3975)
- Error message improvement (#4000)
- Refine read leb int wasm loader of fast interpreter (#4017)
- Enable shrunk memory by default and add related configurations (#4008)
- Add documentation regarding security issues and the status of Wasm proposals (#3972)
- Improve stack consistency by ensuring sufficient space for dummy offsets (#4011)
- Check whether related table has funcref elem in opcode call_indirect (#3999)
- [fuzzing] Use software bound-check during fuzzing (#4003)
- Add an example of how to embed WAMR in Zephyr user mode (#3998)
- Update cmake min to 3.14 (#4175)
- aot: add new u64 intrinsics (#4168)
- Refactor Dockerfile and update .dockerignore for wasi-nn tests; adjust map-dir parameters in smoke test script (#4158)
- improve variable naming and code clarity in SIMD operations (#4157)
- Raise CI runner to ubuntu 22.04 (#4191)
- Remove the dlen to optimize it. (#4193)
- Add missing casts and improve error handling in performance map functions (#4202)
- Raise wasi-sdk to 25 and wabt to 1.0.37 (#4187)
- wamrc: add --disable-llvm-jump-tables option (#4224)
- feat(fuzz): add a new fuzzing target about aot compiler (#4121)
- bypass vptr santizier (#4231)
- use a selected llvm libs list to replace the full list (#4232)
- teach aot emitter/loader about .srodata and .srodata.cst\* sections (#4240)
- run_clang_format_diff: mention homebrew for clang-format installation (#4237)
- Use --target to pass a triple in wamrc (#4199)
- samples/wasm-c-api: skip aot compilation unless necessary (#4239)
- samples/wasm-c-api: remove unused valgrind detection (#4249)
- More detail to python setup, and fixed small typo (#4247)
- JIT: don't join worker threads twice (#4252)
- aot_resolve_object_relocation_group: adapt to LLVM 19 (#4254)
- build-scripts/build_llvm.py: bump to llvm 18 (#4259)
- CI: make macos' build_samples_wasm_c_api similar to ubuntu (#4253)
- Refactor fast-interpreter SIMD compilation flags (#4261)
- Bypass wamr_ide-related components from the release process. (#4268)
- Check for WASM_ENABLE_SIMDE in a couple more places (#4266)
- Add error handling for sgx ci (#4222)
### Security Issues
- Add validation for old_path in wasi_path_symlink (# CVE-2025-43853)
### Others
- Exclude fuzz test python and npm packages in scoreboard scan (#3871)
- Bump AOT_CURRENT_VERSION for WAMR 2.x (gc, memory64) (#3880)
- Add Tianlong into code owners (#3970)
- build(deps): Bump actions/upload-artifact from 4.4.3 to 4.5.0 (#3981)
- docs: Update build instructions suggestions for using Valgrind (#4164)
- test: temporarily skip 'skip-stack-guard-page' test case (#4163)
- build(deps): Bump actions/upload-artifact from 4.6.1 to 4.6.2 (#4159)
- Update NuttX and NuttX Apps references to releases/12.9 in workflow files (#4148)
- build(deps): Bump esbuild, @vitejs/plugin-react and vite (#4149)
- build(deps): Bump ossf/scorecard-action from 2.4.0 to 2.4.1 (#4109)
- build(deps): bump github/codeql-action from 3.26.13 to 3.28.1 (#3888) (#3902)
- build(deps): Bump github/codeql-action from 3.28.10 to 3.28.11 (#4132)
- build(deps): Bump github/codeql-action from 3.28.9 to 3.28.10 (#4108)
- build(deps): Bump actions/upload-artifact from 4.6.0 to 4.6.1 (#4107)
---
## WAMR-2.2.0
### Breaking changes
### New features
- Add support for multi-memory proposal in classic interpreter (#3742)
- wasi-nn: Add a new target for llama.cpp as a wasi-nn backend (#3709)
- Add memory instance support apis (#3786)
- Implement a first version of shared heap feature (#3789)
- Support dynamic aot debug (#3788)
- Implement shared heap for AOT (#3815)
- Support table64 extension in classic-interp and AOT running modes (#3811)
### Bug fixes
- Enable merged os_mmap for aot data sections (#3681)
- Fix arm64 issues on mac (#3688)
- aot loader: Call os_mmap with MMAP_MAP_32BIT only when target is x86-64 or riscv64 (#3755)
- Fix building iwasm_shared and iwasm_static libs on win32 (#3762)
- Fix compile error when multi-module and tags are enabled (#3781)
- Fix aot multi export memory support (#3791)
- Fix Windows compile error when uvwasi is enabled (#3810)
- Fix missing symbols when using aot mode on riscv platforms (#3812)
- Fix mac build of libc_emcc_wrapper.c (#3836)
- aot_comp_option.h: Add missing stdint.h header (#3834)
- Fix compilation error found in tflite test (#3820)
- Fix exec_env_tls assertion in module instantiation (#3844)
- Fix issues of destroy_shared_heaps (#3847)
### Enhancements
- aot loader: Refine os_mmap related code (#3711)
- Enable merged os_mmap for aot data sections and aot text (#3743)
- Improve posix mmap retry logic (#3714)
- Remove unnecessary code duplication in aot runtime (#3767)
- Add wamrc parameter to configure stack frame features (#3763)
- refactoring: Re-use commit IP functionality between exception handling and other cases (#3768)
- AOT call stack optimizations (#3773)
- Appease GCC strict prototypes warning (#3775)
- Appease GCC -Wformat (#3783)
- Fix compiler warnings (#3784)
- Implement option for skipping function index in the callstack (#3785)
- Fix a compile warning in aot_emit_function.c (#3793)
- Restore cmake hidden compile symbol visibility (#3796)
- Refactor shared heap feature for interpreter mode (#3794)
- Add no_resolve to LoadArgs and wasm_runtime_resolve_symbols (#3790)
- shared heap: Fix some issues and add basic unit test case (#3801)
- Add shared heap sample (#3806)
- Fix unused param warning when GC is enabled (#3814)
- Add scoreboard CI for supply-chain security (#3819)
- Emit load_addr and load_size if WAMR_ENABLE_COMPILER is set (#3835)
- libc-emcc: Use alternate method to check getrandom support (#3848)
- Enable libc-wasi for windows msvc build (#3852)
- Remove unused folder samples/gui and samples/littlevgl (#3853)
- Fix some compile warnings and typos (#3854)
- Allow to set native stack boundary to exec_env (#3862)
- Refine wasm/aot function instance lookup (#3865)
- Fix quadratic runtime for duplicate export name detection (#3861)
### Others
- Add a comment on AOT_SECTION_TYPE_SIGNATURE (#3746)
- CI: Freeze version of bloaty for NuttX compilation (#3756)
- aot compiler: Allow to control stack boundary check when boundary check is enabled (#3754)
- Update ref to the multi-memory tests (#3764)
- compilation_on_nuttx.yml: Update checkout action to suppress warnings (#3765)
- CI: Disable parallel test in spectest for NuttX (#3780)
- spec_test_on_nuttx.yml: Disable riscv32_ilp32f for now (#3777)
- Ignore temporary file from aider (#3787)
- Add CODEOWNERS (#3822)
- build(deps): bump github/codeql-action from 2.2.4 to 3.26.9 (#3826)
- build(deps): bump actions/upload-artifact from 3.1.0 to 4.4.0 (#3827)
- build(deps): bump ossf/scorecard-action from 2.3.1 to 2.4.0 (#3828)
- build(deps): bump github/codeql-action from 3.26.9 to 3.26.11 (#3843)
- build(deps): bump actions/upload-artifact from 4.4.0 to 4.4.3 (#3855)
- build(deps): bump github/codeql-action from 3.26.11 to 3.26.12 (#3856)
- Add Windows wamrc and iwasm build in release CI (#3857)
- Fix syntax error in codeql_buildscript.sh (#3864)
- release CI: Add another iwasm binary that supports Garbage Collection and Exception Handling (#3866)
- Fix lookup function issue reported in nightly run (#3868)
---
## WAMR-2.1.2
### Breaking Changes
- wasi-nn: Apply new architecture (#3692)
### New Features
- [wasi-nn] Add a new wasi-nn backend openvino (#3603)
- Add APIs into wasm_c_api.h to summary wasm function execution duration (#3639)
- Add support for RISCV32 ILP32F (#3708)
### Bug Fixes
- libc-builtin: Fix function prototype for wasm_runtime_module_realloc (#3702)
- Fix potential memory leak in insert_native_symbol (#3712)
- aot compiler: Fix NaN handling for opcode f32/f64.const in XIP mode (#3721)
- Fix table idx resolving in op call_indirect/return_call_indirect (#3726)
### Enhancements
- Remove a few hardcoded spec test knowledge from the core library (#3648)
- Change log of import function to be consistent (#3656)
- libc-builtin: Fix a printf format (#3652)
- Set compile symbol visibility to hidden in cmake (#3655)
- wamrc: Add --mllvm= option (#3658)
- wamr-compiler: Avoid size-level tweak if target is specified (#3659)
- aot runtime: Add missing arm/thumb relocations (#3660)
- aot compiler: Enlarge AOTNativeSymbol->symbol (#3662)
- aot compiler: Bail out on too long native symbol names (#3663)
- Support more features for rt-thread (#3661)
- Zephyr User Mode Support (#3650)
- Set posix thread name for debug build (#3657)
- Add emscripten_sleep() wrapper to libc-emcc (#3669)
- Fix a compilation warning (#3682)
- wamrc: Add some help text for --size-level (#3689)
- Restore linux iwasm default visibility (#3691)
- posix_thread.c: Restore old signal alternate stack before thread exit (#3693)
- libc-wasi: Make rights of STDIN/STDOUT/STDERR fixed and overlook their access modes (#3694)
- [refactoring] Extract read leb to a separate file, share the code between loader and mini loader (#3701)
- debug-interp: Only add lock when signal_flag is SIG_SINGSTEP (#3704)
- Fix compilation warnings (#3707)
- Add missing headers in bh_atomic.h and aot_llvm_extra.cpp (#3715)
- Update std atomic check and simd compatibility check for arc compiler (#3716)
- aot compiler: Track non-0x00 tableindex as ref types use (#3695)
- compilation: Use the dedicated stack-sizes section only for AOT (#3732)
- riscv: Add missing relocation intrinsics for **fixdfsi/**ltdf2 (#3733)
### Others
- Fix night run CI (#3640)
- spec-test-script/runtest.py: Don't assume the tmp dir path (#3632)
- wamr-test-suites: Remove dead code (wasi_test) (#3634)
- wamr-test-suites/test_wamr.sh: Add an option to specify wamrc binary (#3635)
- CI: Build llvm for xtensa (#3637)
- spec-test-script/runtest.py: Avoid specifying -v=0 unnecessarily (#3642)
- spec-test-script: Add xtensa case (#3643)
- spec-test-script/runtest.py: Move "--size-level=1" to common place for RISCV64 (#3644)
- spec-test-script/runtest.py: Use a shorter timeout when expected to fail (#3647)
- spec-test-script: Make case_last_words larger (#3651)
- spec-test-script/runtest.py: Reduce stack size for aot w/o gc (#3653)
- spec-test-script: Skip a few tests for xtensa qemu (#3664)
- spec-test-script: Use -mtext-section-literals for xtensa xip (#3666)
- spec_test_on_nuttx.yml: Add xtensa (#3665)
- spec_test_on_nuttx.yml: Enable xip (#3671)
- spec_test_on_nuttx.yml: Record more logs (#3670)
- spec_test_on_nuttx.yml: Replace sed with kconfig-tweak (#3672)
- spec_test_on_nuttx.yml: Retire CONFIG_EOL_IS_LF (#3676)
- spec-test-script/runtest.py: Use wamrc --xip option for xip (#3683)
- CI: Bump NuttX version to 12.6 (#3684)
- wamr-test-suites: Clean up generated tmp files after spec test (#3700)
- test_wamr.sh: Fix build wabt tool (#3703)
- NuttX: Retire CONFIG_ARCH_RV32IM and CONFIG_ARCH_RV64GC (#3717)
- runtest.py: Normallize option handling for XIP mode (#3722)
- CI: Enable XIP spectest for RISCV32 ILP32F (#3727)
- CI: Unify configuration stage for NuttX (#3725)
---
## WAMR-2.1.1
### Breaking Changes
- Sync up with latest wasi-nn spec (#3530)
### New Features
- Add APIs to get package version (#3601)
- Export API wasm_runtime_enlarge_memory (#3569)
- Add table type API support (#3515)
- Add wasm_runtime_get_module_package_type() and wasm_runtime_get_file_package_type() (#3600)
### Bug Fixes
- wasm_application.c: Avoid null pointer dereference (#3620)
- EH: Use the consistent type for EH handlers (#3619)
- wasm loader: Fix several issues in GC and exception handling (#3586)
- wasm loader: Fix push_frame_offset when pushing v128 type (#3588)
- Add integer overflow check for some indices in wasm/aot loader (#3579)
- aot-analyzer: Fix a few printf formats (#3590)
- aot-analyzer: Fix macos build (#3589)
- Fix compilation errors in aot-analyzer tool (#3584)
- interp debugger: Fix setting invalid value to step_count (#3583)
- aot loader: Check import global value type before using (#3571)
- Fix missing stack frame alloc/free in AOT multi-module invoke (#3562)
- aot loader: Verify global value type (#3560)
- aot loader: Add more checks in load_native_symbol_section() (#3559)
- core/shared/platform: Zero memory returned by os_mmap in some platforms (#3551)
- dwarf_extractor.cpp: Fix buffer overruns (#3541)
- aot loader: Prevent loading multiple native symbol sections (#3538)
- Validate func type in aot loader (#3535)
- wamrc: Fix truncated DW_AT_producer (#3537)
- wasm loader: Fix pop invalid offset count when stack top is ANY (#3516)
- Fix two fuzz issues (#3529)
- Fix several issues reported by oss-fuzz (#3526)
### Enhancements
- Fix compile warnings/error reported in Windows (#3616)
- wasm loader: Reject v128 for interpreters (#3611)
- Fix typos in wamrc and wasm_export.h (#3609)
- Bump ocaml/setup-ocaml from 2 to 3 (#3604)
- CMakeLists.txt: Fix Android pthread linkage (#3591)
- Add more arm AOT reloc entries (#3587)
- wasi-nn: Use numpy v1 in wasi-nn test requirements.txt (#3582)
- Optimize for multi-module support in AOT mode (#3563)
- aot compiler: Propagate const-ness by ourselves (#3567)
- aot_resolve_target_info: Avoid in-place modification of e_type (#3564)
- Allow missing imports in wasm loader and report error in wasm instantiation instead (#3539)
- aot compiler: Use larger alignment for load/store when possible (#3552)
- Consistent const keyword position in wasm_export.h (#3558)
- wasm_memory.c: Fix typo: hasn't been initialize -> `hasn't been initialized` (#3547)
- dwarf_extractor.cpp: Try to preserve link name (#3542)
- dwarf_extractor.cpp: Enable limited support for C++ (#3540)
- Sync up with latest wasi-nn spec (#3530)
- Expose more functions related to emitting AOT files (#3520)
- Make wasi-nn backends as separated shared libraries (#3509)
- build_llvm.py: Speed up llvm build with multi procs on windows (#3512)
- Fix compilation warnings of wasi-nn (#3497)
- Add missing functions to make RIOT work with the 2.x.x version (#3508)
### Others
- Update devcontainer.md (#3628)
- Fix compile errors on workload bwa and benchmark jetstream (#3617)
- wasm-mutator-fuzz: Set compilers earlier (#3585)
- wasm-mutator-fuzz: Make compilers overridable (#3578)
- wasi-nn: Add wasmedge-wasinn-example as smoke test (#3554)
- Add standalone cases (#3536)
- wasm-mutator-fuzz: Fix build errors and warnings for macOS (#3519)
- wasm-mutator-fuzz: Use another variable to check if in oss-fuzz environment (#3518)
- Add wasi-nn example as smoke test case (#3501)
---
## WAMR-2.1.0
## WAMR-1.3.3
### Breaking Changes
### New Features
- Add wasm_export.h APIs to expose memory type (#3496)
- Add api to get export global instance (#3452)
- Add wasm-mutator-fuzz test (#3420)
- Implement Memory64 support for AOT (#3362)
- Add wasm module global type information APIs (#3406)
- Add aot binary analysis tool aot-analyzer (#3379)
- Expose API to get import/export function's param/result valkind (#3363)
- Add WASI support for esp-idf platform (#3348)
### Bug Fixes
- Fix posix build when libc wasi is disabled and debug interp is enabled (#3503)
- Fix wasm_mini_loader.c build when jit or multi-module is enabled (#3502)
- Fix wasm loader check data segment count (#3492)
- Fix loader parse block type and calculate dynamic offset for loop args (#3482)
- Fix memory64 handling find_block_addr and execute_main (#3480)
- Fix two issues to make fuzzing test quit earlier (#3471)
- Fix test-wamr-ide CI failure (#3485)
- NuttX: Fix a dbus-related crash on esp32s3 (#3470)
- Clone data segments when specified with load args (#3463)
- Fix codeql compilation error (#3461)
- Fix several typos and fix bh_log calculate mills (#3441)
- ssp_config.h: Fix ifdef for android random api (#3444)
- libc-wasi: Fix a locking botch (#3437)
- Fix fast interp RECOVER_BR_INFO and local set/tee (#3434)
- aot compiler: Fix a type mismatch in compile_op_float_min_max (#3423)
- Correct Exception Handling tag type when GC is enabled (#3413)
- wasm loader: Fix handling if block without op else (#3404)
- ref-types: Correct default value for function local variables (#3397)
- aot compiler: Fix the length type passed to aot_memmove/aot_memset (#3378)
- Fix loader and mini-loader select potiential error (#3374)
- Fix aot debugger compilation error on windows (#3370)
- A few native stack detection fixes for macOS/arm64 (#3368)
- Fix ESP32-S3 compiling error (#3359)
- Fix a few native stack address calculations (#3351)
### Enhancements
- Modify logging for windows exception handler and remove unused function (#3489)
- posix iwasm: Make the timeout logic a bit more robust (#3478)
- libc-builtin: Enhance buffered print for printf_wrapper (#3460)
- Enhance GC const initializer expression to support nested struct/array new (#3447)
- wasi: Tweak the configuration for nuttx and explain why (#3451)
- NuttX: Replace esp32s3 bits with the OS-provided APIs (#3439)
- Allow not copying the wasm binary in wasm-c-api and not referring to the binary in wasm/aot loader (#3389)
- aot: Make precheck functions use short-call for xtensa (#3418)
- Add wasm_runtime_detect_native_stack_overflow_size (#3355)
- Enhance wasm loader checks for opcode br_table (#3352)
### Others
- Bump requests from 2.32.2 to 2.32.3 in /build-scripts (#3494)
- Enable building static library on Android platform (#3488)
- wasm-mutator-fuzz: Generate more kinds of corpus (#3487)
- Correct nuttx repo names (#3484)
- Bump requests from 2.31.0 to 2.32.2 in /build-scripts (#3474)
- wasm-mutator-fuzz: Adapt to oss-fuzz compilation (#3464)
- Add regression tests of BA issue cases (#3462)
- Add malformed test cases (#3459)
- NuttX: Rename a few recently-added nuttx options (#3449)
- wamr-test-suites: Enable AOT multi-module spec tests (#3450)
- Remove install_wasi_sdk from workload preparation script (#3445)
- Add cmake static/shared library build settings (#3443)
- Update spec test to latest commit (#3293)
- Fix typo of WAMR_CONFIGUABLE_BOUNDS_CHECKS (#3424)
- ci/coding_guidelines_check.py: Allow some well-known file names to contain '-' (#3428)
- product-mini/platforms/posix/main.c: Adapt to WASM_MEM_DUAL_BUS_MIRROR (#3427)
- Add comments to global type function declarations (#3431)
- nuttx/esp32s3: Apply ibus/dbus adjustment to internal ram 1 as well (#3421)
- Change WASM_ANYREF to WASM_EXTERNREF (#3426)
- Remove unused macros which were moved to wamr-app-framework (#3425)
- Add WASM_V128 in wasm_valkind_enum (#3412)
- Fix basic example, parameter missmatch between host and wasm (#3415)
- Fix workspaces path in build_wamr.sh (#3414)
- core/iwasm/compilation: Remove stale function prototypes (#3408)
- Add test cases for the requirements of "gc-aot" feature (#3399)
- append_aot_to_wasm.py: Add --ver-str option to emit more info in custom section name (#3398)
- Fix clang compile warnings (#3396)
- Fix some more spelling issues (#3393)
- Fix some spelling issues (#3385)
- samples/native-stack-overflow: Examine native functions with signature (#3382)
- Add some more comments on WASM_STACK_GUARD_SIZE (#3380)
- Fix typo for 'native' in wasm_export.h (#3376)
- CI: Use macos-13 instead of macos-latest (#3366)
- Test more samples in nightly-run CI (#3358)
- Random improvements to samples/native-stack-overflow (#3353)
- Reduce WASM_STACK_GUARD_SIZE a bit for posix-like platforms (#3350)
- doc: Add ADOPTERS.md (#3324)
- Update binary size info in README.md (#3030)
- core/config.h: Bump the default WASM_STACK_GUARD_SIZE (#3344)
- Add unit test suites (#3490)
- Fix internal global getter types (#3495)
- Fix CI build and run unit tests (#3499)
---
## WAMR-2.0.0
### Breaking Changes
- The AOT ABI was changed after GC and memory64 features were introduced:
- Implement GC feature for interpreter, AOT and LLVM-JIT (#3125)
- Implement memory64 for classic interpreter (#3266)
- Always allocate linear memory using mmap (#3052)
- Refactor APIs and data structures as preliminary work for Memory64 (#3209)
- Remove unused argument in wasm_runtime_lookup_function (#3218)
- Separate app-manager and app-framework from WAMR (#3129)
### New Features
- Implement GC feature for interpreter, AOT and LLVM-JIT (#3125)
- Implement memory64 for classic interpreter (#3266)
- Add wasi_ephemeral_nn module support (#3241)
### Bug Fixes
- EH: Fix broken stack usage calculation (#3121)
- Cumulative fixes for release/1.3.x (#3155)
Apply patches in branch main for branch `release/1.3.x`:
- Fix loader check_wasi_abi_compatibility (#3126)
- Zero the memory mapped from os_mmap in NuttX (#3132)
- Fix possible integer overflow in loader target block check (#3133)
- Fix locel.set in polymorphic stack (#3135)
- Fix threads opcodes' boundary check in classic-interp and fast-interp (#3136)
- aot_compile_op_call: Stop setting calling convention explicitly (#3140)
- aot compiler: Place precheck wrapper before the corresponding wrapped function (#3141)
- fast-interp: Fix copy_stack_top_i64 overlap issue (#3146)
- Fix a ubsan complaint "applying zero offset to null pointer" (#3160)
- fast-interp: Fix GC opcode ref.as_non_null (#3156)
- fast-interp: Fix frame_offset overflow issue (#3149)
- Fix null pointer access in fast-interp when configurable soft bound check is enabled (#3150)
- Cumulative fixes for release/1.3.x (#3268)
Apply patches which were fixed branch main to branch `release/1.3.x`:
- zephyr: Use zephyr sys_cache instead of CMSIS (#3162)
- Fix llvm jit push funcref/externref result type issue (#3169)
- Fix inconsistent coding convention (#3171)
- VSCode IDE enhancement and readme update (#3172)
- zephyr: include math only with minimal libc (#3177)
- Fix wasm loader handling opcode br_table (#3176)
- Fix ref.func opcode check when GC is enabled (#3181)
- Specify language in the wasi socket ext project (#3183)
- lldb_function_to_function_dbi: Fix a null dereference (#3189)
- Fix LLVM assertion failure and update CONTRIBUTING.md (#3197)
- lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)
- Fix compilation errors on MinGW (#3217)
- Fix compilation errors on esp-idf platform (#3224)
- Fix aot relocation symbols not found on windows 32-bit (#3231)
- Fix nightly run tsan ASLR issue (#3233)
- Go binding: Change C.long to C.int64_t when call wasm_runtime_set_wasi_args_ex (#3235)
- posix_file.c: Correct the dirfd argument that passes to fstatat (#3244)
- Fix compilation errors on zephyr platform (#3255)
- Fix dynamic offset not updated in op_br for block with ret type (#3269)
- Fix CI error when install packages for macos-14 (#3270)
- Fix ESP-IDF platform mmap data size error (#3288)
- Fix ESP32-S3 compiling error (#3360)
- release/1.3.x: Cumulative fixes for release/1.3.x (#3342)
Apply patches which were fixed in branch main to branch `release/1.3.x`:
- aot debug: Fix a few NULL dereferences on errors (#3273)
- aot debug: Fix a NULL dereference (#3274)
- aot debug: Process lldb_function_to_function_dbi only for C (#3278)
- Revert "lldb_function_to_function_dbi: A hack to avoid crashing on C++ methods (#3190)" (#3281)
- Fix warnings/issues reported in Windows and by CodeQL/Coverity (#3275)
- thread mgr: Free aux stack only when it was allocated (#3282)
- interp: Restore context from prev_frame after tail calling a native function (#3283)
- Sync simd opcode definitions spec (#3290)
- Add more checks in wasm loader (#3300)
- Fix posix_fadvise error handling (#3323)
- Fix windows relocation string parsing issue (#3333)
- Fix readdir for posix (#3339)
- wasm loader: Fix checks for opcode ref.func and opcode else (#3340)
- Enhance wasm loader checks for opcode br_table (#3352)
- CI: Use macos-13 instead of macos-latest (#3366)
### Enhancements
- Zero the memory mapped from os_mmap in NuttX (#3132)
- Use logger for runtime error/debug prints (#3097)
- aot_compile_op_call: Stop setting calling convention explicitly (#3140)
- aot compiler: Place precheck wrapper before the corresponding wrapped function (#3141)
- Fix null pointer access in fast-interp when configurable soft bound check is enabled (#3150)
- Clarify how to verify SGX evidence without an Intel SGX-enabled platform (#3158)
- zephyr: Use zephyr sys_cache instead of CMSIS (#3162)
- VSCode IDE enhancement and readme update (#3172)
- Add vprintf override for android and esp-idf (#3174)
- zephyr: Include math only with minimal libc (#3177)
- zephyr: Implement Alloc_With_System_Allocator (#3179)
- Use indirect call in pre-checker function to avoid relocation in XIP mode (#3142)
- Implement the remaining Windows filesystem functions (#3166)
- Fix LLVM assertion failure and update CONTRIBUTING.md (#3197)
- Allow overriding max memory on module instantiation (#3198)
- Get location info from function indexes in addr2line script (#3206)
- Demangle function names in stack trace when using addr2line script (#3211)
- Refactor APIs and data structures as preliminary work for Memory64 (#3209)
- Allow converting the zero wasm address to native (#3215)
- Small refactor on WASMModuleInstance and fix Go/Python language bindings (#3227)
- Add esp32c6 support (#3234)
- Make android platform's cmake flags configurable (#3239)
- Go binding: Change C.long to C.int64_t when call wasm_runtime_set_wasi_args_ex (#3235)
- Implement apis to set and get the name of a wasm module (#3254)
- Append '\0' to every name string in aot name section (#3249)
- Add cmake flag to control aot intrinsics (#3261)
- Add lock and ref_count for runtime init (#3263)
- nuttx: Migrate NuttX CMake build for WAMR (#3256)
- LLVM 19: Switch to debug records (#3272)
- aot debug: Process lldb_function_to_function_dbi only for C (#3278)
- Fix warnings/issues reported in Windows and by CodeQL/Coverity (#3275)
- Enhance wasm loading with LoadArgs and support module names (#3265)
- Add wamr to esp-idf components registry (#3287)
- zephyr: Add missing pthread library functions (#3291)
- Add more checks in wasm loader (#3300)
- Log warning if growing table failed (#3310)
- Enhance GC subtyping checks (#3317)
- User defined memory allocator for different purposes (#3316)
- Add a comment on WASM_STACK_GUARD_SIZE (#3332)
- Allow executing malloc/free from native in memory64 mode (#3315)
- Add functions to expose module import/export info (#3330)
- Add wamr to esp-idf components registry (#3264)
- Update esp-idf platform support in release/v1.3.x (#3296)
- Add WASI support for esp-idf platform in release/1.3.x (#3334)
### Others
- Add ARM MacOS to the CI (#3120)
- Download jetstream src from github instead of browserbench.org (#3196)
- Update document to add wamr-rust-sdk introduction (#3204)
- Fix nightly run tsan ASLR issue (#3233)
- Add CodeQL Workflow for Code Security Analysis (#2812)
- Add issue templates (#3248)
- Fix CI error when install packages for macos-14 (#3270)
- Update document for GC, exception handling and memory64 features (#3284)
- Update release CI (#3295)
- Add native-stack-overflow sample (#3321)
- Update release CI (#3294)
---
@ -640,14 +72,12 @@
### Breaking Changes
### New Features
- Implement Exception Handling for classic interpreter (#3096)
- Use `cmake -DWAMR_BUILD_EXCE_HANDLING=1/0` option to enable/disable
the feature, and by default it is disabled
- It is still in highly experimental stage
### Bug Fixes
- Fix build errors when initializing wasm_val_t values with macros (#3007)
- fix(wasm-c-api): Do not clone stack frames if there's no trap (#3008)
- classic-interp: Handle SIMD opcode when JIT is enabled (#3046)
@ -666,7 +96,6 @@
- Fix read and validation of misc/simd/atomic sub opcodes (#3115)
### Enhancements
- Clear compilation warning and dead code (#3002)
- aot debug: Try to use a bit more appropriate file names (#3000)
- Increase default app thread stack size (#3010)
@ -675,7 +104,7 @@
- Allow using mmap for shared memory if hw bound check is disabled (#3029)
- Don't redefine D_INO if already defined (#3036)
- Enhancements on wasm function execution time statistic (#2985)
- wamr-compiler: Fix non-x86{\_64} host builds (#3037)
- wamr-compiler: Fix non-x86{_64} host builds (#3037)
- Disable quick aot entry for interp and fast-jit (#3039)
- nuttx: Add option to enable quick aot entry (#3040)
- Set CONFIG_HAS_CAP_ENTER to support posix file api for freertos (#3041)
@ -697,7 +126,6 @@
- Fix windows build error and compilation warnings (#3095)
### Others
- Fix nightly-run CI failure (#3014)
- Build samples in debug mode (#3019)
- Remove deprecated tests in language-bindings python (#3018)
@ -718,7 +146,6 @@
## WAMR-1.3.1
### Breaking Changes
- In multi-threading, when an exception was thrown in wasm_func_call(),
the trap returned contains the stack frames of the thread where the
exception occurs, but not the stack frames of the main thread.
@ -727,11 +154,9 @@
`wamrc --emit-custom-sections=name` to emit it and make it clear.
### New Features
- Enable AOT linux perf support (#2930)
### Bug Fixes
- Corrects Zephyr include files for current versions of Zephyr (#2881)
- Fix possible dead lock in wasm_cluster_spawn_exec_env (#2882)
- Handle ambiguous fstflags on fd_filestat_set_times (#2892)
@ -750,8 +175,7 @@
- Fix linux-sgx build error when libc-wasi is disabled (#2997)
### Enhancements
- fix command-reactor: Look for \_initialize only if \_start not found (#2891)
- fix command-reactor: Look for _initialize only if _start not found (#2891)
- Refactor reloc symbols for riscv (#2894)
- Avoid memory import failure when wasi-threads is enabled (#2893)
- interpreter: Simplify memory.grow a bit (#2899)
@ -763,7 +187,7 @@
- Enable wasm_runtime_terminate for single-threading (#2924)
- nuttx: Add CONFIG_INTERPRETERS_WAMR_DEBUG_AOT (#2929)
- Allow to control built-in libraries for wamrc from command line options (#2928)
- Fix a bug that appends '\_precheck' to aot_func (#2936)
- Fix a bug that appends '_precheck' to aot_func (#2936)
- freertos: Add os_cond_broadcast for pthread wrapper (#2937)
- Append .aot to .wasm as a custom section named "aot" (#2933)
- fix(sgx-ra): Fix building when enclave is built without librats ahead (#2968)
@ -778,7 +202,6 @@
- Refine AOT/JIT code call wasm-c-api import process (#2982)
### Others
- compilation_on_nuttx.yml: Use docker image to simplify env setup (#2878)
- samples/spawn-thread: Disable libc and pthread (#2883)
- Add arm64 to nuttx compilation test (#2886)
@ -793,7 +216,6 @@
## WAMR-1.3.0
### Breaking Changes
- Abstract POSIX filesystem functions (#2585)
- Change API wasm_runtime_set_wasi_args_ex's arguments
`int stdinfd/stdoutfd/stderrfd` to `int64_t stdinfd/stdoutfd/stderrfd`
@ -808,7 +230,6 @@
- libc-wasi: Conditionally support SYNC flags (#2581)
### New Features
- Support muti-module for AOT mode (#2482)
- Implement libc-wasi for Windows platform (#2740)
- Implement module instance context APIs (#2436)
@ -817,9 +238,8 @@
- Add Cosmopolitan Libc Platform (#2598)
### Bug Fixes
- sgx-ra: Disable the building of samples (#2507)
- Handle a return from wasi \_start function correctly (#2529)
- Handle a return from wasi _start function correctly (#2529)
- fd_object_release: Preserve errno (#2535)
- Fix build error with ancient GCC (4.8) (#2553)
- Fix compiling error for RT-Thread (#2569)
@ -870,7 +290,6 @@
- Fix sample basic intToStr was called with wrong length (#2876)
### Enhancements
- Implement strict validation of thread IDs according to the specification (#2521)
- Stop abusing shared memory lock to protect exception (#2509)
- Implement os_usleep for posix (#2517)
@ -886,7 +305,7 @@
- Add user to enlarge memory error callback (#2546)
- runtest.py: Show accurate case amount in summary (#2549)
- Allow using custom signal handler from non-main thread (#2551)
- Return \_\_WASI_EINVAL from fd_prestat_dir_name (#2580)
- Return __WASI_EINVAL from fd_prestat_dir_name (#2580)
- Support AOT compiler with LLVM 17 (#2567)
- Add support for closing/renumbering preopen fds (#2578)
- Enable AOT usage on M1 mac (#2618)
@ -929,7 +348,6 @@
- Fix compilation warnings on Windows (#2868)
### Others
- Add mutex stress test (#2472)
- Add unit tests for the tid allocator (#2519)
- Add support for running tests on apple M1 macs (#2554)
@ -967,18 +385,15 @@
## WAMR-1.2.3
### Breaking Changes
- Increase default native stack size (#2332)
### New Features
- Implement the segue optimization for LLVM AOT/JIT (#2230)
- Implement AOT static PGO (#2243)
- Enable static PGO for Linux SGX (#2270)
- Add Rust Formatters to Debugger (Vector, Map etc.) (#2219)
### Bug Fixes
- The Python language-binding needs python>=3.9 (#2228)
- aot_compile_op_call: Remove a wrong optimization (#2233)
- Fix typo in samples/ref-types (#2236)
@ -1021,7 +436,6 @@
- Fix typo in aot_emit_aot_file.c (#2478)
### Enhancements
- A few changes related to WAMRC_LLC_COMPILER (#2218)
- Enhance linux-sgx CI (#2102)
- Add asan and ubsan to WAMR CI (#2161)
@ -1087,7 +501,6 @@
- Clone the input binary during wasm_module_validate (#2483)
### Others
- Nuttx CI: Ignore the expired certificate for riscv gcc toolchain (#2222)
- core/iwasm/compilation: constify a bit (#2223)
- Bump requests from 2.28.2 to 2.31.0 in /build-scripts (#2229)
@ -1110,11 +523,9 @@
### Breaking Changes
### New Features
- Implement Fast JIT multi-threading feature (#2134)
### Bug Fixes
- Update request.ts wasm_response_send signature (#2122)
- Fix ems allocator unaligned memory access on riscv64 (#2140)
- libc_wasi_wrapper.c: Fix min func issue for size_t < 8 bytes on some platforms (#2152)
@ -1123,7 +534,6 @@
- Fix wamr-ide debugger ignoring launch config (#2155)
### Enhancements
- Add test for validating linear memory size updates (#2078)
- Update Zephyr docs to remove unsupported west subcommand (#2128)
- Update messages/comments to refer the new place of the version definition (#2133)
@ -1142,7 +552,6 @@
- Fix compile warnings on windows platform (#2208)
### Others
- CI: Add ubsan checks to samples/wasm-c-api (#2147)
- CI: More precise trigger paths for github actions (#2157)
@ -1155,7 +564,6 @@
### New Features
### Bug Fixes
- libc-wasi/posix.c: Fix POLL{RD,WR}NORM in uClibc (#2069)
- Fix bh_assert for 64-bit platforms (#2071)
- wamr-ide: Modify Dockerfile to update base image version and fix build issue (#2068)
@ -1169,7 +577,6 @@
- Fix interpreter read linear memory size for multi-threading (#2088)
### Enhancements
- Limit the minimal size of bh_hashmap (#2073)
- Bump tensorflow to 2.11.1 in /core/iwasm/libraries/wasi-nn/test (#2061)
- Bump tensorflow to 2.11.1 in install_tensorflow.sh (#2076)
@ -1177,7 +584,6 @@
- Update documents (#2100)
### Others
- spectest/nuttx: Increase stack size of iwasm task (#2082)
- ci: Refactor windows build definition (#2087)
- ci: Enable WASI threads in CI (#2086)
@ -1189,8 +595,8 @@
### Breaking Changes
### New Features
### New Features
- Implement two-level Multi-tier JIT engine: tier-up from Fast JIT to LLVM JIT to get quick cold startup and better performance
- Enable running mode control for runtime, wasm module instance and iwasm
- Implement wasi-threads feature
@ -1203,7 +609,6 @@
- Add libsodium benchmark
### Bug Fixes
- Fix wasm-c-api import func link issue in wasm_instance_new
- Fix watchpoint segfault when using debug interp without server
- libc-wasi: Fix spurious poll timeout
@ -1232,7 +637,6 @@
- fix debugger: Set termination flags also when in debug mode
### Enhancements
- Add WAMR-IDE vscode extension to the Visual Studio Marketplace
- Refine Windows thread waiting list operations
- Improve wasm-c-api instantiation-time linking
@ -1273,7 +677,6 @@
- Refine aot compiler check suspend_flags and fix issue of multi-tier jit
### Others
- Enable XIP in CI daily test
- Integrate wasi test suite to wamr-test-suites and CI
- Add CI for wasi-threads tests
@ -1288,7 +691,6 @@
## WAMR-1.1.2
### Breaking Changes
- Remove the LLVM MCJIT mode, replace it with LLVM ORC JIT eager mode
- Add option to pass user data to the allocator functions of RuntimeInitArgs
- Change how iwasm returns:
@ -1298,7 +700,6 @@
- Enable bulk memory by default
### New Features
- Add control for the native stack check with hardware trap
- Add memory watchpoint support to debugger
- Add wasm_module_obtain() to clone wasm_module_t
@ -1306,7 +707,6 @@
- esp-idf: Add socket support for esp-idf platform
### Bug Fixes
- Fix XIP issue caused by rem_s on RISC-V
- Fix XIP issues of fp to int cast and int rem/div
- Fix missing float cmp for XIP
@ -1326,7 +726,6 @@
- Fix XIP issue of handling 64-bit const in 32-bit target
### Enhancements
- Refactor the layout of interpreter and AOT module instance
- Refactor LLVM JIT: remove mcjit and legacy pass manager, upgrade to ORCv2 JIT
- Refine Fast JIT call indirect and call native process
@ -1343,7 +742,7 @@
- Refine the stack frame size check in interpreter
- Enlarge the default wasm operand stack size to 64KB
- Use cmake POSITION_INDEPENDENT_CODE instead of hardcoding -pie -fPIE
- Implement R*ARM_THM_MOVT*[ABS|REPL] for thumb
- Implement R_ARM_THM_MOVT_[ABS|REPL] for thumb
- Suppress the warnings when building with GCC11
- samples/native-lib: Add a bit more complicated example
- Add mutex initializer for wasm-c-api engine operations
@ -1371,7 +770,6 @@
- Enable wasm cache loading in wasm-c-api
### Others
- Add CIs to release new version and publish binary files
- Add more compilation groups of fast jit into CI
- Enable spec test on nuttx and daily run it
@ -1520,3 +918,5 @@
### Others
---

1
assembly-script/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

124
assembly-script/README.md Normal file
View File

@ -0,0 +1,124 @@
# AssemblyScript_on_WAMR
This project is based on [Wasm Micro Runtime](https://github.com/bytecodealliance/wasm-micro-runtime) (WAMR) and [AssemblyScript](https://github.com/AssemblyScript/assemblyscript). It implements some of the `wamr app framework` in *assemblyscript*, which allows you to write some applications in *assemblyscript* and dynamically installed on *WAMR Runtime*
## Building
To build the samples in this repo, you need `npm` on your system
``` bash
sudo apt install npm
```
Then install all the dependencies under the repo's root dir
``` bash
cd $repo_root
npm install
```
Use the command to build all samples:
``` bash
npm run build:all
```
or you can build every sample individually:
``` bash
npm run build:timer
npm run build:publisher
npm run build:subscriber
# ...
```
You will get the compiled wasm file under `build` folder
Please refer to [package.json](./package.json) for more commands.
## Run
These applications require WAMR's application framework, you need to build WAMR first.
``` bash
cd ${WAMR_ROOT}/samples/simple
./build.sh
```
You will get two executable files under `out` folder:
`simple`: The wamr runtime with application framework
`host_tool`: The tool used to dynamically install/uninstall applications
1. Start the runtime:
``` bash
./simple -s
```
2. Install the compiled wasm file using `host_tool`:
``` bash
./host_tool -i app_name -f your_compiled_wasm_file.wasm
```
You can also use the WAMR's AoT compiler `wamrc` to compile the wasm bytecode into native code before you run them. Please refer to this [guide](../README.md#build-wamrc-aot-compiler) to build and install `WAMR AoT compiler`.
After installing `wamrc`, you can compile the wasm file using command:
``` bash
wamrc -o file_name.aot file_name.wasm
```
and you can install the AoT file to the runtime:
``` bash
./host_tool -i app_name -f your_compiled_aot_file.aot
```
## Development
You can develop your own application based on the `wamr_app_lib` APIs.
### Console APIs
``` typescript
function log(a: string): void;
function log_number(a: number): void;
```
### Timer APIs
``` typescript
function setTimeout(cb: () => void, timeout: i32): user_timer;
function setInterval(cb: () => void, timeout: i32): user_timer;
function timer_cancel(timer: user_timer): void;
function timer_restart(timer: user_timer, interval: number): void;
function now(): i32;
// export to runtime
function on_timer_callback(on_timer_id: i32): void;
```
### Request APIs
``` typescript
// register handler
function register_resource_handler(url: string,
request_handle: request_handler_f): void;
// request
function post(url: string, payload: ArrayBuffer, payload_len: number,
tag: string, cb: (resp: wamr_response) => void): void;
function get(url: string, tag: string,
cb: (resp: wamr_response) => void): void;
function put(url: string, payload: ArrayBuffer, payload_len: number, tag: string,
cb: (resp: wamr_response) => void): void;
function del(url: string, tag: string,
cb: (resp: wamr_response) => void): void;
// response
function make_response_for_request(req: wamr_request): wamr_response;
function api_response_send(resp: wamr_response): void;
// event
function publish_event(url: string, fmt: number,
payload: ArrayBuffer, payload_len: number): void;
function subscribe_event(url: string, cb: request_handler_f): void;
// export to runtime
function on_request(buffer_offset: i32, size: i32): void;
function on_response(buffer_offset : i32, size: i32): void;
```
You should export the `on_timer_callback`, `on_request` and `on_response` in your application entry file, refer to the samples for example.
To build your application, you can use `asc`:
``` bash
asc app.ts -b build/app.wasm -t build/app.wat --sourceMap --validate --optimize
```
or you can add a command into [package.json](./package.json):
``` json
"build:app": "asc app.ts -b build/app.wasm -t build/app.wat --sourceMap --validate --optimize",
```

30
assembly-script/package-lock.json generated Normal file
View File

@ -0,0 +1,30 @@
{
"name": "assembly_script",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"assemblyscript": {
"version": "0.17.4",
"resolved": "https://registry.npm.taobao.org/assemblyscript/download/assemblyscript-0.17.4.tgz",
"integrity": "sha1-1GEduJpClDNa1H7DxmYaJqRCh3E=",
"dev": true,
"requires": {
"binaryen": "98.0.0-nightly.20201109",
"long": "^4.0.0"
}
},
"binaryen": {
"version": "98.0.0-nightly.20201109",
"resolved": "https://registry.npm.taobao.org/binaryen/download/binaryen-98.0.0-nightly.20201109.tgz",
"integrity": "sha1-USv2yhXGe/dAIURzSkg25jmTqgU=",
"dev": true
},
"long": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/long/download/long-4.0.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Flong%2Fdownload%2Flong-4.0.0.tgz",
"integrity": "sha1-mntxz7fTYaGU6lVSQckvdGjVvyg=",
"dev": true
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "assembly_script",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build:request_handler": "asc samples/request_handler.ts -b build/request_handler.wasm -t build/request_handler.wat --sourceMap --optimize --exportRuntime --use abort=",
"build:request_sender": "asc samples/request_sender.ts -b build/request_sender.wasm -t build/request_sender.wat --sourceMap --optimize --exportRuntime --use abort=",
"build:timer": "asc samples/timer.ts -b build/timer.wasm -t build/timer.wat --sourceMap --optimize --exportRuntime --use abort=",
"build:publisher": "asc samples/event_publisher.ts -b build/event_publisher.wasm -t build/event_publisher.wat --sourceMap --optimize --exportRuntime --use abort=",
"build:subscriber": "asc samples/event_subscriber.ts -b build/event_subscriber.wasm -t build/event_subscriber.wat --sourceMap --optimize --exportRuntime --use abort=",
"build:all": "npm run build:request_handler; npm run build:request_sender; npm run build:timer; npm run build:subscriber; npm run build:publisher"
},
"author": "",
"license": "ISC",
"devDependencies": {
"assemblyscript": "^0.18.15"
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// The entry file of your WebAssembly module.
import * as console from "../wamr_app_lib/console"
import * as timer from "../wamr_app_lib/timer"
import * as request from "../wamr_app_lib/request"
function publish_overheat_event(): void {
var payload = String.UTF8.encode("warning: temperature is over high");
request.publish_event("alert/overheat", 0, payload, payload.byteLength);
}
export function on_init() : void {
timer.setInterval(publish_overheat_event, 2000);
}
export function on_destroy() : void {
}
/* Function below are requred by wamr runtime, don't remove or modify them */
export function _on_timer_callback(on_timer_id: i32): void {
timer.on_timer_callback(on_timer_id);
}
export function _on_request(buffer_offset: i32, size: i32): void {
request.on_request(buffer_offset, size);
}
export function _on_response(buffer_offset : i32, size: i32): void {
request.on_response(buffer_offset, size);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// The entry file of your WebAssembly module.
import * as console from "../wamr_app_lib/console"
import * as timer from "../wamr_app_lib/timer"
import * as request from "../wamr_app_lib/request"
export function on_init() : void {
request.subscribe_event("alert/overheat", (req) => {
console.log("### user over heat event handler called:");
console.log("");
console.log(" " + String.UTF8.decode(req.payload) + "\n");
})
}
export function on_destroy() : void {
}
/* Function below are requred by wamr runtime, don't remove or modify them */
export function _on_timer_callback(on_timer_id: i32): void {
timer.on_timer_callback(on_timer_id);
}
export function _on_request(buffer_offset: i32, size: i32): void {
request.on_request(buffer_offset, size);
}
export function _on_response(buffer_offset : i32, size: i32): void {
request.on_response(buffer_offset, size);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// The entry file of your WebAssembly module.
import * as console from "../wamr_app_lib/console"
import * as timer from "../wamr_app_lib/timer"
import * as request from "../wamr_app_lib/request"
export function on_init() : void {
request.register_resource_handler("/test", (req) => {
console.log("### Req: /test " + String.UTF8.decode(req.payload));
console.log(" request payload:");
console.log(" " + String.UTF8.decode(req.payload) + "\n");
var resp = request.make_response_for_request(req);
resp.set_payload(String.UTF8.encode("Ok"), 2);
request.api_response_send(resp);
});
}
export function on_destroy() : void {
}
/* Function below are requred by wamr runtime, don't remove or modify them */
export function _on_timer_callback(on_timer_id: i32): void {
timer.on_timer_callback(on_timer_id);
}
export function _on_request(buffer_offset: i32, size: i32): void {
request.on_request(buffer_offset, size);
}
export function _on_response(buffer_offset : i32, size: i32): void {
request.on_response(buffer_offset, size);
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// The entry file of your WebAssembly module.
import * as console from "../wamr_app_lib/console"
import * as timer from "../wamr_app_lib/timer"
import * as request from "../wamr_app_lib/request"
export function on_init() : void {
var payload = String.UTF8.encode("test message");
request.post("/test", payload, payload.byteLength, "", (resp) => {
if (resp != null) {
console.log("Post Success");
if (resp.payload != null) {
console.log(" response payload:")
console.log(" " + String.UTF8.decode(resp.payload!) + "\n");
}
}
else
console.log("Post Timeout");
});
}
export function on_destroy() : void {
}
/* Function below are requred by wamr runtime, don't remove or modify them */
export function _on_timer_callback(on_timer_id: i32): void {
timer.on_timer_callback(on_timer_id);
}
export function _on_request(buffer_offset: i32, size: i32): void {
request.on_request(buffer_offset, size);
}
export function _on_response(buffer_offset : i32, size: i32): void {
request.on_response(buffer_offset, size);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
// The entry file of your WebAssembly module.
import * as console from '../wamr_app_lib/console'
import * as timer from '../wamr_app_lib/timer'
/* clousure is not implemented yet, we need to declare global variables
so that they can be accessed inside a callback function */
var cnt = 0;
var my_timer: timer.user_timer;
export function on_init(): void {
/* The callback function will be called every 2 second,
and will stop after 10 calls */
my_timer = timer.setInterval(() => {
cnt ++;
console.log((cnt * 2).toString() + " seconds passed");
if (cnt >= 10) {
timer.timer_cancel(my_timer);
console.log("Stop Timer");
}
}, 2000);
}
export function on_destroy(): void {
}
/* Function below are requred by wamr runtime, don't remove or modify them */
export function _on_timer_callback(on_timer_id: i32): void {
timer.on_timer_callback(on_timer_id);
}

View File

@ -0,0 +1,6 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}

View File

@ -0,0 +1,495 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
import * as console from './console'
import * as timer from './timer'
@external("env", "wasm_response_send")
declare function wasm_response_send(buffer: ArrayBuffer, size: i32): bool;
@external("env", "wasm_register_resource")
declare function wasm_register_resource(url: ArrayBuffer): void;
@external("env", "wasm_post_request")
declare function wasm_post_request(buffer: ArrayBuffer, size: i32): void;
@external("env", "wasm_sub_event")
declare function wasm_sub_event(url: ArrayBuffer): void;
var COAP_GET = 1;
var COAP_POST = 2;
var COAP_PUT = 3;
var COAP_DELETE = 4;
var COAP_EVENT = COAP_DELETE + 2;
/* CoAP response codes */
export enum CoAP_Status {
NO_ERROR = 0,
CREATED_2_01 = 65, /* CREATED */
DELETED_2_02 = 66, /* DELETED */
VALID_2_03 = 67, /* NOT_MODIFIED */
CHANGED_2_04 = 68, /* CHANGED */
CONTENT_2_05 = 69, /* OK */
CONTINUE_2_31 = 95, /* CONTINUE */
BAD_REQUEST_4_00 = 128, /* BAD_REQUEST */
UNAUTHORIZED_4_01 = 129, /* UNAUTHORIZED */
BAD_OPTION_4_02 = 130, /* BAD_OPTION */
FORBIDDEN_4_03 = 131, /* FORBIDDEN */
NOT_FOUND_4_04 = 132, /* NOT_FOUND */
METHOD_NOT_ALLOWED_4_05 = 133, /* METHOD_NOT_ALLOWED */
NOT_ACCEPTABLE_4_06 = 134, /* NOT_ACCEPTABLE */
PRECONDITION_FAILED_4_12 = 140, /* BAD_REQUEST */
REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */
UNSUPPORTED_MEDIA_TYPE_4_15 = 143, /* UNSUPPORTED_MEDIA_TYPE */
INTERNAL_SERVER_ERROR_5_00 = 160, /* INTERNAL_SERVER_ERROR */
NOT_IMPLEMENTED_5_01 = 161, /* NOT_IMPLEMENTED */
BAD_GATEWAY_5_02 = 162, /* BAD_GATEWAY */
SERVICE_UNAVAILABLE_5_03 = 163, /* SERVICE_UNAVAILABLE */
GATEWAY_TIMEOUT_5_04 = 164, /* GATEWAY_TIMEOUT */
PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */
/* Erbium errors */
MEMORY_ALLOCATION_ERROR = 192, PACKET_SERIALIZATION_ERROR,
/* Erbium hooks */
MANUAL_RESPONSE, PING_RESPONSE
};
var g_mid: i32 = 0;
class wamr_request {
mid: i32 = 0;
url: string = "";
action: i32 = 0;
fmt: i32 = 0;
payload: ArrayBuffer;
payload_len: i32 = 0;
sender: i32 = 0;
constructor(mid: i32, url: string, action: i32, fmt: i32,
payload: ArrayBuffer, payload_len: number) {
this.mid = mid;
this.url = url;
this.action = action;
this.fmt = fmt;
this.payload = payload;
this.payload_len = i32(payload_len);
}
}
class wamr_response {
mid: i32 = 0;
status: i32 = 0;
fmt: i32 = 0;
payload: ArrayBuffer | null;
payload_len: i32 = 0;
receiver: i32 = 0;
constructor(mid: i32, status: i32, fmt: i32,
payload: ArrayBuffer | null, payload_len: i32) {
this.mid = mid;
this.status = status;
this.fmt = fmt;
this.payload = payload;
this.payload_len = payload_len;
}
set_status(status: number): void {
this.status = i32(status);
}
set_payload(payload: ArrayBuffer, payload_len: number): void {
this.payload = payload;
this.payload_len = i32(payload_len);
}
}
class wamr_resource {
url: string;
type: number;
cb: request_handler_f;
constructor(url: string, type: number, cb: request_handler_f) {
this.url = url;
this.type = type;
this.cb = cb;
}
}
function is_expire(trans: wamr_transaction, index: i32, array: Array<wamr_transaction>): bool {
var now = timer.now();
var elapsed_ms = (now < trans.time) ?
(now + (0xFFFFFFFF - trans.time) + 1) : (now - trans.time);
return elapsed_ms >= TRANSACTION_TIMEOUT_MS;
}
function not_expire(trans: wamr_transaction, index: i32, array: Array<wamr_transaction>): bool {
var now = timer.now();
var elapsed_ms = (now < trans.time) ?
(now + (0xFFFFFFFF - trans.time) + 1) : (now - trans.time);
return elapsed_ms < TRANSACTION_TIMEOUT_MS;
}
function transaction_timeout_handler(): void {
var now = timer.now();
var expired = transaction_list.filter(is_expire);
transaction_list = transaction_list.filter(not_expire);
expired.forEach(item => {
item.cb(null);
transaction_remove(item);
})
if (transaction_list.length > 0) {
var elpased_ms: number, ms_to_expiry: number;
now = timer.now();
if (now < transaction_list[0].time) {
elpased_ms = now + (0xFFFFFFFF - transaction_list[0].time) + 1;
} else {
elpased_ms = now - transaction_list[0].time;
}
ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms;
timer.timer_restart(g_trans_timer, ms_to_expiry);
} else {
timer.timer_cancel(g_trans_timer);
}
}
function transaction_find(mid: number): wamr_transaction | null {
for (let i = 0; i < transaction_list.length; i++) {
if (transaction_list[i].mid == mid)
return transaction_list[i];
}
return null;
}
function transaction_add(trans: wamr_transaction): void {
transaction_list.push(trans);
if (transaction_list.length == 1) {
g_trans_timer = timer.setTimeout(
transaction_timeout_handler,
TRANSACTION_TIMEOUT_MS
);
}
}
function transaction_remove(trans: wamr_transaction): void {
var index = transaction_list.indexOf(trans);
transaction_list.splice(index, 1);
}
var transaction_list = new Array<wamr_transaction>();
class wamr_transaction {
mid: number;
time: number;
cb: (resp: wamr_response | null) => void;
constructor(mid: number, time: number, cb: (resp: wamr_response) => void) {
this.mid = mid;
this.time = time;
this.cb = cb;
}
}
var REQUEST_PACKET_FIX_PART_LEN = 18;
var RESPONSE_PACKET_FIX_PART_LEN = 16;
var TRANSACTION_TIMEOUT_MS = 5000;
var g_trans_timer: timer.user_timer;
var Reg_Event = 0;
var Reg_Request = 1;
function pack_request(req: wamr_request): DataView {
var url_len = req.url.length + 1;
var len = REQUEST_PACKET_FIX_PART_LEN + url_len + req.payload_len
var buf = new ArrayBuffer(len);
var dataview = new DataView(buf, 0, len);
dataview.setUint8(0, 1);
dataview.setUint8(1, u8(req.action));
dataview.setUint16(2, u16(req.fmt));
dataview.setUint32(4, req.mid);
dataview.setUint32(8, req.sender);
dataview.setUint16(12, u16(url_len))
dataview.setUint32(14, req.payload_len);
var i = 0;
for (i = 0; i < url_len - 1; i++) {
dataview.setUint8(i + 18, u8(req.url.codePointAt(i)));
}
dataview.setUint8(i + 18, 0);
var payload_view = new DataView(req.payload);
for (i = 0; i < req.payload_len; i++) {
dataview.setUint8(i + 18 + url_len, u8(payload_view.getUint8(i)));
}
return dataview;
}
function unpack_request(packet: ArrayBuffer, size: i32): wamr_request {
var dataview = new DataView(packet, 0, size);
if (dataview.getUint8(0) != 1)
throw new Error("packet version mismatch");
if (size < REQUEST_PACKET_FIX_PART_LEN)
throw new Error("packet size error");
var url_len = dataview.getUint16(12);
var payload_len = dataview.getUint32(14);
if (size != (REQUEST_PACKET_FIX_PART_LEN + url_len + payload_len))
throw new Error("packet size error");
var action = dataview.getUint8(1);
var fmt = dataview.getUint16(2);
var mid = dataview.getUint32(4);
var sender = dataview.getUint32(8);
var url = packet.slice(REQUEST_PACKET_FIX_PART_LEN, REQUEST_PACKET_FIX_PART_LEN + url_len - 1);
var payload = packet.slice(REQUEST_PACKET_FIX_PART_LEN + url_len, REQUEST_PACKET_FIX_PART_LEN + url_len + payload_len);
var req = new wamr_request(mid, String.UTF8.decode(url), action, fmt, payload, payload_len);
req.sender = sender;
return req;
}
function pack_response(resp: wamr_response): DataView {
var len = RESPONSE_PACKET_FIX_PART_LEN + resp.payload_len
var buf = new ArrayBuffer(len);
var dataview = new DataView(buf, 0, len);
dataview.setUint8(0, 1);
dataview.setUint8(1, u8(resp.status));
dataview.setUint16(2, u16(resp.fmt));
dataview.setUint32(4, resp.mid);
dataview.setUint32(8, resp.receiver);
dataview.setUint32(12, resp.payload_len)
if (resp.payload != null) {
var payload_view = new DataView(resp.payload!);
for (let i = 0; i < resp.payload_len; i++) {
dataview.setUint8(i + 16, payload_view.getUint8(i));
}
}
return dataview;
}
function unpack_response(packet: ArrayBuffer, size: i32): wamr_response {
var dataview = new DataView(packet, 0, size);
if (dataview.getUint8(0) != 1)
throw new Error("packet version mismatch");
if (size < RESPONSE_PACKET_FIX_PART_LEN)
throw new Error("packet size error");
var payload_len = dataview.getUint32(12);
if (size != RESPONSE_PACKET_FIX_PART_LEN + payload_len)
throw new Error("packet size error");
var status = dataview.getUint8(1);
var fmt = dataview.getUint16(2);
var mid = dataview.getUint32(4);
var receiver = dataview.getUint32(8);
var payload = packet.slice(RESPONSE_PACKET_FIX_PART_LEN);
var resp = new wamr_response(mid, status, fmt, payload, payload_len);
resp.receiver = receiver;
return resp;
}
function do_request(req: wamr_request, cb: (resp: wamr_response) => void): void {
var trans = new wamr_transaction(req.mid, timer.now(), cb);
var msg = pack_request(req);
transaction_add(trans);
wasm_post_request(msg.buffer, msg.byteLength);
}
function do_response(resp: wamr_response): void {
var msg = pack_response(resp);
wasm_response_send(msg.buffer, msg.byteLength);
}
var resource_list = new Array<wamr_resource>();
type request_handler_f = (req: wamr_request) => void;
function registe_url_handler(url: string, cb: request_handler_f, type: number): void {
for (let i = 0; i < resource_list.length; i++) {
if (resource_list[i].type == type && resource_list[i].url == url) {
resource_list[i].cb = cb;
return;
}
}
var res = new wamr_resource(url, type, cb);
resource_list.push(res);
if (type == Reg_Request)
wasm_register_resource(String.UTF8.encode(url));
else
wasm_sub_event(String.UTF8.encode(url));
}
function is_event_type(req: wamr_request): bool {
return req.action == COAP_EVENT;
}
function check_url_start(url: string, leading_str: string): bool {
return url.split('/')[0] == leading_str.split('/')[0];
}
/* User APIs below */
export function post(url: string, payload: ArrayBuffer, payload_len: number, tag: string,
cb: (resp: wamr_response) => void): void {
var req = new wamr_request(g_mid++, url, COAP_POST, 0, payload, payload_len);
do_request(req, cb);
}
export function get(url: string, tag: string,
cb: (resp: wamr_response) => void): void {
var req = new wamr_request(g_mid++, url, COAP_GET, 0, new ArrayBuffer(0), 0);
do_request(req, cb);
}
export function put(url: string, payload: ArrayBuffer, payload_len: number, tag: string,
cb: (resp: wamr_response) => void): void {
var req = new wamr_request(g_mid++, url, COAP_PUT, 0, payload, payload_len);
do_request(req, cb);
}
export function del(url: string, tag: string,
cb: (resp: wamr_response) => void): void {
var req = new wamr_request(g_mid++, url, COAP_DELETE, 0, new ArrayBuffer(0), 0);
do_request(req, cb);
}
export function make_response_for_request(req: wamr_request): wamr_response {
var resp = new wamr_response(req.mid, CoAP_Status.CONTENT_2_05, 0, null, 0);
resp.receiver = req.sender;
return resp;
}
export function api_response_send(resp: wamr_response): void {
do_response(resp);
}
export function register_resource_handler(url: string,
request_handle: request_handler_f): void {
registe_url_handler(url, request_handle, Reg_Request);
}
export function publish_event(url: string, fmt: number,
payload: ArrayBuffer, payload_len: number): void {
var req = new wamr_request(g_mid++, url, COAP_EVENT, i32(fmt), payload, payload_len);
var msg = pack_request(req);
wasm_post_request(msg.buffer, msg.byteLength);
}
export function subscribe_event(url: string, cb: request_handler_f): void {
registe_url_handler(url, cb, Reg_Event);
}
/* These two APIs are required by wamr runtime,
use a wrapper to export them in the entry file
e.g:
import * as request from '.wamr_app_lib/request'
// Your code here ...
export function _on_request(buffer_offset: i32, size: i32): void {
on_request(buffer_offset, size);
}
export function _on_response(buffer_offset: i32, size: i32): void {
on_response(buffer_offset, size);
}
*/
export function on_request(buffer_offset: i32, size: i32): void {
var buffer = new ArrayBuffer(size);
var dataview = new DataView(buffer);
for (let i = 0; i < size; i++) {
dataview.setUint8(i, load<i8>(buffer_offset + i, 0, 1));
}
var req = unpack_request(buffer, size);
var is_event = is_event_type(req);
for (let i = 0; i < resource_list.length; i++) {
if ((is_event && resource_list[i].type == Reg_Event)
|| (!is_event && resource_list[i].type == Reg_Request)) {
if (check_url_start(req.url, resource_list[i].url)) {
resource_list[i].cb(req);
return;
}
}
}
console.log("on_request: exit. no service handler.");
}
export function on_response(buffer_offset: i32, size: i32): void {
var buffer = new ArrayBuffer(size);
var dataview = new DataView(buffer);
for (let i = 0; i < size; i++) {
dataview.setUint8(i, load<i8>(buffer_offset + i, 0, 1));
}
var resp = unpack_response(buffer, size);
var trans = transaction_find(resp.mid);
if (trans != null) {
if (transaction_list.indexOf(trans) == 0) {
if (transaction_list.length >= 2) {
var elpased_ms: number, ms_to_expiry: number;
var now = timer.now();
if (now < transaction_list[1].time) {
elpased_ms = now + (0xFFFFFFFF - transaction_list[1].time) + 1;
} else {
elpased_ms = now - transaction_list[1].time;
}
ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms;
timer.timer_restart(g_trans_timer, ms_to_expiry);
} else {
timer.timer_cancel(g_trans_timer);
}
}
trans.cb(resp);
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
@external("env", "wasm_create_timer")
declare function wasm_create_timer(a: i32, b: bool, c: bool): i32;
@external("env", "wasm_timer_cancel")
declare function wasm_timer_cancel(a: i32): void;
@external("env", "wasm_timer_restart")
declare function wasm_timer_restart(a: i32, b: i32): void;
@external("env", "wasm_get_sys_tick_ms")
declare function wasm_get_sys_tick_ms(): i32;
export var timer_list = new Array<user_timer>();
export class user_timer {
timer_id: i32 = 0;
timeout: i32;
period: bool = false;
cb: () => void;
constructor(cb: () => void, timeout: i32, period: bool) {
this.cb = cb;
this.timeout = timeout;
this.period = period
this.timer_id = timer_create(this.timeout, this.period, true);
}
}
export function timer_create(a: i32, b: bool, c: bool): i32 {
return wasm_create_timer(a, b, c);
}
export function setTimeout(cb: () => void, timeout: i32): user_timer {
var timer = new user_timer(cb, timeout, false);
timer_list.push(timer);
return timer;
}
export function setInterval(cb: () => void, timeout: i32): user_timer {
var timer = new user_timer(cb, timeout, true);
timer_list.push(timer);
return timer;
}
export function timer_cancel(timer: user_timer): void {
wasm_timer_cancel(timer.timer_id);
var i = 0;
for (i = 0; i < timer_list.length; i++) {
if (timer_list[i].timer_id == timer.timer_id)
break;
}
timer_list.splice(i, 1);
}
export function timer_restart(timer: user_timer, interval: number): void {
wasm_timer_restart(timer.timer_id, i32(interval));
}
export function now(): i32 {
return wasm_get_sys_tick_ms();
}
// This export function need to be copied to the top application file
//
export function on_timer_callback(on_timer_id: i32): void {
for (let i = 0; i < timer_list.length; i++) {
if (timer_list[i].timer_id == on_timer_id) {
timer_list[i].cb();
}
}
}

View File

@ -0,0 +1,6 @@
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}

View File

@ -13,6 +13,8 @@ objs = []
WAMR_ROOT_DIR = os.path.join(cwd, "..")
SHARED_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'shared')
IWASM_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'iwasm')
APP_MGR_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-mgr')
APP_FRAMEWORK_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-framework')
DEPS_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'deps')
if GetDepend(['WAMR_BUILD_INTERP']):
@ -26,16 +28,20 @@ if GetDepend(['WAMR_BUILD_AOT']):
script_path = os.path.join(IWASM_DIR, 'compilation', 'SConscript')
objs += SConscript(script_path)
if GetDepend(['WAMR_BUILD_APP_FRAMEWORK']):
objs += SConscript(os.path.join(APP_FRAMEWORK_DIR, 'SConscript'))
objs += SConscript(os.path.join(SHARED_DIR, 'coap', 'SConscript'))
objs += SConscript(os.path.join(APP_MGR_DIR, 'app-manager', 'SConscript'))
objs += SConscript(os.path.join(APP_MGR_DIR, 'app-mgr-shared', 'SConscript'))
if GetDepend(['WAMR_BUILD_LIBC_BUILTIN']):
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-builtin', 'SConscript'))
if GetDepend(['WAMR_BUILD_LIBC_WASI']):
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-wasi', 'SConscript'))
objs += SConscript(os.path.join(SHARED_DIR, 'platform', 'common', 'posix', 'SConscript'))
objs += SConscript(os.path.join(SHARED_DIR, 'platform', 'common', 'libc-util', 'SConscript'))
if GetDepend(['WAMR_BUILD_LIB_PTHREAD']):
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'lib-pthread', 'SConscript'))
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-pthread', 'SConscript'))
if GetDepend(['WAMR_BUILD_THREAD_MGR']):
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'thread-mgr', 'SConscript'))
@ -43,9 +49,6 @@ if GetDepend(['WAMR_BUILD_THREAD_MGR']):
if GetDepend(['WAMR_BUILD_LIBC_EMCC']):
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-emmc', 'SConscript'))
if GetDepend(['WAMR_BUILD_LIB_WASI_THREADS']):
objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'lib-wasi-threads', 'SConscript'))
objs += SConscript(os.path.join(cwd, 'SConscript_config'));
objs += SConscript(os.path.join(SHARED_DIR, 'platform', 'rt-thread', 'SConscript'))

View File

@ -109,27 +109,7 @@ if GetDepend(['WAMR_BUILD_CUSTOM_NAME_SECTION']):
if GetDepend(['WAMR_BUILD_TAIL_CALL']):
CPPDEFINES += ['WASM_ENABLE_TAIL_CALL=1']
print('[WAMR] Tail call enabled')
if GetDepend(['WAMR_BUILD_THREAD_MGR']):
CPPDEFINES += ['WASM_ENABLE_THREAD_MGR=1']
print('[WAMR] Thread manager enabled')
if GetDepend(['WAMR_BUILD_LIBC_WASI']):
CPPDEFINES += ['WASM_ENABLE_LIBC_WASI=1']
CPPDEFINES += ['WASM_ENABLE_MODULE_INST_CONTEXT=1']
print('[WAMR] Libc wasi enabled')
if GetDepend(['WAMR_BUILD_LIB_WASI_THREADS']):
CPPDEFINES += ['WASM_ENABLE_LIB_WASI_THREADS=1']
print('[WAMR] Lib wasi threads enabled')
if GetDepend(['WAMR_BUILD_REF_TYPES']):
CPPDEFINES += ['WASM_ENABLE_REF_TYPES=1']
print('[WAMR] enable ref types')
CPPDEFINES += ['BH_MALLOC=wasm_runtime_malloc']
CPPDEFINES += ['BH_FREE=wasm_runtime_free']
print('[WAMR] Tail call enabledd')
LIBS = ['m']

View File

@ -102,21 +102,12 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
"default": [],
}
experimental_backends = ["ARC", "Xtensa"]
normal_backends = [s for s in backends if s not in experimental_backends]
LLVM_TARGETS_TO_BUILD = [
'-DLLVM_TARGETS_TO_BUILD:STRING="' + ";".join(normal_backends) + '"'
if normal_backends
'-DLLVM_TARGETS_TO_BUILD:STRING="' + ";".join(backends) + '"'
if backends
else '-DLLVM_TARGETS_TO_BUILD:STRING="AArch64;ARM;Mips;RISCV;X86"'
]
# if not on ARC platform, but want to add expeirmental backend ARC as target
if platform != "ARC" and "ARC" in backends:
LLVM_TARGETS_TO_BUILD.extend(
LLVM_EXTRA_COMPILE_OPTIONS["arc"]
)
LLVM_PROJECTS_TO_BUILD = [
'-DLLVM_ENABLE_PROJECTS:STRING="' + ";".join(projects) + '"' if projects else ""
]
@ -134,7 +125,9 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
if not llvm_dir.exists():
raise Exception(f"{llvm_dir} doesn't exist")
build_dir = llvm_dir.joinpath("build").resolve()
build_dir = llvm_dir.joinpath(
"win32build" if "windows" == platform else "build"
).resolve()
build_dir.mkdir(exist_ok=True)
lib_llvm_core_library = build_dir.joinpath("lib/libLLVMCore.a").resolve()
@ -163,15 +156,11 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
CONFIG_CMD += " -A x64"
else:
CONFIG_CMD += " -G'Ninja'"
print(f"Config command: {CONFIG_CMD}")
subprocess.check_call(shlex.split(CONFIG_CMD), cwd=build_dir)
BUILD_CMD = "cmake --build . --target package" + (
" --config Release" if "windows" == platform else ""
)
if "windows" == platform:
BUILD_CMD += " --parallel " + str(os.cpu_count())
print(f"Build command: {BUILD_CMD}")
subprocess.check_call(shlex.split(BUILD_CMD), cwd=build_dir)
return build_dir
@ -185,7 +174,6 @@ def repackage_llvm(llvm_dir):
raise Exception("Find more than one LLVM-*.tar.gz")
if not packs:
raise Exception("Didn't find any LLVM-* package")
return
llvm_package = packs[0].name
@ -201,31 +189,6 @@ def repackage_llvm(llvm_dir):
# rm ./LLVM-1*.gz
os.remove(llvm_dir.joinpath(llvm_package).resolve())
def repackage_llvm_windows(llvm_dir):
build_dir = llvm_dir.joinpath("./build").resolve()
packs_path = [f for f in build_dir.glob("./_CPack_Packages/win64/NSIS/LLVM-*-win64")]
if len(packs_path) > 1:
raise Exception("Find more than one LLVM-* package")
if not packs_path:
raise Exception("Didn't find any LLVM-* package")
return
llvm_package_path = f"_CPack_Packages/win64/NSIS/{packs_path[0].name}"
windows_package_dir = build_dir.joinpath(llvm_package_path).resolve()
# mv package dir outside of build
shutil.move(str(windows_package_dir), str(llvm_dir))
# rm -r build
shutil.rmtree(str(build_dir))
# mkdir build
build_dir.mkdir()
# move back all the subdiretories under cpack directory(bin/include/lib) to build dir
moved_package_dir = llvm_dir.joinpath(packs_path[0].name)
for sub_dir in moved_package_dir.iterdir():
shutil.move(str(sub_dir), str(build_dir))
moved_package_dir.rmdir()
def main():
parser = argparse.ArgumentParser(description="build necessary LLVM libraries")
@ -249,7 +212,6 @@ def main():
"X86",
"Xtensa",
],
default=[],
help="identify LLVM supported backends, separate by space, like '--arch ARM Mips X86'",
)
parser.add_argument(
@ -294,17 +256,17 @@ def main():
"arc": {
"repo": "https://github.com/llvm/llvm-project.git",
"repo_ssh": "git@github.com:llvm/llvm-project.git",
"branch": "release/18.x",
"branch": "release/15.x",
},
"xtensa": {
"repo": "https://github.com/espressif/llvm-project.git",
"repo_ssh": "git@github.com:espressif/llvm-project.git",
"branch": "xtensa_release_18.1.2",
"branch": "xtensa_release_15.x",
},
"default": {
"repo": "https://github.com/llvm/llvm-project.git",
"repo_ssh": "git@github.com:llvm/llvm-project.git",
"branch": "release/18.x",
"branch": "release/15.x",
},
}
@ -338,10 +300,6 @@ def main():
)
is not None
):
# TODO: repackage process may change in the future, this work for LLVM 15.x
if "windows" == platform:
repackage_llvm_windows(llvm_dir)
else:
repackage_llvm(llvm_dir)
return True

View File

@ -39,8 +39,6 @@ elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64")
add_definitions(-DBUILD_TARGET_RISCV64_LP64)
elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32" OR WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32D")
add_definitions(-DBUILD_TARGET_RISCV32_ILP32D)
elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32F")
add_definitions(-DBUILD_TARGET_RISCV32_ILP32F)
elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32")
add_definitions(-DBUILD_TARGET_RISCV32_ILP32)
elseif (WAMR_BUILD_TARGET STREQUAL "ARC")
@ -102,6 +100,9 @@ if (WAMR_BUILD_JIT EQUAL 1)
if (NOT DEFINED LLVM_DIR)
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
endif ()
if (NOT EXISTS "${LLVM_BUILD_ROOT}")
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
endif ()
@ -131,17 +132,9 @@ else ()
unset (LLVM_AVAILABLE_LIBS)
endif ()
# Version
include (${WAMR_ROOT_DIR}/build-scripts/version.cmake)
# Package
include (${WAMR_ROOT_DIR}/build-scripts/package.cmake)
# Sanitizers
if (NOT DEFINED WAMR_BUILD_SANITIZER)
set(WAMR_BUILD_SANITIZER $ENV{WAMR_BUILD_SANITIZER})
endif ()
if (NOT DEFINED WAMR_BUILD_SANITIZER)
set(WAMR_BUILD_SANITIZER "")
@ -157,9 +150,6 @@ elseif (WAMR_BUILD_SANITIZER STREQUAL "asan")
elseif (WAMR_BUILD_SANITIZER STREQUAL "tsan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=thread -fno-sanitize-recover=all" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
elseif (WAMR_BUILD_SANITIZER STREQUAL "posan")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=pointer-overflow -fno-sanitize-recover=all" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=pointer-overflow")
elseif (NOT (WAMR_BUILD_SANITIZER STREQUAL "") )
message(SEND_ERROR "Unsupported sanitizer: ${WAMR_BUILD_SANITIZER}")
endif()
@ -171,68 +161,16 @@ if (WAMR_BUILD_LINUX_PERF EQUAL 1)
endif ()
endif ()
if (NOT DEFINED WAMR_BUILD_SHRUNK_MEMORY)
# Enable shrunk memory by default
set (WAMR_BUILD_SHRUNK_MEMORY 1)
endif ()
########################################
# Default values
########################################
if (NOT DEFINED WAMR_BUILD_BULK_MEMORY)
set (WAMR_BUILD_BULK_MEMORY 1)
endif ()
if (NOT DEFINED WAMR_BUILD_EXCE_HANDLING)
set (WAMR_BUILD_EXCE_HANDLING 0)
endif ()
if (NOT DEFINED WAMR_BUILD_GC)
set (WAMR_BUILD_GC 0)
endif ()
if (NOT DEFINED WAMR_BUILD_MEMORY64)
set (WAMR_BUILD_MEMORY64 0)
endif ()
if (NOT DEFINED WAMR_BUILD_MULTI_MEMORY)
set (WAMR_BUILD_MULTI_MEMORY 0)
endif ()
if (NOT DEFINED WAMR_BUILD_SHARED_MEMORY)
set(WAMR_BUILD_SHARED_MEMORY 0)
endif ()
if (NOT DEFINED WAMR_BUILD_STRINGREF)
set(WAMR_BUILD_STRINGREF 0)
endif ()
if (NOT DEFINED WAMR_BUILD_TAIL_CALL)
set (WAMR_BUILD_TAIL_CALL 0)
endif ()
########################################
# Compilation options to marco
########################################
message ("-- Build Configurations:")
message (" Build as target ${WAMR_BUILD_TARGET}")
message (" Build for platform ${WAMR_BUILD_PLATFORM}")
message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
message (" BUILD_SHARED_LIBS " ${BUILD_SHARED_LIBS})
################## running mode ##################
if (WAMR_BUILD_INTERP EQUAL 1)
message (" WAMR Interpreter enabled")
else ()
message (" WAMR Interpreter disabled")
endif ()
if ((WAMR_BUILD_FAST_INTERP EQUAL 1) AND (WAMR_BUILD_INTERP EQUAL 1))
add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
message (" Fast interpreter enabled")
else ()
add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
message (" Fast interpreter disabled")
endif ()
if (WAMR_BUILD_AOT EQUAL 1)
message (" WAMR AOT enabled")
else ()
@ -263,33 +201,59 @@ if (WAMR_BUILD_FAST_JIT EQUAL 1 AND WAMR_BUILD_JIT EQUAL 1
AND WAMR_BUILD_LAZY_JIT EQUAL 1)
message (" Multi-tier JIT enabled")
endif ()
################## test modes ##################
if (WAMR_BUILD_SPEC_TEST EQUAL 1)
add_definitions (-DWASM_ENABLE_SPEC_TEST=1)
message (" spec test compatible mode is on")
endif ()
if (WAMR_BUILD_WASI_TEST EQUAL 1)
add_definitions (-DWASM_ENABLE_WASI_TEST=1)
message (" wasi test compatible mode is on")
endif ()
################## native ##################
if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
message (" Libc builtin enabled")
else ()
message (" Libc builtin disabled")
endif ()
if (WAMR_BUILD_LIBC_UVWASI EQUAL 1)
message (" Libc WASI enabled with uvwasi implementation\n"
" WANRING:: uvwasi does not currently provide the comprehensive\n"
" file system security properties provided by some WASI runtimes.\n"
" Full support for secure file system sandboxing may or may not\n"
" be implemented in future. In the mean time, DO NOT RELY ON IT\n"
" TO RUN UNTRUSTED CODE.")
message (" Libc WASI enabled with uvwasi implementation")
elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
message (" Libc WASI enabled")
else ()
message (" Libc WASI disabled")
endif ()
if ((WAMR_BUILD_FAST_INTERP EQUAL 1) AND (WAMR_BUILD_INTERP EQUAL 1))
add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
message (" Fast interpreter enabled")
else ()
add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
message (" Fast interpreter disabled")
endif ()
if (WAMR_BUILD_MULTI_MODULE EQUAL 1)
add_definitions (-DWASM_ENABLE_MULTI_MODULE=1)
message (" Multiple modules enabled")
else ()
add_definitions (-DWASM_ENABLE_MULTI_MODULE=0)
message (" Multiple modules disabled")
endif ()
if (WAMR_BUILD_SPEC_TEST EQUAL 1)
add_definitions (-DWASM_ENABLE_SPEC_TEST=1)
message (" spec test compatible mode is on")
endif ()
if (NOT DEFINED WAMR_BUILD_BULK_MEMORY)
# Enable bulk memory by default
set (WAMR_BUILD_BULK_MEMORY 1)
endif ()
if (WAMR_BUILD_BULK_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_BULK_MEMORY=1)
message (" Bulk memory feature enabled")
else ()
add_definitions (-DWASM_ENABLE_BULK_MEMORY=0)
message (" Bulk memory feature disabled")
endif ()
if (WAMR_BUILD_SHARED_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_SHARED_MEMORY=1)
message (" Shared memory enabled")
else ()
add_definitions (-DWASM_ENABLE_SHARED_MEMORY=0)
endif ()
if (WAMR_ENABLE_SHARED_MEMORY_MMAP EQUAL 1)
add_definitions (-DWASM_ENABLE_SHARED_MEMORY_MMAP=1)
message (" Shared memory allocated using mmap enabled")
else ()
add_definitions (-DWASM_ENABLE_SHARED_MEMORY_MMAP=0)
endif ()
if (WAMR_BUILD_THREAD_MGR EQUAL 1)
message (" Thread manager enabled")
endif ()
@ -308,53 +272,6 @@ endif ()
if (WAMR_BUILD_LIB_RATS EQUAL 1)
message (" Lib rats enabled")
endif()
if ((WAMR_BUILD_LIB_SIMDE EQUAL 1))
message (" Lib simde enabled")
endif()
################## WAMR features ##################
if (WAMR_BUILD_MULTI_MODULE EQUAL 1)
add_definitions (-DWASM_ENABLE_MULTI_MODULE=1)
message (" Multiple modules enabled")
else ()
add_definitions (-DWASM_ENABLE_MULTI_MODULE=0)
message (" Multiple modules disabled")
endif ()
if (WAMR_BUILD_BULK_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_BULK_MEMORY=1)
else ()
add_definitions (-DWASM_ENABLE_BULK_MEMORY=0)
endif ()
if (WAMR_BUILD_SHARED_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_SHARED_MEMORY=1)
message (" Shared memory enabled")
else ()
add_definitions (-DWASM_ENABLE_SHARED_MEMORY=0)
endif ()
if (WAMR_BUILD_SHARED_HEAP EQUAL 1)
add_definitions (-DWASM_ENABLE_SHARED_HEAP=1)
message (" Shared heap enabled")
endif()
if (WAMR_ENABLE_COPY_CALLSTACK EQUAL 1)
add_definitions (-DWAMR_ENABLE_COPY_CALLSTACK=1)
message(" Copy callstack enabled")
else ()
add_definitions (-DWAMR_ENABLE_COPY_CALLSTACK=0)
message(" Copy callstack disabled")
endif()
if (WAMR_BUILD_MEMORY64 EQUAL 1)
# if native is 32-bit or cross-compiled to 32-bit
if (NOT WAMR_BUILD_TARGET MATCHES ".*64.*")
message (FATAL_ERROR "-- Memory64 is only available on the 64-bit platform/target")
endif()
add_definitions (-DWASM_ENABLE_MEMORY64=1)
set (WAMR_DISABLE_HW_BOUND_CHECK 1)
endif ()
if (WAMR_BUILD_MULTI_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_MULTI_MEMORY=1)
set (WAMR_BUILD_DEBUG_INTERP 0)
endif ()
if (WAMR_BUILD_MINI_LOADER EQUAL 1)
add_definitions (-DWASM_ENABLE_MINI_LOADER=1)
message (" WASM mini loader enabled")
@ -382,18 +299,12 @@ else ()
message (" Wakeup of blocking operations enabled")
endif ()
if (WAMR_BUILD_SIMD EQUAL 1)
if (WAMR_BUILD_TARGET MATCHES "RISCV64.*")
set(SIMD_ENABLED 0)
message (" SIMD disabled due to not supported on target RISCV64")
else()
set(SIMD_ENABLED 1)
if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*")
add_definitions (-DWASM_ENABLE_SIMD=1)
message (" SIMD enabled")
else ()
message (" SIMD disabled due to not supported on target RISCV64")
endif ()
add_definitions(-DWASM_ENABLE_SIMD=${SIMD_ENABLED})
endif ()
if (WAMR_BUILD_AOT_STACK_FRAME EQUAL 1)
add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1)
message (" AOT stack frame enabled")
endif ()
if (WAMR_BUILD_MEMORY_PROFILING EQUAL 1)
add_definitions (-DWASM_ENABLE_MEMORY_PROFILING=1)
@ -416,36 +327,13 @@ if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
endif ()
if (WAMR_BUILD_TAIL_CALL EQUAL 1)
add_definitions (-DWASM_ENABLE_TAIL_CALL=1)
message (" Tail call enabled")
endif ()
if (WAMR_BUILD_REF_TYPES EQUAL 1)
add_definitions (-DWASM_ENABLE_REF_TYPES=1)
endif ()
if (WAMR_BUILD_GC EQUAL 1)
if (WAMR_TEST_GC EQUAL 1)
message(" GC testing enabled")
endif()
endif ()
if (WAMR_BUILD_GC EQUAL 1 AND WAMR_BUILD_GC_PERF_PROFILING EQUAL 1)
add_definitions (-DWASM_ENABLE_GC_PERF_PROFILING=1)
message (" GC performance profiling enabled")
message (" Reference types enabled")
else ()
message (" GC performance profiling disabled")
endif ()
if (WAMR_BUILD_STRINGREF EQUAL 1)
if (NOT DEFINED WAMR_STRINGREF_IMPL_SOURCE)
message (" Using WAMR builtin implementation for stringref")
else ()
message (" Using custom implementation for stringref")
endif()
endif ()
if (WAMR_BUILD_PERF_PROFILING EQUAL 1 OR
WAMR_BUILD_DUMP_CALL_STACK EQUAL 1 OR
WAMR_BUILD_GC EQUAL 1)
# Enable AOT/JIT stack frame when perf-profiling, dump-call-stack
# or GC is enabled
if (WAMR_BUILD_AOT EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1)
endif ()
message (" Reference types disabled")
endif ()
if (WAMR_BUILD_EXCE_HANDLING EQUAL 1)
add_definitions (-DWASM_ENABLE_EXCE_HANDLING=1)
@ -467,10 +355,6 @@ endif ()
if (WAMR_BUILD_DEBUG_AOT EQUAL 1)
message (" Debug AOT enabled")
endif ()
if (WAMR_BUILD_DYNAMIC_AOT_DEBUG EQUAL 1)
add_definitions (-DWASM_ENABLE_DYNAMIC_AOT_DEBUG=1)
message (" Dynamic AOT debug enabled")
endif ()
if (WAMR_BUILD_LOAD_CUSTOM_SECTION EQUAL 1)
add_definitions (-DWASM_ENABLE_LOAD_CUSTOM_SECTION=1)
message (" Load custom section enabled")
@ -508,26 +392,6 @@ endif ()
if (WAMR_BUILD_WASI_NN EQUAL 1)
message (" WASI-NN enabled")
add_definitions (-DWASM_ENABLE_WASI_NN=1)
# Variant backends
if (NOT WAMR_BUILD_WASI_NN_TFLITE EQUAL 1 AND
NOT WAMR_BUILD_WASI_NN_OPENVINO EQUAL 1 AND
NOT WAMR_BUILD_WASI_NN_LLAMACPP EQUAL 1)
message (FATAL_ERROR " Need to select a backend for WASI-NN")
endif ()
if (WAMR_BUILD_WASI_NN_TFLITE EQUAL 1)
message (" WASI-NN: backend tflite enabled")
add_definitions (-DWASM_ENABLE_WASI_NN_TFLITE)
endif ()
if (WAMR_BUILD_WASI_NN_OPENVINO EQUAL 1)
message (" WASI-NN: backend openvino enabled")
add_definitions (-DWASM_ENABLE_WASI_NN_OPENVINO)
endif ()
if (WAMR_BUILD_WASI_NN_LLAMACPP EQUAL 1)
message (" WASI-NN: backend llamacpp enabled")
add_definitions (-DWASM_ENABLE_WASI_NN_LLAMACPP)
endif ()
# Variant devices
if (WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1)
message (" WASI-NN: GPU enabled")
add_definitions (-DWASM_ENABLE_WASI_NN_GPU=1)
@ -539,10 +403,6 @@ if (WAMR_BUILD_WASI_NN EQUAL 1)
if (DEFINED WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH)
add_definitions (-DWASM_WASI_NN_EXTERNAL_DELEGATE_PATH="${WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH}")
endif ()
if (WAMR_BUILD_WASI_EPHEMERAL_NN EQUAL 1)
message (" WASI-NN: use 'wasi_ephemeral_nn' instead of 'wasi-nn'")
add_definitions (-DWASM_ENABLE_WASI_EPHEMERAL_NN=1)
endif()
endif ()
if (WAMR_BUILD_ALLOC_WITH_USER_DATA EQUAL 1)
add_definitions(-DWASM_MEM_ALLOC_WITH_USER_DATA=1)
@ -556,7 +416,7 @@ if (WAMR_BUILD_MODULE_INST_CONTEXT EQUAL 1)
message (" Module instance context enabled")
endif ()
if (WAMR_BUILD_GC_HEAP_VERIFY EQUAL 1)
add_definitions (-DBH_ENABLE_GC_VERIFY=1)
add_definitions (-DWASM_ENABLE_GC_VERIFY=1)
message (" GC heap verification enabled")
endif ()
if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
@ -614,7 +474,7 @@ if (WAMR_BUILD_TARGET STREQUAL "X86_64"
message (" Write linear memory base addr to x86 GS register enabled")
endif ()
endif ()
if (WAMR_CONFIGURABLE_BOUNDS_CHECKS EQUAL 1)
if (WAMR_CONFIGUABLE_BOUNDS_CHECKS EQUAL 1)
add_definitions (-DWASM_CONFIGURABLE_BOUNDS_CHECKS=1)
message (" Configurable bounds checks enabled")
endif ()
@ -638,69 +498,3 @@ else ()
# Disable quick aot/jit entries for interp and fast-jit
add_definitions (-DWASM_ENABLE_QUICK_AOT_ENTRY=0)
endif ()
if (WAMR_BUILD_AOT EQUAL 1)
if (NOT DEFINED WAMR_BUILD_AOT_INTRINSICS)
# Enable aot intrinsics by default
set (WAMR_BUILD_AOT_INTRINSICS 1)
endif ()
if (WAMR_BUILD_AOT_INTRINSICS EQUAL 1)
add_definitions (-DWASM_ENABLE_AOT_INTRINSICS=1)
message (" AOT intrinsics enabled")
else ()
add_definitions (-DWASM_ENABLE_AOT_INTRINSICS=0)
message (" AOT intrinsics disabled")
endif ()
else ()
# Disable aot intrinsics for interp, fast-jit and llvm-jit
add_definitions (-DWASM_ENABLE_AOT_INTRINSICS=0)
endif ()
if (WAMR_BUILD_ALLOC_WITH_USAGE EQUAL 1)
add_definitions(-DWASM_MEM_ALLOC_WITH_USAGE=1)
endif()
if (NOT WAMR_BUILD_SANITIZER STREQUAL "")
message (" Sanitizer ${WAMR_BUILD_SANITIZER} enabled")
endif ()
if (WAMR_BUILD_SHRUNK_MEMORY EQUAL 1)
add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=1)
message (" Shrunk memory enabled")
else ()
add_definitions (-DWASM_ENABLE_SHRUNK_MEMORY=0)
message (" Shrunk memory disabled")
endif()
if (WAMR_BUILD_AOT_VALIDATOR EQUAL 1)
message (" AOT validator enabled")
add_definitions (-DWASM_ENABLE_AOT_VALIDATOR=1)
endif ()
########################################
# Show Phase4 Wasm proposals status.
########################################
message (
"-- About Wasm Proposals:\n"
" Always-on:\n"
" \"Multi-value\"\n"
" \"Non-trapping float-to-int conversions\"\n"
" \"Sign-extension operators\"\n"
" \"WebAssembly C and C++ API\"\n"
" Configurable. 0 is OFF. 1 is ON:\n"
" \"Bulk Memory Operation\" via WAMR_BUILD_BULK_MEMORY: ${WAMR_BUILD_BULK_MEMORY}\n"
" \"Fixed-width SIMD\" via WAMR_BUILD_SIMD: ${WAMR_BUILD_SIMD}\n"
" \"Garbage collection\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n"
" \"Legacy Exception handling\" via WAMR_BUILD_EXCE_HANDLING: ${WAMR_BUILD_EXCE_HANDLING}\n"
" \"Memory64\" via WAMR_BUILD_MEMORY64: ${WAMR_BUILD_MEMORY64}\n"
" \"Multiple memories\" via WAMR_BUILD_MULTI_MEMORY: ${WAMR_BUILD_MULTI_MEMORY}\n"
" \"Reference Types\" via WAMR_BUILD_REF_TYPES: ${WAMR_BUILD_REF_TYPES}\n"
" \"Reference-Typed Strings\" via WAMR_BUILD_STRINGREF: ${WAMR_BUILD_STRINGREF}\n"
" \"Tail call\" via WAMR_BUILD_TAIL_CALL: ${WAMR_BUILD_TAIL_CALL}\n"
" \"Threads\" via WAMR_BUILD_SHARED_MEMORY: ${WAMR_BUILD_SHARED_MEMORY}\n"
" \"Typed Function References\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n"
" Unsupported (>= Phase4):\n"
" \"Branch Hinting\"\n"
" \"Custom Annotation Syntax in the Text Format\"\n"
" \"Exception handling\"\n"
" \"Extended Constant Expressions\"\n"
" \"Import/Export of Mutable Globals\"\n"
" \"JS String Builtins\"\n"
" \"Relaxed SIMD\"\n"
)

View File

@ -11,7 +11,7 @@ You can build an ESP-IDF project with wasm-micro-runtime as a component:
- In the newly created project folder edit the `CMakeList.txt`:
```
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

View File

@ -5,11 +5,7 @@
if (NOT CMAKE_BUILD_EARLY_EXPANSION)
if (CONFIG_IDF_TARGET_ARCH_RISCV)
if (CONFIG_IDF_TARGET_ESP32P4)
set (WAMR_BUILD_TARGET "RISCV32_ILP32F")
else ()
set (WAMR_BUILD_TARGET "RISCV32_ILP32")
endif ()
set (WAMR_BUILD_TARGET "RISCV32")
elseif (CONFIG_IDF_TARGET_ARCH_XTENSA)
set (WAMR_BUILD_TARGET "XTENSA")
else ()
@ -40,6 +36,12 @@ if (NOT CMAKE_BUILD_EARLY_EXPANSION)
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()
if (CONFIG_WAMR_ENABLE_APP_FRAMEWORK)
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE)
set (WAMR_APP_THREAD_STACK_SIZE_MAX ${CONFIG_WAMR_APP_THREAD_STACK_SIZE_MAX})
endif ()
if (CONFIG_WAMR_INTERP_LOADER_MINI)
set (WAMR_BUILD_MINI_LOADER 1)
endif ()
@ -83,6 +85,14 @@ if (NOT CMAKE_BUILD_EARLY_EXPANSION)
"${PLATFORM_SHARED_DIR}"
"${PLATFORM_SHARED_DIR}/../include"
"${IWASM_COMMON_DIR}")
if (CONFIG_WAMR_ENABLE_APP_FRAMEWORK)
list (APPEND include_dirs "${APP_MGR_SHARED_DIR}"
"${__APP_MGR_DIR}"
"${NATIVE_INTERFACE_DIR}"
"${WASM_APP_LIBS_DIR}"
"${APP_FRAMEWORK_ROOT_DIR}/base/app")
endif ()
endif ()
idf_component_register(SRCS ${srcs}
@ -93,11 +103,7 @@ idf_component_register(SRCS ${srcs}
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
if (CONFIG_IDF_TARGET_ARCH_RISCV)
if (CONFIG_IDF_TARGET_ESP32P4)
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_RISCV32_ILP32F=1)
else ()
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_RISCV32_ILP32=1)
endif ()
elseif (CONFIG_IDF_TARGET_ARCH_XTENSA)
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_XTENSA=1)
endif ()

View File

@ -74,4 +74,15 @@ menu "WASM Micro Runtime"
config WAMR_ENABLE_SHARED_MEMORY
bool "Shared memory"
default n
menuconfig WAMR_ENABLE_APP_FRAMEWORK
bool "App framework"
default y
if WAMR_ENABLE_APP_FRAMEWORK
config WAMR_APP_THREAD_STACK_SIZE_MAX
int "Application thread max stack size"
default 131072
endif
endmenu

View File

@ -1,30 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set(_WAMR_BUILD_SCRIPTS_DIR "${CMAKE_CURRENT_LIST_DIR}")
function(install_iwasm_package)
install (EXPORT iwasmTargets
FILE iwasmTargets.cmake
NAMESPACE iwasm::
DESTINATION lib/cmake/iwasm
)
include (CMakePackageConfigHelpers)
configure_package_config_file (${_WAMR_BUILD_SCRIPTS_DIR}/iwasmConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/iwasmConfig.cmake"
INSTALL_DESTINATION lib/cmake/iwasm
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/iwasmConfigVersion.cmake"
VERSION ${WAMR_VERSION_MAJOR}.${WAMR_VERSION_MINOR}.${WAMR_VERSION_PATCH}
COMPATIBILITY SameMajorVersion
)
install (FILES
"${CMAKE_CURRENT_BINARY_DIR}/iwasmConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/iwasmConfigVersion.cmake"
DESTINATION lib/cmake/iwasm
)
endfunction()

View File

@ -1 +1 @@
requests==2.32.3
requests==2.31.0

View File

@ -10,11 +10,17 @@ endif ()
if (NOT DEFINED IWASM_DIR)
set (IWASM_DIR ${WAMR_ROOT_DIR}/core/iwasm)
endif ()
if (NOT DEFINED APP_MGR_DIR)
set (APP_MGR_DIR ${WAMR_ROOT_DIR}/core/app-mgr)
endif ()
if (NOT DEFINED APP_FRAMEWORK_DIR)
set (APP_FRAMEWORK_DIR ${WAMR_ROOT_DIR}/core/app-framework)
endif ()
if (NOT DEFINED DEPS_DIR)
set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
endif ()
if (NOT DEFINED SHARED_PLATFORM_CONFIG)
# CMake file for platform configuration. The PLATFORM_SHARED_SOURCE variable
# CMake file for platform configuration. The PLATFORM_SHARED_SOURCE varable
# should point to a list of platform-specfic source files to compile.
set (SHARED_PLATFORM_CONFIG ${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
endif ()
@ -59,13 +65,8 @@ if (WAMR_BUILD_INTERP EQUAL 1)
endif ()
if (WAMR_BUILD_FAST_JIT EQUAL 1)
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
message ("Fast JIT currently not supported on Windows")
set (WAMR_BUILD_FAST_JIT 0)
else ()
include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake)
endif ()
endif ()
if (WAMR_BUILD_JIT EQUAL 1)
# Enable AOT if LLVM JIT is enabled
@ -77,14 +78,11 @@ if (WAMR_BUILD_AOT EQUAL 1)
include (${IWASM_DIR}/aot/iwasm_aot.cmake)
endif ()
if (WAMR_BUILD_STRINGREF EQUAL 1)
set (WAMR_BUILD_GC 1)
endif ()
if (WAMR_BUILD_GC EQUAL 1)
include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
# Enable the dependent feature if GC is enabled
set (WAMR_BUILD_REF_TYPES 1)
if (WAMR_BUILD_APP_FRAMEWORK EQUAL 1)
include (${APP_FRAMEWORK_DIR}/app_framework.cmake)
include (${SHARED_DIR}/coap/lib_coap.cmake)
include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
endif ()
if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
@ -109,10 +107,6 @@ if (WAMR_BUILD_WASI_NN EQUAL 1)
endif ()
if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
set (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 0)
message ("Lib pthread semaphore currently not supported on Windows")
endif ()
include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
# Enable the dependent feature if lib pthread is enabled
set (WAMR_BUILD_THREAD_MGR 1)
@ -128,10 +122,6 @@ if (WAMR_BUILD_LIB_WASI_THREADS EQUAL 1)
set (WAMR_BUILD_SHARED_MEMORY 1)
endif ()
if (WAMR_BUILD_SHARED_HEAP EQUAL 1)
include (${IWASM_DIR}/libraries/shared-heap/shared_heap.cmake)
endif ()
if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
set (WAMR_BUILD_THREAD_MGR 1)
include (${IWASM_DIR}/libraries/debug-engine/debug_engine.cmake)
@ -168,18 +158,6 @@ endif ()
# include the build config template file
include (${CMAKE_CURRENT_LIST_DIR}/config_common.cmake)
if (WAMR_BUILD_SIMD EQUAL 1 AND WAMR_BUILD_FAST_INTERP EQUAL 1)
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
message(STATUS "SIMDe doesnt support platform " ${WAMR_BUILD_PLATFORM})
set(WAMR_BUILD_SIMDE 0)
else()
include (${IWASM_DIR}/libraries/simde/simde.cmake)
set (WAMR_BUILD_SIMDE 1)
endif()
else()
set(WAMR_BUILD_SIMDE 0)
endif ()
include_directories (${IWASM_DIR}/include)
file (GLOB header
@ -211,14 +189,15 @@ set (source_all
${IWASM_AOT_SOURCE}
${IWASM_COMPL_SOURCE}
${IWASM_FAST_JIT_SOURCE}
${IWASM_GC_SOURCE}
${WASM_APP_LIB_SOURCE_ALL}
${NATIVE_INTERFACE_SOURCE}
${APP_MGR_SOURCE}
${LIB_WASI_THREADS_SOURCE}
${LIB_PTHREAD_SOURCE}
${THREAD_MGR_SOURCE}
${LIBC_EMCC_SOURCE}
${LIB_RATS_SOURCE}
${DEBUG_ENGINE_SOURCE}
${LIB_SHARED_HEAP_SOURCE}
)
set (WAMR_RUNTIME_LIB_SOURCE ${source_all})

View File

@ -1,28 +0,0 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
if(NOT WAMR_ROOT_DIR)
# if from wamr-compiler
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
endif()
set(WAMR_VERSION_MAJOR 2)
set(WAMR_VERSION_MINOR 3)
set(WAMR_VERSION_PATCH 0)
message("-- WAMR version: ${WAMR_VERSION_MAJOR}.${WAMR_VERSION_MINOR}.${WAMR_VERSION_PATCH}")
# Configure the version header file
configure_file(
${WAMR_ROOT_DIR}/core/version.h.in
${WAMR_ROOT_DIR}/core/version.h
)
# Set the library version and SOVERSION
function(set_version_info target)
set_target_properties(${target}
PROPERTIES
VERSION ${WAMR_VERSION_MAJOR}.${WAMR_VERSION_MINOR}.${WAMR_VERSION_PATCH}
SOVERSION ${WAMR_VERSION_MAJOR}
)
endfunction()

View File

@ -14,7 +14,7 @@ docker build \
--cap-add=SYS_PTRACE \
--cpus=".5" \
--memory=4G \
--mount type=bind,src="${ROOT}",dst=/workspaces \
--mount type=bind,src="${ROOT}",dst=/workspace \
--name wamr_build_env \
--security-opt=seccomp=unconfined \
wamr_dev_${VARIANT}:0.1 \

View File

@ -5,7 +5,7 @@
#
import argparse
import re
from pathlib import Path
import pathlib
import re
import shlex
import shutil
@ -13,14 +13,15 @@ import subprocess
import sys
import unittest
CLANG_FORMAT_CMD = "clang-format-14"
GIT_CLANG_FORMAT_CMD = "git-clang-format-14"
CLANG_FORMAT_CMD = "clang-format-12"
GIT_CLANG_FORMAT_CMD = "git-clang-format-12"
# glob style patterns
EXCLUDE_PATHS = [
"**/.git/*",
"**/.github/*",
"**/.vscode/*",
"**/assembly-script/*",
"**/build/*",
"**/build-scripts/*",
"**/ci/*",
@ -29,10 +30,12 @@ EXCLUDE_PATHS = [
"**/samples/wasm-c-api/src/*.*",
"**/samples/workload/*",
"**/test-tools/wasi-sdk/*",
"**/test-tools/IoT-APP-Store-Demo/*",
"**/tests/wamr-test-suites/workspace/*",
"**/wamr-sdk/*",
]
C_SUFFIXES = [".c", ".cc", ".cpp", ".h"]
C_SUFFIXES = [".c", ".cpp", ".h"]
INVALID_DIR_NAME_SEGMENT = r"([a-zA-Z0-9]+\_[a-zA-Z0-9]+)"
INVALID_FILE_NAME_SEGMENT = r"([a-zA-Z0-9]+\-[a-zA-Z0-9]+)"
@ -46,18 +49,18 @@ def locate_command(command: str) -> bool:
def is_excluded(path: str) -> bool:
path = Path(path).resolve()
path = pathlib.Path(path).resolve()
for exclude_path in EXCLUDE_PATHS:
if path.match(exclude_path):
return True
return False
def pre_flight_check(root: Path) -> bool:
def pre_flight_check(root: pathlib) -> bool:
def check_aspell(root):
return True
def check_clang_format(root: Path) -> bool:
def check_clang_foramt(root: pathlib) -> bool:
if not locate_command(CLANG_FORMAT_CMD):
return False
@ -74,10 +77,10 @@ def pre_flight_check(root: Path) -> bool:
def check_git_clang_format() -> bool:
return locate_command(GIT_CLANG_FORMAT_CMD)
return check_aspell(root) and check_clang_format(root) and check_git_clang_format()
return check_aspell(root) and check_clang_foramt(root) and check_git_clang_format()
def run_clang_format(file_path: Path, root: Path) -> bool:
def run_clang_format(file_path: pathlib, root: pathlib) -> bool:
try:
subprocess.check_call(
shlex.split(
@ -91,31 +94,22 @@ def run_clang_format(file_path: Path, root: Path) -> bool:
return False
def run_clang_format_diff(root: Path, commits: str) -> bool:
def run_clang_format_diff(root: pathlib, commits: str) -> bool:
"""
Use `clang-format-14` or `git-clang-format-14` to check code format of
Use `clang-format-12` or `git-clang-format-12` to check code format of
the PR, with a commit range specified. It is required to format the
code before committing the PR, or it might fail to pass the CI check:
1. Install clang-format-14.0.0
You can download the package from
https://github.com/llvm/llvm-project/releases
and install it.
For Debian/Ubuntu, we can probably use
`sudo apt-get install clang-format-14`.
Homebrew has it as a part of llvm@14.
```shell
brew install llvm@14
/usr/local/opt/llvm@14/bin/clang-format
```
1. Install clang-format-12.0.0
Normally we can install it by `sudo apt-get install clang-format-12`,
or download the `clang+llvm-12.0.0-xxx-tar.xz` package from
https://github.com/llvm/llvm-project/releases/tag/llvmorg-12.0.0
and install it
2. Format the C/C++ source file
``` shell
cd path/to/wamr/root
clang-format-14 --style file -i path/to/file
clang-format-12 --style file -i path/to/file
```
The code wrapped by `/* clang-format off */` and `/* clang-format on */`
@ -154,7 +148,7 @@ def run_clang_format_diff(root: Path, commits: str) -> bool:
found = False
for summary in [x for x in diff_content if x.startswith("diff --git")]:
# b/path/to/file -> path/to/file
with_invalid_format = re.split(r"\s+", summary)[-1][2:]
with_invalid_format = re.split("\s+", summary)[-1][2:]
if not is_excluded(with_invalid_format):
print(f"--- {with_invalid_format} failed on code style checking.")
found = True
@ -164,11 +158,11 @@ def run_clang_format_diff(root: Path, commits: str) -> bool:
return False
def run_aspell(file_path: Path, root: Path) -> bool:
def run_aspell(file_path: pathlib, root: pathlib) -> bool:
return True
def check_dir_name(path: Path, root: Path) -> bool:
def check_dir_name(path: pathlib, root: pathlib) -> bool:
m = re.search(INVALID_DIR_NAME_SEGMENT, str(path.relative_to(root).parent))
if m:
print(f"--- found a character '_' in {m.groups()} in {path}")
@ -176,23 +170,7 @@ def check_dir_name(path: Path, root: Path) -> bool:
return not m
def check_file_name(path: Path) -> bool:
"""
file names should not contain any character '-'
but some names are well known and use '-' as the separator, e.g.:
- docker-compose
- package-lock
- vite-env.d
"""
if path.stem in [
"docker-compose",
"package-lock",
"vite-env.d",
"osv-scanner",
]:
return True
def check_file_name(path: pathlib) -> bool:
m = re.search(INVALID_FILE_NAME_SEGMENT, path.stem)
if m:
print(f"--- found a character '-' in {m.groups()} in {path}")
@ -200,7 +178,7 @@ def check_file_name(path: Path) -> bool:
return not m
def parse_commits_range(root: Path, commits: str) -> list:
def parse_commits_range(root: pathlib, commits: str) -> list:
GIT_LOG_CMD = f"git log --pretty='%H' {commits}"
try:
ret = subprocess.check_output(
@ -212,7 +190,7 @@ def parse_commits_range(root: Path, commits: str) -> list:
return []
def analysis_new_item_name(root: Path, commit: str) -> bool:
def analysis_new_item_name(root: pathlib, commit: str) -> bool:
"""
For any file name in the repo, it is required to use '_' to replace '-'.
@ -241,7 +219,7 @@ def analysis_new_item_name(root: Path, commit: str) -> bool:
continue
new_item = match.group(1)
new_item = Path(new_item).resolve()
new_item = pathlib.Path(new_item).resolve()
if new_item.is_file():
if not check_file_name(new_item):
@ -260,7 +238,7 @@ def analysis_new_item_name(root: Path, commit: str) -> bool:
return False
def process_entire_pr(root: Path, commits: str) -> bool:
def process_entire_pr(root: pathlib, commits: str) -> bool:
if not commits:
print("Please provide a commits range")
return False
@ -293,7 +271,7 @@ def main() -> int:
)
options = parser.parse_args()
wamr_root = Path(__file__).parent.joinpath("..").resolve()
wamr_root = pathlib.Path(__file__).parent.joinpath("..").resolve()
if not pre_flight_check(wamr_root):
return False
@ -304,23 +282,23 @@ def main() -> int:
# run with python3 -m unitest ci/coding_guidelines_check.py
class TestCheck(unittest.TestCase):
def test_check_dir_name_failed(self):
root = Path("/root/Workspace/")
root = pathlib.Path("/root/Workspace/")
new_file_path = root.joinpath("core/shared/platform/esp_idf/espid_memmap.c")
self.assertFalse(check_dir_name(new_file_path, root))
def test_check_dir_name_pass(self):
root = Path("/root/Workspace/")
root = pathlib.Path("/root/Workspace/")
new_file_path = root.joinpath("core/shared/platform/esp-idf/espid_memmap.c")
self.assertTrue(check_dir_name(new_file_path, root))
def test_check_file_name_failed(self):
new_file_path = Path(
new_file_path = pathlib.Path(
"/root/Workspace/core/shared/platform/esp-idf/espid-memmap.c"
)
self.assertFalse(check_file_name(new_file_path))
def test_check_file_name_pass(self):
new_file_path = Path(
new_file_path = pathlib.Path(
"/root/Workspace/core/shared/platform/esp-idf/espid_memmap.c"
)
self.assertTrue(check_file_name(new_file_path))

View File

@ -0,0 +1,120 @@
# Application framework
By using the WAMR VM core, we are flexible to build different application frameworks for the specific domains, although it would take quite some effort.
The WAMR has offered a comprehensive framework for programming WASM applications for device and IoT usages. The framework supports running multiple applications, that are based on the event driven programming model. Here are the supporting API sets by the [WAMR application framework library](../doc/wamr_api.md) :
- Timer, Inter-app communication (request/response and pub/sub), Sensor, Connectivity and data transmission, 2D graphic UI
Browse the folder [core/app-framework](./app-framework) for how to extend the application framework.
## Directory structure
This folder "app-native-shared" is for the source files shared by both WASM APP and native runtime
- The c files in this directory are compiled into both the WASM APP and runtime.
- The header files for distributing to SDK are placed in the "bi-inc" folder.
This folder "template" contains a pre-defined directory structure for a framework component. The developers can copy the template folder to create new components to the application framework.
Every other subfolder is framework component. Each component contains two library parts: **app and native**.
- The "base" component provide timer API and inter-app communication support. It must be enabled if other components are selected.
- Under the "app" folder of a component, the subfolder "wa_inc" holds all header files that should be included by the WASM applications
## Application framework basic model
The app framework is built on top of two fundamental operations:
- [Native calls into WASM function](../../doc/embed_wamr.md)
- [WASM app calls into native API](../../doc/export_native_api.md)
Asynchronized programming model is supported for WASM applications
- Every WASM app has its own sandbox and thread
- Queue and messaging
<img src="../../doc/pics/app_framework.PNG" style="zoom:67%;" />
## Customized building of app framework
A component can be compilation configurable to the runtime. The wamr SDK tool "build_sdk.sh" supports menu config to select app components for building a customized runtime.
A number of CMAKE variables are defined to control build of framework and components. You can create a cmake file for defining these variables and include it in the CMakeList.txt for your software, or pass it in "-x" argument when run the [build_sdk.sh](../../wamr-sdk/build_sdk.sh) for building the runtime SDK.
```cmake
set (WAMR_BUILD_APP_FRAMEWORK 1)
set (WAMR_BUILD_APP_LIST WAMR_APP_BUILD_BASE)
```
Variables:
- **WAMR_BUILD_APP_FRAMEWORK**: enable the application framework
- **WAMR_BUILD_APP_LIST**: the selected components to be built into the final runtime
The configuration file can be generated through the wamr-sdk menu config:
```bash
cd wamr-sdk
./build_sdk -n [profile] -i
```
## Create new components
Generally you should follow following steps to create a new component:
- Copy the “template” for creating a new folder
- Implement the app part
- If your component exports native function to WASM, ensure your created a header file under app for declaring the function prototype.
- If you component provides header files for the WASM applications to include, ensure it is placed under subfolder "wa_inc".
- Implement the native part
- If your native function is exported to WASM, you need to create an inl file for the registration. It can be any file name, assuming the file name is "my_component.inl" here:
```c
//use right signature for your functions
EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_1, "(i*~)i"),
EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_2, "(i)i"),
```
- Ensure "wasm_lib.cmake" is provided as it will be included by the WAMR SDK building script
- Add a definition in "wasm_lib.cmake" for your component, e.g.
```cmake
add_definitions (-DAPP_FRAMEWORK_MY_COMPONENT)
```
- Modify the file [app_ext_lib_export.c](./app_ext_lib_export.c) to register native APIs exported for the new introduced component. Skip it if not exporting native functions.
```
#include "lib_export.h"
...
#ifdef APP_FRAMEWORK_MY_COMPONENT // this definition is created in wasm_lib.cmake
#include "my_component_native_api.h"
#endif
static NativeSymbol extended_native_symbol_defs[] = {
...
#ifdef APP_FRAMEWORK_MY_COMPONENT
#include "my_component.inl"
#endif
};
```
## Sensor component working flow
![](../../doc/pics/sensor_callflow.PNG)

View File

@ -0,0 +1,11 @@
Notes:
=======
This folder is for the source files shared by both WASM APP and native runtime
- The c files in this directory are compiled into both the WASM APP and runtime.
- The header files for distributing to SDK are placed in the "bi-inc" folder.

View File

@ -0,0 +1,986 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bi-inc/attr_container.h"
typedef union jvalue {
bool z;
int8_t i8;
uint8_t u8;
int16_t i16;
uint16_t u16;
int32_t i32;
uint32_t u32;
int64_t i64;
uint64_t u64;
float f;
double d;
} jvalue;
static inline int16_t
get_int16(const char *buf)
{
int16_t ret;
bh_memcpy_s(&ret, sizeof(int16_t), buf, sizeof(int16_t));
return ret;
}
static inline uint16_t
get_uint16(const char *buf)
{
uint16_t ret;
bh_memcpy_s(&ret, sizeof(uint16_t), buf, sizeof(uint16_t));
return ret;
}
static inline int32_t
get_int32(const char *buf)
{
int32_t ret;
bh_memcpy_s(&ret, sizeof(int32_t), buf, sizeof(int32_t));
return ret;
}
static inline uint32_t
get_uint32(const char *buf)
{
uint32_t ret;
bh_memcpy_s(&ret, sizeof(uint32_t), buf, sizeof(uint32_t));
return ret;
}
static inline int64_t
get_int64(const char *buf)
{
int64_t ret;
bh_memcpy_s(&ret, sizeof(int64_t), buf, sizeof(int64_t));
return ret;
}
static inline uint64_t
get_uint64(const char *buf)
{
uint64_t ret;
bh_memcpy_s(&ret, sizeof(uint64_t), buf, sizeof(uint64_t));
return ret;
}
static inline void
set_int16(char *buf, int16_t v)
{
bh_memcpy_s(buf, sizeof(int16_t), &v, sizeof(int16_t));
}
static inline void
set_uint16(char *buf, uint16_t v)
{
bh_memcpy_s(buf, sizeof(uint16_t), &v, sizeof(uint16_t));
}
static inline void
set_int32(char *buf, int32_t v)
{
bh_memcpy_s(buf, sizeof(int32_t), &v, sizeof(int32_t));
}
static inline void
set_uint32(char *buf, uint32_t v)
{
bh_memcpy_s(buf, sizeof(uint32_t), &v, sizeof(uint32_t));
}
static inline void
set_int64(char *buf, int64_t v)
{
bh_memcpy_s(buf, sizeof(int64_t), &v, sizeof(int64_t));
}
static inline void
set_uint64(char *buf, uint64_t v)
{
bh_memcpy_s(buf, sizeof(uint64_t), &v, sizeof(uint64_t));
}
char *
attr_container_get_attr_begin(const attr_container_t *attr_cont,
uint32_t *p_total_length, uint16_t *p_attr_num)
{
char *p = (char *)attr_cont->buf;
uint16_t str_len, attr_num;
uint32_t total_length;
/* skip total length */
total_length = get_uint32(p);
p += sizeof(uint32_t);
if (!total_length)
return NULL;
/* tag length */
str_len = get_uint16(p);
p += sizeof(uint16_t);
if (!str_len)
return NULL;
/* tag content */
p += str_len;
if ((uint32_t)(p - attr_cont->buf) >= total_length)
return NULL;
/* attribute num */
attr_num = get_uint16(p);
p += sizeof(uint16_t);
if ((uint32_t)(p - attr_cont->buf) >= total_length)
return NULL;
if (p_total_length)
*p_total_length = total_length;
if (p_attr_num)
*p_attr_num = attr_num;
/* first attribute */
return p;
}
static char *
attr_container_get_attr_next(const char *curr_attr)
{
char *p = (char *)curr_attr;
uint8_t type;
/* key length and key */
p += sizeof(uint16_t) + get_uint16(p);
type = *p++;
/* Byte type to Boolean type */
if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) {
p += 1 << (type & 3);
return p;
}
/* String type */
else if (type == ATTR_TYPE_STRING) {
p += sizeof(uint16_t) + get_uint16(p);
return p;
}
/* ByteArray type */
else if (type == ATTR_TYPE_BYTEARRAY) {
p += sizeof(uint32_t) + get_uint32(p);
return p;
}
return NULL;
}
static const char *
attr_container_find_attr(const attr_container_t *attr_cont, const char *key)
{
uint32_t total_length;
uint16_t str_len, attr_num, i;
const char *p = attr_cont->buf;
if (!key)
return NULL;
if (!(p = attr_container_get_attr_begin(attr_cont, &total_length,
&attr_num)))
return NULL;
for (i = 0; i < attr_num; i++) {
/* key length */
if (!(str_len = get_uint16(p)))
return NULL;
if (str_len == strlen(key) + 1
&& memcmp(p + sizeof(uint16_t), key, str_len) == 0) {
if ((uint32_t)(p + sizeof(uint16_t) + str_len - attr_cont->buf)
>= total_length)
return NULL;
return p;
}
if (!(p = attr_container_get_attr_next(p)))
return NULL;
}
return NULL;
}
char *
attr_container_get_attr_end(const attr_container_t *attr_cont)
{
uint32_t total_length;
uint16_t attr_num, i;
char *p;
if (!(p = attr_container_get_attr_begin(attr_cont, &total_length,
&attr_num)))
return NULL;
for (i = 0; i < attr_num; i++)
if (!(p = attr_container_get_attr_next(p)))
return NULL;
return p;
}
static char *
attr_container_get_msg_end(attr_container_t *attr_cont)
{
char *p = attr_cont->buf;
return p + get_uint32(p);
}
uint16_t
attr_container_get_attr_num(const attr_container_t *attr_cont)
{
uint16_t str_len;
/* skip total length */
const char *p = attr_cont->buf + sizeof(uint32_t);
str_len = get_uint16(p);
/* skip tag length and tag */
p += sizeof(uint16_t) + str_len;
/* attribute num */
return get_uint16(p);
}
static void
attr_container_inc_attr_num(attr_container_t *attr_cont)
{
uint16_t str_len, attr_num;
/* skip total length */
char *p = attr_cont->buf + sizeof(uint32_t);
str_len = get_uint16(p);
/* skip tag length and tag */
p += sizeof(uint16_t) + str_len;
/* attribute num */
attr_num = get_uint16(p) + 1;
set_uint16(p, attr_num);
}
attr_container_t *
attr_container_create(const char *tag)
{
attr_container_t *attr_cont;
int length, tag_length;
char *p;
tag_length = tag ? strlen(tag) + 1 : 1;
length = offsetof(attr_container_t, buf) +
/* total length + tag length + tag + reserved 100 bytes */
sizeof(uint32_t) + sizeof(uint16_t) + tag_length + 100;
if (!(attr_cont = attr_container_malloc(length))) {
attr_container_printf(
"Create attr_container failed: allocate memory failed.\r\n");
return NULL;
}
memset(attr_cont, 0, length);
p = attr_cont->buf;
/* total length */
set_uint32(p, length - offsetof(attr_container_t, buf));
p += 4;
/* tag length, tag */
set_uint16(p, tag_length);
p += 2;
if (tag)
bh_memcpy_s(p, tag_length, tag, tag_length);
return attr_cont;
}
void
attr_container_destroy(const attr_container_t *attr_cont)
{
if (attr_cont)
attr_container_free((char *)attr_cont);
}
static bool
check_set_attr(attr_container_t **p_attr_cont, const char *key)
{
uint32_t flags;
if (!p_attr_cont || !*p_attr_cont || !key || strlen(key) == 0) {
attr_container_printf(
"Set attribute failed: invalid input arguments.\r\n");
return false;
}
flags = get_uint32((char *)*p_attr_cont);
if (flags & ATTR_CONT_READONLY_SHIFT) {
attr_container_printf(
"Set attribute failed: attribute container is readonly.\r\n");
return false;
}
return true;
}
bool
attr_container_set_attr(attr_container_t **p_attr_cont, const char *key,
int type, const void *value, int value_length)
{
attr_container_t *attr_cont, *attr_cont1;
uint16_t str_len;
uint32_t total_length, attr_len;
char *p, *p1, *attr_end, *msg_end, *attr_buf;
if (!check_set_attr(p_attr_cont, key)) {
return false;
}
attr_cont = *p_attr_cont;
p = attr_cont->buf;
total_length = get_uint32(p);
if (!(attr_end = attr_container_get_attr_end(attr_cont))) {
attr_container_printf("Set attr failed: get attr end failed.\r\n");
return false;
}
msg_end = attr_container_get_msg_end(attr_cont);
/* key len + key + '\0' + type */
attr_len = sizeof(uint16_t) + strlen(key) + 1 + 1;
if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN)
attr_len += 1 << (type & 3);
else if (type == ATTR_TYPE_STRING)
attr_len += sizeof(uint16_t) + value_length;
else if (type == ATTR_TYPE_BYTEARRAY)
attr_len += sizeof(uint32_t) + value_length;
if (!(p = attr_buf = attr_container_malloc(attr_len))) {
attr_container_printf("Set attr failed: allocate memory failed.\r\n");
return false;
}
/* Set the attr buf */
str_len = (uint16_t)(strlen(key) + 1);
set_uint16(p, str_len);
p += sizeof(uint16_t);
bh_memcpy_s(p, str_len, key, str_len);
p += str_len;
*p++ = type;
if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN)
bh_memcpy_s(p, 1 << (type & 3), value, 1 << (type & 3));
else if (type == ATTR_TYPE_STRING) {
set_uint16(p, value_length);
p += sizeof(uint16_t);
bh_memcpy_s(p, value_length, value, value_length);
}
else if (type == ATTR_TYPE_BYTEARRAY) {
set_uint32(p, value_length);
p += sizeof(uint32_t);
bh_memcpy_s(p, value_length, value, value_length);
}
if ((p = (char *)attr_container_find_attr(attr_cont, key))) {
/* key found */
p1 = attr_container_get_attr_next(p);
if (p1 - p == attr_len) {
bh_memcpy_s(p, attr_len, attr_buf, attr_len);
attr_container_free(attr_buf);
return true;
}
if ((uint32_t)(p1 - p + msg_end - attr_end) >= attr_len) {
memmove(p, p1, attr_end - p1);
bh_memcpy_s(p + (attr_end - p1), attr_len, attr_buf, attr_len);
attr_container_free(attr_buf);
return true;
}
total_length += attr_len + 100;
if (!(attr_cont1 = attr_container_malloc(offsetof(attr_container_t, buf)
+ total_length))) {
attr_container_printf(
"Set attr failed: allocate memory failed.\r\n");
attr_container_free(attr_buf);
return false;
}
bh_memcpy_s(attr_cont1, p - (char *)attr_cont, attr_cont,
p - (char *)attr_cont);
bh_memcpy_s((char *)attr_cont1 + (unsigned)(p - (char *)attr_cont),
attr_end - p1, p1, attr_end - p1);
bh_memcpy_s((char *)attr_cont1 + (unsigned)(p - (char *)attr_cont)
+ (unsigned)(attr_end - p1),
attr_len, attr_buf, attr_len);
p = attr_cont1->buf;
set_uint32(p, total_length);
*p_attr_cont = attr_cont1;
/* Free original buffer */
attr_container_free(attr_cont);
attr_container_free(attr_buf);
return true;
}
else {
/* key not found */
if ((uint32_t)(msg_end - attr_end) >= attr_len) {
bh_memcpy_s(attr_end, msg_end - attr_end, attr_buf, attr_len);
attr_container_inc_attr_num(attr_cont);
attr_container_free(attr_buf);
return true;
}
total_length += attr_len + 100;
if (!(attr_cont1 = attr_container_malloc(offsetof(attr_container_t, buf)
+ total_length))) {
attr_container_printf(
"Set attr failed: allocate memory failed.\r\n");
attr_container_free(attr_buf);
return false;
}
bh_memcpy_s(attr_cont1, attr_end - (char *)attr_cont, attr_cont,
attr_end - (char *)attr_cont);
bh_memcpy_s((char *)attr_cont1
+ (unsigned)(attr_end - (char *)attr_cont),
attr_len, attr_buf, attr_len);
attr_container_inc_attr_num(attr_cont1);
p = attr_cont1->buf;
set_uint32(p, total_length);
*p_attr_cont = attr_cont1;
/* Free original buffer */
attr_container_free(attr_cont);
attr_container_free(attr_buf);
return true;
}
return false;
}
bool
attr_container_set_short(attr_container_t **p_attr_cont, const char *key,
short value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_SHORT, &value,
2);
}
bool
attr_container_set_int16(attr_container_t **p_attr_cont, const char *key,
int16_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT16, &value,
2);
}
bool
attr_container_set_int(attr_container_t **p_attr_cont, const char *key,
int value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT, &value, 4);
}
bool
attr_container_set_int32(attr_container_t **p_attr_cont, const char *key,
int32_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT32, &value,
4);
}
bool
attr_container_set_uint32(attr_container_t **p_attr_cont, const char *key,
uint32_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT32, &value,
4);
}
bool
attr_container_set_int64(attr_container_t **p_attr_cont, const char *key,
int64_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT64, &value,
8);
}
bool
attr_container_set_uint64(attr_container_t **p_attr_cont, const char *key,
uint64_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT64, &value,
8);
}
bool
attr_container_set_byte(attr_container_t **p_attr_cont, const char *key,
int8_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BYTE, &value, 1);
}
bool
attr_container_set_int8(attr_container_t **p_attr_cont, const char *key,
int8_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT8, &value, 1);
}
bool
attr_container_set_uint8(attr_container_t **p_attr_cont, const char *key,
uint8_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT8, &value,
1);
}
bool
attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key,
uint16_t value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT16, &value,
2);
}
bool
attr_container_set_float(attr_container_t **p_attr_cont, const char *key,
float value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_FLOAT, &value,
4);
}
bool
attr_container_set_double(attr_container_t **p_attr_cont, const char *key,
double value)
{
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_DOUBLE, &value,
8);
}
bool
attr_container_set_bool(attr_container_t **p_attr_cont, const char *key,
bool value)
{
int8_t value1 = value ? 1 : 0;
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BOOLEAN, &value1,
1);
}
bool
attr_container_set_string(attr_container_t **p_attr_cont, const char *key,
const char *value)
{
if (!value) {
attr_container_printf("Set attr failed: invald input arguments.\r\n");
return false;
}
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_STRING, value,
strlen(value) + 1);
}
bool
attr_container_set_bytearray(attr_container_t **p_attr_cont, const char *key,
const int8_t *value, unsigned length)
{
if (!value) {
attr_container_printf("Set attr failed: invald input arguments.\r\n");
return false;
}
return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BYTEARRAY, value,
length);
}
static const char *
attr_container_get_attr(const attr_container_t *attr_cont, const char *key)
{
const char *attr_addr;
if (!attr_cont || !key) {
attr_container_printf(
"Get attribute failed: invalid input arguments.\r\n");
return NULL;
}
if (!(attr_addr = attr_container_find_attr(attr_cont, key))) {
attr_container_printf("Get attribute failed: lookup key failed.\r\n");
return NULL;
}
/* key len + key + '\0' */
return attr_addr + 2 + strlen(key) + 1;
}
#define TEMPLATE_ATTR_BUF_TO_VALUE(attr, key, var_name) \
do { \
jvalue val; \
const char *addr = attr_container_get_attr(attr, key); \
uint8_t type; \
if (!addr) \
return 0; \
val.i64 = 0; \
type = *(uint8_t *)addr++; \
switch (type) { \
case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ \
case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ \
case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ \
case ATTR_TYPE_INT64: \
case ATTR_TYPE_UINT8: \
case ATTR_TYPE_UINT16: \
case ATTR_TYPE_UINT32: \
case ATTR_TYPE_UINT64: \
case ATTR_TYPE_FLOAT: \
case ATTR_TYPE_DOUBLE: \
case ATTR_TYPE_BOOLEAN: \
bh_memcpy_s(&val, sizeof(val.var_name), addr, \
1 << (type & 3)); \
break; \
case ATTR_TYPE_STRING: \
{ \
unsigned len = get_uint16(addr); \
addr += 2; \
if (len > sizeof(val.var_name)) \
len = sizeof(val.var_name); \
bh_memcpy_s(&val.var_name, sizeof(val.var_name), addr, len); \
break; \
} \
case ATTR_TYPE_BYTEARRAY: \
{ \
unsigned len = get_uint32(addr); \
addr += 4; \
if (len > sizeof(val.var_name)) \
len = sizeof(val.var_name); \
bh_memcpy_s(&val.var_name, sizeof(val.var_name), addr, len); \
break; \
} \
default: \
bh_assert(0); \
break; \
} \
return val.var_name; \
} while (0)
short
attr_container_get_as_short(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i16);
}
int16_t
attr_container_get_as_int16(const attr_container_t *attr_cont, const char *key)
{
return (int16_t)attr_container_get_as_short(attr_cont, key);
}
int
attr_container_get_as_int(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i32);
}
int32_t
attr_container_get_as_int32(const attr_container_t *attr_cont, const char *key)
{
return (int32_t)attr_container_get_as_int(attr_cont, key);
}
uint32_t
attr_container_get_as_uint32(const attr_container_t *attr_cont, const char *key)
{
return (uint32_t)attr_container_get_as_int(attr_cont, key);
}
int64_t
attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i64);
}
uint64_t
attr_container_get_as_uint64(const attr_container_t *attr_cont, const char *key)
{
return (uint64_t)attr_container_get_as_int64(attr_cont, key);
}
int8_t
attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i8);
}
int8_t
attr_container_get_as_int8(const attr_container_t *attr_cont, const char *key)
{
return attr_container_get_as_byte(attr_cont, key);
}
uint8_t
attr_container_get_as_uint8(const attr_container_t *attr_cont, const char *key)
{
return (uint8_t)attr_container_get_as_byte(attr_cont, key);
}
uint16_t
attr_container_get_as_uint16(const attr_container_t *attr_cont, const char *key)
{
return (uint16_t)attr_container_get_as_short(attr_cont, key);
}
float
attr_container_get_as_float(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, f);
}
double
attr_container_get_as_double(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, d);
}
bool
attr_container_get_as_bool(const attr_container_t *attr_cont, const char *key)
{
TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, z);
}
const int8_t *
attr_container_get_as_bytearray(const attr_container_t *attr_cont,
const char *key, unsigned *array_length)
{
const char *addr = attr_container_get_attr(attr_cont, key);
uint8_t type;
uint32_t length;
if (!addr)
return NULL;
if (!array_length) {
attr_container_printf("Get attribute failed: invalid input arguments.");
return NULL;
}
type = *(uint8_t *)addr++;
switch (type) {
case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */
case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */
case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */
case ATTR_TYPE_INT64:
case ATTR_TYPE_UINT8:
case ATTR_TYPE_UINT16:
case ATTR_TYPE_UINT32:
case ATTR_TYPE_UINT64:
case ATTR_TYPE_FLOAT:
case ATTR_TYPE_DOUBLE:
case ATTR_TYPE_BOOLEAN:
length = 1 << (type & 3);
break;
case ATTR_TYPE_STRING:
length = get_uint16(addr);
addr += 2;
break;
case ATTR_TYPE_BYTEARRAY:
length = get_uint32(addr);
addr += 4;
break;
default:
return NULL;
}
*array_length = length;
return (const int8_t *)addr;
}
char *
attr_container_get_as_string(const attr_container_t *attr_cont, const char *key)
{
unsigned array_length;
return (char *)attr_container_get_as_bytearray(attr_cont, key,
&array_length);
}
const char *
attr_container_get_tag(const attr_container_t *attr_cont)
{
return attr_cont ? attr_cont->buf + sizeof(uint32_t) + sizeof(uint16_t)
: NULL;
}
bool
attr_container_contain_key(const attr_container_t *attr_cont, const char *key)
{
if (!attr_cont || !key || !strlen(key)) {
attr_container_printf(
"Check contain key failed: invalid input arguments.\r\n");
return false;
}
return attr_container_find_attr(attr_cont, key) ? true : false;
}
unsigned int
attr_container_get_serialize_length(const attr_container_t *attr_cont)
{
const char *p;
if (!attr_cont) {
attr_container_printf("Get container serialize length failed: invalid "
"input arguments.\r\n");
return 0;
}
p = attr_cont->buf;
return sizeof(uint16_t) + get_uint32(p);
}
bool
attr_container_serialize(char *buf, const attr_container_t *attr_cont)
{
const char *p;
uint16_t flags;
uint32_t length;
if (!buf || !attr_cont) {
attr_container_printf(
"Container serialize failed: invalid input arguments.\r\n");
return false;
}
p = attr_cont->buf;
length = sizeof(uint16_t) + get_uint32(p);
bh_memcpy_s(buf, length, attr_cont, length);
/* Set readonly */
flags = get_uint16((const char *)attr_cont);
set_uint16(buf, flags | (1 << ATTR_CONT_READONLY_SHIFT));
return true;
}
bool
attr_container_is_constant(const attr_container_t *attr_cont)
{
uint16_t flags;
if (!attr_cont) {
attr_container_printf(
"Container check const: invalid input arguments.\r\n");
return false;
}
flags = get_uint16((const char *)attr_cont);
return (flags & (1 << ATTR_CONT_READONLY_SHIFT)) ? true : false;
}
void
attr_container_dump(const attr_container_t *attr_cont)
{
uint32_t total_length;
uint16_t attr_num, i, type;
const char *p, *tag, *key;
jvalue value;
if (!attr_cont)
return;
tag = attr_container_get_tag(attr_cont);
if (!tag)
return;
attr_container_printf("Attribute container dump:\n");
attr_container_printf("Tag: %s\n", tag);
p = attr_container_get_attr_begin(attr_cont, &total_length, &attr_num);
if (!p)
return;
attr_container_printf("Attribute list:\n");
for (i = 0; i < attr_num; i++) {
key = p + 2;
/* Skip key len and key */
p += 2 + get_uint16(p);
type = *p++;
attr_container_printf(" key: %s", key);
switch (type) {
case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */
bh_memcpy_s(&value.i8, 1, p, 1);
attr_container_printf(", type: byte, value: 0x%x\n",
value.i8 & 0xFF);
p++;
break;
case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */
bh_memcpy_s(&value.i16, sizeof(int16_t), p, sizeof(int16_t));
attr_container_printf(", type: short, value: 0x%x\n",
value.i16 & 0xFFFF);
p += 2;
break;
case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */
bh_memcpy_s(&value.i32, sizeof(int32_t), p, sizeof(int32_t));
attr_container_printf(", type: int, value: 0x%x\n", value.i32);
p += 4;
break;
case ATTR_TYPE_INT64:
bh_memcpy_s(&value.i64, sizeof(int64_t), p, sizeof(int64_t));
attr_container_printf(", type: int64, value: 0x%llx\n",
(long long unsigned int)(value.i64));
p += 8;
break;
case ATTR_TYPE_UINT8:
bh_memcpy_s(&value.u8, 1, p, 1);
attr_container_printf(", type: uint8, value: 0x%x\n", value.u8);
p++;
break;
case ATTR_TYPE_UINT16:
bh_memcpy_s(&value.u16, sizeof(uint16_t), p, sizeof(uint16_t));
attr_container_printf(", type: uint16, value: 0x%x\n",
value.u16);
p += 2;
break;
case ATTR_TYPE_UINT32:
bh_memcpy_s(&value.u32, sizeof(uint32_t), p, sizeof(uint32_t));
attr_container_printf(", type: uint32, value: 0x%x\n",
value.u32);
p += 4;
break;
case ATTR_TYPE_UINT64:
bh_memcpy_s(&value.u64, sizeof(uint64_t), p, sizeof(uint64_t));
attr_container_printf(", type: int64, value: 0x%llx\n",
(long long unsigned int)(value.u64));
p += 8;
break;
case ATTR_TYPE_FLOAT:
bh_memcpy_s(&value.f, sizeof(float), p, sizeof(float));
attr_container_printf(", type: float, value: %f\n", value.f);
p += 4;
break;
case ATTR_TYPE_DOUBLE:
bh_memcpy_s(&value.d, sizeof(double), p, sizeof(double));
attr_container_printf(", type: double, value: %f\n", value.d);
p += 8;
break;
case ATTR_TYPE_BOOLEAN:
bh_memcpy_s(&value.z, 1, p, 1);
attr_container_printf(", type: bool, value: 0x%x\n", value.z);
p++;
break;
case ATTR_TYPE_STRING:
attr_container_printf(", type: string, value: %s\n",
p + sizeof(uint16_t));
p += sizeof(uint16_t) + get_uint16(p);
break;
case ATTR_TYPE_BYTEARRAY:
attr_container_printf(", type: byte array, length: %d\n",
get_uint32(p));
p += sizeof(uint32_t) + get_uint32(p);
break;
default:
bh_assert(0);
break;
}
}
attr_container_printf("\n");
}

View File

@ -0,0 +1,596 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _ATTR_CONTAINER_H_
#define _ATTR_CONTAINER_H_
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Attribute type */
enum {
ATTR_TYPE_BEGIN = 0,
ATTR_TYPE_BYTE = ATTR_TYPE_BEGIN,
ATTR_TYPE_INT8 = ATTR_TYPE_BYTE,
ATTR_TYPE_SHORT,
ATTR_TYPE_INT16 = ATTR_TYPE_SHORT,
ATTR_TYPE_INT,
ATTR_TYPE_INT32 = ATTR_TYPE_INT,
ATTR_TYPE_INT64,
ATTR_TYPE_UINT8,
ATTR_TYPE_UINT16,
ATTR_TYPE_UINT32,
ATTR_TYPE_UINT64,
/**
* Why ATTR_TYPE_FLOAT = 10?
* We determine the number of bytes that should be copied through 1<<(type &
* 3). ATTR_TYPE_BYTE = 0, so the number of bytes is 1 << 0 = 1.
* ATTR_TYPE_UINT64 = 7, so the number of bytes is 1 << 3 = 8.
* Since the float type takes up 4 bytes, ATTR_TYPE_FLOAT should be 10.
* Calculation: (1 << (10&3)) = (1 << 2) = 4
*/
ATTR_TYPE_FLOAT = 10,
ATTR_TYPE_DOUBLE,
ATTR_TYPE_BOOLEAN,
ATTR_TYPE_STRING,
ATTR_TYPE_BYTEARRAY,
ATTR_TYPE_END = ATTR_TYPE_BYTEARRAY
};
#define ATTR_CONT_READONLY_SHIFT 2
typedef struct attr_container {
/* container flag:
* bit0, bit1 denote the implemenation algorithm, 00: buffer, 01: link list
* bit2 denotes the readonly flag: 1 is readonly and attr cannot be set
*/
char flags[2];
/**
* Buffer format
* for buffer implementation:
* buf length (4 bytes)
* tag length (2 bytes)
* tag
* attr num (2bytes)
* attr[0..n-1]:
* attr key length (2 bytes)
* attr type (1byte)
* attr value (length depends on attr type)
*/
char buf[1];
} attr_container_t;
/**
* Create attribute container
*
* @param tag tag of current attribute container
*
* @return the created attribute container, NULL if failed
*/
attr_container_t *
attr_container_create(const char *tag);
/**
* Destroy attribute container
*
* @param attr_cont the attribute container to destroy
*/
void
attr_container_destroy(const attr_container_t *attr_cont);
/**
* Set short attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_short(attr_container_t **p_attr_cont, const char *key,
short value);
/**
* Set int16 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_int16(attr_container_t **p_attr_cont, const char *key,
int16_t value);
/**
* Set int attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_int(attr_container_t **p_attr_cont, const char *key,
int value);
/**
* Set int32 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_int32(attr_container_t **p_attr_cont, const char *key,
int32_t value);
/**
* Set uint32 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_uint32(attr_container_t **p_attr_cont, const char *key,
uint32_t value);
/**
* Set int64 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_int64(attr_container_t **p_attr_cont, const char *key,
int64_t value);
/**
* Set uint64 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_uint64(attr_container_t **p_attr_cont, const char *key,
uint64_t value);
/**
* Set byte attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_byte(attr_container_t **p_attr_cont, const char *key,
int8_t value);
/**
* Set int8 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_int8(attr_container_t **p_attr_cont, const char *key,
int8_t value);
/**
* Set uint8 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_uint8(attr_container_t **p_attr_cont, const char *key,
uint8_t value);
/**
* Set uint16 attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key,
uint16_t value);
/**
* Set float attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_float(attr_container_t **p_attr_cont, const char *key,
float value);
/**
* Set double attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_double(attr_container_t **p_attr_cont, const char *key,
double value);
/**
* Set bool attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_bool(attr_container_t **p_attr_cont, const char *key,
bool value);
/**
* Set string attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the attribute value
*
* @return true if success, false otherwise
*/
bool
attr_container_set_string(attr_container_t **p_attr_cont, const char *key,
const char *value);
/**
* Set bytearray attribute in attribute container
*
* @param p_attr_cont pointer to attribute container to set attribute, and
* return the new attribute container if it is re-created
* @param key the attribute key
* @param value the bytearray buffer
* @param length the bytearray length
*
* @return true if success, false otherwise
*/
bool
attr_container_set_bytearray(attr_container_t **p_attr_cont, const char *key,
const int8_t *value, unsigned length);
/**
* Get tag of current attribute container
*
* @param attr_cont the attribute container
*
* @return tag of current attribute container
*/
const char *
attr_container_get_tag(const attr_container_t *attr_cont);
/**
* Get attribute number of current attribute container
*
* @param attr_cont the attribute container
*
* @return attribute number of current attribute container
*/
uint16_t
attr_container_get_attr_num(const attr_container_t *attr_cont);
/**
* Whether the attribute container contains an attribute key.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return true if key is contained in message, false otherwise
*/
bool
attr_container_contain_key(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as short value,
* return 0 if attribute isn't found in message.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the short value of the attribute, 0 if key isn't found
*/
short
attr_container_get_as_short(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as int16 value,
* return 0 if attribute isn't found in message.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the short value of the attribute, 0 if key isn't found
*/
int16_t
attr_container_get_as_int16(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as int value,
* return 0 if attribute isn't found in message.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the int value of the attribute, 0 if key isn't found
*/
int
attr_container_get_as_int(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as int32 value,
* return 0 if attribute isn't found in message.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the int value of the attribute, 0 if key isn't found
*/
int32_t
attr_container_get_as_int32(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as uint32 value,
* return 0 if attribute isn't found in message.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the unsigned int value of the attribute, 0 if key isn't found
*/
uint32_t
attr_container_get_as_uint32(const attr_container_t *attr_cont,
const char *key);
/**
* Get attribute from attribute container and return it as int64 value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the long value of the attribute, 0 if key isn't found
*/
int64_t
attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as uint64 value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the unsigned long value of the attribute, 0 if key isn't found
*/
uint64_t
attr_container_get_as_uint64(const attr_container_t *attr_cont,
const char *key);
/**
* Get attribute from attribute container and return it as byte value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the byte value of the attribute, 0 if key isn't found
*/
int8_t
attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as int8 value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the byte value of the attribute, 0 if key isn't found
*/
int8_t
attr_container_get_as_int8(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as uint8 value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the uint8 value of the attribute, 0 if key isn't found
*/
uint8_t
attr_container_get_as_uint8(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as uint16 value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the char value of the attribute, 0 if key isn't found
*/
uint16_t
attr_container_get_as_uint16(const attr_container_t *attr_cont,
const char *key);
/**
* Get attribute from attribute container and return it as float value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the float value of the attribute, 0 if key isn't found
*/
float
attr_container_get_as_float(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as double value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the double value of the attribute, 0 if key isn't found
*/
double
attr_container_get_as_double(const attr_container_t *attr_cont,
const char *key);
/**
* Get attribute from attribute container and return it as bool value,
* return false if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the bool value of the attribute, 0 if key isn't found
*/
bool
attr_container_get_as_bool(const attr_container_t *attr_cont, const char *key);
/**
* Get attribute from attribute container and return it as string value,
* return NULL if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the string value of the attribute, NULL if key isn't found
*/
char *
attr_container_get_as_string(const attr_container_t *attr_cont,
const char *key);
/**
* Get attribute from attribute container and return it as bytearray value,
* return 0 if attribute isn't found in attribute container.
*
* @param attr_cont the attribute container
* @param key the attribute key
*
* @return the bytearray value of the attribute, NULL if key isn't found
*/
const int8_t *
attr_container_get_as_bytearray(const attr_container_t *attr_cont,
const char *key, unsigned *array_length);
/**
* Get the buffer size of attribute container
*
* @param attr_cont the attribute container
*
* @return the buffer size of attribute container
*/
unsigned
attr_container_get_serialize_length(const attr_container_t *attr_cont);
/**
* Serialize attribute container to a buffer
*
* @param buf the buffer to receive the serialized data
* @param attr_cont the attribute container to be serialized
*
* @return true if success, false otherwise
*/
bool
attr_container_serialize(char *buf, const attr_container_t *attr_cont);
/**
* Whether the attribute container is const, or set attribute isn't supported
*
* @param attr_cont the attribute container
*
* @return true if const, false otherwise
*/
bool
attr_container_is_constant(const attr_container_t *attr_cont);
void
attr_container_dump(const attr_container_t *attr_cont);
#ifndef attr_container_malloc
#define attr_container_malloc WA_MALLOC
#endif
#ifndef attr_container_free
#define attr_container_free WA_FREE
#endif
#ifndef attr_container_printf
#define attr_container_printf printf
#endif
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* end of _ATTR_CONTAINER_H_ */

View File

@ -0,0 +1,155 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _SHARED_UTILS_H_
#define _SHARED_UTILS_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
#define FMT_ATTR_CONTAINER 99
#define FMT_APP_RAW_BINARY 98
/* the request structure */
typedef struct request {
// message id
uint32 mid;
// url of the request
char *url;
// action of the request, can be PUT/GET/POST/DELETE
int action;
// payload format, currently only support attr_container_t type
int fmt;
// payload of the request, currently only support attr_container_t type
void *payload;
// length in bytes of the payload
int payload_len;
// sender of the request
unsigned long sender;
} request_t;
/* the response structure */
typedef struct response {
// message id
uint32 mid;
// status of the response
int status;
// payload format
int fmt;
// payload of the response,
void *payload;
// length in bytes of the payload
int payload_len;
// receiver of the response
unsigned long reciever;
} response_t;
int
check_url_start(const char *url, int url_len, const char *leading_str);
bool
match_url(char *pattern, char *matched);
char *
find_key_value(char *buffer, int buffer_len, char *key, char *value,
int value_len, char delimiter);
request_t *
clone_request(request_t *request);
void
request_cleaner(request_t *request);
response_t *
clone_response(response_t *response);
void
response_cleaner(response_t *response);
/**
* @brief Set fields of response.
*
* @param response pointer of the response to be set
* @param status status of response
* @param fmt format of the response payload
* @param payload payload of the response
* @param payload_len length in bytes of the response payload
*
* @return pointer to the response
*
* @warning the response pointer MUST NOT be NULL
*/
response_t *
set_response(response_t *response, int status, int fmt, const char *payload,
int payload_len);
/**
* @brief Make a response for a request.
*
* @param request pointer of the request
* @param response pointer of the response to be made
*
* @return pointer to the response
*
* @warning the request and response pointers MUST NOT be NULL
*/
response_t *
make_response_for_request(request_t *request, response_t *response);
/**
* @brief Initialize a request.
*
* @param request pointer of the request to be initialized
* @param url url of the request
* @param action action of the request
* @param fmt format of the request payload
* @param payload payload of the request
* @param payload_len length in bytes of the request payload
*
* @return pointer to the request
*
* @warning the request pointer MUST NOT be NULL
*/
request_t *
init_request(request_t *request, char *url, int action, int fmt, void *payload,
int payload_len);
char *
pack_request(request_t *request, int *size);
request_t *
unpack_request(char *packet, int size, request_t *request);
char *
pack_response(response_t *response, int *size);
response_t *
unpack_response(char *packet, int size, response_t *response);
void
free_req_resp_packet(char *packet);
char *
wa_strdup(const char *str);
#ifdef __cplusplus
}
#endif
#endif /* end of _SHARED_UTILS_H_ */

View File

@ -0,0 +1,101 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H
#define WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
/* Object native function IDs */
enum {
OBJ_FUNC_ID_DEL,
OBJ_FUNC_ID_DEL_ASYNC,
OBJ_FUNC_ID_CLEAN,
OBJ_FUNC_ID_SET_EVT_CB,
OBJ_FUNC_ID_ALIGN,
/* Number of functions */
_OBJ_FUNC_ID_NUM,
};
/* Button native function IDs */
enum {
BTN_FUNC_ID_CREATE,
BTN_FUNC_ID_SET_TOGGLE,
BTN_FUNC_ID_SET_STATE,
BTN_FUNC_ID_TOGGLE,
BTN_FUNC_ID_SET_INK_IN_TIME,
BTN_FUNC_ID_SET_INK_WAIT_TIME,
BTN_FUNC_ID_SET_INK_OUT_TIME,
BTN_FUNC_ID_GET_STATE,
BTN_FUNC_ID_GET_TOGGLE,
BTN_FUNC_ID_GET_INK_IN_TIME,
BTN_FUNC_ID_GET_INK_WAIT_TIME,
BTN_FUNC_ID_GET_INK_OUT_TIME,
/* Number of functions */
_BTN_FUNC_ID_NUM,
};
/* Check box native function IDs */
enum {
CB_FUNC_ID_CREATE,
CB_FUNC_ID_SET_TEXT,
CB_FUNC_ID_SET_STATIC_TEXT,
CB_FUNC_ID_GET_TEXT,
CB_FUNC_ID_GET_TEXT_LENGTH,
/* Number of functions */
_CB_FUNC_ID_NUM,
};
/* List native function IDs */
enum {
LIST_FUNC_ID_CREATE,
LIST_FUNC_ID_ADD_BTN,
/* Number of functions */
_LIST_FUNC_ID_NUM,
};
/* Label native function IDs */
enum {
LABEL_FUNC_ID_CREATE,
LABEL_FUNC_ID_SET_TEXT,
LABEL_FUNC_ID_SET_ARRAY_TEXT,
LABEL_FUNC_ID_SET_STATIC_TEXT,
LABEL_FUNC_ID_SET_LONG_MODE,
LABEL_FUNC_ID_SET_ALIGN,
LABEL_FUNC_ID_SET_RECOLOR,
LABEL_FUNC_ID_SET_BODY_DRAW,
LABEL_FUNC_ID_SET_ANIM_SPEED,
LABEL_FUNC_ID_SET_TEXT_SEL_START,
LABEL_FUNC_ID_SET_TEXT_SEL_END,
LABEL_FUNC_ID_GET_TEXT,
LABEL_FUNC_ID_GET_TEXT_LENGTH,
LABEL_FUNC_ID_GET_LONG_MODE,
LABEL_FUNC_ID_GET_ALIGN,
LABEL_FUNC_ID_GET_RECOLOR,
LABEL_FUNC_ID_GET_BODY_DRAW,
LABEL_FUNC_ID_GET_ANIM_SPEED,
LABEL_FUNC_ID_GET_LETTER_POS,
LABEL_FUNC_ID_GET_TEXT_SEL_START,
LABEL_FUNC_ID_GET_TEXT_SEL_END,
LABEL_FUNC_ID_INS_TEXT,
LABEL_FUNC_ID_CUT_TEXT,
/* Number of functions */
_LABEL_FUNC_ID_NUM,
};
#ifdef __cplusplus
}
#endif
#endif /* WAMR_GRAPHIC_LIBRARY_SHARED_UTILS_H */

View File

@ -0,0 +1,15 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (NATIVE_INTERFACE_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${NATIVE_INTERFACE_DIR})
file (GLOB_RECURSE source_all ${NATIVE_INTERFACE_DIR}/*.c)
set (NATIVE_INTERFACE_SOURCE ${source_all})
set (WASM_APP_BI_INC_DIR "${NATIVE_INTERFACE_DIR}/bi-inc")
LIST (APPEND RUNTIME_LIB_HEADER_LIST "${NATIVE_INTERFACE_DIR}/native_interface.h")

View File

@ -0,0 +1,13 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _NATIVE_INTERFACE_H_
#define _NATIVE_INTERFACE_H_
/* Note: the bh_plaform.h is the only head file separately
implemented by both [app] and [native] worlds */
#include "bh_platform.h"
#endif /* end of _NATIVE_INTERFACE_H */

View File

@ -0,0 +1,493 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include "bi-inc/shared_utils.h"
/* Serialization of request and response message
*
* Choices:
* We considered a few options:
* 1. coap
* 2. flatbuffer
* 3. cbor
* 4. attr-containers of our own
* 5. customized serialization for request/response
*
* Now we choose the #5 mainly because we need to quickly get the URL for
* dispatching and sometimes we want to change the URL in the original packet.
* the request format: fixed part: version: (1 byte), code (1 byte), fmt(2
* byte), mid (4 bytes), sender_id(4 bytes), url_len(2 bytes),
* payload_len(4bytes) dynamic part: url (bytes in url_len), payload
*
* response format:
* fixed part: (1 byte), code (1 byte), fmt(2 byte), mid (4 bytes), sender_id(4
* bytes), payload_len(4bytes) dynamic part: payload
*/
#define REQUES_PACKET_VER 1
#define REQUEST_PACKET_FIX_PART_LEN 18
#define REQUEST_PACKET_URL_OFFSET REQUEST_PACKET_FIX_PART_LEN
#define REQUEST_PACKET_URL_LEN \
*((uint16 *)((char *)buffer + 12)) /* to ensure little endian */
#define REQUEST_PACKET_PAYLOAD_LEN \
*((uint32 *)((char *)buffer + 14)) /* to ensure little endian */
#define REQUEST_PACKET_URL(buffer) ((char *)buffer + REQUEST_PACKET_URL_OFFSET)
#define REQUEST_PACKET_PAYLOAD(buffer) \
((char *)buffer + REQUEST_PACKET_URL_OFFSET \
+ REQUEST_PACKET_URL_LEN(buffer))
#define RESPONSE_PACKET_FIX_PART_LEN 16
char *
pack_request(request_t *request, int *size)
{
int url_len = strlen(request->url) + 1;
int len = REQUEST_PACKET_FIX_PART_LEN + url_len + request->payload_len;
uint16 u16;
uint32 u32;
char *packet;
if ((packet = (char *)WA_MALLOC(len)) == NULL)
return NULL;
/* TODO: ensure little endian for words and dwords */
*packet = REQUES_PACKET_VER;
*((uint8 *)(packet + 1)) = request->action;
u16 = htons(request->fmt);
memcpy(packet + 2, &u16, 2);
u32 = htonl(request->mid);
memcpy(packet + 4, &u32, 4);
u32 = htonl(request->sender);
memcpy(packet + 8, &u32, 4);
u16 = htons(url_len);
memcpy(packet + 12, &u16, 2);
u32 = htonl(request->payload_len);
memcpy(packet + 14, &u32, 4);
strcpy(packet + REQUEST_PACKET_URL_OFFSET, request->url);
memcpy(packet + REQUEST_PACKET_URL_OFFSET + url_len, request->payload,
request->payload_len);
*size = len;
return packet;
}
void
free_req_resp_packet(char *packet)
{
WA_FREE(packet);
}
request_t *
unpack_request(char *packet, int size, request_t *request)
{
uint16 url_len, u16;
uint32 payload_len, u32;
if (*packet != REQUES_PACKET_VER) {
return NULL;
}
if (size < REQUEST_PACKET_FIX_PART_LEN) {
return NULL;
}
memcpy(&u16, packet + 12, 2);
url_len = ntohs(u16);
memcpy(&u32, packet + 14, 4);
payload_len = ntohl(u32);
if (size != (REQUEST_PACKET_FIX_PART_LEN + url_len + payload_len)) {
return NULL;
}
if (*(packet + REQUEST_PACKET_FIX_PART_LEN + url_len - 1) != 0) {
return NULL;
}
request->action = *((uint8 *)(packet + 1));
memcpy(&u16, packet + 2, 2);
request->fmt = ntohs(u16);
memcpy(&u32, packet + 4, 4);
request->mid = ntohl(u32);
memcpy(&u32, packet + 8, 4);
request->sender = ntohl(u32);
request->payload_len = payload_len;
request->url = REQUEST_PACKET_URL(packet);
if (payload_len > 0)
request->payload = packet + REQUEST_PACKET_URL_OFFSET + url_len;
else
request->payload = NULL;
return request;
}
char *
pack_response(response_t *response, int *size)
{
int len = RESPONSE_PACKET_FIX_PART_LEN + response->payload_len;
uint16 u16;
uint32 u32;
char *packet;
if ((packet = (char *)WA_MALLOC(len)) == NULL)
return NULL;
/* TODO: ensure little endian for words and dwords */
*packet = REQUES_PACKET_VER;
*((uint8 *)(packet + 1)) = response->status;
u16 = htons(response->fmt);
memcpy(packet + 2, &u16, 2);
u32 = htonl(response->mid);
memcpy(packet + 4, &u32, 4);
u32 = htonl(response->reciever);
memcpy(packet + 8, &u32, 4);
u32 = htonl(response->payload_len);
memcpy(packet + 12, &u32, 4);
memcpy(packet + RESPONSE_PACKET_FIX_PART_LEN, response->payload,
response->payload_len);
*size = len;
return packet;
}
response_t *
unpack_response(char *packet, int size, response_t *response)
{
uint16 u16;
uint32 payload_len, u32;
if (*packet != REQUES_PACKET_VER)
return NULL;
if (size < RESPONSE_PACKET_FIX_PART_LEN)
return NULL;
memcpy(&u32, packet + 12, 4);
payload_len = ntohl(u32);
if (size != (RESPONSE_PACKET_FIX_PART_LEN + payload_len))
return NULL;
response->status = *((uint8 *)(packet + 1));
memcpy(&u16, packet + 2, 2);
response->fmt = ntohs(u16);
memcpy(&u32, packet + 4, 4);
response->mid = ntohl(u32);
memcpy(&u32, packet + 8, 4);
response->reciever = ntohl(u32);
response->payload_len = payload_len;
if (payload_len > 0)
response->payload = packet + RESPONSE_PACKET_FIX_PART_LEN;
else
response->payload = NULL;
return response;
}
request_t *
clone_request(request_t *request)
{
/* deep clone */
request_t *req = (request_t *)WA_MALLOC(sizeof(request_t));
if (req == NULL)
return NULL;
memset(req, 0, sizeof(*req));
req->action = request->action;
req->fmt = request->fmt;
req->url = wa_strdup(request->url);
req->sender = request->sender;
req->mid = request->mid;
if (req->url == NULL)
goto fail;
req->payload_len = request->payload_len;
if (request->payload_len) {
req->payload = (char *)WA_MALLOC(request->payload_len);
if (!req->payload)
goto fail;
memcpy(req->payload, request->payload, request->payload_len);
}
else {
/* when payload_len is 0, the payload may be used for
carrying some handle or integer */
req->payload = request->payload;
}
return req;
fail:
request_cleaner(req);
return NULL;
}
void
request_cleaner(request_t *request)
{
if (request->url != NULL)
WA_FREE(request->url);
if (request->payload != NULL && request->payload_len > 0)
WA_FREE(request->payload);
WA_FREE(request);
}
void
response_cleaner(response_t *response)
{
if (response->payload != NULL && response->payload_len > 0)
WA_FREE(response->payload);
WA_FREE(response);
}
response_t *
clone_response(response_t *response)
{
response_t *clone = (response_t *)WA_MALLOC(sizeof(response_t));
if (clone == NULL)
return NULL;
memset(clone, 0, sizeof(*clone));
clone->fmt = response->fmt;
clone->mid = response->mid;
clone->status = response->status;
clone->reciever = response->reciever;
clone->payload_len = response->payload_len;
if (clone->payload_len) {
clone->payload = (char *)WA_MALLOC(response->payload_len);
if (!clone->payload)
goto fail;
memcpy(clone->payload, response->payload, response->payload_len);
}
else {
/* when payload_len is 0, the payload may be used for
carrying some handle or integer */
clone->payload = response->payload;
}
return clone;
fail:
response_cleaner(clone);
return NULL;
}
response_t *
set_response(response_t *response, int status, int fmt, const char *payload,
int payload_len)
{
response->payload = (void *)payload;
response->payload_len = payload_len;
response->status = status;
response->fmt = fmt;
return response;
}
response_t *
make_response_for_request(request_t *request, response_t *response)
{
response->mid = request->mid;
response->reciever = request->sender;
return response;
}
static unsigned int mid = 0;
request_t *
init_request(request_t *request, char *url, int action, int fmt, void *payload,
int payload_len)
{
request->url = url;
request->action = action;
request->fmt = fmt;
request->payload = payload;
request->payload_len = payload_len;
request->mid = ++mid;
return request;
}
/*
check if the "url" is starting with "leading_str"
return: 0 - not match; >0 - the offset of matched url, include any "/" at the
end notes:
1. it ensures the leading_str "/abc" can pass "/abc/cde" and "/abc/, but fail
"/ab" and "/abcd". leading_str "/abc/" can pass "/abc"
2. it omit the '/' at the first char
3. it ensure the leading_str "/abc" can pass "/abc?cde
*/
int
check_url_start(const char *url, int url_len, const char *leading_str)
{
int offset = 0;
if (*leading_str == '/')
leading_str++;
if (url_len > 0 && *url == '/') {
url_len--;
url++;
offset++;
}
int len = strlen(leading_str);
if (len == 0)
return 0;
/* ensure leading_str not end with "/" */
if (leading_str[len - 1] == '/') {
len--;
if (len == 0)
return 0;
}
/* equal length */
if (url_len == len) {
if (memcmp(url, leading_str, url_len) == 0) {
return (offset + len);
}
else {
return 0;
}
}
if (url_len < len)
return 0;
else if (memcmp(url, leading_str, len) != 0)
return 0;
else if (url[len] != '/' && url[len] != '?')
return 0;
else
return (offset + len + 1);
}
// * @pattern:
// * sample 1: /abcd, match /abcd only
// * sample 2: /abcd/ match match "/abcd" and "/abcd/*"
// * sample 3: /abcd*, match any url started with "/abcd"
// * sample 4: /abcd/*, exclude "/abcd"
bool
match_url(char *pattern, char *matched)
{
if (*pattern == '/')
pattern++;
if (*matched == '/')
matched++;
int matched_len = strlen(matched);
if (matched_len == 0)
return false;
if (matched[matched_len - 1] == '/') {
matched_len--;
if (matched_len == 0)
return false;
}
int len = strlen(pattern);
if (len == 0)
return false;
if (pattern[len - 1] == '/') {
len--;
if (strncmp(pattern, matched, len) != 0)
return false;
if (len == matched_len)
return true;
if (matched_len > len && matched[len] == '/')
return true;
return false;
}
else if (pattern[len - 1] == '*') {
if (pattern[len - 2] == '/') {
if (strncmp(pattern, matched, len - 1) == 0)
return true;
else
return false;
}
else {
return (strncmp(pattern, matched, len - 1) == 0);
}
}
else {
return (strcmp(pattern, matched) == 0);
}
}
/*
* get the value of the key from following format buffer:
* key1=value1;key2=value2;key3=value3
*/
char *
find_key_value(char *buffer, int buffer_len, char *key, char *value,
int value_len, char delimiter)
{
char *p = buffer;
int remaining = buffer_len;
int key_len = strlen(key);
while (*p != 0 && remaining > 0) {
while (*p == ' ' || *p == delimiter) {
p++;
remaining--;
}
if (remaining <= key_len)
return NULL;
/* find the key */
if (0 == strncmp(p, key, key_len) && p[key_len] == '=') {
p += (key_len + 1);
remaining -= (key_len + 1);
char *v = value;
memset(value, 0, value_len);
value_len--; /* ensure last char is 0 */
while (*p != delimiter && remaining > 0 && value_len > 0) {
*v++ = *p++;
remaining--;
value_len--;
}
return value;
}
/* goto next key */
while (*p != delimiter && remaining > 0) {
p++;
remaining--;
}
}
return NULL;
}

View File

@ -0,0 +1,38 @@
#include "lib_export.h"
#ifdef APP_FRAMEWORK_SENSOR
#include "sensor_native_api.h"
#endif
#ifdef APP_FRAMEWORK_CONNECTION
#include "connection_native_api.h"
#endif
#ifdef APP_FRAMEWORK_WGL
#include "gui_native_api.h"
#endif
/* More header file here */
static NativeSymbol extended_native_symbol_defs[] = {
#ifdef APP_FRAMEWORK_SENSOR
#include "runtime_sensor.inl"
#endif
#ifdef APP_FRAMEWORK_CONNECTION
#include "connection.inl"
#endif
#ifdef APP_FRAMEWORK_WGL
#include "wamr_gui.inl"
#endif
/* More inl file here */
};
int
get_ext_lib_export_apis(NativeSymbol **p_ext_lib_apis)
{
*p_ext_lib_apis = extended_native_symbol_defs;
return sizeof(extended_native_symbol_defs) / sizeof(NativeSymbol);
}

View File

@ -0,0 +1,93 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
add_definitions (-DWASM_ENABLE_APP_FRAMEWORK=1)
set (APP_FRAMEWORK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE )
LIST (APPEND WASM_APP_LIB_SOURCE_ALL ${CMAKE_CURRENT_LIST_DIR}/app_ext_lib_export.c)
endif()
# app-native-shared and base are required
include (${APP_FRAMEWORK_ROOT_DIR}/app-native-shared/native_interface.cmake)
LIST (APPEND WASM_APP_SOURCE_ALL ${NATIVE_INTERFACE_SOURCE})
MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
function (add_module_native arg)
message ("Add native module ${ARGV0}")
include (${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/wasm_lib.cmake)
file (GLOB header
${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/*.h
${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native/*.inl
)
LIST (APPEND WASM_APP_LIBS_DIR ${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/native)
set (WASM_APP_LIBS_DIR ${WASM_APP_LIBS_DIR} PARENT_SCOPE)
LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
set (RUNTIME_LIB_HEADER_LIST ${RUNTIME_LIB_HEADER_LIST} PARENT_SCOPE)
LIST (APPEND WASM_APP_LIB_SOURCE_ALL ${WASM_APP_LIB_CURRENT_SOURCE})
set (WASM_APP_LIB_SOURCE_ALL ${WASM_APP_LIB_SOURCE_ALL} PARENT_SCOPE)
endfunction ()
function (add_module_app arg)
message ("Add app module ${ARGV0}")
include (${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/app/wasm_app.cmake)
LIST (APPEND WASM_APP_WA_INC_DIR_LIST "${APP_FRAMEWORK_ROOT_DIR}/${ARGV0}/app/wa-inc")
set (WASM_APP_WA_INC_DIR_LIST ${WASM_APP_WA_INC_DIR_LIST} PARENT_SCOPE)
LIST (APPEND WASM_APP_NAME ${ARGV0})
set (WASM_APP_NAME ${WASM_APP_NAME} PARENT_SCOPE)
LIST (APPEND WASM_APP_SOURCE_ALL ${WASM_APP_CURRENT_SOURCE})
set (WASM_APP_SOURCE_ALL ${WASM_APP_SOURCE_ALL} PARENT_SCOPE)
endfunction ()
if ("${WAMR_BUILD_APP_LIST}" STREQUAL "WAMR_APP_BUILD_ALL")
# add all modules under this folder
SUBDIRLIST(SUBDIRS ${APP_FRAMEWORK_ROOT_DIR})
FOREACH(subdir ${SUBDIRS})
if ("${subdir}" STREQUAL "app-native-shared")
continue()
endif ()
if ("${subdir}" STREQUAL "template")
continue()
endif ()
if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE )
add_module_native (${subdir})
else ()
add_module_app (${subdir})
endif ()
ENDFOREACH()
else ()
# add each module in the list
FOREACH (dir IN LISTS WAMR_BUILD_APP_LIST)
string(REPLACE "WAMR_APP_BUILD_" "" dir ${dir})
string(TOLOWER ${dir} dir)
if ( NOT DEFINED APP_FRAMEWORK_INCLUDE_TYPE )
add_module_native (${dir})
else ()
add_module_app (${dir})
endif ()
ENDFOREACH (dir)
endif()

View File

@ -0,0 +1,89 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_platform.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*
*
*/
static bool
is_little_endian()
{
long i = 0x01020304;
unsigned char *c = (unsigned char *)&i;
return (*c == 0x04) ? true : false;
}
static void
swap32(uint8 *pData)
{
uint8 value = *pData;
*pData = *(pData + 3);
*(pData + 3) = value;
value = *(pData + 1);
*(pData + 1) = *(pData + 2);
*(pData + 2) = value;
}
static void
swap16(uint8 *pData)
{
uint8 value = *pData;
*(pData) = *(pData + 1);
*(pData + 1) = value;
}
uint32
htonl(uint32 value)
{
uint32 ret;
if (is_little_endian()) {
ret = value;
swap32((uint8 *)&ret);
return ret;
}
return value;
}
uint32
ntohl(uint32 value)
{
return htonl(value);
}
uint16
htons(uint16 value)
{
uint16 ret;
if (is_little_endian()) {
ret = value;
swap16((uint8 *)&ret);
return ret;
}
return value;
}
uint16
ntohs(uint16 value)
{
return htons(value);
}
char *
wa_strdup(const char *s)
{
char *s1 = NULL;
if (s && (s1 = WA_MALLOC(strlen(s) + 1)))
memcpy(s1, s, strlen(s) + 1);
return s1;
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_
#define DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_
#include <stdbool.h>
typedef unsigned char uint8;
typedef char int8;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned int uint32;
typedef int int32;
#ifndef NULL
#define NULL ((void *)0)
#endif
#ifndef __cplusplus
#define true 1
#define false 0
#define inline __inline
#endif
// all wasm-app<->native shared source files should use WA_MALLOC/WA_FREE.
// they will be mapped to different implementations in each side
#ifndef WA_MALLOC
#define WA_MALLOC malloc
#endif
#ifndef WA_FREE
#define WA_FREE free
#endif
uint32
htonl(uint32 value);
uint32
ntohl(uint32 value);
uint16
htons(uint16 value);
uint16
ntohs(uint16 value);
// We are not worried for the WASM world since the sandbox will catch it.
#define bh_memcpy_s(dst, dst_len, src, src_len) memcpy(dst, src, src_len)
#ifdef NDEBUG
#define bh_assert(v) (void)0
#else
#define bh_assert(v) \
do { \
if (!(v)) { \
int _count; \
printf("ASSERTION FAILED: %s, at %s, line %d", #v, __FILE__, \
__LINE__); \
_count = printf("\n"); \
printf("%d\n", _count / (_count - 1)); \
} \
} while (0)
#endif
#endif /* DEPS_IWASM_APP_LIBS_BASE_BH_PLATFORM_H_ */

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _REQ_RESP_API_H_
#define _REQ_RESP_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
bool
wasm_response_send(const char *buf, int size);
void
wasm_register_resource(const char *url);
void
wasm_post_request(const char *buf, int size);
void
wasm_sub_event(const char *url);
#ifdef __cplusplus
}
#endif
#endif /* end of _REQ_RESP_API_H_ */

View File

@ -0,0 +1,365 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bi-inc/attr_container.h"
#include "wa-inc/request.h"
#include "wa-inc/timer_wasm_app.h"
#include "bi-inc/shared_utils.h"
#include "wasm_app.h"
#include "req_resp_api.h"
#include "timer_api.h"
#define TRANSACTION_TIMEOUT_MS 5000
typedef enum { Reg_Event, Reg_Request } reg_type_t;
typedef struct _res_register {
struct _res_register *next;
const char *url;
reg_type_t reg_type;
void (*request_handler)(request_t *);
} res_register_t;
typedef struct transaction {
struct transaction *next;
int mid;
unsigned int time; /* start time */
response_handler_f handler;
void *user_data;
} transaction_t;
static res_register_t *g_resources = NULL;
static transaction_t *g_transactions = NULL;
static user_timer_t g_trans_timer = NULL;
static transaction_t *
transaction_find(int mid)
{
transaction_t *t = g_transactions;
while (t) {
if (t->mid == mid)
return t;
t = t->next;
}
return NULL;
}
/*
* new transaction is added to the tail of the list, so the list
* is sorted by expiry time naturally.
*/
static void
transaction_add(transaction_t *trans)
{
transaction_t *t;
if (g_transactions == NULL) {
g_transactions = trans;
return;
}
t = g_transactions;
while (t) {
if (t->next == NULL) {
t->next = trans;
return;
}
}
}
static void
transaction_remove(transaction_t *trans)
{
transaction_t *prev = NULL, *current = g_transactions;
while (current) {
if (current == trans) {
if (prev == NULL) {
g_transactions = current->next;
free(current);
return;
}
prev->next = current->next;
free(current);
return;
}
prev = current;
current = current->next;
}
}
static bool
is_event_type(request_t *req)
{
return req->action == COAP_EVENT;
}
static bool
register_url_handler(const char *url, request_handler_f request_handler,
reg_type_t reg_type)
{
res_register_t *r = g_resources;
while (r) {
if (reg_type == r->reg_type && strcmp(r->url, url) == 0) {
r->request_handler = request_handler;
return true;
}
r = r->next;
}
r = (res_register_t *)malloc(sizeof(res_register_t));
if (r == NULL)
return false;
memset(r, 0, sizeof(*r));
r->url = strdup(url);
if (!r->url) {
free(r);
return false;
}
r->request_handler = request_handler;
r->reg_type = reg_type;
r->next = g_resources;
g_resources = r;
// tell app mgr to route this url to me
if (reg_type == Reg_Request)
wasm_register_resource(url);
else
wasm_sub_event(url);
return true;
}
bool
api_register_resource_handler(const char *url,
request_handler_f request_handler)
{
return register_url_handler(url, request_handler, Reg_Request);
}
static void
transaction_timeout_handler(user_timer_t timer)
{
transaction_t *cur, *expired = NULL;
unsigned int elpased_ms, now = wasm_get_sys_tick_ms();
/*
* Since he transaction list is sorted by expiry time naturally,
* we can easily get all expired transactions.
* */
cur = g_transactions;
while (cur) {
if (now < cur->time)
elpased_ms = now + (0xFFFFFFFF - cur->time) + 1;
else
elpased_ms = now - cur->time;
if (elpased_ms >= TRANSACTION_TIMEOUT_MS) {
g_transactions = cur->next;
cur->next = expired;
expired = cur;
cur = g_transactions;
}
else {
break;
}
}
/* call each transaction's handler with response set to NULL */
cur = expired;
while (cur) {
transaction_t *tmp = cur;
cur->handler(NULL, cur->user_data);
cur = cur->next;
free(tmp);
}
/*
* If the transaction list is not empty, restart the timer according
* to the first transaction. Otherwise, stop the timer.
*/
if (g_transactions != NULL) {
unsigned int elpased_ms, ms_to_expiry, now = wasm_get_sys_tick_ms();
if (now < g_transactions->time) {
elpased_ms = now + (0xFFFFFFFF - g_transactions->time) + 1;
}
else {
elpased_ms = now - g_transactions->time;
}
ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms;
api_timer_restart(g_trans_timer, ms_to_expiry);
}
else {
api_timer_cancel(g_trans_timer);
g_trans_timer = NULL;
}
}
void
api_send_request(request_t *request, response_handler_f response_handler,
void *user_data)
{
int size;
char *buffer;
transaction_t *trans;
if ((trans = (transaction_t *)malloc(sizeof(transaction_t))) == NULL) {
printf(
"send request: allocate memory for request transaction failed!\n");
return;
}
memset(trans, 0, sizeof(transaction_t));
trans->handler = response_handler;
trans->mid = request->mid;
trans->time = wasm_get_sys_tick_ms();
trans->user_data = user_data;
if ((buffer = pack_request(request, &size)) == NULL) {
printf("send request: pack request failed!\n");
free(trans);
return;
}
transaction_add(trans);
/* if the trans is the 1st one, start the timer */
if (trans == g_transactions) {
/* assert(g_trans_timer == NULL); */
if (g_trans_timer == NULL) {
g_trans_timer = api_timer_create(TRANSACTION_TIMEOUT_MS, false,
true, transaction_timeout_handler);
}
}
wasm_post_request(buffer, size);
free_req_resp_packet(buffer);
}
/*
*
* APIs for the native layers to callback for request/response arrived to this
* app
*
*/
void
on_response(char *buffer, int size)
{
response_t response[1];
transaction_t *trans;
if (NULL == unpack_response(buffer, size, response)) {
printf("unpack response failed\n");
return;
}
if ((trans = transaction_find(response->mid)) == NULL) {
printf("cannot find the transaction\n");
return;
}
/*
* When the 1st transaction get response:
* 1. If the 2nd trans exist, restart the timer according to its expiry
* time;
* 2. Otherwise, stop the timer since there is no more transactions;
*/
if (trans == g_transactions) {
if (trans->next != NULL) {
unsigned int elpased_ms, ms_to_expiry, now = wasm_get_sys_tick_ms();
if (now < trans->next->time) {
elpased_ms = now + (0xFFFFFFFF - trans->next->time) + 1;
}
else {
elpased_ms = now - trans->next->time;
}
ms_to_expiry = TRANSACTION_TIMEOUT_MS - elpased_ms;
api_timer_restart(g_trans_timer, ms_to_expiry);
}
else {
api_timer_cancel(g_trans_timer);
g_trans_timer = NULL;
}
}
trans->handler(response, trans->user_data);
transaction_remove(trans);
}
void
on_request(char *buffer, int size)
{
request_t request[1];
bool is_event;
res_register_t *r = g_resources;
if (NULL == unpack_request(buffer, size, request)) {
printf("unpack request failed\n");
return;
}
is_event = is_event_type(request);
while (r) {
if ((is_event && r->reg_type == Reg_Event)
|| (!is_event && r->reg_type == Reg_Request)) {
if (check_url_start(request->url, strlen(request->url), r->url)
> 0) {
r->request_handler(request);
return;
}
}
r = r->next;
}
printf("on_request: exit. no service handler\n");
}
void
api_response_send(response_t *response)
{
int size;
char *buffer = pack_response(response, &size);
if (buffer == NULL)
return;
wasm_response_send(buffer, size);
free_req_resp_packet(buffer);
}
/// event api
bool
api_publish_event(const char *url, int fmt, void *payload, int payload_len)
{
int size;
request_t request[1];
init_request(request, (char *)url, COAP_EVENT, fmt, payload, payload_len);
char *buffer = pack_request(request, &size);
if (buffer == NULL)
return false;
wasm_post_request(buffer, size);
free_req_resp_packet(buffer);
return true;
}
bool
api_subscribe_event(const char *url, request_handler_f handler)
{
return register_url_handler(url, handler, Reg_Event);
}

View File

@ -0,0 +1,100 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdlib.h>
#include <string.h>
#include "wa-inc/timer_wasm_app.h"
#include "timer_api.h"
#if 1
#include <stdio.h>
#else
#define printf (...)
#endif
struct user_timer {
struct user_timer *next;
int timer_id;
void (*user_timer_callback)(user_timer_t);
};
struct user_timer *g_timers = NULL;
user_timer_t
api_timer_create(int interval, bool is_period, bool auto_start,
on_user_timer_update_f on_timer_update)
{
int timer_id = wasm_create_timer(interval, is_period, auto_start);
// TODO
struct user_timer *timer =
(struct user_timer *)malloc(sizeof(struct user_timer));
if (timer == NULL) {
// TODO: remove the timer_id
printf("### api_timer_create malloc faild!!! \n");
return NULL;
}
memset(timer, 0, sizeof(*timer));
timer->timer_id = timer_id;
timer->user_timer_callback = on_timer_update;
if (g_timers == NULL)
g_timers = timer;
else {
timer->next = g_timers;
g_timers = timer;
}
return timer;
}
void
api_timer_cancel(user_timer_t timer)
{
user_timer_t t = g_timers, prev = NULL;
wasm_timer_cancel(timer->timer_id);
while (t) {
if (t == timer) {
if (prev == NULL) {
g_timers = t->next;
free(t);
}
else {
prev->next = t->next;
free(t);
}
return;
}
else {
prev = t;
t = t->next;
}
}
}
void
api_timer_restart(user_timer_t timer, int interval)
{
wasm_timer_restart(timer->timer_id, interval);
}
void
on_timer_callback(int timer_id)
{
struct user_timer *t = g_timers;
while (t) {
if (t->timer_id == timer_id) {
t->user_timer_callback(t);
break;
}
t = t->next;
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _TIMER_API_H_
#define _TIMER_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int timer_id_t;
timer_id_t
wasm_create_timer(int interval, bool is_period, bool auto_start);
void
wasm_timer_destroy(timer_id_t timer_id);
void
wasm_timer_cancel(timer_id_t timer_id);
void
wasm_timer_restart(timer_id_t timer_id, int interval);
uint32
wasm_get_sys_tick_ms(void);
#ifdef __cplusplus
}
#endif
#endif /* end of _TIMER_API_H_ */

View File

@ -0,0 +1,171 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _AEE_REQUEST_H_
#define _AEE_REQUEST_H_
#include "bi-inc/shared_utils.h"
#ifdef __cplusplus
extern "C" {
#endif
/* CoAP request method codes */
typedef enum {
COAP_GET = 1,
COAP_POST,
COAP_PUT,
COAP_DELETE,
COAP_EVENT = (COAP_DELETE + 2)
} coap_method_t;
/* CoAP response codes */
typedef enum {
NO_ERROR = 0,
CREATED_2_01 = 65, /* CREATED */
DELETED_2_02 = 66, /* DELETED */
VALID_2_03 = 67, /* NOT_MODIFIED */
CHANGED_2_04 = 68, /* CHANGED */
CONTENT_2_05 = 69, /* OK */
CONTINUE_2_31 = 95, /* CONTINUE */
BAD_REQUEST_4_00 = 128, /* BAD_REQUEST */
UNAUTHORIZED_4_01 = 129, /* UNAUTHORIZED */
BAD_OPTION_4_02 = 130, /* BAD_OPTION */
FORBIDDEN_4_03 = 131, /* FORBIDDEN */
NOT_FOUND_4_04 = 132, /* NOT_FOUND */
METHOD_NOT_ALLOWED_4_05 = 133, /* METHOD_NOT_ALLOWED */
NOT_ACCEPTABLE_4_06 = 134, /* NOT_ACCEPTABLE */
PRECONDITION_FAILED_4_12 = 140, /* BAD_REQUEST */
REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */
UNSUPPORTED_MEDIA_TYPE_4_15 = 143, /* UNSUPPORTED_MEDIA_TYPE */
INTERNAL_SERVER_ERROR_5_00 = 160, /* INTERNAL_SERVER_ERROR */
NOT_IMPLEMENTED_5_01 = 161, /* NOT_IMPLEMENTED */
BAD_GATEWAY_5_02 = 162, /* BAD_GATEWAY */
SERVICE_UNAVAILABLE_5_03 = 163, /* SERVICE_UNAVAILABLE */
GATEWAY_TIMEOUT_5_04 = 164, /* GATEWAY_TIMEOUT */
PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */
/* Erbium errors */
MEMORY_ALLOCATION_ERROR = 192,
PACKET_SERIALIZATION_ERROR,
/* Erbium hooks */
MANUAL_RESPONSE,
PING_RESPONSE
} coap_status_t;
/**
* @typedef request_handler_f
*
* @brief Define the signature of callback function for API
* api_register_resource_handler() to handle request or for API
* api_subscribe_event() to handle event.
*
* @param request pointer of the request to be handled
*
* @see api_register_resource_handler
* @see api_subscribe_event
*/
typedef void (*request_handler_f)(request_t *request);
/**
* @typedef response_handler_f
*
* @brief Define the signature of callback function for API
* api_send_request() to handle response of a request.
*
* @param response pointer of the response to be handled
* @param user_data user data associated with the request which is set when
* calling api_send_request().
*
* @see api_send_request
*/
typedef void (*response_handler_f)(response_t *response, void *user_data);
/*
*****************
* Request APIs
*****************
*/
/**
* @brief Register resource.
*
* @param url url of the resource
* @param handler callback function to handle the request to the resource
*
* @return true if success, false otherwise
*/
bool
api_register_resource_handler(const char *url, request_handler_f handler);
/**
* @brief Send request asynchronously.
*
* @param request pointer of the request to be sent
* @param response_handler callback function to handle the response
* @param user_data user data
*/
void
api_send_request(request_t *request, response_handler_f response_handler,
void *user_data);
/**
* @brief Send response.
*
* @param response pointer of the response to be sent
*
* @par
* @code
* void res1_handler(request_t *request)
* {
* response_t response[1];
* make_response_for_request(request, response);
* set_response(response, DELETED_2_02, 0, NULL, 0);
* api_response_send(response);
* }
* @endcode
*/
void
api_response_send(response_t *response);
/*
*****************
* Event APIs
*****************
*/
/**
* @brief Publish an event.
*
* @param url url of the event
* @param fmt format of the event payload
* @param payload payload of the event
* @param payload_len length in bytes of the event payload
*
* @return true if success, false otherwise
*/
bool
api_publish_event(const char *url, int fmt, void *payload, int payload_len);
/**
* @brief Subscribe an event.
*
* @param url url of the event
* @param handler callback function to handle the event.
*
* @return true if success, false otherwise
*/
bool
api_subscribe_event(const char *url, request_handler_f handler);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _AEE_TIMER_H_
#define _AEE_TIMER_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* board producer define user_timer */
struct user_timer;
typedef struct user_timer *user_timer_t;
/**
* @typedef on_user_timer_update_f
*
* @brief Define the signature of callback function for API api_timer_create().
*
* @param timer the timer
*
* @see api_timer_create
*/
typedef void (*on_user_timer_update_f)(user_timer_t timer);
/*
*****************
* Timer APIs
*****************
*/
/**
* @brief Create timer.
*
* @param interval timer interval
* @param is_period whether the timer is periodic
* @param auto_start whether start the timer immediately after created
* @param on_timer_update callback function called when timer expired
*
* @return the timer created if success, NULL otherwise
*/
user_timer_t
api_timer_create(int interval, bool is_period, bool auto_start,
on_user_timer_update_f on_timer_update);
/**
* @brief Cancel timer.
*
* @param timer the timer to cancel
*/
void
api_timer_cancel(user_timer_t timer);
/**
* @brief Restart timer.
*
* @param timer the timer to cancel
* @param interval the timer interval
*/
void
api_timer_restart(user_timer_t timer, int interval);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,13 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WASM_APP_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${WASM_APP_BASE_DIR})
add_definitions (-DWASM_ENABLE_BASE_LIB)
file (GLOB_RECURSE source_all ${WASM_APP_BASE_DIR}/*.c)
set (WASM_APP_CURRENT_SOURCE ${source_all})
set (WASM_APP_BASE_DIR ${WASM_APP_BASE_DIR} PARENT_SCOPE)

View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _LIB_AEE_H_
#define _LIB_AEE_H_
#include "bi-inc/shared_utils.h"
#include "bi-inc/attr_container.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* end of _LIB_AEE_H_ */

View File

@ -0,0 +1,14 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
EXPORT_WASM_API_WITH_SIG(wasm_register_resource, "($)"),
EXPORT_WASM_API_WITH_SIG(wasm_response_send, "(*~)i"),
EXPORT_WASM_API_WITH_SIG(wasm_post_request, "(*~)"),
EXPORT_WASM_API_WITH_SIG(wasm_sub_event, "($)"),
EXPORT_WASM_API_WITH_SIG(wasm_create_timer, "(iii)i"),
EXPORT_WASM_API_WITH_SIG(wasm_timer_destroy, "(i)"),
EXPORT_WASM_API_WITH_SIG(wasm_timer_cancel, "(i)"),
EXPORT_WASM_API_WITH_SIG(wasm_timer_restart, "(ii)"),
EXPORT_WASM_API_WITH_SIG(wasm_get_sys_tick_ms, "()i"),

View File

@ -0,0 +1,24 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib_export.h"
#include "req_resp_native_api.h"
#include "timer_native_api.h"
static NativeSymbol extended_native_symbol_defs[] = {
/* TODO: use macro EXPORT_WASM_API() or EXPORT_WASM_API2() to
add functions to register. */
#include "base_lib.inl"
};
uint32
get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
{
*p_base_lib_apis = extended_native_symbol_defs;
return sizeof(extended_native_symbol_defs) / sizeof(NativeSymbol);
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _REQ_RESP_API_H_
#define _REQ_RESP_API_H_
#include "bh_platform.h"
#include "wasm_export.h"
#ifdef __cplusplus
extern "C" {
#endif
bool
wasm_response_send(wasm_exec_env_t exec_env, char *buffer, int size);
void
wasm_register_resource(wasm_exec_env_t exec_env, char *url);
void
wasm_post_request(wasm_exec_env_t exec_env, char *buffer, int size);
void
wasm_sub_event(wasm_exec_env_t exec_env, char *url);
#ifdef __cplusplus
}
#endif
#endif /* end of _REQ_RESP_API_H_ */

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "app_manager_export.h"
#include "coap_ext.h"
#include "wasm_export.h"
#include "bh_assert.h"
extern void
module_request_handler(request_t *request, void *user_data);
bool
wasm_response_send(wasm_exec_env_t exec_env, char *buffer, int size)
{
if (buffer != NULL) {
response_t response[1];
if (NULL == unpack_response(buffer, size, response))
return false;
am_send_response(response);
return true;
}
return false;
}
void
wasm_register_resource(wasm_exec_env_t exec_env, char *url)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (url != NULL) {
unsigned int mod_id =
app_manager_get_module_id(Module_WASM_App, module_inst);
bh_assert(mod_id != ID_NONE);
am_register_resource(url, module_request_handler, mod_id);
}
}
void
wasm_post_request(wasm_exec_env_t exec_env, char *buffer, int size)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (buffer != NULL) {
request_t req[1];
if (!unpack_request(buffer, size, req))
return;
// TODO: add permission check, ensure app can't do harm
// set sender to help dispatch the response to the sender ap
unsigned int mod_id =
app_manager_get_module_id(Module_WASM_App, module_inst);
bh_assert(mod_id != ID_NONE);
req->sender = mod_id;
if (req->action == COAP_EVENT) {
am_publish_event(req);
return;
}
am_dispatch_request(req);
}
}
void
wasm_sub_event(wasm_exec_env_t exec_env, char *url)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
if (url != NULL) {
unsigned int mod_id =
app_manager_get_module_id(Module_WASM_App, module_inst);
bh_assert(mod_id != ID_NONE);
am_register_event(url, mod_id);
}
}

View File

@ -0,0 +1,22 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef LIB_BASE_RUNTIME_LIB_H_
#define LIB_BASE_RUNTIME_LIB_H_
#include "runtime_timer.h"
bool
init_wasm_timer();
void
exit_wasm_timer();
timer_ctx_t
get_wasm_timer_ctx();
timer_ctx_t
create_wasm_timer_ctx(unsigned int module_id, int prealloc_num);
void
destroy_module_timer_ctx(unsigned int module_id);
#endif /* LIB_BASE_RUNTIME_LIB_H_ */

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _TIMER_API_H_
#define _TIMER_API_H_
#include "bh_platform.h"
#include "wasm_export.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int timer_id_t;
/*
* timer interfaces
*/
typedef unsigned int timer_id_t;
timer_id_t
wasm_create_timer(wasm_exec_env_t exec_env, int interval, bool is_period,
bool auto_start);
void
wasm_timer_destroy(wasm_exec_env_t exec_env, timer_id_t timer_id);
void
wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id);
void
wasm_timer_restart(wasm_exec_env_t exec_env, timer_id_t timer_id, int interval);
uint32
wasm_get_sys_tick_ms(wasm_exec_env_t exec_env);
#ifdef __cplusplus
}
#endif
#endif /* end of _TIMER_API_H_ */

View File

@ -0,0 +1,220 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_platform.h"
#include "app_manager_export.h"
#include "../app-manager/module_wasm_app.h"
#include "timer_native_api.h"
typedef struct {
bh_list_link l;
timer_ctx_t timer_ctx;
} timer_ctx_node_t;
static bool timer_thread_run = true;
static bh_list g_timer_ctx_list;
static korp_cond g_timer_ctx_list_cond;
static korp_mutex g_timer_ctx_list_mutex;
void
wasm_timer_callback(timer_id_t id, unsigned int mod_id)
{
module_data *module = module_data_list_lookup_id(mod_id);
if (module == NULL)
return;
// !!! the length parameter must be 0, so the receiver will
// not free the payload pointer.
bh_post_msg(module->queue, TIMER_EVENT_WASM, (char *)(uintptr_t)id, 0);
}
/**
* why we create a separate link for module timer contexts
* rather than traverse the module list?
* It helps to reduce the lock frequency for the module list.
* Also when we lock the module list and then call the callback for
* timer expire, the callback is request the list lock again for lookup
* the module from module id. It is for avoiding that situation.
*/
void *
thread_modulers_timer_check(void *arg)
{
uint32 ms_to_expiry;
uint64 us_to_wait;
while (timer_thread_run) {
ms_to_expiry = (uint32)-1;
os_mutex_lock(&g_timer_ctx_list_mutex);
timer_ctx_node_t *elem =
(timer_ctx_node_t *)bh_list_first_elem(&g_timer_ctx_list);
while (elem) {
uint32 next = check_app_timers(elem->timer_ctx);
if (next != (uint32)-1) {
if (ms_to_expiry == (uint32)-1 || ms_to_expiry > next)
ms_to_expiry = next;
}
elem = (timer_ctx_node_t *)bh_list_elem_next(elem);
}
os_mutex_unlock(&g_timer_ctx_list_mutex);
if (ms_to_expiry == (uint32)-1)
us_to_wait = BHT_WAIT_FOREVER;
else
us_to_wait = (uint64)ms_to_expiry * 1000;
os_mutex_lock(&g_timer_ctx_list_mutex);
os_cond_reltimedwait(&g_timer_ctx_list_cond, &g_timer_ctx_list_mutex,
us_to_wait);
os_mutex_unlock(&g_timer_ctx_list_mutex);
}
return NULL;
}
void
wakeup_modules_timer_thread(timer_ctx_t ctx)
{
os_mutex_lock(&g_timer_ctx_list_mutex);
os_cond_signal(&g_timer_ctx_list_cond);
os_mutex_unlock(&g_timer_ctx_list_mutex);
}
bool
init_wasm_timer()
{
korp_tid tm_tid;
bh_list_init(&g_timer_ctx_list);
if (os_cond_init(&g_timer_ctx_list_cond) != 0) {
return false;
}
/* temp solution for: thread_modulers_timer_check thread
would recursive lock the mutex */
if (os_recursive_mutex_init(&g_timer_ctx_list_mutex) != 0) {
goto fail1;
}
if (0
!= os_thread_create(&tm_tid, thread_modulers_timer_check, NULL,
BH_APPLET_PRESERVED_STACK_SIZE)) {
goto fail2;
}
return true;
fail2:
os_mutex_destroy(&g_timer_ctx_list_mutex);
fail1:
os_cond_destroy(&g_timer_ctx_list_cond);
return false;
}
void
exit_wasm_timer()
{
timer_thread_run = false;
}
timer_ctx_t
create_wasm_timer_ctx(unsigned int module_id, int prealloc_num)
{
timer_ctx_t ctx =
create_timer_ctx(wasm_timer_callback, wakeup_modules_timer_thread,
prealloc_num, module_id);
if (ctx == NULL)
return NULL;
timer_ctx_node_t *node =
(timer_ctx_node_t *)wasm_runtime_malloc(sizeof(timer_ctx_node_t));
if (node == NULL) {
destroy_timer_ctx(ctx);
return NULL;
}
memset(node, 0, sizeof(*node));
node->timer_ctx = ctx;
os_mutex_lock(&g_timer_ctx_list_mutex);
bh_list_insert(&g_timer_ctx_list, node);
os_mutex_unlock(&g_timer_ctx_list_mutex);
return ctx;
}
void
destroy_module_timer_ctx(unsigned int module_id)
{
timer_ctx_node_t *elem;
os_mutex_lock(&g_timer_ctx_list_mutex);
elem = (timer_ctx_node_t *)bh_list_first_elem(&g_timer_ctx_list);
while (elem) {
if (timer_ctx_get_owner(elem->timer_ctx) == module_id) {
bh_list_remove(&g_timer_ctx_list, elem);
destroy_timer_ctx(elem->timer_ctx);
wasm_runtime_free(elem);
break;
}
elem = (timer_ctx_node_t *)bh_list_elem_next(elem);
}
os_mutex_unlock(&g_timer_ctx_list_mutex);
}
timer_ctx_t
get_wasm_timer_ctx(wasm_module_inst_t module_inst)
{
module_data *m = app_manager_get_module_data(Module_WASM_App, module_inst);
if (m == NULL)
return NULL;
return m->timer_ctx;
}
timer_id_t
wasm_create_timer(wasm_exec_env_t exec_env, int interval, bool is_period,
bool auto_start)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
return sys_create_timer(timer_ctx, interval, is_period, auto_start);
}
void
wasm_timer_destroy(wasm_exec_env_t exec_env, timer_id_t timer_id)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
sys_timer_destroy(timer_ctx, timer_id);
}
void
wasm_timer_cancel(wasm_exec_env_t exec_env, timer_id_t timer_id)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
sys_timer_cancel(timer_ctx, timer_id);
}
void
wasm_timer_restart(wasm_exec_env_t exec_env, timer_id_t timer_id, int interval)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
sys_timer_restart(timer_ctx, timer_id, interval);
}
uint32
wasm_get_sys_tick_ms(wasm_exec_env_t exec_env)
{
return (uint32)bh_get_tick_ms();
}

View File

@ -0,0 +1,13 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WASM_LIB_BASE_DIR ${CMAKE_CURRENT_LIST_DIR})
add_definitions (-DWASM_ENABLE_BASE_LIB)
include_directories(${WASM_LIB_BASE_DIR})
file (GLOB_RECURSE source_all ${WASM_LIB_BASE_DIR}/*.c)
set (WASM_APP_LIB_CURRENT_SOURCE ${source_all})

View File

@ -0,0 +1,118 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wa-inc/connection.h"
#include "connection_api.h"
/* Raw connection structure */
typedef struct _connection {
/* Next connection */
struct _connection *next;
/* Handle of the connection */
uint32 handle;
/* Callback function called when event on this connection occurs */
on_connection_event_f on_event;
/* User data */
void *user_data;
} connection_t;
/* Raw connections list */
static connection_t *g_conns = NULL;
connection_t *
api_open_connection(const char *name, attr_container_t *args,
on_connection_event_f on_event, void *user_data)
{
connection_t *conn;
char *args_buffer = (char *)args;
uint32 handle, args_len = attr_container_get_serialize_length(args);
handle = wasm_open_connection(name, args_buffer, args_len);
if (handle == -1)
return NULL;
conn = (connection_t *)malloc(sizeof(*conn));
if (conn == NULL) {
wasm_close_connection(handle);
return NULL;
}
memset(conn, 0, sizeof(*conn));
conn->handle = handle;
conn->on_event = on_event;
conn->user_data = user_data;
if (g_conns != NULL) {
conn->next = g_conns;
g_conns = conn;
}
else {
g_conns = conn;
}
return conn;
}
void
api_close_connection(connection_t *c)
{
connection_t *conn = g_conns, *prev = NULL;
while (conn) {
if (conn == c) {
wasm_close_connection(c->handle);
if (prev != NULL)
prev->next = conn->next;
else
g_conns = conn->next;
free(conn);
return;
}
else {
prev = conn;
conn = conn->next;
}
}
}
int
api_send_on_connection(connection_t *conn, const char *data, uint32 len)
{
return wasm_send_on_connection(conn->handle, data, len);
}
bool
api_config_connection(connection_t *conn, attr_container_t *cfg)
{
char *cfg_buffer = (char *)cfg;
uint32 cfg_len = attr_container_get_serialize_length(cfg);
return wasm_config_connection(conn->handle, cfg_buffer, cfg_len);
}
void
on_connection_data(uint32 handle, char *buffer, uint32 len)
{
connection_t *conn = g_conns;
while (conn != NULL) {
if (conn->handle == handle) {
if (len == 0) {
conn->on_event(conn, CONN_EVENT_TYPE_DISCONNECT, NULL, 0,
conn->user_data);
}
else {
conn->on_event(conn, CONN_EVENT_TYPE_DATA, buffer, len,
conn->user_data);
}
return;
}
conn = conn->next;
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef CONNECTION_API_H_
#define CONNECTION_API_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
uint32
wasm_open_connection(const char *name, char *args_buf, uint32 args_buf_len);
void
wasm_close_connection(uint32 handle);
int
wasm_send_on_connection(uint32 handle, const char *data, uint32 data_len);
bool
wasm_config_connection(uint32 handle, const char *cfg_buf, uint32 cfg_buf_len);
#ifdef __cplusplus
}
#endif
#endif /* end of CONNECTION_API_H_ */

View File

@ -0,0 +1,94 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _CONNECTION_H_
#define _CONNECTION_H_
#include "bi-inc/attr_container.h"
#ifdef __cplusplus
extern "C" {
#endif
struct _connection;
typedef struct _connection connection_t;
/* Connection event type */
typedef enum {
/* Data is received */
CONN_EVENT_TYPE_DATA = 1,
/* Connection is disconnected */
CONN_EVENT_TYPE_DISCONNECT
} conn_event_type_t;
/*
* @typedef on_connection_event_f
*
* @param conn the connection that the event belongs to
* @param type event type
* @param data the data received for CONN_EVENT_TYPE_DATA event
* @param len length of the data in byte
* @param user_data user data
*/
typedef void (*on_connection_event_f)(connection_t *conn,
conn_event_type_t type, const char *data,
uint32 len, void *user_data);
/*
*****************
* Connection API's
*****************
*/
/*
* @brief Open a connection.
*
* @param name name of the connection, "TCP", "UDP" or "UART"
* @param args connection arguments, such as: ip:127.0.0.1, port:8888
* @param on_event callback function called when event occurs
* @param user_data user data
*
* @return the connection or NULL means fail
*/
connection_t *
api_open_connection(const char *name, attr_container_t *args,
on_connection_event_f on_event, void *user_data);
/*
* @brief Close a connection.
*
* @param conn connection
*/
void
api_close_connection(connection_t *conn);
/*
* Send data to the connection in non-blocking manner which returns immediately
*
* @param conn the connection
* @param data data buffer to be sent
* @param len length of the data in byte
*
* @return actual length sent, or -1 if fail(maybe underlying buffer is full)
*/
int
api_send_on_connection(connection_t *conn, const char *data, uint32 len);
/*
* @brief Configure connection.
*
* @param conn the connection
* @param cfg configurations
*
* @return true if success, false otherwise
*/
bool
api_config_connection(connection_t *conn, attr_container_t *cfg);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,11 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
set (WASM_APP_CONN_DIR ${CMAKE_CURRENT_LIST_DIR})
include_directories(${WASM_APP_CONN_DIR})
file (GLOB source_all ${WASM_APP_CONN_DIR}/*.c)
set (WASM_APP_CURRENT_SOURCE ${source_all})

Some files were not shown because too many files have changed in this diff Show More