Skip to content

Commit

Permalink
[7.2.0] Combined cc_shared_library cherry-picks (#22321)
Browse files Browse the repository at this point in the history
Cherry-picks:
* d160b12
* d1df1be
* 8ee8f79
* f2eb91a
* 8e7ef00

Closes #21986
Closes #22053
Closes #22113

---------

Co-authored-by: Googler <noreply@google.com>
Co-authored-by: Alina Sbirlea <asbirlea@google.com>
  • Loading branch information
3 people committed May 10, 2024
1 parent d4d852c commit cfb9491
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 101 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Expand Up @@ -29,7 +29,7 @@ bazel_dep(name = "rules_graalvm", version = "0.11.1")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_jvm_external", version = "6.0")
bazel_dep(name = "rules_python", version = "0.26.0")
bazel_dep(name = "rules_testing", version = "0.0.4")
bazel_dep(name = "rules_testing", version = "0.6.0")
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "com_google_googletest")
bazel_dep(name = "with_cfg.bzl", version = "0.2.4")

Expand Down
38 changes: 20 additions & 18 deletions MODULE.bazel.lock
@@ -1,6 +1,6 @@
{
"lockFileVersion": 6,
"moduleFileHash": "a456aed4701b3b5246c04e0ed200775ee337ca70f3a583baddd65bb0434fa2ba",
"moduleFileHash": "dea29024bdcd8f84856d5187b9d45ade34a8a0349387397a95abec1c998a3e30",
"flags": {
"cmdRegistries": [
"https://bcr.bazel.build/"
Expand Down Expand Up @@ -629,7 +629,7 @@
"rules_proto": "rules_proto@5.3.0-21.7",
"rules_jvm_external": "rules_jvm_external@6.0",
"rules_python": "rules_python@0.26.0",
"rules_testing": "rules_testing@0.0.4",
"rules_testing": "rules_testing@0.6.0",
"com_google_googletest": "googletest@1.14.0",
"with_cfg.bzl": "with_cfg.bzl@0.2.4",
"remoteapis": "remoteapis@_",
Expand Down Expand Up @@ -1739,16 +1739,18 @@
}
}
},
"rules_testing@0.0.4": {
"rules_testing@0.6.0": {
"name": "rules_testing",
"version": "0.0.4",
"key": "rules_testing@0.0.4",
"version": "0.6.0",
"key": "rules_testing@0.6.0",
"repoName": "rules_testing",
"executionPlatformsToRegister": [],
"toolchainsToRegister": [],
"extensionUsages": [],
"deps": {
"platforms": "platforms@0.0.9",
"bazel_skylib": "bazel_skylib@1.5.0",
"rules_license": "rules_license@0.0.7",
"bazel_tools": "bazel_tools@_",
"local_config_platform": "local_config_platform@_"
},
Expand All @@ -1757,14 +1759,14 @@
"ruleClassName": "http_archive",
"attributes": {
"urls": [
"https://github.com/bazelbuild/rules_testing/releases/download/v0.0.4/rules_testing-v0.0.4.tar.gz"
"https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz"
],
"integrity": "sha256-TiH5qnmWlEzpFDHye8o3S/9W5oCs/klydgdNVrxdmvI=",
"strip_prefix": "rules_testing-0.0.4",
"integrity": "sha256-AsYldGMYdqTjsCoYIMtRFnu5zc3qI4Gy+p2bixHEB8Q=",
"strip_prefix": "rules_testing-0.6.0",
"remote_patches": {
"https://bcr.bazel.build/modules/rules_testing/0.0.4/patches/module_dot_bazel_version.patch": "sha256-0bNxHP/dstK5Ftz0e6FMQ2tyV4BZwp6Bh2et7ZuD1kk="
"https://bcr.bazel.build/modules/rules_testing/0.6.0/patches/module_dot_bazel_version.patch": "sha256-zHdszG0CcODGvv3mz84d9MlwLrZEOr1r+dpVDpsvs8U="
},
"remote_patch_strip": 0
"remote_patch_strip": 1
}
}
},
Expand Down Expand Up @@ -2742,7 +2744,7 @@
"moduleExtensions": {
"//:extensions.bzl%bazel_android_deps": {
"general": {
"bzlTransitiveDigest": "6vqJ6yadlUU86rSzRzNsiG2x5RGOCIg0gyw3j7iFVK4=",
"bzlTransitiveDigest": "EBPshmASCYr3Po+LywYJajCUdE2qG2E1+ffXTN7dDnk=",
"recordedFileInputs": {},
"recordedDirentsInputs": {},
"envVariables": {},
Expand Down Expand Up @@ -2888,9 +2890,9 @@
},
"//:extensions.bzl%bazel_build_deps": {
"general": {
"bzlTransitiveDigest": "6vqJ6yadlUU86rSzRzNsiG2x5RGOCIg0gyw3j7iFVK4=",
"bzlTransitiveDigest": "EBPshmASCYr3Po+LywYJajCUdE2qG2E1+ffXTN7dDnk=",
"recordedFileInputs": {
"@@//MODULE.bazel": "a456aed4701b3b5246c04e0ed200775ee337ca70f3a583baddd65bb0434fa2ba",
"@@//MODULE.bazel": "dea29024bdcd8f84856d5187b9d45ade34a8a0349387397a95abec1c998a3e30",
"@@//src/test/tools/bzlmod/MODULE.bazel.lock": "6eb7a8bfc1274585712c029c8fd1e2a9a3fa089b30cf6f91cff6823580cf2f5c"
},
"recordedDirentsInputs": {},
Expand Down Expand Up @@ -3058,7 +3060,7 @@
"rules_license-0.0.7.tar.gz",
"rules_python-0.24.0.tar.gz",
"rules_pkg-0.9.1.tar.gz",
"rules_testing-v0.0.4.tar.gz",
"rules_testing-v0.6.0.tar.gz",
"coverage_output_generator-v2.6.zip"
],
"sha256": {
Expand All @@ -3069,7 +3071,7 @@
"rules_license-0.0.7.tar.gz": "4531deccb913639c30e5c7512a054d5d875698daeb75d8cf90f284375fe7c360",
"rules_python-0.24.0.tar.gz": "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
"rules_pkg-0.9.1.tar.gz": "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
"rules_testing-v0.0.4.tar.gz": "4e21f9aa7996944ce91431f27bca374bff56e680acfe497276074d56bc5d9af2",
"rules_testing-v0.6.0.tar.gz": "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
"coverage_output_generator-v2.6.zip": "7006375f6756819b7013ca875eab70a541cf7d89142d9c511ed78ea4fefa38af"
},
"urls": {
Expand All @@ -3094,8 +3096,8 @@
"rules_pkg-0.9.1.tar.gz": [
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz"
],
"rules_testing-v0.0.4.tar.gz": [
"https://github.com/bazelbuild/rules_testing/releases/download/v0.0.4/rules_testing-v0.0.4.tar.gz"
"rules_testing-v0.6.0.tar.gz": [
"https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz"
],
"coverage_output_generator-v2.6.zip": [
"https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v2.6.zip"
Expand Down Expand Up @@ -3263,7 +3265,7 @@
},
"//:extensions.bzl%bazel_test_deps": {
"general": {
"bzlTransitiveDigest": "6vqJ6yadlUU86rSzRzNsiG2x5RGOCIg0gyw3j7iFVK4=",
"bzlTransitiveDigest": "EBPshmASCYr3Po+LywYJajCUdE2qG2E1+ffXTN7dDnk=",
"recordedFileInputs": {},
"recordedDirentsInputs": {},
"envVariables": {},
Expand Down
Expand Up @@ -1056,6 +1056,9 @@ public Object call(StarlarkThread thread, Tuple args, Dict<String, Object> kwarg
BazelStarlarkContext bazelStarlarkContext = BazelStarlarkContext.fromOrFail(thread);
try {
thread.setThreadLocal(BazelStarlarkContext.class, null);
// Allow access to the LabelConverter to support native.package_relative_label() in an
// initializer.
thread.setThreadLocal(LabelConverter.class, pkgContext.getBuilder().getLabelConverter());
thread.setUncheckedExceptionContext(() -> "an initializer");

// We call all the initializers of the rule and its ancestor rules, proceeding from child to
Expand Down Expand Up @@ -1143,6 +1146,7 @@ public Object call(StarlarkThread thread, Tuple args, Dict<String, Object> kwarg
}
}
} finally {
thread.setThreadLocal(LabelConverter.class, null);
bazelStarlarkContext.storeInThread(thread);
}

Expand Down
Expand Up @@ -627,13 +627,17 @@ public String repoName(StarlarkThread thread) throws EvalException {

@Override
public Label packageRelativeLabel(Object input, StarlarkThread thread) throws EvalException {
BazelStarlarkContext.checkLoadingPhase(thread, "native.package_relative_label");
if (input instanceof Label) {
return (Label) input;
// In an initializer, BazelStarlarkContext isn't available, just the label converter.
LabelConverter labelConverter = thread.getThreadLocal(LabelConverter.class);
if (labelConverter == null) {
BazelStarlarkContext.checkLoadingPhase(thread, "native.package_relative_label");
labelConverter = getContext(thread).getBuilder().getLabelConverter();
}
if (input instanceof Label inputLabel) {
return inputLabel;
}
try {
String s = (String) input;
return getContext(thread).getBuilder().getLabelConverter().convert(s);
return labelConverter.convert((String) input);
} catch (LabelSyntaxException e) {
throw Starlark.errorf("invalid label in native.package_relative_label: %s", e.getMessage());
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl
Expand Up @@ -19,6 +19,7 @@ load(":common/cc/cc_helper.bzl", "cc_helper")
load(":common/cc/cc_info.bzl", "CcInfo")
load(":common/cc/cc_shared_library_hint_info.bzl", "CcSharedLibraryHintInfo")
load(":common/cc/semantics.bzl", "semantics")
load(":common/paths.bzl", "paths")
load(":common/proto/proto_info.bzl", "ProtoInfo")

# TODO(#5200): Add export_define to library_to_link and cc_library
Expand Down Expand Up @@ -682,6 +683,15 @@ def _cc_shared_library_impl(ctx):
if ctx.attr.shared_lib_name:
main_output = ctx.actions.declare_file(ctx.attr.shared_lib_name)

additional_output_groups = {}
pdb_file = None
if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "generate_pdb_file"):
if ctx.attr.shared_lib_name:
pdb_file = ctx.actions.declare_file(paths.replace_extension(ctx.attr.shared_lib_name, ".pdb"))
else:
pdb_file = ctx.actions.declare_file(ctx.label.name + ".pdb")
additional_output_groups["pdb_file"] = depset([pdb_file])

win_def_file = None
if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows"):
object_files = []
Expand All @@ -699,6 +709,7 @@ def _cc_shared_library_impl(ctx):
generated_def_file = None
if def_parser != None:
generated_def_file = cc_helper.generate_def_file(ctx, def_parser, object_files, ctx.label.name)
additional_output_groups["def_file"] = depset([generated_def_file])
custom_win_def_file = ctx.file.win_def_file
win_def_file = cc_helper.get_windows_def_file_for_linking(ctx, custom_win_def_file, generated_def_file, feature_configuration)

Expand All @@ -714,6 +725,7 @@ def _cc_shared_library_impl(ctx):
name = ctx.label.name,
output_type = "dynamic_library",
main_output = main_output,
pdb_file = pdb_file,
win_def_file = win_def_file,
)

Expand Down Expand Up @@ -772,6 +784,7 @@ def _cc_shared_library_impl(ctx):
OutputGroupInfo(
main_shared_library_output = depset(library),
interface_library = depset(interface_library),
**additional_output_groups
),
CcSharedLibraryInfo(
dynamic_deps = merged_cc_shared_library_info,
Expand Down

0 comments on commit cfb9491

Please sign in to comment.