diff --git a/core/iwasm/app-samples/hello-world-cmake/CMakeLists.txt b/core/iwasm/app-samples/hello-world-cmake/CMakeLists.txt new file mode 100644 index 00000000..fd4b2cca --- /dev/null +++ b/core/iwasm/app-samples/hello-world-cmake/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required (VERSION 3.5) +project(hello_world) + +add_library(print print.c) + +add_executable(hello_world main.c) +target_link_libraries(hello_world print) \ No newline at end of file diff --git a/core/iwasm/app-samples/hello-world-cmake/build.sh b/core/iwasm/app-samples/hello-world-cmake/build.sh new file mode 100755 index 00000000..56077177 --- /dev/null +++ b/core/iwasm/app-samples/hello-world-cmake/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +mkdir build +cd build +cmake .. -DCMAKE_TOOLCHAIN_FILE=../../../../test-tools/toolchain/wamr_toolchain.cmake +make \ No newline at end of file diff --git a/core/iwasm/app-samples/hello-world-cmake/main.c b/core/iwasm/app-samples/hello-world-cmake/main.c new file mode 100644 index 00000000..ced44196 --- /dev/null +++ b/core/iwasm/app-samples/hello-world-cmake/main.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdio.h" + +void print_line(char* str); + +int main() +{ + print_line("Hello World!"); + print_line("Wasm Micro Runtime"); + return 0; +} \ No newline at end of file diff --git a/core/iwasm/app-samples/hello-world-cmake/print.c b/core/iwasm/app-samples/hello-world-cmake/print.c new file mode 100644 index 00000000..62378b83 --- /dev/null +++ b/core/iwasm/app-samples/hello-world-cmake/print.c @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdio.h" +#include "string.h" + +void print_line(char* str) +{ + printf("%s\n", str); +} \ No newline at end of file diff --git a/doc/building.md b/doc/building.md index 13c5bdc1..ff1be640 100644 --- a/doc/building.md +++ b/doc/building.md @@ -235,6 +235,26 @@ clang-8 --target=wasm32 -O3 -Wl,--initial-memory=131072,--allow-undefined,--expo You will get ```test.wasm``` which is the WASM app binary. +## Use cmake + +If you have a cmake project, you can cross compile your project by using the toolchain provided by WAMR, the compiler used by WAMR toolchain is `clang-8`. + +We can generate a `CMakeLists.txt` file for `test.c`: +```cmake +cmake_minimum_required (VERSION 3.5) +project(hello_world) +add_executable(hello_world test.c) +``` +It is quite simple to build this project by cmake: +```Bash +mkdir build && cd build +cmake .. -DCMAKE_TOOLCHAIN_FILE=$WAMR_ROOT/test-tools/toolchain/wamr_toolchain.cmake +make +``` +You will get ```hello_world``` which is the WASM app binary. + +For more details about wamr toolchain, please refer to [test-tools/toolchain](../test-tools/toolchain/README.md). + ## Using Docker The last method availble is using [Docker](https://www.docker.com/). We assume you've already configured Docker (see Platform section above) and have a running interactive shell. Currently the Dockerfile only supports compiling apps with clang, with Emscripten planned for the future. diff --git a/test-tools/toolchain/README.md b/test-tools/toolchain/README.md new file mode 100644 index 00000000..65d3b186 --- /dev/null +++ b/test-tools/toolchain/README.md @@ -0,0 +1,16 @@ +# Cross Compile Toolchain for Wasm Micro Runtime +This folder contains sysroot and toolchain files for building wasm application by using cmake. + +## Build a project +To build a C project into wasm, you may use the toolchain file provided here as `wamr_toolchain.cmake`: +```Bash +cmake /path/to/CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE=/path/to/wamr_toolchain.cmake +make +``` + +## Generate a toolchain for your runtime +If you extend more APIs of wasm runtime by using `EXPORT_WASM_API` API, we also provide a tool which allow you to generate the toolchain for your runtime: +```Bash +./generate_toolchain.py -o out_dir -f api_list_file +``` +A toolchain which enables your extended APIs should be generated in the path you specified. \ No newline at end of file diff --git a/test-tools/toolchain/generate_toolchain.py b/test-tools/toolchain/generate_toolchain.py new file mode 100755 index 00000000..58b2154f --- /dev/null +++ b/test-tools/toolchain/generate_toolchain.py @@ -0,0 +1,124 @@ +#!/usr/bin/python3 + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +import shutil +from optparse import OptionParser + +import re + +optParser = OptionParser() +optParser.add_option("-o", "", dest="output_dir", help="the output path of sysroot") +optParser.add_option("-f", "--api_file", dest="api_file_name", + help="append user defined APIs to toolchain") +(options, args) = optParser.parse_args() +optParser.usage = "%prog [options] output_dir" + +sysroot_path = os.path.join(os.getcwd(), "sysroot") +if not os.path.isdir(sysroot_path): + print("Error: No sysroot folder in current path.") + exit(0) + +if options.output_dir == None: + out_dir = sysroot_path +else: + out_dir = os.path.join(os.path.abspath(options.output_dir), "sysroot") + +def check_sysroot(): + if out_dir != sysroot_path and not os.path.isdir(out_dir): + try: + shutil.copytree(sysroot_path,out_dir) + except: + print('Error while copy sysroot') + +def Search_API(pattern, file): + f = open(file, 'r') + content = f.read() + f.close() + p = re.compile(pattern, re.S | re.M) + return p.findall(content) + +def fill_defined_symbols(): + wamr_root = os.path.join(os.getcwd(), "../..") + user_lib_dir = os.path.join(wamr_root, "core/iwasm/lib/native/extension") + + defined_symbols = [] + # WAMR extension APIs + for lib in os.listdir(user_lib_dir): + for file in os.listdir(os.path.join(user_lib_dir, lib)): + if re.match(r'.*.inl', file): + defined_symbols += Search_API(r'EXPORT_WASM_API[(](.*?)[)]', os.path.join(user_lib_dir, lib, file)) + + # Base lib APIs + defined_symbols += Search_API(r'EXPORT_WASM_API[(](.*?)[)]', + os.path.join(wamr_root, "core/iwasm/lib/native/base", "base_lib_export.c")) + + # libc + defined_symbols += Search_API(r'REG_NATIVE_FUNC[(]env, _(.*?)[)]', + os.path.join(wamr_root, "core/iwasm/lib/native/libc", "libc_wrapper.c")) + + # User defined APIs + if options.api_file_name != None: + api_file = open(options.api_file_name) + APIs = api_file.read().split('\n') + if APIs != None and APIs != []: + defined_symbols += APIs + + defined_symbols = [i for i in defined_symbols if len(i) != 0] + symbol_file = open(os.path.join(out_dir, "share/defined-symbols.txt"), 'w') + symbol_file.write('\n'.join(defined_symbols)) + symbol_file.close() + +def generate_toolchain_file(): + cmake_content = """ + SET(CMAKE_SYSTEM_NAME Linux) + SET(CMAKE_SYSTEM_PROCESSOR wasm32) + SET (CMAKE_SYSROOT {}) + + SET (CMAKE_C_FLAGS "-nostdlib" CACHE INTERNAL "") + SET (CMAKE_C_COMPILER_TARGET "wasm32") + SET (CMAKE_C_COMPILER "clang-8") + + SET (CMAKE_CXX_FLAGS "-nostdlib" CACHE INTERNAL "") + SET (CMAKE_CXX_COMPILER_TARGET "wasm32") + SET (CMAKE_CXX_COMPILER "clang++-8") + + SET (CMAKE_EXE_LINKER_FLAGS "-Wl,--no-entry,--export-all,--allow-undefined-file=${{CMAKE_SYSROOT}}/share/defined-symbols.txt" CACHE INTERNAL "") + SET (CMAKE_LINKER "/usr/bin/wasm-ld-8" CACHE INTERNAL "") + + SET (CMAKE_AR "/usr/bin/llvm-ar-8" CACHE INTERNAL "") + SET (CMAKE_NM "/usr/bin/llvm-nm-8" CACHE INTERNAL "") + SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump-8" CACHE INTERNAL "") + SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib-8" CACHE INTERNAL "") + """.format(out_dir) + f = open(os.path.join(out_dir, "..", "wamr_toolchain.cmake"), 'w') + f.write(cmake_content) + f.close() + +def main(): + check_sysroot() + fill_defined_symbols() + generate_toolchain_file() + + print("Successfully generate wamr toolchain") + print("Now you can use this command to build your cmake based project:") + print("cmake /path/to/CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE={}" + .format(os.path.abspath(os.path.join(out_dir, "..", "wamr_toolchain.cmake")))) + +if __name__ == '__main__': + main() + diff --git a/test-tools/toolchain/sysroot/include/assert.h b/test-tools/toolchain/sysroot/include/assert.h new file mode 100644 index 00000000..5dbcbd56 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/assert.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_ASSERT_H +#define _WAMR_LIBC_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/ctype.h b/test-tools/toolchain/sysroot/include/ctype.h new file mode 100644 index 00000000..c23308f1 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/ctype.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_CTYPE_H +#define _WAMR_LIBC_CTYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/errno.h b/test-tools/toolchain/sysroot/include/errno.h new file mode 100644 index 00000000..69d9ec4d --- /dev/null +++ b/test-tools/toolchain/sysroot/include/errno.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_ERRNO_H +#define _WAMR_LIBC_ERRNO_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/fcntl.h b/test-tools/toolchain/sysroot/include/fcntl.h new file mode 100644 index 00000000..4d6d24da --- /dev/null +++ b/test-tools/toolchain/sysroot/include/fcntl.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_FCNTL_H +#define _WAMR_LIBC_FCNTL_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/inttypes.h b/test-tools/toolchain/sysroot/include/inttypes.h new file mode 100644 index 00000000..f79aaf5b --- /dev/null +++ b/test-tools/toolchain/sysroot/include/inttypes.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_INTTYPES_H +#define _WAMR_LIBC_INTTYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/limits.h b/test-tools/toolchain/sysroot/include/limits.h new file mode 100644 index 00000000..6e6fd85f --- /dev/null +++ b/test-tools/toolchain/sysroot/include/limits.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_LIMITS_H +#define _WAMR_LIBC_LIMITS_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/stdbool.h b/test-tools/toolchain/sysroot/include/stdbool.h new file mode 100644 index 00000000..e87c74b5 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/stdbool.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_STDBOOL_H +#define _WAMR_LIBC_STDBOOL_H + +#define __bool_true_false_are_defined 1 + +#ifndef __cplusplus + +#define bool _Bool +#define false 0 +#define true 1 + +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/stdint.h b/test-tools/toolchain/sysroot/include/stdint.h new file mode 100644 index 00000000..5054e80f --- /dev/null +++ b/test-tools/toolchain/sysroot/include/stdint.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_STDINT_H +#define _WAMR_LIBC_STDINT_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/stdio.h b/test-tools/toolchain/sysroot/include/stdio.h new file mode 100644 index 00000000..cccf2296 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/stdio.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_STDIO_H +#define _WAMR_LIBC_STDIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned int size_t; + +int printf(const char *format, ...); +int putchar(int c); +int snprintf(char *str, size_t size, const char *format, ...); +int sprintf(char *str, const char *format, ...); +int puts(char *string); + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/stdlib.h b/test-tools/toolchain/sysroot/include/stdlib.h new file mode 100644 index 00000000..d65f6184 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/stdlib.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_STDLIB_H +#define _WAMR_LIBC_STDLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned int size_t; + +void *malloc(size_t size); +void *calloc(size_t n, size_t size); +void free(void *ptr); + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/string.h b/test-tools/toolchain/sysroot/include/string.h new file mode 100644 index 00000000..2921de4e --- /dev/null +++ b/test-tools/toolchain/sysroot/include/string.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_STRING_H +#define _WAMR_LIBC_STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned int size_t; + +int memcmp(const void *s1, const void *s2, size_t n); +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); +char *strchr(const char *s, int c); +int strcmp(const char *s1, const char *s2); +char *strcpy(char *dest, const char *src); +size_t strlen(const char *s); +int strncmp(const char * str1, const char * str2, size_t n); +char *strncpy(char *dest, const char *src, unsigned long n); +char * strdup(const char *s); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/strings.h b/test-tools/toolchain/sysroot/include/strings.h new file mode 100644 index 00000000..d29dc512 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/strings.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_STRINGS_H +#define _WAMR_LIBC_STRINGS_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/include/time.h b/test-tools/toolchain/sysroot/include/time.h new file mode 100644 index 00000000..c08f3bf5 --- /dev/null +++ b/test-tools/toolchain/sysroot/include/time.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WAMR_LIBC_TIME_H +#define _WAMR_LIBC_TIME_H + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test-tools/toolchain/sysroot/share/defined-symbols.txt b/test-tools/toolchain/sysroot/share/defined-symbols.txt new file mode 100644 index 00000000..a10eac14 --- /dev/null +++ b/test-tools/toolchain/sysroot/share/defined-symbols.txt @@ -0,0 +1,56 @@ +wasm_open_connection +wasm_close_connection +wasm_send_on_connection +wasm_config_connection +wasm_sensor_open +wasm_sensor_config +wasm_sensor_config_with_attr_container +wasm_sensor_close +wasm_btn_native_call +wasm_obj_native_call +wasm_label_native_call +wasm_cont_native_call +wasm_page_native_call +wasm_list_native_call +wasm_ddlist_native_call +wasm_cb_native_call +wasm_register_resource +wasm_response_send +wasm_post_request +wasm_sub_event +wasm_create_timer +wasm_timer_destroy +wasm_timer_cancel +wasm_timer_restart +wasm_get_sys_tick_ms +wasm_runtime_get_current_module_inst1 +wasm_runtime_validate_app_addr1 +wasm_runtime_validate_native_addr1 +wasm_runtime_addr_app_to_native1 +wasm_runtime_addr_native_to_app1 +printf +sprintf +snprintf +puts +putchar +memcmp +memcpy +memmove +memset +strchr +strcmp +strcpy +strlen +strncmp +strncpy +malloc +calloc +strdup +free +llvm_bswap_i16 +llvm_bswap_i32 +bitshift64Lshr +bitshift64Shl +llvm_stackrestore +llvm_stacksave +emscripten_memcpy_big \ No newline at end of file diff --git a/test-tools/toolchain/wamr_toolchain.cmake b/test-tools/toolchain/wamr_toolchain.cmake new file mode 100644 index 00000000..97b730ea --- /dev/null +++ b/test-tools/toolchain/wamr_toolchain.cmake @@ -0,0 +1,33 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SET(CMAKE_SYSTEM_NAME Linux) +SET(CMAKE_SYSTEM_PROCESSOR wasm32) +SET (CMAKE_SYSROOT ${CMAKE_CURRENT_LIST_DIR}/sysroot) + +SET (CMAKE_C_FLAGS "-nostdlib" CACHE INTERNAL "") +SET (CMAKE_C_COMPILER_TARGET "wasm32") +SET (CMAKE_C_COMPILER "clang-8") + +SET (CMAKE_CXX_FLAGS "-nostdlib" CACHE INTERNAL "") +SET (CMAKE_CXX_COMPILER_TARGET "wasm32") +SET (CMAKE_CXX_COMPILER "clang++-8") + +SET (CMAKE_EXE_LINKER_FLAGS "-Wl,--no-entry,--export-all,--allow-undefined-file=${CMAKE_SYSROOT}/share/defined-symbols.txt" CACHE INTERNAL "") +SET (CMAKE_LINKER "/usr/bin/wasm-ld-8" CACHE INTERNAL "") + +SET (CMAKE_AR "/usr/bin/llvm-ar-8" CACHE INTERNAL "") +SET (CMAKE_NM "/usr/bin/llvm-nm-8" CACHE INTERNAL "") +SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump-8" CACHE INTERNAL "") +SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib-8" CACHE INTERNAL "")