@@ -25,3 +25,67 @@ def _cc_configure_extension_impl(ctx):
2525 return None
2626
2727cc_configure_extension = module_extension (implementation = _cc_configure_extension_impl )
28+
29+ def _compatibility_proxy_repo_impl (rctx ):
30+ rctx .file ("BUILD" , "" )
31+ bazel = native .bazel_version
32+ if not bazel or bazel >= "9" :
33+ rctx .file (
34+ "proxy.bzl" ,
35+ """
36+ load("@rules_cc//cc/private/rules_impl:cc_binary.bzl", _cc_binary = "cc_binary")
37+ load("@rules_cc//cc/private/rules_impl:cc_import.bzl", _cc_import = "cc_import")
38+ load("@rules_cc//cc/private/rules_impl:cc_library.bzl", _cc_library = "cc_library")
39+ load("@rules_cc//cc/private/rules_impl:cc_shared_library.bzl", _cc_shared_library = "cc_shared_library")
40+ load("@rules_cc//cc/private/rules_impl:cc_static_library.bzl", _cc_static_library = "cc_static_library")
41+ load("@rules_cc//cc/private/rules_impl:cc_test.bzl", _cc_test = "cc_test")
42+ load("@rules_cc//cc/private/rules_impl:objc_import.bzl", _objc_import = "objc_import")
43+ load("@rules_cc//cc/private/rules_impl:objc_library.bzl", _objc_library = "objc_library")
44+
45+ cc_binary = _cc_binary
46+ cc_import = _cc_import
47+ cc_library = _cc_library
48+ cc_shared_library = _cc_shared_library
49+ cc_static_library = _cc_static_library
50+ cc_test = _cc_test
51+ objc_import = _objc_import
52+ objc_library = _objc_library
53+ """ ,
54+ )
55+ else :
56+ rctx .file (
57+ "proxy.bzl" ,
58+ """
59+ cc_binary = native.cc_binary
60+ cc_import = native.cc_import
61+ cc_library = native.cc_library
62+ cc_shared_library = native.cc_shared_library
63+ cc_static_library = getattr(native, "cc_static_library", None) # only in Bazel 8+
64+ cc_test = native.cc_test
65+ objc_import = native.objc_import
66+ objc_library = native.objc_library
67+ """ ,
68+ )
69+
70+ _compatibility_proxy_repo_rule = repository_rule (
71+ _compatibility_proxy_repo_impl ,
72+ # force reruns on server restarts to use correct native.bazel_version
73+ local = True ,
74+ )
75+
76+ def compatibility_proxy_repo ():
77+ _compatibility_proxy_repo_rule (name = "cc_compatibility_proxy" )
78+
79+ def _compat_proxy_impl (module_ctx ):
80+ compatibility_proxy_repo ()
81+
82+ # module_ctx.extension_metadata has the paramater `reproducible` as of Bazel 7.1.0. We can't
83+ # test for it directly and would ideally use bazel_features to check for it, but don't want
84+ # to add a dependency for as long as WORKSPACE is still around. Thus, test for it by
85+ # checking the availability of another feature introduced in 7.1.0.
86+ if hasattr (module_ctx , "watch" ):
87+ return module_ctx .extension_metadata (reproducible = True )
88+ else :
89+ return None
90+
91+ compatibility_proxy = module_extension (_compat_proxy_impl )
0 commit comments