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

chore: add logic for ten_enable_clean_build #280

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .github/workflows/build_linux_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_ubuntu1804.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_ubuntu2204.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 60 additions & 0 deletions build/common/rust/rust.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
}
1 change: 0 additions & 1 deletion build/common/rust/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self):
origin_wd = os.getcwd()

try:

os.chdir(args.project_path)

cmd = [
Expand Down
73 changes: 73 additions & 0 deletions build/common/rust/rust_clean.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 2 additions & 4 deletions build/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
#
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.
#
# 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
}
18 changes: 17 additions & 1 deletion core/src/ten_manager/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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" ]
}
}
}
2 changes: 1 addition & 1 deletion core/ten_gn
Loading