Skip to content

Commit e3d2dad

Browse files
authored
deps: load cc symbols from @rules_cc (bazel-contrib#1852)
Adds dependency on rules_cc 0.0.9 for both bzlmod and workspace This elevates rules_cc from a dev dependency to a full dependency of rules_python. Work towards incompatible_stop_exporting_language_modules, see bazelbuild/bazel#19455
1 parent ced8cc6 commit e3d2dad

17 files changed

+51
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ user.bazelrc
4343
*.swp
4444
*.swo
4545

46+
# CLion
47+
.clwb
48+
4649
# Python cache
4750
**/__pycache__/
4851

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ A brief description of the categories of changes:
7373
the whl and sdist files will be written to the lock file. Controlling whether
7474
the downloading of metadata is done in parallel can be done using
7575
`parallel_download` attribute.
76+
* (deps): `rules_python` depends now on `rules_cc` 0.0.9
7677

7778
[0.XX.0]: https://github.com/bazelbuild/rules_python/releases/tag/0.XX.0
7879
[python_default_visibility]: gazelle/README.md#directive-python_default_visibility

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module(
66

77
bazel_dep(name = "bazel_features", version = "1.9.1")
88
bazel_dep(name = "bazel_skylib", version = "1.3.0")
9+
bazel_dep(name = "rules_cc", version = "0.0.9")
910
bazel_dep(name = "platforms", version = "0.0.4")
1011

1112
# Those are loaded only when using py_proto_library
@@ -71,7 +72,6 @@ use_repo(pip, "rules_python_publish_deps")
7172
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
7273
bazel_dep(name = "rules_bazel_integration_test", version = "0.20.0", dev_dependency = True)
7374
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
74-
bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True)
7575

7676
# Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests.
7777
# We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides.

internal_deps.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,10 @@ def rules_python_internal_deps():
217217
strip_prefix = "bazel_features-1.9.1",
218218
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz",
219219
)
220+
221+
http_archive(
222+
name = "rules_cc",
223+
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
224+
strip_prefix = "rules_cc-0.0.9",
225+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
226+
)

python/private/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ bzl_library(
143143
],
144144
deps = [
145145
":py_cc_toolchain_info_bzl",
146+
":rules_cc_srcs_bzl",
146147
":util_bzl",
147148
],
148149
)
@@ -293,6 +294,13 @@ bzl_library(
293294
],
294295
)
295296

297+
# @rules_cc does not offer a bzl_library target for @rules_cc//cc:defs.bzl
298+
bzl_library(
299+
name = "rules_cc_srcs_bzl",
300+
srcs = ["@rules_cc//cc:bzl_srcs"],
301+
deps = [":bazel_tools_bzl"],
302+
)
303+
296304
# Needed to define bzl_library targets for docgen. (We don't define the
297305
# bzl_library target here because it'd give our users a transitive dependency
298306
# on Skylib.)

python/private/common/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package(
2121
bzl_library(
2222
name = "attributes_bazel_bzl",
2323
srcs = ["attributes_bazel.bzl"],
24+
deps = ["//python/private:rules_cc_srcs_bzl"],
2425
)
2526

2627
bzl_library(
@@ -61,6 +62,7 @@ bzl_library(
6162
":py_internal_bzl",
6263
":semantics_bzl",
6364
"//python/private:reexports_bzl",
65+
"//python/private:rules_cc_srcs_bzl",
6466
],
6567
)
6668

@@ -74,6 +76,7 @@ bzl_library(
7476
srcs = ["providers.bzl"],
7577
deps = [
7678
":semantics_bzl",
79+
"//python/private:rules_cc_srcs_bzl",
7780
"//python/private:util_bzl",
7881
],
7982
)
@@ -121,6 +124,7 @@ bzl_library(
121124
":common_bzl",
122125
":providers_bzl",
123126
":py_internal_bzl",
127+
"//python/private:rules_cc_srcs_bzl",
124128
"@bazel_skylib//lib:dicts",
125129
],
126130
)

python/private/common/attributes.bzl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Attributes for Python rules."""
1515

16+
load("@rules_cc//cc:defs.bzl", "CcInfo")
1617
load("//python/private:reexports.bzl", "BuiltinPyInfo")
1718
load(":common.bzl", "union_attrs")
1819
load(":providers.bzl", "PyInfo")
@@ -23,8 +24,6 @@ load(
2324
"SRCS_ATTR_ALLOW_FILES",
2425
)
2526

26-
# TODO: Load CcInfo from rules_cc
27-
_CcInfo = CcInfo
2827
_PackageSpecificationInfo = getattr(py_internal, "PackageSpecificationInfo", None)
2928

3029
_STAMP_VALUES = [-1, 0, 1]
@@ -166,7 +165,7 @@ PY_SRCS_ATTRS = union_attrs(
166165
"deps": attr.label_list(
167166
providers = [
168167
[PyInfo],
169-
[_CcInfo],
168+
[CcInfo],
170169
[BuiltinPyInfo],
171170
],
172171
# TODO(b/228692666): Google-specific; remove these allowances once

python/private/common/common_bazel.bzl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@
1414
"""Common functions that are specific to Bazel rule implementation"""
1515

1616
load("@bazel_skylib//lib:paths.bzl", "paths")
17+
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_common")
1718
load(":common.bzl", "is_bool")
1819
load(":providers.bzl", "PyCcLinkParamsProvider")
1920
load(":py_internal.bzl", "py_internal")
2021

21-
# TODO: Load cc_common from rules_cc
22-
_cc_common = cc_common
23-
24-
# TODO: Load CcInfo from rules_cc
25-
_CcInfo = CcInfo
26-
2722
_py_builtins = py_internal
2823

2924
def collect_cc_info(ctx, extra_deps = []):
@@ -42,13 +37,13 @@ def collect_cc_info(ctx, extra_deps = []):
4237
deps.extend(extra_deps)
4338
cc_infos = []
4439
for dep in deps:
45-
if _CcInfo in dep:
46-
cc_infos.append(dep[_CcInfo])
40+
if CcInfo in dep:
41+
cc_infos.append(dep[CcInfo])
4742

4843
if PyCcLinkParamsProvider in dep:
4944
cc_infos.append(dep[PyCcLinkParamsProvider].cc_info)
5045

51-
return _cc_common.merge_cc_infos(cc_infos = cc_infos)
46+
return cc_common.merge_cc_infos(cc_infos = cc_infos)
5247

5348
def maybe_precompile(ctx, srcs):
5449
"""Computes all the outputs (maybe precompiled) from the input srcs.

python/private/common/providers.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
# limitations under the License.
1414
"""Providers for Python rules."""
1515

16+
load("@rules_cc//cc:defs.bzl", "CcInfo")
1617
load("//python/private:util.bzl", "IS_BAZEL_6_OR_HIGHER")
1718

18-
# TODO: load CcInfo from rules_cc
19-
_CcInfo = CcInfo
20-
2119
DEFAULT_STUB_SHEBANG = "#!/usr/bin/env python3"
2220

2321
DEFAULT_BOOTSTRAP_TEMPLATE = Label("//python/private:python_bootstrap_template.txt")
@@ -241,7 +239,7 @@ This field is currently unused in Bazel and may go away in the future.
241239

242240
def _PyCcLinkParamsProvider_init(cc_info):
243241
return {
244-
"cc_info": _CcInfo(linking_context = cc_info.linking_context),
242+
"cc_info": CcInfo(linking_context = cc_info.linking_context),
245243
}
246244

247245
# buildifier: disable=name-conventions

python/private/common/py_executable.bzl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Common functionality between test/binary executables."""
1515

1616
load("@bazel_skylib//lib:dicts.bzl", "dicts")
17+
load("@rules_cc//cc:defs.bzl", "cc_common")
1718
load("//python/private:reexports.bzl", "BuiltinPyRuntimeInfo")
1819
load(
1920
":attributes.bzl",
@@ -53,9 +54,6 @@ load(
5354
"PY_RUNTIME_ATTR_NAME",
5455
)
5556

56-
# TODO: Load cc_common from rules_cc
57-
_cc_common = cc_common
58-
5957
_py_builtins = py_internal
6058

6159
# Bazel 5.4 doesn't have config_common.toolchain_type
@@ -559,10 +557,10 @@ def _create_shared_native_deps_dso(
559557
linkstamps = py_internal.linking_context_linkstamps(cc_info.linking_context)
560558

561559
partially_disabled_thin_lto = (
562-
_cc_common.is_enabled(
560+
cc_common.is_enabled(
563561
feature_name = "thin_lto_linkstatic_tests_use_shared_nonlto_backends",
564562
feature_configuration = feature_configuration,
565-
) and not _cc_common.is_enabled(
563+
) and not cc_common.is_enabled(
566564
feature_name = "thin_lto_all_linkstatic_use_shared_nonlto_backends",
567565
feature_configuration = feature_configuration,
568566
)
@@ -876,7 +874,7 @@ def cc_configure_features(ctx, *, cc_toolchain, extra_features):
876874
requested_features.extend(ctx.features)
877875
if "legacy_whole_archive" not in ctx.disabled_features:
878876
requested_features.append("legacy_whole_archive")
879-
feature_configuration = _cc_common.configure_features(
877+
feature_configuration = cc_common.configure_features(
880878
ctx = ctx,
881879
cc_toolchain = cc_toolchain,
882880
requested_features = requested_features,

python/private/current_py_cc_headers.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Implementation of current_py_cc_headers rule."""
1616

17+
load("@rules_cc//cc:defs.bzl", "CcInfo")
18+
1719
def _current_py_cc_headers_impl(ctx):
1820
py_cc_toolchain = ctx.toolchains["//python/cc:toolchain_type"].py_cc_toolchain
1921
return py_cc_toolchain.headers.providers_map.values()

python/private/current_py_cc_libs.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Implementation of current_py_cc_libs rule."""
1616

17+
load("@rules_cc//cc:defs.bzl", "CcInfo")
18+
1719
def _current_py_cc_libs_impl(ctx):
1820
py_cc_toolchain = ctx.toolchains["//python/cc:toolchain_type"].py_cc_toolchain
1921
return py_cc_toolchain.libs.providers_map.values()

python/private/py_cc_toolchain_rule.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ NOTE: This is a beta-quality feature. APIs subject to change until
1818
https://github.com/bazelbuild/rules_python/issues/824 is considered done.
1919
"""
2020

21+
load("@rules_cc//cc:defs.bzl", "CcInfo")
2122
load(":py_cc_toolchain_info.bzl", "PyCcToolchainInfo")
2223

2324
def _py_cc_toolchain_impl(ctx):

python/repositories.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def py_repositories():
6262
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
6363
],
6464
)
65+
http_archive(
66+
name = "rules_cc",
67+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz"],
68+
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
69+
strip_prefix = "rules_cc-0.0.9",
70+
)
6571
pip_install_dependencies()
6672

6773
########

tests/cc/current_py_cc_headers/current_py_cc_headers_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Tests for current_py_cc_headers."""
1616

17+
load("@rules_cc//cc:defs.bzl", "CcInfo")
1718
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
1819
load("@rules_testing//lib:truth.bzl", "matching")
1920
load("//tests:cc_info_subject.bzl", "cc_info_subject")

tests/cc/current_py_cc_libs/current_py_cc_libs_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Tests for current_py_cc_libs."""
1616

17+
load("@rules_cc//cc:defs.bzl", "CcInfo")
1718
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
1819
load("@rules_testing//lib:truth.bzl", "matching")
1920
load("//tests:cc_info_subject.bzl", "cc_info_subject")

tests/cc/fake_cc_toolchain_config.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Fake for providing CcToolchainConfigInfo."""
1616

17+
load("@rules_cc//cc:defs.bzl", "cc_common")
18+
1719
def _impl(ctx):
1820
return cc_common.create_cc_toolchain_config_info(
1921
ctx = ctx,

0 commit comments

Comments
 (0)