From 8e1c00f971c138c15ed7e29d21eebeeb4945dce0 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Mon, 14 Oct 2024 00:07:40 +0800 Subject: [PATCH 1/4] doc: update summary part --- docs/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 300550651e..111935af74 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -60,3 +60,4 @@ ## Tutorials * [How to debug with logs](tutorials/how_to_debug_with_logs.md) +* [How to run local AI model in Python extension](tutorials/how_to_run_local_model_in_python_extensions.md) From 22f545b5b9713d39ff7807a8c0f5b57aabdcc5db Mon Sep 17 00:00:00 2001 From: Jay Zhang Date: Mon, 14 Oct 2024 10:04:22 +0800 Subject: [PATCH 2/4] feat: add linux/arm64 (#98) Co-authored-by: Hu Yueh-Wei --- .github/workflows/build_docker.yml | 6 ++ .github/workflows/build_linux_arm64.yml | 99 +++++++++++++++++++ build/common/scripts/package_asan_lib.py | 24 +++-- build/ten_manager/options.gni | 4 +- build/ten_runtime/feature/autotool.py | 10 +- build/ten_runtime/feature/cmake.py | 17 ++-- build/ten_runtime/options.gni | 3 +- build/ten_rust/options.gni | 3 +- core/ten_gn | 2 +- .../ubuntu/22.04/Dockerfile | 18 ++-- 10 files changed, 157 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/build_linux_arm64.yml diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index d469efd6ac..2d6f616cb6 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -18,13 +18,18 @@ jobs: include: - image_name: "ubuntu2204" workdir: "tools/docker_for_building/ubuntu/22.04" + platforms: linux/amd64,linux/arm64 - image_name: "ubuntu1804" workdir: "tools/docker_for_building/ubuntu/18.04" + platforms: linux/amd64 runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build & Publish to Github Container Registry uses: elgohr/Publish-Docker-Github-Action@v5 with: @@ -33,5 +38,6 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: ${{ matrix.workdir }} + platforms: ${{ matrix.platforms }} snapshot: true tags: "${{ github.ref == 'refs/heads/main' && 'latest,' || '' }}" diff --git a/.github/workflows/build_linux_arm64.yml b/.github/workflows/build_linux_arm64.yml new file mode 100644 index 0000000000..50b73511b1 --- /dev/null +++ b/.github/workflows/build_linux_arm64.yml @@ -0,0 +1,99 @@ +name: Build - linux arm64 + +on: + release: + types: [created] + pull_request: + types: [opened, synchronize, reopened] + paths-ignore: + - "tools/**" + - "docs/**" + - ".vscode/**" + - ".devcontainer/**" + - ".github/**" + - "!.github/workflows/build_linux_arm64.yml" + - "**.md" + +jobs: + build: + runs-on: ubuntu-latest + concurrency: + group: build-linux-arm64-${{ github.head_ref }}-${{ matrix.compiler }}-${{ matrix.build_type }} + cancel-in-progress: true + strategy: + matrix: + compiler: [gcc] + build_type: [release] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + submodules: "true" + + - name: Update version + run: | + git config --global --add safe.directory $(pwd) + python3 tools/version/update_version_in_ten_framework.py + python3 tools/version/check_version_in_ten_framework.py + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + + - name: Build + run: | + docker run --rm --platform linux/arm64 \ + -v $(pwd):/${{ github.workspace }} -w ${{ github.workspace }} \ + ghcr.io/ten-framework/ten_building_ubuntu2204 \ + bash -c "\ + export PATH=$(pwd)/core/ten_gn:/usr/local/go/bin:/root/go/bin:/root/.cargo/bin:$PATH && \ + echo $PATH && \ + go env -w GOFLAGS="-buildvcs=false" && \ + go1.20.12 download && \ + rustup default nightly && \ + tgn gen linux arm64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_enable_tests=false ten_enable_libwebsockets=false && \ + tgn build linux arm64 ${{ matrix.build_type }} && \ + tree -I 'gen|obj' out \ + " + + - name: Upload tman + uses: actions/upload-artifact@v4 + with: + name: tman-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }} + path: out/linux/arm64/ten_manager/bin/tman + + - name: Upload ten_packages + uses: actions/upload-artifact@v4 + with: + name: ten_packages-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }} + path: | + out/linux/x64/ten_packages/system/ten_runtime + out/linux/x64/ten_packages/system/ten_runtime_go + out/linux/x64/ten_packages/system/ten_runtime_python + out/linux/arm64/ten_packages/extension/default_extension_cpp + out/linux/arm64/ten_packages/extension/default_extension_go + out/linux/arm64/ten_packages/extension/default_extension_python + out/linux/arm64/ten_packages/extension/py_init_extension_cpp + + - name: Package assets + if: startsWith(github.ref, 'refs/tags/') + run: | + cd out/linux/arm64 + zip -vr tman-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip ten_manager/bin/tman + zip -vr ten_packages-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip \ + ten_packages/system/ten_runtime \ + ten_packages/system/ten_runtime_go \ + ten_packages/system/ten_runtime_python \ + ten_packages/extension/default_extension_cpp \ + ten_packages/extension/default_extension_go \ + ten_packages/extension/default_extension_python \ + ten_packages/extension/py_init_extension_cpp + + - name: Publish to release assets + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + out/linux/arm64/tman-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip + out/linux/arm64/ten_packages-linux-arm64-${{ matrix.compiler }}-${{ matrix.build_type }}.zip diff --git a/build/common/scripts/package_asan_lib.py b/build/common/scripts/package_asan_lib.py index a4ee39bdcd..aba618a169 100644 --- a/build/common/scripts/package_asan_lib.py +++ b/build/common/scripts/package_asan_lib.py @@ -52,7 +52,7 @@ def detect_mac_asan_lib(arch: str) -> str: def detect_linux_asan_lib(arch: str) -> str: - if arch == "x64": + if arch in ["x64", "arm64"]: out, _ = subprocess.Popen( "gcc -print-file-name=libasan.so", shell=True, @@ -79,13 +79,21 @@ def detect_linux_asan_lib(arch: str) -> str: # Generally speaking, this function should not need to be called because Clang's # default ASan mechanism is static linking. -def detect_linux_clang_asan_lib(_arch: str) -> str: - out, _ = subprocess.Popen( - "clang -print-file-name=libclang_rt.asan-x86_64.so", - shell=True, - stdout=subprocess.PIPE, - encoding="utf-8", - ).communicate() +def detect_linux_clang_asan_lib(arch: str) -> str: + if arch == "x64": + out, _ = subprocess.Popen( + "clang -print-file-name=libclang_rt.asan-x86_64.so", + shell=True, + stdout=subprocess.PIPE, + encoding="utf-8", + ).communicate() + elif arch == "arm64": + out, _ = subprocess.Popen( + "clang -print-file-name=libclang_rt.asan-aarch64.so", + shell=True, + stdout=subprocess.PIPE, + encoding="utf-8", + ).communicate() libasan_path = out.strip() diff --git a/build/ten_manager/options.gni b/build/ten_manager/options.gni index 539ac3eb57..a92482b9aa 100644 --- a/build/ten_manager/options.gni +++ b/build/ten_manager/options.gni @@ -9,6 +9,6 @@ declare_args() { } declare_args() { - ten_package_manager_enable_tests = - is_linux || is_win || (is_mac && target_cpu == "x64") + ten_package_manager_enable_tests = (is_linux && target_cpu == "x64") || + is_win || (is_mac && target_cpu == "x64") } diff --git a/build/ten_runtime/feature/autotool.py b/build/ten_runtime/feature/autotool.py index 58f3bd2887..db2ab65325 100644 --- a/build/ten_runtime/feature/autotool.py +++ b/build/ten_runtime/feature/autotool.py @@ -149,9 +149,15 @@ def copy_system_deps(self): if sys.platform == "linux": libs.extend( - glob.glob(f"/usr/lib/x86_64-linux-gnu/lib{dep}.so.*") + glob.glob( + f"/usr/lib/{os.uname().machine}-linux-gnu/lib{dep}.so.*" + ) + ) + libs.extend( + glob.glob( + f"/usr/lib/{os.uname().machine}-linux-gnu/lib{dep}.so" + ) ) - libs.extend(glob.glob(f"/usr/lib/x86_64-linux-gnu/lib{dep}.so")) else: print("TODO: Add support for other platforms.") sys.exit(1) diff --git a/build/ten_runtime/feature/cmake.py b/build/ten_runtime/feature/cmake.py index 283102e558..e4f08ac48e 100644 --- a/build/ten_runtime/feature/cmake.py +++ b/build/ten_runtime/feature/cmake.py @@ -192,13 +192,16 @@ def _fill_attributes(self): self.sharedlinkerflags.append("--target=arm-linux-gnueabihf") self.exelinkerflags.append("--target=arm-linux-gnueabihf") elif self.args.target_cpu == "arm64": - self.cflags.append("--target=aarch64-linux-gnu") - self.sharedlinkerflags.append("--target=aarch64-linux-gnu") - self.exelinkerflags.append("--target=aarch64-linux-gnu") - if self.args.use_clang: - self.cflags.append("-fuse-ld=lld") - self.sharedlinkerflags.append("-fuse-ld=lld") - self.exelinkerflags.append("-fuse-ld=lld") + if os.uname().machine in ["arm64", "aarch64"]: + pass + else: + self.cflags.append("--target=aarch64-linux-gnu") + self.sharedlinkerflags.append("--target=aarch64-linux-gnu") + self.exelinkerflags.append("--target=aarch64-linux-gnu") + if self.args.use_clang: + self.cflags.append("-fuse-ld=lld") + self.sharedlinkerflags.append("-fuse-ld=lld") + self.exelinkerflags.append("-fuse-ld=lld") else: raise Exception( "Currently can not build Linux target with CPU arch" diff --git a/build/ten_runtime/options.gni b/build/ten_runtime/options.gni index d687200b3f..67c40b9510 100644 --- a/build/ten_runtime/options.gni +++ b/build/ten_runtime/options.gni @@ -24,7 +24,8 @@ declare_args() { ten_enable_go_binding = is_mac || is_linux # TODO: enable it on mac and win - ten_enable_python_binding = is_linux && target_cpu == "x64" + ten_enable_python_binding = + is_linux && (target_cpu == "x64" || target_cpu == "arm64") } # ten_runtime extensions diff --git a/build/ten_rust/options.gni b/build/ten_rust/options.gni index b2ed891358..e271b1140a 100644 --- a/build/ten_rust/options.gni +++ b/build/ten_rust/options.gni @@ -94,5 +94,6 @@ declare_args() { } declare_args() { - ten_rust_enable_tests = is_linux || is_win || (is_mac && target_cpu == "x64") + ten_rust_enable_tests = (is_linux && target_cpu == "x64") || is_win || + (is_mac && target_cpu == "x64") } diff --git a/core/ten_gn b/core/ten_gn index 258196d871..897e03ff7f 160000 --- a/core/ten_gn +++ b/core/ten_gn @@ -1 +1 @@ -Subproject commit 258196d871c6cf8665b93b735d812be3662a528c +Subproject commit 897e03ff7f3f13c20644d74e55739d6bd6adb771 diff --git a/tools/docker_for_building/ubuntu/22.04/Dockerfile b/tools/docker_for_building/ubuntu/22.04/Dockerfile index 2528ba2783..878d8c7bd1 100644 --- a/tools/docker_for_building/ubuntu/22.04/Dockerfile +++ b/tools/docker_for_building/ubuntu/22.04/Dockerfile @@ -22,11 +22,13 @@ RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommend tree \ zip \ unzip \ + jq \ + cpulimit \ + util-linux \ libasan5 \ autoconf \ libtool \ uuid-dev \ - g++-multilib \ libmsgpack-dev \ libmysqlclient-dev \ libmysqlcppconn-dev \ @@ -54,6 +56,11 @@ RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommend python3-pip \ python3-venv +RUN export ARCH=$(dpkg --print-architecture) && \ + if [ ${ARCH} = "amd64" ]; then \ + apt-get install -y --no-install-recommends g++-multilib; \ + fi + # ======================================= # Installing Python deps @@ -84,10 +91,7 @@ RUN wget --no-check-certificate -O - https://apt.llvm.org/llvm-snapshot.gpg.key update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-18 100 && \ update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-18 100 && \ update-alternatives --install /usr/bin/clang-check clang-check /usr/bin/clang-check-18 100 && \ - update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-18 100 && \ - mkdir -p /usr/lib/llvm-18/lib/x86_64-pc-linux-gnu && \ - ln -sf $(clang -print-file-name=libc++.a) /usr/lib/llvm-18/lib/x86_64-pc-linux-gnu && \ - ln -sf $(clang -print-file-name=libclang_rt.asan.so) $(dirname $(clang -print-file-name=libclang_rt.asan.so))/libclang_rt.asan-x86_64.so + update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-18 100 # ======================================= # Install golang @@ -97,8 +101,8 @@ ENV PATH="$PATH:/usr/local/go/bin:/root/go/bin" # TEN go binding needs to be compatible with GO 1.20, so we need to install GO # 1.20 to check the compatibility. -RUN curl -OL https://go.dev/dl/go1.22.3.linux-amd64.tar.gz && \ - rm -rf /usr/local/go && tar -C /usr/local -xvf go1.22.3.linux-amd64.tar.gz && rm go1.22.3.linux-amd64.tar.gz && \ +RUN export ARCH=$(dpkg --print-architecture) && curl -OL https://go.dev/dl/go1.22.3.linux-${ARCH}.tar.gz && \ + rm -rf /usr/local/go && tar -C /usr/local -xvf go1.22.3.linux-${ARCH}.tar.gz && rm go1.22.3.linux-${ARCH}.tar.gz && \ go install golang.org/dl/go1.20.12@latest && go1.20.12 download # ======================================= From 78c4ca6d94d110f2b9f3c794ac74a17d16aa5c54 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Mon, 14 Oct 2024 10:14:23 +0800 Subject: [PATCH 3/4] chore: update to latest ten_gn --- core/ten_gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/ten_gn b/core/ten_gn index 897e03ff7f..16810350fc 160000 --- a/core/ten_gn +++ b/core/ten_gn @@ -1 +1 @@ -Subproject commit 897e03ff7f3f13c20644d74e55739d6bd6adb771 +Subproject commit 16810350fc78948a255ba0bb45d3bc338341a029 From 9b2378963ca478a805c6d51498d181188659bf79 Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Mon, 14 Oct 2024 12:53:59 +0700 Subject: [PATCH 4/4] chore: add more CI test cases (#136) --- .github/workflows/build_win.yml | 27 +++++++++------------ .vscode/launch.json | 10 +++++++- core/src/ten_utils/lib/sys/posix/mutex.c | 4 ++- core/src/ten_utils/sanitizer/memory_check.c | 12 +++++++++ 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build_win.yml b/.github/workflows/build_win.yml index 7ccec6f716..d819d5411b 100644 --- a/.github/workflows/build_win.yml +++ b/.github/workflows/build_win.yml @@ -54,24 +54,21 @@ jobs: - name: Run Tests (ten_utils_unit_test) env: - TEN_ENABLE_MEMORY_TRACKING: "true" TEN_ENABLE_BACKTRACE_DUMP: "true" run: | chmod +x out/win/x64/tests/standalone/ten_utils_unit_test out/win/x64/tests/standalone/ten_utils_unit_test - # - name: Run Tests (ten_runtime_unit_test) - # env: - # TEN_ENABLE_MEMORY_TRACKING: "true" - # TEN_ENABLE_BACKTRACE_DUMP: "true" - # run: | - # chmod +x out/win/x64/tests/standalone/ten_runtime_unit_test - # out/win/x64/tests/standalone/ten_runtime_unit_test + - name: Run Tests (ten_runtime_unit_test) + env: + TEN_ENABLE_BACKTRACE_DUMP: "true" + run: | + chmod +x out/win/x64/tests/standalone/ten_runtime_unit_test + out/win/x64/tests/standalone/ten_runtime_unit_test - # - name: Run Tests (ten_runtime_smoke_test) - # env: - # TEN_ENABLE_MEMORY_TRACKING: "true" - # TEN_ENABLE_BACKTRACE_DUMP: "true" - # run: | - # chmod +x out/win/x64/tests/standalone/ten_runtime_smoke_test - # out/win/x64/tests/standalone/ten_runtime_smoke_test + - name: Run Tests (ten_runtime_smoke_test) + env: + TEN_ENABLE_BACKTRACE_DUMP: "true" + run: | + chmod +x out/win/x64/tests/standalone/ten_runtime_smoke_test + out/win/x64/tests/standalone/ten_runtime_smoke_test diff --git a/.vscode/launch.json b/.vscode/launch.json index a8d74cb9fc..df34bc8443 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -47,7 +47,7 @@ "request": "launch", "program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_unit_test", "args": [ - "--gtest_filter=SchemaTest.SchemaStoreValidateProperty" + // "--gtest_filter=TenErrorTest.cpp_thread" ], "stopAtEntry": false, "cwd": "${workspaceFolder}/out/linux/x64/", @@ -59,6 +59,14 @@ { "name": "LD_PRELOAD", "value": "/usr/lib/gcc/x86_64-linux-gnu/10/libasan.so" + }, + { + "name": "TEN_ENABLE_MEMORY_TRACKING", + "value": "true" + }, + { + "name": "TEN_ENABLE_BACKTRACE_DUMP", + "value": "true" } ], "externalConsole": false, diff --git a/core/src/ten_utils/lib/sys/posix/mutex.c b/core/src/ten_utils/lib/sys/posix/mutex.c index 45936e1ba0..783f93e0d8 100644 --- a/core/src/ten_utils/lib/sys/posix/mutex.c +++ b/core/src/ten_utils/lib/sys/posix/mutex.c @@ -64,11 +64,13 @@ ten_mutex_t *ten_mutex_create(void) { } int ten_mutex_lock(ten_mutex_t *mutex) { - TEN_ASSERT(mutex && ten_mutex_check_integrity(mutex), "Invalid argument."); + TEN_ASSERT(mutex, "Invalid argument."); if (!mutex) { return -1; } + TEN_ASSERT(ten_mutex_check_integrity(mutex), "Invalid argument."); + int rc = pthread_mutex_lock(&mutex->mutex); if (rc) { TEN_ASSERT(0, "Should not happen: %d", rc); diff --git a/core/src/ten_utils/sanitizer/memory_check.c b/core/src/ten_utils/sanitizer/memory_check.c index e3c689eb6b..bf90854d8b 100644 --- a/core/src/ten_utils/sanitizer/memory_check.c +++ b/core/src/ten_utils/sanitizer/memory_check.c @@ -52,6 +52,8 @@ static void ten_sanitizer_memory_record_check_enabled(void) { } void ten_sanitizer_memory_record_init(void) { +#if defined(TEN_ENABLE_MEMORY_CHECK) + #if defined(TEN_USE_ASAN) __lsan_disable(); #endif @@ -73,9 +75,15 @@ void ten_sanitizer_memory_record_init(void) { #if defined(TEN_USE_ASAN) __lsan_enable(); #endif + +#else + TEN_LOGI("The memory check is disabled."); +#endif } void ten_sanitizer_memory_record_deinit(void) { +#if defined(TEN_ENABLE_MEMORY_CHECK) + #if defined(TEN_USE_ASAN) __lsan_disable(); #endif @@ -89,6 +97,10 @@ void ten_sanitizer_memory_record_deinit(void) { #if defined(TEN_USE_ASAN) __lsan_enable(); #endif + +#else + TEN_LOGI("The memory check is disabled."); +#endif } static ten_sanitizer_memory_record_t *ten_sanitizer_memory_record_create(