From 66cf3048e9bd314fc1ad3ffeb65051e56dfa163a Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Wed, 11 Jan 2023 04:32:58 -0800 Subject: [PATCH] Copybara Merge: https://github.com/bazelbuild/rules_cc/pull/165 BEGIN_PUBLIC Copybara import of the project: -- 56e69b82484f1a9fb55d8173cc112f9f608f3581 by Fabian Meumertzheim : Simplify WORKSPACE setup and update ancient deps By removing a single unused `bzl_library` target, rules_cc no longer has any dependencies that would need to be loaded by a dependency macro. The existing macro is made a no-op. The few needed Bazel Federation dependencies are inlined and, in the case of bazel_skylib and abseil-py, updated to modern versions. Also reorders `WORKSPACE` to list direct dependencies first and keeps `MODULE.bazel` in sync with the dependency versions used in WORKSPACE. The `ubuntu1604` CI pipeline is removed as the version of Python used by it is no longer supported and the distribution is EOL. Instead, a new pipeline is added to check the Bzlmod build. END_PUBLIC COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/165 from fmeum:fix-workspace-module 56e69b82484f1a9fb55d8173cc112f9f608f3581 PiperOrigin-RevId: 501245864 Change-Id: Ib71ad910705807a00929a76774387a38d2da0f9f --- .bazelci/presubmit.yml | 10 +++- BUILD | 25 ---------- MODULE.bazel | 5 +- README.md | 4 +- WORKSPACE | 99 +++++++++++++++++++------------------ cc/private/rules_impl/BUILD | 8 --- cc/repositories.bzl | 24 +-------- internal_deps.bzl | 30 ----------- internal_setup.bzl | 30 ----------- 9 files changed, 65 insertions(+), 170 deletions(-) delete mode 100644 internal_deps.bzl delete mode 100644 internal_setup.bzl diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 0776ded..5e9f9a6 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -35,11 +35,17 @@ buildifier: warnings: "all" tasks: - ubuntu1604: - <<: *common ubuntu1804: <<: *common macos: <<: *common windows: <<: *common + ubuntu_bzlmod: + name: Bzlmod + platform: ubuntu1804 + build_flags: + - "--enable_bzlmod" + - "--ignore_dev_dependency" + build_targets: + - "//cc/..." diff --git a/BUILD b/BUILD index cdaf96f..001dcb9 100644 --- a/BUILD +++ b/BUILD @@ -1,30 +1,5 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - package(default_visibility = ["//visibility:public"]) licenses(["notice"]) exports_files(["LICENSE"]) - -filegroup( - name = "distribution", - srcs = [ - "BUILD", - "LICENSE", - "internal_deps.bzl", - "internal_setup.bzl", - ], - visibility = ["@//distro:__pkg__"], -) - -bzl_library( - name = "internal_deps_bzl", - srcs = ["internal_deps.bzl"], - visibility = ["//visibility:private"], -) - -bzl_library( - name = "internal_setup_bzl", - srcs = ["internal_setup.bzl"], - visibility = ["//visibility:private"], -) diff --git a/MODULE.bazel b/MODULE.bazel index 946b1b6..b12e396 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,10 +4,11 @@ module( compatibility_level = 1, ) -bazel_dep(name = "bazel_skylib", version = "1.0.3") -bazel_dep(name = "platforms", version = "0.0.4") +bazel_dep(name = "platforms", version = "0.0.6") cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure") use_repo(cc_configure, "local_config_cc_toolchains") register_toolchains("@local_config_cc_toolchains//:all") + +bazel_dep(name = "bazel_skylib", dev_dependency = True, version = "1.3.0") diff --git a/README.md b/README.md index ea6e547..2cc1973 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_cc", - urls = ["https://github.com/bazelbuild/rules_cc/archive/TODO"], - sha256 = "TODO", + urls = ["https://github.com/bazelbuild/rules_cc/archive/refs/tags/.tar.gz"], + sha256 = "...", ) ``` diff --git a/WORKSPACE b/WORKSPACE index 5958d8d..8804f6f 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,11 +3,30 @@ workspace(name = "rules_cc") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "platforms", - sha256 = "5308fc1d8865406a49427ba24a9ab53087f17f5266a7aabbfc28823f3916e1ca", + name = "bazel_skylib", + sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", - "https://github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + ], +) + +http_archive( + name = "com_google_googletest", + sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2", + strip_prefix = "googletest-release-1.12.1", + urls = [ + "https://mirror.bazel.build/github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz", + "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz", + ], +) + +http_archive( + name = "io_abseil_py", + sha256 = "c0bf3e839b7b1c58ac75e41f72a708597087a6c7dd0582aec4914e0d98ec8b04", + strip_prefix = "abseil-py-1.3.0", + urls = [ + "https://github.com/abseil/abseil-py/archive/refs/tags/v1.3.0.tar.gz", ], ) @@ -20,46 +39,29 @@ http_archive( ], ) -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.1") - http_archive( - name = "bazel_federation", - sha256 = "0d6893f0d18f417a3324ce7f0ed2e6e5b825d6d5ab42f0f3d7877cb313f36453", - strip_prefix = "bazel-federation-6ad33bc586701e9836a2bf4432c7aff1235b04d2", - type = "zip", - url = "https://github.com/bazelbuild/bazel-federation/archive/6ad33bc586701e9836a2bf4432c7aff1235b04d2.zip", # 2019-09-30 + name = "platforms", + sha256 = "5308fc1d8865406a49427ba24a9ab53087f17f5266a7aabbfc28823f3916e1ca", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", + "https://github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz", + ], ) -load("@bazel_federation//:repositories.bzl", "rules_cc_deps") - -rules_cc_deps() - -load("@bazel_federation//setup:rules_cc.bzl", "rules_cc_setup") - -rules_cc_setup() - -# -# Dependencies for development of rules_cc itself. -# -load("//:internal_deps.bzl", "rules_cc_internal_deps") - -rules_cc_internal_deps() - -load("//:internal_setup.bzl", "rules_cc_internal_setup") - -rules_cc_internal_setup() - http_archive( - name = "com_google_googletest", - sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2", - strip_prefix = "googletest-release-1.12.1", + name = "py_mock", + patch_cmds = [ + "mkdir -p py/mock", + "mv mock.py py/mock/__init__.py", + """echo 'licenses(["notice"])' > BUILD""", + "touch py/BUILD", + """echo 'py_library(name = "mock", srcs = ["__init__.py"], visibility = ["//visibility:public"],)' > py/mock/BUILD""", + ], + sha256 = "b839dd2d9c117c701430c149956918a423a9863b48b09c90e30a6013e7d2f44f", + strip_prefix = "mock-1.0.1", urls = [ - "https://mirror.bazel.build/github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz", - "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz", + "https://mirror.bazel.build/pypi.python.org/packages/source/m/mock/mock-1.0.1.tar.gz", + "https://pypi.python.org/packages/source/m/mock/mock-1.0.1.tar.gz", ], ) @@ -73,17 +75,18 @@ http_archive( ], ) +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + +go_rules_dependencies() + +go_register_toolchains(version = "1.19.4") + load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") rules_proto_dependencies() rules_proto_toolchains() - -load("//cc:repositories.bzl", "rules_cc_toolchains") - -rules_cc_toolchains() - -local_repository( - name = "test_repo", - path = "examples/test_cc_shared_library2", -) diff --git a/cc/private/rules_impl/BUILD b/cc/private/rules_impl/BUILD index 3d79d9a..dc74dfe 100644 --- a/cc/private/rules_impl/BUILD +++ b/cc/private/rules_impl/BUILD @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - package(default_visibility = ["//visibility:public"]) licenses(["notice"]) # Apache 2.0 @@ -18,9 +16,3 @@ filegroup( "**/BUILD", ]), ) - -bzl_library( - name = "native_bzl", - srcs = ["native.bzl"], - visibility = ["//cc:__pkg__"], -) diff --git a/cc/repositories.bzl b/cc/repositories.bzl index 5d0c56b..3ff7dbc 100644 --- a/cc/repositories.bzl +++ b/cc/repositories.bzl @@ -1,32 +1,10 @@ """Repository rules entry point module for rules_cc.""" -# WARNING: This file only exists for backwards-compatibility. -# rules_cc uses the Bazel federation, so please add any new dependencies to -# rules_cc_deps() in -# https://github.com/bazelbuild/bazel-federation/blob/master/repositories.bzl -# Third party dependencies can be added to -# https://github.com/bazelbuild/bazel-federation/blob/master/third_party_repositories.bzl -# Ideally we'd delete this entire file. - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("//cc/private/toolchain:cc_configure.bzl", "cc_configure") def rules_cc_dependencies(): - _maybe( - http_archive, - name = "bazel_skylib", - sha256 = "2ea8a5ed2b448baf4a6855d3ce049c4c452a6470b1efd1504fdb7c1c134d220a", - strip_prefix = "bazel-skylib-0.8.0", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/archive/0.8.0.tar.gz", - ], - ) + pass # buildifier: disable=unnamed-macro def rules_cc_toolchains(*args): cc_configure(*args) - -def _maybe(repo_rule, name, **kwargs): - if not native.existing_rule(name): - repo_rule(name = name, **kwargs) diff --git a/internal_deps.bzl b/internal_deps.bzl deleted file mode 100644 index 8373b10..0000000 --- a/internal_deps.bzl +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# 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 -# -# http://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. - -"""Dependencies that are needed for rules_cc tests and tools.""" - -load("@bazel_federation//:repositories.bzl", "bazel_skylib", "protobuf", "rules_go", "rules_python") -load("@bazel_federation//:third_party_repositories.bzl", "abseil_py", "py_mock", "six", "zlib") - -def rules_cc_internal_deps(): - """Fetches all dependencies for rules_cc tests and tools.""" - bazel_skylib() - protobuf() - rules_go() - rules_python() - - abseil_py() - py_mock() - six() - zlib() diff --git a/internal_setup.bzl b/internal_setup.bzl deleted file mode 100644 index 709f4b1..0000000 --- a/internal_setup.bzl +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# 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 -# -# http://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. - -"""Setup for rules_cc tests and tools.""" - -load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup") - -# TODO(fweikert): Add setup.bzl file for skylib to the federation and load it instead of workspace.bzl -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -# TODO(fweikert): Also load rules_go's setup.bzl file from the federation once it exists -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -def rules_cc_internal_setup(): - """Setup of dependencies of tests and development-only tools used in rules_cc repository.""" - bazel_skylib_workspace() - go_rules_dependencies() - go_register_toolchains() - rules_python_setup()