Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/.bazelrc.ci
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

common --keep_going
common --remote_upload_local_results

common:bzlmod --enable_bzlmod
common:workspace --noenable_bzlmod
27 changes: 22 additions & 5 deletions .github/workflows/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
os:
- ubuntu-22.04
- ubuntu-24.04
bzlmod_config:
- bzlmod
- workspace
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -35,14 +38,17 @@ jobs:
- name: Test
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel test //...
bazel test --config ${{ matrix.bzlmod_config }} //...
compilation_modes:
strategy:
matrix:
compilation_mode:
- fastbuild
- dbg
- opt
bzlmod_config:
- bzlmod
- workspace
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand All @@ -56,7 +62,7 @@ jobs:
- name: Test
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel test --compilation_mode ${{ matrix.compilation_mode }} //...
bazel test --compilation_mode ${{ matrix.compilation_mode }} --config ${{ matrix.bzlmod_config }} //...
sanitizers:
strategy:
matrix:
Expand All @@ -65,6 +71,9 @@ jobs:
- lsan
- tsan
- ubsan
bzlmod_config:
- bzlmod
- workspace
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand All @@ -78,8 +87,13 @@ jobs:
- name: Test ${{ matrix.sanitizer }}
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel test --config ${{ matrix.sanitizer }} //tests/sanitizers:${{ matrix.sanitizer }}_test
bazel test --config ${{ matrix.sanitizer }} --config ${{ matrix.bzlmod_config }} //tests/sanitizers:${{ matrix.sanitizer }}_test
coverage:
strategy:
matrix:
bzlmod_config:
- bzlmod
- workspace
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand All @@ -93,13 +107,16 @@ jobs:
- name: Test Coverage
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel coverage //examples/hello_world_cpp:hello_world_cpp_test
bazel coverage --config ${{ matrix.bzlmod_config }} //examples/hello_world_cpp:hello_world_cpp_test
rbe:
strategy:
matrix:
os:
- ubuntu-22.04
- macos-14
bzlmod_config:
- bzlmod
- workspace
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -113,4 +130,4 @@ jobs:
- name: Test with RBE
run: |
ln -s .github/workflows/.bazelrc.ci .bazelrc.ci
bazel test --config rbe //...
bazel test --config rbe --config ${{ matrix.bzlmod_config }} //...
64 changes: 64 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module(name = "gcc_toolchain")

# Dependencies
# ============
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "aspect_bazel_lib", version = "1.40.2")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.0")

# Local Toolchains
# ================
gcc_toolchains = use_extension("//toolchain:module_extensions.bzl", "gcc_toolchains", dev_dependency = True)

[
[
gcc_toolchains.toolchain(
name = "gcc_toolchain_{}".format(arch),
target_arch = arch,
),
use_repo(gcc_toolchains, "gcc_toolchain_{}".format(arch)),
register_toolchains(
"@gcc_toolchain_{}//:cc_toolchain".format(arch),
"@gcc_toolchain_{}//:fortran_toolchain".format(arch),
# Register toolchains as dev dependencies so that we don't pollute the toolchain resolution of consumers.
dev_dependency = True,
),
]
# Unfortunately, we can't load `ARCHS` directly here.
# But the attributes in `gcc_toolchains.toolchain` are gated to only contain values from ARCHS.
for arch in [
"aarch64",
"armv7",
"x86_64",
]
]

# Dev Dependencies (for examples/)
# ===============================
bazel_dep(name = "rules_proto", version = "7.1.0", dev_dependency = True)
bazel_dep(name = "rules_foreign_cc", version = "0.15.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.6", dev_dependency = True, repo_name = "io_bazel_stardoc")
# We pin stardoc because a dependency requests a newer version (0.7.2), but the non-workspace flow doesn't work with it.
single_version_override(
module_name = "stardoc",
version = "0.5.6",
)

bazel_dep(name = "protobuf", version = "29.3", dev_dependency = True, repo_name = "com_google_protobuf")
single_version_override(
module_name = "protobuf",
patch_strip = 1,
patches = [
"//third_party/patches:com_google_protobuf.bzlmod.patch",
],
version = "29.3",
)

non_bazel_dependencies = use_extension("//:internal.bzl", "non_bazel_dependencies")
use_repo(
non_bazel_dependencies,
"avl",
"lapack",
"openssl",
)
24 changes: 24 additions & 0 deletions docs/defs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion examples/lapack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.

load("@rules_foreign_cc//foreign_cc:make.bzl", "make")
load(":patches.bzl", "lapack_repo_name")

_libs = [
"liblapack.a",
Expand Down Expand Up @@ -43,7 +44,10 @@ make(
lib_source = "@lapack//:srcs",
out_static_libs = _libs,
postfix_script = "\n".join([
"mv $$EXT_BUILD_ROOT/external/lapack/{0} $$INSTALLDIR/lib/{0}".format(lib)
"mv $$EXT_BUILD_ROOT/external/{0}/{1} $$INSTALLDIR/lib/{1}".format(
lapack_repo_name,
lib,
)
for lib in _libs
]),
targets = [
Expand Down
4 changes: 4 additions & 0 deletions examples/lapack/patches.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ EOF
"""

LAPACK_PATCHES = [_create_make_inc]

# Canonical repository name of the @lapack dependency.
# Documentation: https://bazel.build/external/module#repository_names_and_strict_deps
lapack_repo_name = Label("@lapack").repo_name
66 changes: 41 additions & 25 deletions internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,36 @@
"""Internal dependencies the users don't need."""

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

load("//examples/lapack:patches.bzl", "LAPACK_PATCHES")

def _openssl():
http_archive(
name = "openssl",
build_file_content = _ALL_SRCS,
sha256 = "40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a",
strip_prefix = "openssl-1.1.1n",
url = "https://www.openssl.org/source/openssl-1.1.1n.tar.gz",
)

def _lapack():
http_archive(
name = "lapack",
build_file_content = _ALL_SRCS,
patch_cmds = LAPACK_PATCHES,
sha256 = "eac9570f8e0ad6f30ce4b963f4f033f0f643e7c3912fc9ee6cd99120675ad48b",
strip_prefix = "lapack-3.12.0",
url = "https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.12.0.tar.gz",
)

def _avl():
http_archive(
name = "avl",
build_file = "@//:examples/avl/avl.BUILD.bazel",
sha256 = "6d62e563578b79795a84958cfe4e221a4c9847fbeb4a821d45bc049934fc6a90",
strip_prefix = "Avl",
url = "https://web.mit.edu/drela/Public/web/avl/avl3.40b.tgz",
)

# buildifier: disable=function-docstring
def internal_dependencies():
http_archive(
Expand Down Expand Up @@ -53,30 +80,8 @@ def internal_dependencies():
url = "https://github.com/bazel-contrib/rules_python/releases/download/1.4.1/rules_python-1.4.1.tar.gz",
)

http_archive(
name = "openssl",
build_file_content = _ALL_SRCS,
sha256 = "40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a",
strip_prefix = "openssl-1.1.1n",
url = "https://www.openssl.org/source/openssl-1.1.1n.tar.gz",
)

http_archive(
name = "lapack",
build_file_content = _ALL_SRCS,
patch_cmds = LAPACK_PATCHES,
sha256 = "eac9570f8e0ad6f30ce4b963f4f033f0f643e7c3912fc9ee6cd99120675ad48b",
strip_prefix = "lapack-3.12.0",
url = "https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.12.0.tar.gz",
)

http_archive(
name = "avl",
build_file = "@//:examples/avl/avl.BUILD.bazel",
sha256 = "6d62e563578b79795a84958cfe4e221a4c9847fbeb4a821d45bc049934fc6a90",
strip_prefix = "Avl",
url = "https://web.mit.edu/drela/Public/web/avl/avl3.40b.tgz",
)
_openssl()
_lapack()

http_archive(
name = "com_google_protobuf",
Expand All @@ -87,6 +92,8 @@ def internal_dependencies():
url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.3/protobuf-29.3.tar.gz",
)

_avl()

http_archive(
name = "rules_pkg",
sha256 = "b7215c636f22c1849f1c3142c72f4b954bb12bb8dcf3cbe229ae6e69cc6479db",
Expand All @@ -103,3 +110,12 @@ filegroup(
visibility = ["//visibility:public"],
)
"""

def _non_bazel_dependencies_ext_impl(mctx):
_openssl()
_lapack()
_avl()

non_bazel_dependencies = module_extension(
implementation = _non_bazel_dependencies_ext_impl,
)
71 changes: 71 additions & 0 deletions third_party/patches/com_google_protobuf.bzlmod.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/BUILD.bazel b/BUILD.bazel
index 32b26cbdc..3b6026976 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1,6 +1,6 @@
# Bazel (https://bazel.build/) BUILD file for Protobuf.

-load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
+load("@gcc_toolchain//rules_cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_license//rules:license.bzl", "license")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
diff --git a/MODULE.bazel b/MODULE.bazel
index cbe66f826..31fd30b9d 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -180,3 +180,15 @@ bazel_dep(
version = "4.0.0",
dev_dependency = True,
)
+
+# We load gcc_toolchain by the same name as we declare it in module().
+# Then, we use use_repo to bring the @gcc_toolchain_<arch> repositories into scope
+# so that we can reference them later when depending in libstdcxx
+bazel_dep(
+ name = "gcc_toolchain",
+ version = "0.0.0",
+)
+gcc_toolchains = use_extension("@gcc_toolchain//toolchain:module_extensions.bzl", "gcc_toolchains")
+use_repo(gcc_toolchains, "gcc_toolchain_aarch64")
+use_repo(gcc_toolchains, "gcc_toolchain_armv7")
+use_repo(gcc_toolchains, "gcc_toolchain_x86_64")
diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel
index 9d7938d75..e8db19453 100644
--- a/conformance/BUILD.bazel
+++ b/conformance/BUILD.bazel
@@ -1,6 +1,7 @@
# Conformance testing for Protobuf.

-load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "objc_library")
+load("@rules_cc//cc:defs.bzl", "objc_library")
+load("@gcc_toolchain//rules_cc:defs.bzl", "cc_binary", "cc_library")
load(
"@rules_pkg//pkg:mappings.bzl",
"pkg_filegroup",
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel
index 4b701c403..3f0c9acb7 100644
--- a/examples/BUILD.bazel
+++ b/examples/BUILD.bazel
@@ -9,7 +9,7 @@ load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto
load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
-load("@rules_cc//cc:defs.bzl", "cc_binary")
+load("@gcc_toolchain//rules_cc:defs.bzl", "cc_binary")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_python//python:py_binary.bzl", "py_binary")

diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel
index 5012ee793..cac054e7b 100644
--- a/src/google/protobuf/compiler/BUILD.bazel
+++ b/src/google/protobuf/compiler/BUILD.bazel
@@ -2,7 +2,7 @@
# Protocol Buffers Compiler
################################################################################

-load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
+load("@gcc_toolchain//rules_cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load(
"@rules_pkg//pkg:mappings.bzl",
"pkg_attributes",
Loading