Skip to content

Commit

Permalink
add aarch64 CI pipeline (#16)
Browse files Browse the repository at this point in the history
* add aarch64 CI pipeline
  • Loading branch information
oathdruid authored May 17, 2024
1 parent 5db6b61 commit 9eb00ef
Show file tree
Hide file tree
Showing 32 changed files with 370 additions and 100 deletions.
10 changes: 5 additions & 5 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17

test --//:werror --features external_include_paths
test --@rules_cuda//cuda:enable=False
test:asan --copt=-fsanitize=address --host_copt=-fsanitize=address --linkopt=-fsanitize=address --host_linkopt=-fsanitize=address
# SwissMemoryResource的Arena patch机制违背了odr,但是要保证尺寸一致,修改detect_odr_violation检测等级
test:asan --test_env ASAN_OPTIONS=detect_odr_violation=1
test:tsan --copt=-fsanitize=thread --host_copt=-fsanitize=thread --linkopt=-fsanitize=thread --host_linkopt=-fsanitize=thread
# SwissMemoryResource's patch obey odr rule. But still keep same struct with same defination and same size
# change detect_odr_violation to level 1 to check that
test --test_env=ASAN_OPTIONS=detect_odr_violation=1

test:arenastring --//proto:arenastring
test:mutable-donated-string --config=arenastring --copt=-DGOOGLE_PROTOBUF_MUTABLE_DONATED_STRING=1 --host_copt=-DGOOGLE_PROTOBUF_MUTABLE_DONATED_STRING=1
test:mutable-donated-string --config=arenastring --copt=-DGOOGLE_PROTOBUF_MUTABLE_DONATED_STRING=1

build:ci --disk_cache=bazel-disk
build:ci --repository_cache=bazel-repo
45 changes: 34 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
restore-keys: |
bazel-disk-gcc12-basic-asan-
bazel-disk-
- run: bazel test --config ci --action_env=CC=gcc-12 --config asan ...
- run: bazel test --config=ci --action_env=CC=gcc-12 --features=asan test/...

gcc12-basic-tsan:
runs-on: ubuntu-latest
Expand All @@ -43,7 +43,7 @@ jobs:
restore-keys: |
bazel-disk-gcc12-basic-tsan-
bazel-disk-
- run: bazel test --config ci --action_env=CC=gcc-12 --config tsan ...
- run: bazel test --config=ci --action_env=CC=gcc-12 --features=tsan test/...

gcc12-arenastring-asan:
runs-on: ubuntu-latest
Expand All @@ -63,7 +63,7 @@ jobs:
bazel-disk-gcc12-arenastring-
bazel-disk-
- run: sed -i '/single_version_override.*protobuf/s/25.3/25.3.arenastring/' MODULE.bazel
- run: bazel test --config ci --action_env=CC=gcc-12 --config arenastring --config asan ...
- run: bazel test --config=ci --action_env=CC=gcc-12 --config=arenastring --features=asan test/...

gcc12-mutable-donated-string-asan:
runs-on: ubuntu-latest
Expand All @@ -83,7 +83,7 @@ jobs:
bazel-disk-gcc12-mutable-donated-string-
bazel-disk-
- run: sed -i '/single_version_override.*protobuf/s/25.3/25.3.arenastring/' MODULE.bazel
- run: bazel test --config ci --action_env=CC=gcc-12 --config mutable-donated-string --config asan ...
- run: bazel test --config=ci --action_env=CC=gcc-12 --config=mutable-donated-string --features=asan test/...

clang14-basic-asan:
runs-on: ubuntu-latest
Expand All @@ -102,7 +102,7 @@ jobs:
restore-keys: |
bazel-disk-clang14-basic-asan-
bazel-disk-
- run: bazel test --config ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --config asan ...
- run: bazel test --config=ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --features=asan test/...

clang14-basic-tsan:
runs-on: ubuntu-latest
Expand All @@ -121,7 +121,7 @@ jobs:
restore-keys: |
bazel-disk-clang14-basic-tsan-
bazel-disk-
- run: bazel test --config ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --config tsan ...
- run: bazel test --config=ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --features=tsan test/...

clang14-arenastring-asan:
runs-on: ubuntu-latest
Expand All @@ -141,7 +141,7 @@ jobs:
bazel-disk-clang14-arenastring-
bazel-disk-
- run: sed -i '/single_version_override.*protobuf/s/25.3/25.3.arenastring/' MODULE.bazel
- run: bazel test --config ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --config arenastring --config asan ...
- run: bazel test --config=ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --config=arenastring --features=asan test/...

clang14-mutable-donated-string-asan:
runs-on: ubuntu-latest
Expand All @@ -161,7 +161,29 @@ jobs:
bazel-disk-clang14-mutable-donated-string-
bazel-disk-
- run: sed -i '/single_version_override.*protobuf/s/25.3/25.3.arenastring/' MODULE.bazel
- run: bazel test --config ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --config mutable-donated-string --config asan ...
- run: bazel test --config=ci --action_env=CC=clang-14 --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ --config=mutable-donated-string --features=asan test/...

gcc12-aarch64-asan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: bazel-repo
key: bazel-repo-${{hashFiles('MODULE.bazel')}}
restore-keys: |
bazel-repo-
- uses: actions/cache@v4
with:
path: bazel-disk
key: bazel-disk-gcc12-aarch64-asan-${{github.sha}}
restore-keys: |
bazel-disk-gcc12-aarch64-asan-
bazel-disk-
- run: sudo apt install g++-12-aarch64-linux-gnu
- run: sudo apt install qemu-user
- run: sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/
- run: bazel test --config=ci --platforms='@cross_config_toolchain//:cross' --action_env=CROSS_CC=/usr/bin/aarch64-linux-gnu-gcc-12 --features=-default_link_flags --features=asan --linkopt=-fuse-ld=gold --test_env=LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib --test_env=ASAN_OPTIONS=detect_odr_violation=1:detect_leaks=0 test/...

coverage:
runs-on: ubuntu-latest
Expand All @@ -180,7 +202,7 @@ jobs:
restore-keys: |
bazel-disk-coverage-
bazel-disk-
- run: bazel coverage --config ci --combined_report=lcov --instrumentation_filter='src/babylon,-src/babylon/reusable/patch' test/...
- run: bazel coverage --config=ci --combined_report=lcov --instrumentation_filter='src/babylon,-src/babylon/reusable/patch' test/...
- uses: coverallsapp/github-action@v2
with:
github-token: ${{github.token}}
Expand All @@ -191,6 +213,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cmake -Bbuild -DBUILD_DEPS=ON
- uses: hendrikmuhs/ccache-action@v1.2
- run: cmake -Bbuild -DBUILD_DEPS=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- run: cmake --build build --parallel $(nproc)
- run: ctest --test-dir build
- run: ctest --test-dir build --parallel $(nproc)
17 changes: 16 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package(
default_visibility = ['//visibility:public'],
)

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load('@bazel_skylib//rules:common_settings.bzl', 'bool_flag')

################################################################################
bool_flag(
Expand Down Expand Up @@ -210,3 +210,18 @@ alias(
actual = '//src/babylon:type_traits',
)
################################################################################

################################################################################
# bzlmod and workspace use different boost bazel support repo
load('bazel/module_name.bzl', 'module_name')

alias(
name = 'boost.preprocessor',
actual = '@boost.preprocessor' if module_name() else '@boost//:preprocessor',
)

alias(
name = 'boost.spirit',
actual = '@boost.spirit' if module_name() else '@boost//:spirit',
)
################################################################################
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(babylon VERSION 1.1.4)
project(babylon VERSION 1.1.5)

include(CTest) # for BUILD_TESTING option
include(CMakePackageConfigHelpers) # for write_basic_package_version_file
Expand Down
15 changes: 11 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = 'babylon',
version = '1.1.4',
version = '1.1.5',
compatibility_level = 1,
)

Expand All @@ -11,9 +11,9 @@ module(
# Thus the highest version in their module graph is resolved.

# --registry=https://bcr.bazel.build
bazel_dep(name = 'abseil-cpp', version = '20211102.0')
bazel_dep(name = 'abseil-cpp', version = '20211102.0', repo_name = 'com_google_absl')
bazel_dep(name = 'bazel_skylib', version = '1.4.1')
bazel_dep(name = 'protobuf', version = '3.19.6')
bazel_dep(name = 'protobuf', version = '3.19.6', repo_name = 'com_google_protobuf')

# --registry=https://raw.githubusercontent.com/bazelboost/registry/main
bazel_dep(name = 'boost.preprocessor', version = '1.83.0.bzl.1')
Expand All @@ -25,7 +25,7 @@ bazel_dep(name = 'boost.spirit', version = '1.83.0.bzl.1')

# --registry=https://bcr.bazel.build
single_version_override(module_name = 'abseil-cpp', version = '20230802.1')
bazel_dep(name = 'googletest', version = '1.14.0', dev_dependency = True)
bazel_dep(name = 'googletest', version = '1.14.0', repo_name = 'com_google_googletest', dev_dependency = True)

# --registry=file://%workspace%/registry
# protobuf 25.3 is not officially support in BCR
Expand All @@ -35,4 +35,11 @@ bazel_dep(name = 'rules_cuda', version = '0.2.2-dev', dev_dependency = True)

cuda = use_extension('@rules_cuda//cuda:extensions.bzl', 'toolchain', dev_dependency = True)
cuda.local_toolchain()

# cross compile toolchain
bazel_dep(name = 'rules_cc', version = '0.0.9', dev_dependency = True)
bazel_dep(name = 'platforms', version = '0.0.10', dev_dependency = True)
cross_config = use_extension('//:bazel/cross_toolchain.bzl', 'cross_config', dev_dependency = True)
use_repo(cross_config, 'cross_config_toolchain')
register_toolchains('@cross_config_toolchain//:cross-toolchain', dev_dependency = True)
################################################################################
50 changes: 50 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
workspace(name = 'com_baidu_babylon')

load('@bazel_tools//tools/build_defs/repo:http.bzl', 'http_archive')

http_archive(
name = 'com_google_absl',
urls = ['https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.1.tar.gz'],
strip_prefix = 'abseil-cpp-20230802.1',
sha256 = '987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed',
)

http_archive(
name = 'com_google_protobuf',
urls = ['https://github.com/protocolbuffers/protobuf/archive/refs/tags/v25.3.tar.gz'],
strip_prefix = 'protobuf-25.3',
sha256 = 'd19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e',
patches = ['@com_baidu_babylon//:registry/modules/protobuf/25.3.arenastring/patches/arenastring.patch'],
patch_args = ['-p1'],
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()

http_archive(
name = 'com_github_nelhage_rules_boost',
urls = ['https://github.com/nelhage/rules_boost/archive/4ab574f9a84b42b1809978114a4664184716f4bf.tar.gz'],
strip_prefix = 'rules_boost-4ab574f9a84b42b1809978114a4664184716f4bf',
sha256 = '2215e6910eb763a971b1f63f53c45c0f2b7607df38c96287666d94d954da8cdc',
)
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

################################################################################
# test only dependency
http_archive(
name = 'com_google_googletest',
urls = ['https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz'],
strip_prefix = 'googletest-1.14.0',
sha256 = '8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7',
)

http_archive(
name = "rules_cuda",
urls = ["https://github.com/bazel-contrib/rules_cuda/archive/3482c70dc60d9ab1ad26b768c117fcd61ee12494.tar.gz"],
strip_prefix = "rules_cuda-3482c70dc60d9ab1ad26b768c117fcd61ee12494",
sha256 = 'c7bf1da41b5a31480a0477f4ced49eed08ab1cb3aff77c704e373cf9c52694f5',
)
load("@rules_cuda//cuda:repositories.bzl", "register_detected_cuda_toolchains", "rules_cuda_dependencies")
rules_cuda_dependencies()
register_detected_cuda_toolchains()
################################################################################
45 changes: 45 additions & 0 deletions bazel/cross_toolchain.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load('@bazel_tools//tools/cpp:cc_configure.bzl', 'cc_autoconf_impl')

def cross_config_cc_impl(repository_ctx):
cc_autoconf_impl(repository_ctx,
overriden_tools = {
'gcc': repository_ctx.getenv('CROSS_CC')})

cross_config_cc = repository_rule(
implementation = cross_config_cc_impl,
configure = True,
)

def cross_config_toolchain_impl(repository_ctx):
repository_ctx.file('BUILD',
'''
load('@platforms//host:constraints.bzl', 'HOST_CONSTRAINTS')
constraint_setting(name = 'compile_mode')
constraint_value(
name = 'cross_compile',
constraint_setting = 'compile_mode',
)
platform(
name = 'cross',
constraint_values = [':cross_compile'],
)
toolchain(
name = 'cross-toolchain',
exec_compatible_with = HOST_CONSTRAINTS,
target_compatible_with = [':cross_compile'],
toolchain = '@cross_config_cc//:cc-compiler-k8',
toolchain_type = '@bazel_tools//tools/cpp:toolchain_type',
)
''')

cross_config_toolchain = repository_rule(
implementation = cross_config_toolchain_impl,
)

def cross_config_impl(module_ctx):
cross_config_cc(name = 'cross_config_cc')
cross_config_toolchain(name = 'cross_config_toolchain')

cross_config = module_extension(
implementation = cross_config_impl,
)
2 changes: 2 additions & 0 deletions bazel/module_name.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def module_name():
return native.module_name() if ('module_name' in dir(native)) else None
50 changes: 50 additions & 0 deletions example/depend-use-cmake-subdir/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
#!/bin/sh
set -ex

URL=https://github.com/baidu/babylon/archive/refs/tags/v1.1.4.tar.gz
NAME=babylon-1.1.4
SHA256=2e7efea3f0a8aeffc03f908ff2875a82eb5a94cd1de3e591b6dc388f7a992411
if ! echo "$SHA256 $NAME.tar.gz" | sha256sum -c; then
wget $URL --continue -O $NAME.tar.gz
fi
rm -rf $NAME babylon
tar xzf $NAME.tar.gz
mv $NAME babylon

URL=https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.1.tar.gz
NAME=abseil-cpp-20230802.1
SHA256=987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed
if ! echo "$SHA256 $NAME.tar.gz" | sha256sum -c; then
wget $URL --continue -O $NAME.tar.gz
fi
rm -rf $NAME abseil-cpp
tar xzf $NAME.tar.gz
mv $NAME abseil-cpp

URL=https://github.com/protocolbuffers/protobuf/archive/refs/tags/v25.3.tar.gz
NAME=protobuf-25.3
SHA256=d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e
if ! echo "$SHA256 $NAME.tar.gz" | sha256sum -c; then
wget $URL --continue -O $NAME.tar.gz
fi
rm -rf $NAME protobuf
tar xzf $NAME.tar.gz
mv $NAME protobuf

URL=https://github.com/boostorg/boost/releases/download/boost-1.83.0/boost-1.83.0.tar.gz
NAME=boost-1.83.0
SHA256=0c6049764e80aa32754acd7d4f179fd5551d8172a83b71532ae093e7384e98da
if ! echo "$SHA256 $NAME.tar.gz" | sha256sum -c; then
wget $URL --continue -O $NAME.tar.gz
fi
rm -rf $NAME boost
tar xzf $NAME.tar.gz
mv $NAME boost

URL=https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
NAME=googletest-1.14.0
SHA256=8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7
if ! echo "$SHA256 $NAME.tar.gz" | sha256sum -c; then
wget $URL --continue -O $NAME.tar.gz
fi
rm -rf $NAME googletest
tar xzf $NAME.tar.gz
mv $NAME googletest

cmake -Bbuild
cmake --build build
2 changes: 2 additions & 0 deletions example/depend-use-workspace/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BAZELISK_BASE_URL=https://github.com/bazelbuild/bazel/releases/download
USE_BAZEL_VERSION=7.1.1
1 change: 1 addition & 0 deletions example/depend-use-workspace/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
8 changes: 8 additions & 0 deletions example/depend-use-workspace/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_binary(
name = 'example',
srcs = ['example.cpp'],
deps = [
'@com_baidu_babylon//:future',
'@com_baidu_babylon//:logging',
],
)
Loading

0 comments on commit 9eb00ef

Please sign in to comment.