Skip to content

Commit

Permalink
ci: use bzlmod in most Bazel builds (#14401)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan authored Jul 9, 2024
1 parent d43e267 commit 0cf3449
Show file tree
Hide file tree
Showing 21 changed files with 411 additions and 41 deletions.
4 changes: 1 addition & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ build --experimental_convenience_symlinks=ignore
# frustrating when they fail and don't give any output. So, remove the limit.
build --experimental_ui_max_stdouterr_bytes=-1

# TODO(#11485) - enable bzlmod once it works
common --noenable_bzlmod

# TODO(#13311) - remove once gRPC works with Bazel v7 or when gRPC stops using
# `apple_rules`.
common:macos --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
Expand Down Expand Up @@ -84,6 +81,7 @@ build:asan --copt=-fsanitize=address
# may be assuming that some compiler flags are set when compiling with Address
# Sanitizier (-DADDRESS_SANITIZER=1 is one possibility).
build:asan --per_file_copt=com_google_protobuf//@-Wno-error
build:asan --per_file_copt=protobuf~//@-Wno-error
build:asan --linkopt=-fsanitize=address
build:asan --action_env=ASAN_OPTIONS=detect_leaks=1:color=always
build:asan --action_env=LSAN_OPTIONS=report_objects=1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ cmake-build-*/

# Ignore the file with user-defined CMake presets
CMakeUserPresets.json

# Lock files created by bzlmod. We do not want to accidentally commit these.
MODULE.bazel.lock
75 changes: 75 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Idiomatic C++ client libraries for Google Cloud Platform."""

module(
name = "google_cloud_cpp",
# TODO(#11485) - automatically synchronize from (or to) the CMakeList.txt
# file.
version = "2.26.0-rc",
# TODO(#11485) - automatically increase on each major release.
compatibility_level = 1,
)

bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "abseil-cpp", version = "20240116.2", repo_name = "com_google_absl")
bazel_dep(name = "protobuf", version = "27.2", repo_name = "com_google_protobuf")
bazel_dep(name = "boringssl", version = "0.0.0-20230215-5c22014")
bazel_dep(name = "grpc", version = "1.63.1", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "com_github_nlohmann_json")
bazel_dep(name = "crc32c", version = "1.1.0", repo_name = "com_github_google_crc32c")
bazel_dep(name = "opentelemetry-cpp", version = "1.16.0", repo_name = "io_opentelemetry_cpp")

bazel_dep(name = "rules_proto", version = "6.0.2", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "google_benchmark", version = "1.8.4", dev_dependency = True, repo_name = "com_google_benchmark")
bazel_dep(name = "yaml-cpp", version = "0.8.0", dev_dependency = True, repo_name = "com_github_jbeder_yaml_cpp")
bazel_dep(name = "pugixml", version = "1.14.bcr.1", dev_dependency = True, repo_name = "com_github_zeux_pugixml")

# Our `curl.BUILD` file uses these.
bazel_dep(name = "zlib", version = "1.2.13")
bazel_dep(name = "c-ares", version = "1.15.0", repo_name = "com_github_cares_cares")

# `google-cloud-cpp` uses this indirectly in the coverage build. And we need
# to configure it for our CI builds.
bazel_dep(name = "rules_python", version = "0.33.2", dev_dependency = True)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
ignore_root_user_error = True,
python_version = "3.11",
)

bazel_dep(name = "googleapis", version = "0.0.0", repo_name = "com_google_googleapis")
archive_override(
module_name = "googleapis",
integrity = "sha256-M8YsA/lHlyi9qhplU9izX6Jz0BBwbHXqhc2N/haHWGw=",
patch_strip = 1,
patches = ["//bazel:googleapis.modules.patch"],
strip_prefix = "googleapis-622e10a1e8b2b6908e0ac7448d347a0c1b4130de",
urls = [
"https://storage.googleapis.com/cloud-cpp-community-archive/com_google_googleapis/622e10a1e8b2b6908e0ac7448d347a0c1b4130de.tar.gz",
"https://github.com/googleapis/googleapis/archive/622e10a1e8b2b6908e0ac7448d347a0c1b4130de.tar.gz",
],
)

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(
cc = True,
grpc = True,
)
use_repo(switched_rules, "com_google_googleapis_imports")
4 changes: 4 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ gl_cpp_development0()
load("//bazel:development1.bzl", "gl_cpp_development1")

gl_cpp_development1()

load("//bazel:development2.bzl", "gl_cpp_development2")

gl_cpp_development2()
23 changes: 23 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

workspace(name = "google_cloud_cpp")

load("//bazel:bzlmod0.bzl", "gl_cpp_bzlmod0")

gl_cpp_bzlmod0()

load("//bazel:bzlmod1.bzl", "gl_cpp_bzlmod1")

gl_cpp_bzlmod1()
43 changes: 43 additions & 0 deletions bazel/bzlmod0.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Load dependencies needed to use the google-cloud-cpp libraries."""

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

def gl_cpp_bzlmod0(name = None):
"""Loads dependencies need to compile the google-cloud-cpp libraries.
This is a workaround until all dependencies of `google-cloud-cpp` can
be managed via bzlmod.
Args:
name: Unused. It is conventional to provide a `name` argument to all
workspace functions.
"""

# TODO(#11485) - use some bazel_dep() from BCR.
# We need libcurl for the Google Cloud Storage client.
maybe(
http_archive,
name = "com_github_curl_curl",
urls = [
"https://storage.googleapis.com/cloud-cpp-community-archive/com_github_curl_curl/curl-7.69.1.tar.gz",
"https://curl.haxx.se/download/curl-7.69.1.tar.gz",
],
sha256 = "01ae0c123dee45b01bbaef94c0bc00ed2aec89cb2ee0fd598e0d302a6b5e0a98",
strip_prefix = "curl-7.69.1",
build_file = Label("//bazel:curl.BUILD"),
)
26 changes: 26 additions & 0 deletions bazel/bzlmod1.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Load dependencies needed to use the google-cloud-cpp libraries."""

def gl_cpp_bzlmod1(name = None):
"""Loads dependencies need to compile the google-cloud-cpp libraries.
This is a workaround until all dependencies of `google-cloud-cpp` can
be managed via bzlmod.
Args:
name: Unused. It is conventional to provide a `name` argument to all
workspace functions.
"""
8 changes: 8 additions & 0 deletions bazel/curl.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Description:
# curl is a tool for talking to web servers.

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

licenses(["notice"]) # MIT/X derivative license
Expand All @@ -26,6 +27,13 @@ config_setting(
visibility = ["//visibility:public"],
)

# This is unused, it is here just for compatibility with the Bazel Central
# Registry modules.
bool_flag(
name = "http_only",
build_setting_default = False,
)

# On Linux, libcurl needs to know, at compile time, the location for the
# Certificate Authority (CA) bundle file. By default we dynamically guess the
# location for most common Linux distribution, but this guessing makes the build
Expand Down
14 changes: 0 additions & 14 deletions bazel/development0.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@ def gl_cpp_development0(name = None):
strip_prefix = "benchmark-1.8.4",
)

# An XML parser and generator, this is only used in //docfx.
# This is an internal tool used to generate the reference documentation.
maybe(
http_archive,
name = "com_github_zeux_pugixml",
urls = [
"https://storage.googleapis.com/cloud-cpp-community-archive/com_github_zeux_pugixml/v1.14.tar.gz",
"https://github.com/zeux/pugixml/archive/v1.14.tar.gz",
],
sha256 = "610f98375424b5614754a6f34a491adbddaaec074e9044577d965160ec103d2e",
strip_prefix = "pugixml-1.14",
build_file = Label("//bazel:pugixml.BUILD"),
)

# A YAML parser and generator, this is only used in //docfx and //generator.
# Both are internal tools used for development only.
maybe(
Expand Down
43 changes: 43 additions & 0 deletions bazel/development2.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Load dependencies needed for google-cloud-cpp development / Phase 2."""

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

def gl_cpp_development2(name = None):
"""Loads dependencies needed to develop the google-cloud-cpp libraries.
This function assumes the repositories needed by our dependencies are loaded
Args:
name: Unused. It is conventional to provide a `name` argument to all
workspace functions.
"""

# An XML parser and generator, this is only used in //docfx.
# This is an internal tool used to generate the reference documentation.
maybe(
http_archive,
name = "com_github_zeux_pugixml",
urls = [
"https://storage.googleapis.com/cloud-cpp-community-archive/com_github_zeux_pugixml/v1.14.tar.gz",
"https://github.com/zeux/pugixml/archive/v1.14.tar.gz",
],
sha256 = "610f98375424b5614754a6f34a491adbddaaec074e9044577d965160ec103d2e",
strip_prefix = "pugixml-1.14",
build_file = Label("//bazel:pugixml.BUILD"),
)
Loading

0 comments on commit 0cf3449

Please sign in to comment.