From 4ef834ae877d520bb2f314e9249ed6a27ab129e9 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Fri, 13 Sep 2024 08:56:51 +0000 Subject: [PATCH] Switch to bazelmod and use bazelrc to specify the ci configuration --- .bazelrc | 35 +++++++++++++++++++++++++++++++++++ .gitignore | 1 + BUILD.bazel | 19 +++++++++---------- MODULE.bazel | 17 +++++++++++++++++ WORKSPACE | 21 +++------------------ bazel/ci/docker/Dockerfile | 10 ++-------- scripts/make_release.sh | 3 +++ 7 files changed, 70 insertions(+), 36 deletions(-) create mode 100644 .bazelrc create mode 100644 MODULE.bazel diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..62cbe994 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,35 @@ +############################################################################### +# Common flags that apply to all configurations. +# Use sparingly for things common to all compilers and platforms. +############################################################################### + +# Enable Bzlmod for every Bazel command +common --enable_bzlmod + +# Prevent invalid caching if input files are modified during a build. +build --experimental_guard_against_concurrent_changes + +############################################################################### +# Options for continuous integration. +############################################################################### + +# Speedup bazel using a ramdisk. +build:ci --sandbox_base=/dev/shm + +# Show as many errors as possible. +build:ci --keep_going + +# Show subcommands when building +build:ci --subcommands=true + +# Make sure we test for C99 compliance when building the library +build:ci --conlyopt=-std=c99 + +# Show test errors. +test:ci --test_output=errors + +############################################################################### + +# The user.bazelrc file is not checked in but available for local mods. +# Always keep this at the end of the file so that user flags override. +try-import %workspace%/user.bazelrc diff --git a/.gitignore b/.gitignore index f918154b..c4ee9c80 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ out/ # Bazel artifacts **/bazel-* +MODULE.bazel.lock # Per-user bazelrc files user.bazelrc diff --git a/BUILD.bazel b/BUILD.bazel index f55c47fc..31384214 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,7 +14,6 @@ exports_files(["LICENSE"]) INCLUDES = ["include"] C99_FLAGS = [ - "-std=c99", "-Wall", "-Wextra", "-Wmissing-declarations", @@ -56,7 +55,7 @@ cc_test( includes = INCLUDES, deps = [ ":bit_utils", - "@com_google_googletest//:gtest_main", + "@googletest//:gtest_main", ], ) @@ -90,7 +89,7 @@ cc_test( includes = INCLUDES, deps = [ ":string_view", - "@com_google_googletest//:gtest_main", + "@googletest//:gtest_main", ], ) @@ -148,7 +147,7 @@ cc_test( ":cpu_features_macros", ":filesystem_for_testing", ":string_view", - "@com_google_googletest//:gtest_main", + "@googletest//:gtest_main", ], ) @@ -312,7 +311,7 @@ cc_library( PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"], PLATFORM_CPU_ARM64: [ "include/cpuinfo_aarch64.h", - "include/internal/cpuid_aarch64.h" + "include/internal/cpuid_aarch64.h", ], PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"], PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"], @@ -322,10 +321,10 @@ cc_library( copts = C99_FLAGS, defines = selects.with_or({ PLATFORM_CPU_X86_64: ["CPU_FEATURES_MOCK_CPUID_X86"], - PLATFORM_CPU_ARM64: [ - "CPU_FEATURES_MOCK_CPUID_AARCH64", - "CPU_FEATURES_MOCK_SYSCTL_AARCH64", - ], + PLATFORM_CPU_ARM64: [ + "CPU_FEATURES_MOCK_CPUID_AARCH64", + "CPU_FEATURES_MOCK_SYSCTL_AARCH64", + ], "//conditions:default": [], }) + selects.with_or({ PLATFORM_OS_MACOS: ["HAVE_SYSCTLBYNAME"], @@ -369,7 +368,7 @@ cc_test( ":filesystem_for_testing", ":hwcaps_for_testing", ":string_view", - "@com_google_googletest//:gtest_main", + "@googletest//:gtest_main", ], ) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..c96f9f64 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,17 @@ +############################################################################### +# Bazel now uses Bzlmod by default to manage external dependencies. +# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. +# +# For more details, please check https://github.com/bazelbuild/bazel/issues/18958 +############################################################################### + +CPU_FEATURES_VERSION = "0.9.0" + +module( + name = "cpu_features", + repo_name = "com_google_cpufeatures", + version = CPU_FEATURES_VERSION, +) + +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "googletest", version = "1.15.2") diff --git a/WORKSPACE b/WORKSPACE index c26a7725..925c1e39 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,19 +1,4 @@ -workspace(name = "com_google_cpufeatures") - -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") - -git_repository( - name = "com_google_googletest", - tag = "release-1.11.0", - remote = "https://github.com/google/googletest.git", -) +# This file marks the root of the Bazel workspace. +# See MODULE.bazel for external dependencies setup. -git_repository( - name = "bazel_skylib", - tag = "1.2.0", - remote = "https://github.com/bazelbuild/bazel-skylib.git", -) - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() +workspace(name = "com_google_cpufeatures") diff --git a/bazel/ci/docker/Dockerfile b/bazel/ci/docker/Dockerfile index a46b4936..ed33464e 100644 --- a/bazel/ci/docker/Dockerfile +++ b/bazel/ci/docker/Dockerfile @@ -25,13 +25,7 @@ COPY . . FROM devel AS build RUN bazel version -RUN bazel build \ - -c opt \ - --subcommands=true \ - ... +RUN bazel build --config=ci ... FROM build AS test -RUN bazel test \ - -c opt \ - --test_output=errors \ - ... +RUN bazel test --config=ci ... diff --git a/scripts/make_release.sh b/scripts/make_release.sh index 0f4063d8..5b7d3a0f 100755 --- a/scripts/make_release.sh +++ b/scripts/make_release.sh @@ -62,6 +62,9 @@ fi echo -e "${ACTION}Modifying CMakeLists.txt${NOCOLOR}" sed -i "s/CpuFeatures VERSION ${LATEST_VERSION}/CpuFeatures VERSION ${VERSION}/g" CMakeLists.txt +echo -e "${ACTION}Modifying MODULE.bazel${NOCOLOR}" +sed -i "s/CPU_FEATURES_VERSION = \"${LATEST_VERSION}\"/CPU_FEATURES_VERSION = \"${VERSION}\"/g" MODULE.bazel + echo -e "${ACTION}Commit new revision${NOCOLOR}" git add CMakeLists.txt git commit -m"Release ${GIT_TAG}"