Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate app framework apis #93

Merged
merged 29 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b7102ec
support request and timer
yviansu Dec 6, 2023
42641f3
config build scripts
yviansu Dec 7, 2023
53fd3ad
add GC_binaryen flag
yviansu Dec 8, 2023
8bbcdc4
Merge remote-tracking branch 'upstream/main' into connectionAPI
yviansu Dec 12, 2023
ece2af9
fix source ts code bug
yviansu Dec 12, 2023
69238ad
support charCodeAt
yviansu Dec 13, 2023
619b49c
fix I32ToArrayBuffer
yviansu Dec 13, 2023
e602b11
fix framework ts code
yviansu Dec 14, 2023
34700ed
fix getUint16 error
yviansu Dec 14, 2023
f73fced
fix load in sign and unsign
yviansu Dec 14, 2023
1e43414
support connection app-framework code
yviansu Dec 14, 2023
6ae3fe9
implement attr_container code
yviansu Dec 15, 2023
0445fe4
fix compile error
yviansu Dec 15, 2023
a753b26
fix attr_container ts code error
yviansu Dec 15, 2023
dc5a014
fix some bug
yviansu Dec 15, 2023
20d4ab3
remove unused code
yviansu Dec 15, 2023
83c7ab9
use malloc and free in nativeSignature
yviansu Dec 19, 2023
933c90d
fix endian
yviansu Dec 19, 2023
96de2e2
Merge remote-tracking branch 'upstream/main' into connectionAPI
yviansu Dec 19, 2023
b66cfe6
adjust test samples
yviansu Dec 19, 2023
ec4ff0f
adjust structure
yviansu Dec 19, 2023
e69f3c4
customize build.sh
yviansu Dec 20, 2023
56eb6b0
add timer as a param in cb
yviansu Dec 20, 2023
eb6452b
add setStart config
yviansu Dec 20, 2023
d974e9f
add host-aot profile
yviansu Dec 20, 2023
698de20
fix aot cmake profile
yviansu Dec 20, 2023
b77ba0e
use simple libdyntype for app-framework example
xujuntwt95329 Dec 20, 2023
b749fac
Merge remote-tracking branch 'upstream/main' into connectionAPI
yviansu Dec 21, 2023
f577a2d
rename config
yviansu Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ logs
*.wasm
*.log
*.swo
example/app-framework/cmake-build/
example/app-framework/out/
5 changes: 5 additions & 0 deletions cli/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
"description": "Specify the entry function, default is _entry",
"default": "_entry"
},
"startSection": {
"category": "Compile",
"description": "Whether to use start section to do initialization, default is false",
"default": false
},
"dumpSemanticTree": {
"category": "Debug",
"description": "dump semantic tree, default is false",
Expand Down
2 changes: 2 additions & 0 deletions config/config_mgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ConfigMgr {
enableException: boolean;
enableStringRef: boolean;
entry: string;
startSection: boolean;
dumpSemanticTree: boolean;
}

Expand All @@ -20,6 +21,7 @@ const defaultConfig: ConfigMgr = {
enableException: false,
enableStringRef: true,
entry: '_entry',
startSection: false,
dumpSemanticTree: false,
};

Expand Down
113 changes: 113 additions & 0 deletions example/app-framework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright (C) 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required (VERSION 2.9)

project (simple)

################ wamr runtime settings ################
message(STATUS "WAMR_BUILD_SDK_PROFILE=${WAMR_BUILD_SDK_PROFILE}")

# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif ()

set (RUNTIMR_DIR ${CMAKE_CURRENT_LIST_DIR}/../../runtime-library)
set (WAMR_ROOT_DIR ${RUNTIMR_DIR}/deps/wamr-gc)

## use library and headers in the SDK
link_directories(${WAMR_ROOT_DIR}/wamr-sdk/out/${WAMR_BUILD_SDK_PROFILE}/runtime-sdk/lib)
include_directories(
${WAMR_ROOT_DIR}/wamr-sdk/out/${WAMR_BUILD_SDK_PROFILE}/runtime-sdk/include
${WAMR_ROOT_DIR}/core/shared/utils
${WAMR_ROOT_DIR}/core/shared/platform/linux
)

################ application related ################

include_directories(${CMAKE_CURRENT_LIST_DIR}/src)

#Note: uncomment below line to use UART mode
#add_definitions (-DCONNECTION_UART)


## wamr
# include(${CMAKE_CURRENT_LIST_DIR}/wamr_config_wasmnizer_ts.cmake)
# add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
set (WAMR_BUILD_PLATFORM "linux")
set (WAMR_BUILD_TARGET X86_64)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 0)
set (WAMR_BUILD_GC 1)
set (WAMR_BUILD_GC_BINARYEN 1)
set (WAMR_BUILD_STRINGREF 1)
set (USE_SIMPLE_LIBDYNTYPE 1)

## stringref
set(STRINGREF_DIR ${RUNTIMR_DIR}/stringref)
set(WAMR_STRINGREF_IMPL_SOURCE
${STRINGREF_DIR}/stringref_simple.c
)

include(${RUNTIMR_DIR}/deps/wamr-gc/build-scripts/runtime_lib.cmake)

## libdyntype
set(LIBDYNTYPE_DIR ${RUNTIMR_DIR}/libdyntype)
include (${LIBDYNTYPE_DIR}/libdyntype.cmake)

## stdlib
set(STDLIB_DIR ${RUNTIMR_DIR}/stdlib)
include_directories(${STDLIB_DIR})
set(STDLIB_SOURCE
${STDLIB_DIR}/lib_console.c
${STDLIB_DIR}/lib_array.c
${STDLIB_DIR}/lib_timer.c
)

## struct-indirect
set(STRUCT_INDIRECT_DIR ${RUNTIMR_DIR}/struct-indirect)
include_directories(${STRUCT_INDIRECT_DIR})
set(STRUCT_INDIRECT_SOURCE
${STRUCT_INDIRECT_DIR}/lib_struct_indirect.c
)

## utils
set(UTILS_DIR ${RUNTIMR_DIR}/utils)
include_directories(${UTILS_DIR})
set(TYPE_UTILS_SOURCE
${UTILS_DIR}/type_utils.c
)
set(OBJECT_UTILS_SOURCE
${UTILS_DIR}/object_utils.c
)
set(WAMR_UTILS_SOURCE
${UTILS_DIR}/wamr_utils.c
)
# Ignore warnings of QuickJS
set_source_files_properties(
${QUICKJS_SOURCE}
PROPERTIES
COMPILE_FLAGS "-w"
)

add_executable (simple src/main.c src/iwasm_main.c
${QUICKJS_SOURCE}
${LIBDYNTYPE_SRC}
${STDLIB_SOURCE}
${STRUCT_INDIRECT_SOURCE}
${TYPE_UTILS_SOURCE}
${OBJECT_UTILS_SOURCE}
${WAMR_UTILS_SOURCE}
)
target_link_libraries (simple vmlib -lm -ldl -lpthread -lrt)



73 changes: 73 additions & 0 deletions example/app-framework/app/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

import * as connection from '../lib/connection';
import * as timer from '../lib/timer';
import * as request from '../lib/request';
import * as attr_container from '../lib/attr_container';

let num = 0;
let g_conn: connection.wamr_connection | null;

function timer1_update(my_timer: timer.user_timer) {
const message = 'Hello, ' + num;
num++;
connection.send_on_connection(g_conn!, message, message.length);
}

export function on_init(): void {
request.register_resource_handler('/close', (req) => {
if (g_conn !== null) {
timer.timer_cancel(my_timer);
connection.close_connection(g_conn);
}
const resp = request.make_response_for_request(req);
resp.set_response(request.CoAP_Status.DELETED_2_02, 0, null, 0);
request.api_response_send(resp);
});

let args = attr_container.attr_container_create('');
let isSuccess = attr_container.attr_container_set_string(
args,
'address',
'127.0.0.1',
);
if (isSuccess) {
args = attr_container.global_attr_cont;
}
isSuccess = attr_container.attr_container_set_uint16(args, 'port', 7777);
if (isSuccess) {
args = attr_container.global_attr_cont;
}

g_conn = connection.open_connection(
'TCP',
args,
(conn, type, data, len) => {
if (type == connection.CONN_EVENT_TYPE_DATA) {
const message = data;
console.log('Client got a message from server ->' + message);
} else if (type == connection.CONN_EVENT_TYPE_DISCONNECT) {
console.log('connection is close by server!');
} else {
console.log('error: got unknown event type!!!');
}
},
);
if (g_conn == null) {
console.log('connect to server fail!');
return;
}

console.log('connect to server success!');

// const my_timer = new timer.user_timer(timer1_update, 1000, true);
// timer.timer_restart(my_timer, 1000);
const my_timer = timer.setInterval(timer1_update, 2000);
}

export function on_destroy(): void {
// on destory actions
}
28 changes: 28 additions & 0 deletions example/app-framework/app/request_handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

import * as request from '../lib/request';
import { arraybuffer_to_string, string_to_arraybuffer } from '../lib/utils';

export function on_init(): void {
request.register_resource_handler('/test', (req) => {
const payload_string = arraybuffer_to_string(
req.payload,
req.payload_len,
);

console.log('### Req: /test ' + payload_string);
console.log(' request payload:');
console.log(' ' + payload_string + '\n');

const resp = request.make_response_for_request(req);
resp.set_payload(string_to_arraybuffer('OK'), 2);
request.api_response_send(resp);
});
}

export function on_destroy(): void {
// on destory actions
}
29 changes: 29 additions & 0 deletions example/app-framework/app/request_sender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

import * as request from '../lib/request';
import { arraybuffer_to_string, string_to_arraybuffer } from '../lib/utils';

export function on_init(): void {
const payload = string_to_arraybuffer('hello, handler');
request.post('/test', payload, payload.byteLength, '', (resp) => {
if (resp != null) {
console.log('Post Success');

if (resp.payload != null) {
console.log(' response payload:');
const resp_payload_string = arraybuffer_to_string(
resp.payload,
resp.payload_len,
);
console.log(' ' + resp_payload_string + '\n');
}
} else console.log('Post Timeout');
});
}

export function on_destroy(): void {
// on destory actions
}
26 changes: 26 additions & 0 deletions example/app-framework/app/timer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

import * as timer from '../lib/timer';

let cnt = 0;

export function on_init(): void {
/* The callback function will be called every 2 second,
and will stop after 10 calls */
const my_timer = timer.setInterval((my_timer) => {
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 {
// on destory actions
}
Loading