diff --git a/.github/workflows/build_linux_arm64.yml b/.github/workflows/build_linux_arm64.yml index 5f93ed5197..d88e83fa9e 100644 --- a/.github/workflows/build_linux_arm64.yml +++ b/.github/workflows/build_linux_arm64.yml @@ -78,7 +78,7 @@ jobs: 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 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 ten_enable_clean_build=true && \ tgn build linux arm64 ${{ matrix.build_type }} && \ tree -I 'gen|obj' out \ " diff --git a/.github/workflows/build_linux_ubuntu1804.yml b/.github/workflows/build_linux_ubuntu1804.yml index 1dcd263fa5..cf770de2c0 100644 --- a/.github/workflows/build_linux_ubuntu1804.yml +++ b/.github/workflows/build_linux_ubuntu1804.yml @@ -50,7 +50,7 @@ jobs: echo $PATH go env -w GOFLAGS="-buildvcs=false" rustup default nightly - tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=false log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_enable_package_manager=false ten_rust_enable_gen_cargo_config=false + tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=false log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_enable_package_manager=false ten_rust_enable_gen_cargo_config=false ten_enable_clean_build=true tgn build linux x64 ${{ matrix.build_type }} tree -I 'gen|obj' out diff --git a/.github/workflows/build_linux_ubuntu2204.yml b/.github/workflows/build_linux_ubuntu2204.yml index 8cb3b141ef..05f2118aae 100644 --- a/.github/workflows/build_linux_ubuntu2204.yml +++ b/.github/workflows/build_linux_ubuntu2204.yml @@ -45,7 +45,7 @@ jobs: go env -w GOFLAGS="-buildvcs=false" go1.20.12 download rustup default nightly - tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_package_manager_enable_tests=false ten_rust_enable_gen_cargo_config=false + tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_package_manager_enable_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_clean_build=true tgn build linux x64 ${{ matrix.build_type }} tree -I 'gen|obj' out diff --git a/.github/workflows/build_mac.yml b/.github/workflows/build_mac.yml index 2a55c26b66..a2ca95fc4a 100644 --- a/.github/workflows/build_mac.yml +++ b/.github/workflows/build_mac.yml @@ -76,7 +76,7 @@ jobs: fi export PATH=$(pwd)/core/ten_gn:$PATH echo $PATH - tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_rust_enable_gen_cargo_config=false + tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_clean_build=true tgn build mac arm64 ${{ matrix.build_type }} tree -I 'gen|obj' out diff --git a/.github/workflows/build_win.yml b/.github/workflows/build_win.yml index d819d5411b..54569c016e 100644 --- a/.github/workflows/build_win.yml +++ b/.github/workflows/build_win.yml @@ -49,7 +49,7 @@ jobs: - name: Build run: | $ENV:PATH += ";$PWD/core/ten_gn" - tgn gen win x64 ${{ matrix.build_type }} -- vs_version=2022 log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_package_manager_enable_tests=false ten_rust_enable_gen_cargo_config=false + tgn gen win x64 ${{ matrix.build_type }} -- vs_version=2022 log_level=1 enable_serialized_actions=true ten_enable_integration_tests=false ten_enable_private_tests=false ten_rust_enable_tests=false ten_package_manager_enable_tests=false ten_rust_enable_gen_cargo_config=false ten_enable_clean_build=true tgn build win x64 ${{ matrix.build_type }} - name: Run Tests (ten_utils_unit_test) diff --git a/build/common/rust/rust.gni b/build/common/rust/rust.gni index 291b23139f..f3df921008 100644 --- a/build/common/rust/rust.gni +++ b/build/common/rust/rust.gni @@ -479,3 +479,63 @@ template("rust_gen_cargo_config") { outputs = [ _output ] } } + +template("rust_clean") { + _project_path = rebase_path(invoker.project_path) + _target_path = rebase_path(invoker.target_path) + + _target_name = target_name + + action("${_target_name}") { + script = "//build/common/rust/rust_clean.py" + _output = "${target_gen_dir}/${_target_name}_rust_clean" + + args = [ + "--project-path", + _project_path, + "--target-path", + _target_path, + "--tg-timestamp-proxy-file", + rebase_path(_output), + "--log-level", + "${log_level}", + ] + + if (is_win) { + if (target_cpu == "x86") { + target = "i686-pc-windows-msvc" + } else if (target_cpu == "x64") { + target = "x86_64-pc-windows-msvc" + } else if (target_cpu == "arm64") { + target = "aarch64-pc-windows-msvc" + } + } else if (is_linux) { + if (target_cpu == "arm64") { + target = "aarch64-unknown-linux-gnu" + } else if (target_cpu == "arm") { + target = "armv7-unknown-linux-gnueabi" + } else if (target_cpu == "x86") { + target = "i686-unknown-linux-gnu" + } else if (target_cpu == "x64") { + target = "x86_64-unknown-linux-gnu" + } + } else if (is_mac) { + if (target_cpu == "arm64") { + target = "aarch64-apple-darwin" + } else if (target_cpu == "x86") { + target = "i686-apple-darwin" + } else if (target_cpu == "x64") { + target = "x86_64-apple-darwin" + } + } + + args += [ + "--target", + target, + ] + + forward_variables_from(invoker, [ "deps" ]) + + outputs = [ _output ] + } +} diff --git a/build/common/rust/rust.py b/build/common/rust/rust.py index 71145e8dbe..97dc92499f 100644 --- a/build/common/rust/rust.py +++ b/build/common/rust/rust.py @@ -49,7 +49,6 @@ def __init__(self): origin_wd = os.getcwd() try: - os.chdir(args.project_path) cmd = [ diff --git a/build/common/rust/rust_clean.py b/build/common/rust/rust_clean.py new file mode 100644 index 0000000000..31d51a52b4 --- /dev/null +++ b/build/common/rust/rust_clean.py @@ -0,0 +1,73 @@ +# +# Copyright © 2024 Agora +# This file is part of TEN Framework, an open source project. +# Licensed under the Apache License, Version 2.0, with certain conditions. +# Refer to the "LICENSE" file in the root directory for more information. +# +import argparse +import sys +import os +from build.scripts import cmd_exec, timestamp_proxy + + +class ArgumentInfo(argparse.Namespace): + def __init__(self): + super().__init__() + self.project_path: str + self.target_path: str + self.target: str + self.log_level: int + self.tg_timestamp_proxy_file: str | None = None + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + + parser.add_argument("--project-path", type=str, required=True) + parser.add_argument("--target-path", type=str, required=True) + parser.add_argument("--target", type=str, required=True) + parser.add_argument("--log-level", type=int, required=True) + parser.add_argument( + "--tg-timestamp-proxy-file", type=str, default="", required=False + ) + + arg_info = ArgumentInfo() + args = parser.parse_args(namespace=arg_info) + + origin_wd = os.getcwd() + + returncode = 0 + try: + os.chdir(args.project_path) + + cmd = [ + "cargo", + "clean", + "--target-dir", + args.target_path, + "--target", + args.target, + ] + + returncode, logs = cmd_exec.run_cmd(cmd, args.log_level) + if returncode: + raise Exception( + f"Failed to run `cargo clean` on {args.project_path}: {logs}" + ) + else: + print(logs) + + # Success to clean the rust project, update the stamp file to represent + # this fact. + timestamp_proxy.touch_timestamp_proxy_file(args.tg_timestamp_proxy_file) + + except Exception as exc: + returncode = 1 + timestamp_proxy.remove_timestamp_proxy_file( + args.tg_timestamp_proxy_file + ) + print(exc) + + finally: + os.chdir(origin_wd) + sys.exit(-1 if returncode != 0 else 0) diff --git a/build/options.gni b/build/options.gni index 415d79a1d3..fcbcb698bd 100644 --- a/build/options.gni +++ b/build/options.gni @@ -6,9 +6,7 @@ # declare_args() { ten_enable_memory_check = true -} -declare_args() { # The 'ten_rust' crate depends on the 'ten_utils' (C codes) static library. # The C compiler supports AddressSanitizer on Linux x86, however the rustc # does not. Therefore, the 'ten_rust' crate is disabled on x86. @@ -16,8 +14,8 @@ declare_args() { # TODO(Liu): Add a gn target to compile the 'ten_utils' static without asan on # x86. ten_enable_ten_rust = !(enable_sanitizer && target_cpu == "x86") -} -declare_args() { ten_enable_package_manager = true + + ten_enable_clean_build = false } diff --git a/core/src/ten_manager/BUILD.gn b/core/src/ten_manager/BUILD.gn index bfc344a053..42d7c019c4 100644 --- a/core/src/ten_manager/BUILD.gn +++ b/core/src/ten_manager/BUILD.gn @@ -98,8 +98,9 @@ if (ten_enable_package_manager) { } # Assembling the final ten manager package. - ten_package("ten_manager") { + ten_package("ten_manager_package") { package_kind = "custom" + package_output_root_dir_name = "ten_manager" tman_output = get_target_outputs(":tman") @@ -137,4 +138,19 @@ if (ten_enable_package_manager) { deps += [ ":copy_clingo_config_files" ] } } + + rust_clean("tman_cargo_clean") { + project_path = "//core/src/ten_manager" + target_path = get_path_info("tman", "gen_dir") + + deps = [ ":ten_manager_package" ] + } + + group("ten_manager") { + if (ten_enable_clean_build) { + deps = [ ":tman_cargo_clean" ] + } else { + deps = [ ":ten_manager_package" ] + } + } } diff --git a/core/ten_gn b/core/ten_gn index 16810350fc..91efc263dd 160000 --- a/core/ten_gn +++ b/core/ten_gn @@ -1 +1 @@ -Subproject commit 16810350fc78948a255ba0bb45d3bc338341a029 +Subproject commit 91efc263dd0ff84bc4d153a794fd482e6862d961