Skip to content

Commit

Permalink
refactor: refine build script
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Oct 8, 2024
1 parent 5e1ab18 commit 54047aa
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_ubuntu1804.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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_test=false ten_enable_package_manager=false
tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=false log_level=1 enable_serialized_actions=true ten_enable_tests=false ten_enable_package_manager=false
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 @@ -46,7 +46,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_test=false
tgn gen linux x64 ${{ matrix.build_type }} -- is_clang=${{ matrix.compiler == 'gcc' && 'false' || 'true' }} log_level=1 enable_serialized_actions=true ten_enable_tests=false
tgn build linux x64 ${{ matrix.build_type }}
tree -I 'gen|obj' out
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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_test=false
tgn gen mac arm64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_tests=false
tgn build mac arm64 ${{ matrix.build_type }}
tree -I 'gen|obj' out
Expand Down Expand Up @@ -121,6 +121,6 @@ jobs:
fi
export PATH=$(pwd)/core/ten_gn:$PATH
echo $PATH
tgn gen mac x64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_test=false
tgn gen mac x64 ${{ matrix.build_type }} -- log_level=1 enable_serialized_actions=true ten_enable_tests=false
tgn build mac x64 ${{ matrix.build_type }}
tree -I 'gen|obj' out
2 changes: 1 addition & 1 deletion .github/workflows/build_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ 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_test=false
tgn gen win x64 ${{ matrix.build_type }} -- vs_version=2022 log_level=1 enable_serialized_actions=true ten_enable_tests=false
tgn build win x64 ${{ matrix.build_type }}
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ group("ten_framework_all") {
deps += [ "//core/src/ten_manager" ]
}

if (ten_enable_test) {
if (ten_enable_tests) {
deps += [ "//tests" ]
}
}
5 changes: 3 additions & 2 deletions build/common/rust/rust.gni
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/options.gni")
import("//build/ten_rust/options.gni")

template("rust_target") {
assert(defined(invoker.project_path), "project_file is not defined")
Expand Down Expand Up @@ -43,7 +44,7 @@ template("rust_target") {
}

if (is_debug) {
if (ten_enable_rust_asan) {
if (ten_rust_enable_asan) {
if (enable_sanitizer) {
_rustflags = "${_rustflags} -Zsanitizer=address"
}
Expand Down Expand Up @@ -209,7 +210,7 @@ template("rust_test") {
}

if (is_debug) {
if (ten_enable_rust_asan) {
if (ten_rust_enable_asan) {
if (enable_sanitizer) {
_rustflags = "${_rustflags} -Zsanitizer=address"
}
Expand Down
16 changes: 8 additions & 8 deletions build/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ declare_args() {
}

declare_args() {
ten_enable_test = true
ten_enable_private_tests = false
# 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() {
# Rust AddressSanitizer is supported on Linux x64 and macOS x64/arm64. Refer
# to: https://doc.rust-lang.org/stable/unstable-book/compiler-flags/sanitizer.html#addresssanitizer
#
# rustc finds the asan runtime library in ~/.rustup/toolchains/<target_cpu>/
# lib/rustlib/<target_cpu>/lib/librustc-nightly_rt.asan.a
ten_enable_rust_asan = is_mac || (is_linux && target_cpu == "x64")
ten_enable_package_manager = true
}
9 changes: 9 additions & 0 deletions build/ten_manager/options.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# 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.
#
declare_args() {
ten_package_manager_enable_publish = target_cpu != "arm64"
}
3 changes: 2 additions & 1 deletion build/ten_runtime/feature/publish.gni
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_manager/options.gni")
import("//build/ten_runtime/options.gni")

template("ten_package_publish") {
Expand Down Expand Up @@ -36,7 +37,7 @@ template("ten_package_publish") {
rebase_path(published_results),
]

if (!ten_enable_package_manager_publish) {
if (!ten_package_manager_enable_publish) {
args += [ "--no-enable-publish" ]
}

Expand Down
11 changes: 8 additions & 3 deletions build/ten_runtime/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ declare_args() {
ten_enable_libwebsockets = true

ten_enable_curl = true

ten_enable_package_manager = true
ten_enable_package_manager_publish = target_cpu != "arm64"
}

# ten_runtime binding
Expand Down Expand Up @@ -55,6 +52,14 @@ declare_args() {
ten_enable_go_lint = ten_enable_go_binding && is_linux && is_clang && is_debug
}

declare_args() {
ten_enable_tests = true
ten_enable_unit_tests = true
ten_enable_smoke_tests = true
ten_enable_integration_tests = true
ten_enable_private_tests = false
}

ten_runtime_common_defines = common_defines
if (ten_enable_memory_check) {
ten_runtime_common_defines += [ "TEN_ENABLE_MEMORY_CHECK" ]
Expand Down
15 changes: 9 additions & 6 deletions build/ten_rust/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
# Refer to the "LICENSE" file in the root directory for more information.
#
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.
# Rust AddressSanitizer is supported on Linux x64 and macOS x64/arm64. Refer
# to: https://doc.rust-lang.org/stable/unstable-book/compiler-flags/sanitizer.html#addresssanitizer
#
# TODO(Liu): Add a gn target to compile the 'ten_utils' static without asan on
# x86.
enable_ten_rust = !(enable_sanitizer && target_cpu == "x86")
# rustc finds the asan runtime library in ~/.rustup/toolchains/<target_cpu>/
# lib/rustlib/<target_cpu>/lib/librustc-nightly_rt.asan.a
ten_rust_enable_asan = is_mac || (is_linux && target_cpu == "x64")
}

declare_args() {
ten_rust_enable_tests = is_linux || is_win || (is_mac && target_cpu == "x64")
}
3 changes: 2 additions & 1 deletion build/ten_utils/options.gni
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ declare_args() {
ten_utils_enable_value = true

# If set, including tests
ten_utils_enable_tests = is_linux
ten_utils_enable_tests = true
ten_utils_enable_unit_tests = is_linux
}
8 changes: 4 additions & 4 deletions core/src/ten_rust/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ copy("ten_rust_test_data") {
outputs = [ "${root_out_dir}/tests/standalone/ten_rust/tests/test_data" ]
}

if (enable_ten_rust) {
if (is_linux || is_win || (is_mac && target_cpu == "x64")) {
if (ten_enable_ten_rust) {
if (ten_rust_enable_tests) {
rust_test("ten_rust_test") {
project_path = "//core/src/ten_rust"
integration_test_output_name = "integration_test"
Expand Down Expand Up @@ -84,10 +84,10 @@ group("ten_rust") {
deps = []
public_deps = []

if (enable_ten_rust) {
if (ten_enable_ten_rust) {
public_deps += [ ":ten_rust_binding" ]

if (is_linux || is_win || (is_mac && target_cpu == "x64")) {
if (ten_rust_enable_tests) {
deps += [ ":ten_rust_test" ]
}
}
Expand Down
30 changes: 18 additions & 12 deletions tests/ten_runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Licensed under the Apache License, Version 2.0, with certain conditions.
# Refer to the "LICENSE" file in the root directory for more information.
#
import("//build/ten_runtime/options.gni")
import("//build/ten_runtime/ten.gni")
import("//core/src/ten_runtime/output_libs.gni")
import("//core/src/ten_utils/output_libs.gni")
Expand Down Expand Up @@ -44,19 +45,24 @@ copy("copy_libraries_for_test") {
}

group("ten_runtime") {
deps = [
"smoke",
"unit",
]
deps = []

if (ten_enable_tests && ten_enable_unit_tests) {
deps += [ "unit" ]
}

if (ten_enable_tests && ten_enable_smoke_tests) {
deps += [ "smoke" ]
}

if (
# Almost all integration test cases needs ten_manager.
ten_enable_package_manager &&
# Currently, there is only x64 Mac machine in TEN CI clusters, and we need to
# run 'tman' during the preparation phase of each 'dev' test case, and tman of
# non-x64 version could not be run in x64 Mac machine, so we have to only
# enable 'dev' test cases on Mac for x64 only.
(is_linux || is_win || (is_mac && target_cpu == "x64"))) {
if (ten_enable_tests && ten_enable_integration_tests &&
# Almost all integration test cases needs ten_manager.
ten_enable_package_manager &&
# Currently, there is only x64 Mac machine in TEN CI clusters, and we need to
# run 'tman' during the preparation phase of each 'dev' test case, and tman of
# non-x64 version could not be run in x64 Mac machine, so we have to only
# enable 'dev' test cases on Mac for x64 only.
(is_linux || is_win || (is_mac && target_cpu == "x64"))) {
deps += [ "integration" ]
}
}
2 changes: 1 addition & 1 deletion tests/ten_utils/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ten_utils_test("ten_utils_unit_test") {
}

ten_utils_group("ten_utils") {
if (ten_utils_enable_tests) {
if (ten_utils_enable_tests && ten_utils_enable_unit_tests) {
public_deps = [ ":ten_utils_unit_test" ]
}
}

0 comments on commit 54047aa

Please sign in to comment.