Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.2.0] Combined cc_shared_library cherry-picks #22321

Merged
merged 5 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading
Loading