From 5e66ab13a7abb7039d04c45f38c348ab754635ba Mon Sep 17 00:00:00 2001 From: AshFungor Date: Sat, 17 May 2025 02:17:17 +0300 Subject: [PATCH 1/5] remove pch, moved some deps to bazel deps management --- MODULE.bazel | 10 ++-- conandata.yml | 5 -- src/PCH/BUILD.bazel | 8 ++-- src/Pog/BUILD.bazel | 17 ++----- tools/bazel/pch.bzl | 113 -------------------------------------------- 5 files changed, 12 insertions(+), 141 deletions(-) delete mode 100644 tools/bazel/pch.bzl diff --git a/MODULE.bazel b/MODULE.bazel index 3b3570dd..f1da3f9d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -10,22 +10,22 @@ module( conan = use_extension("//conan:conan_deps_module_extension.bzl", "conan_extension") use_repo( conan, - "abseil", - "argparse", - "benchmark", "boost", "bzip2", "eternal", "fmt", - "gtest", "libbacktrace", "libunwind", - "re2", "spdlog", "xz_utils", "zlib", ) +bazel_dep(name = "argparse", version = "3.0.0") +bazel_dep(name = "google_benchmark", version = "1.9.2") +bazel_dep(name = "googletest", version = "1.17.0") +bazel_dep(name = "re2", version = "2024-07-02.bcr.1") + bazel_dep(name = "rules_cc", version = "0.0.17") bazel_dep(name = "aspect_rules_lint", version = "1.3.5") bazel_dep(name = "bazel_skylib", version = "1.7.1") diff --git a/conandata.yml b/conandata.yml index aa465698..001724e4 100644 --- a/conandata.yml +++ b/conandata.yml @@ -1,11 +1,6 @@ requirements: - gtest: "1.14.0" - benchmark: "1.9.1" - abseil: "20240116.1" libbacktrace: "cci.20210118" - argparse: "3.2" eternal: "1.0.1" - re2: "20230801" fmt: "11.0.2" libunwind: "1.8.1" boost: "1.87.0" diff --git a/src/PCH/BUILD.bazel b/src/PCH/BUILD.bazel index 123b0274..ced4bf68 100644 --- a/src/PCH/BUILD.bazel +++ b/src/PCH/BUILD.bazel @@ -1,7 +1,7 @@ -load("//tools/bazel:pch.bzl", "precompiled_headers") +load("@rules_cc//cc:defs.bzl", "cc_library") -precompiled_headers( +cc_library( name = "pch_cstd", - main = "CStd.hpp", - visibility = ["//visibility:public"], + hdrs = ["CStd.hpp"], + visibility = ["//visibility:public"] ) diff --git a/src/Pog/BUILD.bazel b/src/Pog/BUILD.bazel index 5cd65d04..1d9c8847 100644 --- a/src/Pog/BUILD.bazel +++ b/src/Pog/BUILD.bazel @@ -1,24 +1,13 @@ load("@rules_cc//cc:defs.bzl", "cc_library") -load("//tools/bazel:pch.bzl", "precompiled_headers") cc_library( - name = "pog_core", + name = "pog", hdrs = glob( - ["**/*.hpp"], - exclude = ["Pog.hpp"], + ["**/*.hpp"] ), - visibility = ["//visibility:private"], + visibility = ["//visibility:public"], deps = [ "@fmt", "@re2", ], ) - -precompiled_headers( - name = "pog", - main = "Pog.hpp", - visibility = ["//visibility:public"], - deps = [ - ":pog_core", - ], -) diff --git a/tools/bazel/pch.bzl b/tools/bazel/pch.bzl deleted file mode 100644 index 6f7eb9ae..00000000 --- a/tools/bazel/pch.bzl +++ /dev/null @@ -1,113 +0,0 @@ -"Custom target to support precompiled headers. Notice, this is relevant to end-consumer project, like ours" -# Inspired by: https://github.com/erenon/rules_pch - -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") -load("@rules_cc//cc:action_names.bzl", "CPP_COMPILE_ACTION_NAME") - -def _global_flags(ctx, cc_toolchain): - feature_configuration = cc_common.configure_features( - ctx = ctx, - cc_toolchain = cc_toolchain, - ) - compile_variables = cc_common.create_compile_variables( - feature_configuration = feature_configuration, - cc_toolchain = cc_toolchain, - user_compile_flags = ctx.fragments.cpp.cxxopts + ctx.fragments.cpp.copts, - ) - tc_flags = cc_common.get_memory_inefficient_command_line( - feature_configuration = feature_configuration, - action_name = CPP_COMPILE_ACTION_NAME, - variables = compile_variables, - ) - - if cc_toolchain.needs_pic_for_dynamic_libraries(feature_configuration = feature_configuration): - return tc_flags + ["-fPIC"] - - return tc_flags - -def _precompiled_headers_impl(ctx): - files = ctx.attr.main.files.to_list() - if len(files) != 1: - fail("expected a single aggregated header to compile, got: {}".format(files)) - main_file = files[0] - - args = ctx.actions.args() - - # add args specified by the toolchain and on the command line - cc_toolchain = find_cpp_toolchain(ctx) - args.add_all(_global_flags(ctx, cc_toolchain)) - - # collect headers, include paths and defines of dependencies - headers = [] - for dep in ctx.attr.deps: - if not CcInfo in dep: - fail("dep arguments must provide CcInfo (e.g: cc_library)") - - # collect exported header files - compilation_context = dep[CcInfo].compilation_context - headers.append(compilation_context.headers) - - # add defines - for define in compilation_context.defines.to_list(): - args.add("-D" + define) - - # add include dirs - for i in compilation_context.includes.to_list(): - args.add("-I" + i) - - args.add_all(compilation_context.quote_includes.to_list(), before_each = "-iquote") - args.add_all(compilation_context.system_includes.to_list(), before_each = "-isystem") - - inputs = depset(direct = [main_file], transitive = headers + [cc_toolchain.all_files]) - - # add args specified for this rule - args.add_all(ctx.attr.copts) - - # force compilation of header - args.add("-xc++-header") - args.add(main_file.path) - - # specify output - output = ctx.actions.declare_file("{}.pch".format(main_file.basename)) - args.add("-o", output.path) - - # Unless -MD is specified while creating the precompiled file, - # the .d file of the user of the precompiled file will not - # show the precompiled file: therefore bazel will not rebuild - # the user if the pch file changes. - args.add("-MD") - args.add("-MF", "/dev/null") - - ctx.actions.run( - inputs = inputs, - outputs = [output], - executable = cc_toolchain.compiler_executable, - arguments = [args], - mnemonic = "PrecompileHdrs", - progress_message = "Pre-compiling header: {}".format(main_file.basename), - ) - - # create a CcInfo output that cc_binary rules can depend on - compilation_context = cc_common.create_compilation_context( - headers = depset(direct = [output, main_file]), - includes = depset(direct = [output.dirname]), - ) - main_cc_info = CcInfo(compilation_context = compilation_context, linking_context = None) - cc_info = cc_common.merge_cc_infos( - direct_cc_infos = [main_cc_info], - cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep], - ) - - return [cc_info] - -precompiled_headers = rule( - implementation = _precompiled_headers_impl, - attrs = { - "main": attr.label(allow_files = True, mandatory = True), - "deps": attr.label_list(), - "copts": attr.string_list(), - "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), - }, - toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], - fragments = ["cpp"], -) From a99eb7f6a7259dc637e23a660a96a364c48516c6 Mon Sep 17 00:00:00 2001 From: AshFungor Date: Sat, 14 Jun 2025 00:12:30 +0300 Subject: [PATCH 2/5] update actions --- .github/workflows/distro-ci.yml | 33 +++++++++------ .github/workflows/docker-autobuild.yml | 1 - .../workflows/run-tests-feature-branch.yml | 28 +++++++------ .github/workflows/testing.yml | 31 +++++++------- .github/workflows/version-increment.yml | 42 ++++++++----------- conanfile.py | 10 ++--- 6 files changed, 73 insertions(+), 72 deletions(-) diff --git a/.github/workflows/distro-ci.yml b/.github/workflows/distro-ci.yml index d7860526..07c2ce18 100644 --- a/.github/workflows/distro-ci.yml +++ b/.github/workflows/distro-ci.yml @@ -13,9 +13,9 @@ jobs: runs-on: ubuntu-latest container: image: hyperwin/hcpu-ci:${{ matrix.config.tag }} - # see https://github.com/bazelbuild/bazel/issues/13823 + # NOTE: see https://github.com/bazelbuild/bazel/issues/13823 options: --init - name: "Build on ${{matrix.config.name}}" + name: Build on ${{ matrix.config.name }} strategy: matrix: config: @@ -37,15 +37,22 @@ jobs: name: Ubuntu steps: - - run: | - set -e - DISTRO=$( cat /etc/*-release | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|fedora|gentoo|alpine)' | uniq ) - if [ "$DISTRO" == "gentoo" ]; then - source /etc/profile - fi - git clone https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git && cd HyperCPU - git checkout ${{ github.event.pull_request.head.sha }} - git submodule update --init --recursive + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: true + + - name: Run with sourced profile (only for gentoo) + if: contains(${{ matrix.config.name }}, 'gentoo') + run: | + source /etc/profile \ + && conan profile detect && conan install . --build=missing \ + && bazel test //src/... //tests/... --config=linux-opt - conan profile detect && conan install . --build=cmake --build=missing - bazelisk build //src/... //tests/... --config=linux-opt + - name: Install conan dependencies + if: ! contains(${{ matrix.config.name }}, 'gentoo') + run: conan profile detect && conan install . --build=missing + + - name: Build and test on Release profile + if: ! contains(${{ matrix.config.name }}, 'gentoo') + run: bazel test //src/... //tests/... --config=linux-opt diff --git a/.github/workflows/docker-autobuild.yml b/.github/workflows/docker-autobuild.yml index db5b838e..63979641 100644 --- a/.github/workflows/docker-autobuild.yml +++ b/.github/workflows/docker-autobuild.yml @@ -45,7 +45,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 2 submodules: true - name: Build and push diff --git a/.github/workflows/run-tests-feature-branch.yml b/.github/workflows/run-tests-feature-branch.yml index f162b636..fbb88273 100644 --- a/.github/workflows/run-tests-feature-branch.yml +++ b/.github/workflows/run-tests-feature-branch.yml @@ -2,32 +2,36 @@ name: HyperCPU CI/CD Pipeline (feature branch) on: push: + branches-ignore: + - master + - dev jobs: testing: runs-on: ubuntu-latest container: image: hyperwin/hcpu-ci:debian-unstable - # see https://github.com/bazelbuild/bazel/issues/13823 + # NOTE: see https://github.com/bazelbuild/bazel/issues/13823 options: --init - if: (github.ref != 'refs/heads/master' && github.ref != 'refs/heads/dev') || !contains(github.event.head_commit.message, '[ci skip]') + if: ! contains(github.event.head_commit.message, '[ci skip]') steps: - name: Checkout code uses: actions/checkout@v4 with: - submodules: "true" + submodules: true - - name: Install conan dependecies - run: | - conan profile detect && conan install . --build=missing + - uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + + - name: Install conan dependencies + run: conan profile detect && conan install . --build=missing - name: Build and test with GCC on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=gcc - bazelisk clean --expunge + run: CC=gcc bazel test //src/... //tests/... --config=linux-dbg && bazel clean --expunge - name: Build and test with LLVM on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=clang - bazelisk clean --expunge + run: CC=clang bazel test //src/... //tests/... --config=linux-dbg && bazel clean --expunge diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index cf42f349..3340f191 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest container: image: hyperwin/hcpu-ci:debian-unstable - # see https://github.com/bazelbuild/bazel/issues/13823 + # NOTE: see https://github.com/bazelbuild/bazel/issues/13823 options: --init name: Run full test suite @@ -18,28 +18,25 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - submodules: "true" + submodules: true - - name: Install conan dependecies - run: | - conan profile detect && conan install . --build=missing + - uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + + - name: Install conan dependencies + run: conan profile detect && conan install . --build=missing - name: Build and test with GCC on Debug profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=gcc - bazelisk clean --expunge + run: CC=gcc bazel test //src/... //tests/... --config=linux-dbg && bazel clean --expunge - name: Build and test with GCC on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-opt --compiler=gcc - bazelisk clean --expunge + run: CC=gcc bazel test //src/... //tests/... --config=linux-opt && bazel clean --expunge - name: Build and test with LLVM on Debug profile - run: | - bazelisk test //src/... //tests/... --config=linux-dbg --compiler=clang - bazelisk clean --expunge + run: CC=clang bazel test //src/... //tests/... --config=linux-dbg && bazel clean --expunge - name: Build and test with LLVM on Release profile - run: | - bazelisk test //src/... //tests/... --config=linux-opt --compiler=clang - bazelisk clean --expunge + run: CC=clang bazel test //src/... //tests/... --config=linux-opt && bazel clean --expunge diff --git a/.github/workflows/version-increment.yml b/.github/workflows/version-increment.yml index 887ea69e..04b33566 100644 --- a/.github/workflows/version-increment.yml +++ b/.github/workflows/version-increment.yml @@ -8,10 +8,8 @@ on: jobs: versioning-patch-increment: runs-on: ubuntu-latest - container: - image: hyperwin/hcpu-ci:debian-unstable - options: --user root - if: "contains(github.event.head_commit.message, '[ci patch inc]')" + container: hyperwin/hcpu-ci:debian-unstable + if: contains(github.event.head_commit.message, '[ci patch inc]') permissions: contents: write @@ -19,26 +17,24 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: "0" + fetch-depth: 0 - name: Setup git user uses: fregante/setup-git-user@v1 - name: Increment version (patch) - run: | - tools/increment_version.py --increment patch + run: tools/increment_version.py --increment patch - - name: Push changes to master branch - run: | - git config --global --add safe.directory '*' - git add . - git commit -m "[auto]: Increment patch version" - git push origin master + - name: Auto-commit version bump + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "[auto]: Increment patch version" + branch: master versioning-minor-increment: runs-on: ubuntu-latest container: hyperwin/hcpu-ci:debian-unstable - if: "contains(github.event.head_commit.message, '[ci minor inc]')" + if: contains(github.event.head_commit.message, '[ci minor inc]') permissions: contents: write @@ -46,18 +42,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: "0" + fetch-depth: 0 - name: Setup git user uses: fregante/setup-git-user@v1 - name: Increment version (minor) - run: | - tools/increment_version.py --increment minor - - - name: Push changes to master branch - run: | - git config --global --add safe.directory '*' - git add . - git commit -m "[auto]: Increment minor version" - git push origin master + run: tools/increment_version.py --increment minor + + - name: Auto-commit version bump + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "[auto]: Increment minor version" + branch: master diff --git a/conanfile.py b/conanfile.py index 0707284c..3c7a8bdf 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,5 @@ -from typing import Dict, Any, Collection from functools import cached_property, lru_cache +from typing import Callable, Mapping, Any, Iterable from conan import ConanFile from conan.tools.google import bazel_layout @@ -9,12 +9,12 @@ class HyperCPU(ConanFile): name: "HyperCPU" settings = ["os", "compiler", "build_type", "arch"] - # conan data is fetched dynamically from - # conandata.yml - conan_data: Dict[str, Any] + # dynamically set conanfile attributes + conan_data: Mapping[str, Any] + requires: Callable[[str], None] @cached_property - def generators(self) -> Collection[str]: + def generators(self) -> Iterable[str]: return ["BazelToolchain", "BazelDeps"] @lru_cache From 2e18675c1a8aed85628670b5e49a54f72f69aad5 Mon Sep 17 00:00:00 2001 From: AshFungor Date: Sat, 14 Jun 2025 00:16:13 +0300 Subject: [PATCH 3/5] refactor conditionals --- .github/workflows/distro-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/distro-ci.yml b/.github/workflows/distro-ci.yml index 07c2ce18..cd063874 100644 --- a/.github/workflows/distro-ci.yml +++ b/.github/workflows/distro-ci.yml @@ -43,16 +43,16 @@ jobs: submodules: true - name: Run with sourced profile (only for gentoo) - if: contains(${{ matrix.config.name }}, 'gentoo') + if: contains(matrix.config.name, 'gentoo') run: | source /etc/profile \ && conan profile detect && conan install . --build=missing \ && bazel test //src/... //tests/... --config=linux-opt - name: Install conan dependencies - if: ! contains(${{ matrix.config.name }}, 'gentoo') + if: ! contains(matrix.config.name, 'gentoo') run: conan profile detect && conan install . --build=missing - name: Build and test on Release profile - if: ! contains(${{ matrix.config.name }}, 'gentoo') + if: ! contains(matrix.config.name, 'gentoo') run: bazel test //src/... //tests/... --config=linux-opt From 5c05f317e099b6ac9bba264f1dcbde260dc6d3e9 Mon Sep 17 00:00:00 2001 From: AshFungor Date: Sat, 14 Jun 2025 00:21:17 +0300 Subject: [PATCH 4/5] refactor conditionals --- .github/workflows/distro-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/distro-ci.yml b/.github/workflows/distro-ci.yml index cd063874..22ad6a43 100644 --- a/.github/workflows/distro-ci.yml +++ b/.github/workflows/distro-ci.yml @@ -50,9 +50,9 @@ jobs: && bazel test //src/... //tests/... --config=linux-opt - name: Install conan dependencies - if: ! contains(matrix.config.name, 'gentoo') + if: ${{ ! contains(matrix.config.name, 'gentoo') }} run: conan profile detect && conan install . --build=missing - name: Build and test on Release profile - if: ! contains(matrix.config.name, 'gentoo') + if: ${{ ! contains(matrix.config.name, 'gentoo') }} run: bazel test //src/... //tests/... --config=linux-opt From 5cf5bd073ee5ca0c92e3cf520902b11f297082dd Mon Sep 17 00:00:00 2001 From: AshFungor Date: Sat, 14 Jun 2025 01:36:56 +0300 Subject: [PATCH 5/5] add missing step --- .github/workflows/distro-ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/distro-ci.yml b/.github/workflows/distro-ci.yml index 22ad6a43..8342ddf8 100644 --- a/.github/workflows/distro-ci.yml +++ b/.github/workflows/distro-ci.yml @@ -41,7 +41,13 @@ jobs: uses: actions/checkout@v4 with: submodules: true - + + - uses: bazel-contrib/setup-bazel@0.15.0 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + - name: Run with sourced profile (only for gentoo) if: contains(matrix.config.name, 'gentoo') run: |