Skip to content

Commit 6607a4a

Browse files
authored
internal: update native deps and linkstamp API updates to Bazel rolling APIs (#1697)
This basically upstreams part of Google-internal patches for building native dep DSOs. The APIs it uses are only available on Bazel rolling, but the code paths that activate them aren't enabled in rules_python.
1 parent bd22419 commit 6607a4a

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

python/private/common/py_executable.bzl

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment =
200200
providers = modern_providers,
201201
)
202202

203+
def _get_build_info(ctx, cc_toolchain):
204+
build_info_files = py_internal.cc_toolchain_build_info_files(cc_toolchain)
205+
if cc_helper.is_stamping_enabled(ctx):
206+
return build_info_files.non_redacted_build_info_files.to_list()
207+
else:
208+
return build_info_files.redacted_build_info_files.to_list()
209+
203210
def _validate_executable(ctx):
204211
if ctx.attr.python_version != "PY3":
205212
fail("It is not allowed to use Python 2")
@@ -509,6 +516,7 @@ def _get_native_deps_details(ctx, *, semantics, cc_details, is_test):
509516
is_test = is_test,
510517
requested_features = cc_feature_config.requested_features,
511518
feature_configuration = cc_feature_config.feature_configuration,
519+
cc_toolchain = cc_details.cc_toolchain,
512520
)
513521
ctx.actions.symlink(
514522
output = dso,
@@ -517,19 +525,22 @@ def _get_native_deps_details(ctx, *, semantics, cc_details, is_test):
517525
)
518526
else:
519527
linked_lib = dso
520-
_cc_common.link(
528+
529+
# The regular cc_common.link API can't be used because several
530+
# args are private-use only; see # private comments
531+
py_internal.link(
521532
name = ctx.label.name,
522533
actions = ctx.actions,
523534
linking_contexts = [cc_info.linking_context],
524535
output_type = "dynamic_library",
525-
never_link = True,
526-
native_deps = True,
536+
never_link = True, # private
537+
native_deps = True, # private
527538
feature_configuration = cc_feature_config.feature_configuration,
528539
cc_toolchain = cc_details.cc_toolchain,
529-
test_only_target = is_test,
540+
test_only_target = is_test, # private
530541
stamp = 1 if is_stamping_enabled(ctx, semantics) else 0,
531-
main_output = linked_lib,
532-
use_shareable_artifact_factory = True,
542+
main_output = linked_lib, # private
543+
use_shareable_artifact_factory = True, # private
533544
# NOTE: Only flags not captured by cc_info.linking_context need to
534545
# be manually passed
535546
user_link_flags = semantics.get_native_deps_user_link_flags(ctx),
@@ -545,8 +556,9 @@ def _create_shared_native_deps_dso(
545556
cc_info,
546557
is_test,
547558
feature_configuration,
548-
requested_features):
549-
linkstamps = cc_info.linking_context.linkstamps()
559+
requested_features,
560+
cc_toolchain):
561+
linkstamps = py_internal.linking_context_linkstamps(cc_info.linking_context)
550562

551563
partially_disabled_thin_lto = (
552564
_cc_common.is_enabled(
@@ -570,8 +582,11 @@ def _create_shared_native_deps_dso(
570582
for input in cc_info.linking_context.linker_inputs.to_list()
571583
for flag in input.user_link_flags
572584
],
573-
linkstamps = [linkstamp.file() for linkstamp in linkstamps.to_list()],
574-
build_info_artifacts = _cc_common.get_build_info(ctx) if linkstamps else [],
585+
linkstamps = [
586+
py_internal.linkstamp_file(linkstamp)
587+
for linkstamp in linkstamps.to_list()
588+
],
589+
build_info_artifacts = _get_build_info(ctx, cc_toolchain) if linkstamps else [],
575590
features = requested_features,
576591
is_test_target_partially_disabled_thin_lto = is_test and partially_disabled_thin_lto,
577592
)

0 commit comments

Comments
 (0)