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

[8.0.1] Fix linking objc binaries in the root package #24726

Merged
merged 1 commit into from
Dec 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ load(":common/objc/compilation_artifacts_info.bzl", "CompilationArtifactsInfo")
load(":common/objc/intermediate_artifacts.bzl", "create_intermediate_artifacts")
load(":common/objc/objc_common.bzl", "objc_common")
load(":common/objc/providers.bzl", "J2ObjcEntryClassInfo", "J2ObjcMappingFileInfo")
load(":common/paths.bzl", "paths")
load(":common/xcode/providers.bzl", "XcodeVersionInfo")

objc_internal = _builtins.internal.objc_internal
Expand Down Expand Up @@ -617,9 +618,13 @@ def _register_j2objc_dead_code_removal_actions(common_variables, deps, build_con
replace_libs = {}
for j2objc_archive in common_variables.objc_provider.j2objc_library.to_list():
pruned_j2objc_archive = ctx.actions.declare_shareable_artifact(
ctx.label.package + "/_j2objc_pruned/" + ctx.label.name + "/" +
j2objc_archive.short_path[:-len(j2objc_archive.extension)].strip(".") +
"_pruned." + j2objc_archive.extension,
paths.join(
ctx.label.package,
"_j2objc_pruned",
ctx.label.name,
j2objc_archive.short_path[:-len(j2objc_archive.extension)].strip(".") +
"_pruned." + j2objc_archive.extension,
),
build_config.bin_dir,
)
replace_libs[j2objc_archive] = pruned_j2objc_archive
Expand Down Expand Up @@ -674,7 +679,7 @@ def _register_obj_filelist_action(ctx, build_config, obj_files):
This File is suitable to signal symbols to archive in a libtool archiving invocation.
"""
obj_list = ctx.actions.declare_shareable_artifact(
ctx.label.package + "/" + ctx.label.name + "-linker.objlist",
paths.join(ctx.label.package, ctx.label.name + "-linker.objlist"),
build_config.bin_dir,
)

Expand Down Expand Up @@ -712,7 +717,7 @@ def _register_binary_strip_action(
strip_safe = True

stripped_binary = ctx.actions.declare_shareable_artifact(
ctx.label.package + "/" + name,
paths.join(ctx.label.package, name),
build_config.bin_dir,
)
args = ctx.actions.args()
Expand Down Expand Up @@ -773,12 +778,12 @@ def _linkstamp_map(ctx, linkstamps, output, build_config):
# create linkstamps_map - mapping from linkstamps to object files
linkstamps_map = {}

stamp_output_dir = ctx.label.package + "/_objs/" + output.basename + "/"
stamp_output_dir = paths.join(ctx.label.package, "_objs", output.basename)
for linkstamp in linkstamps.to_list():
linkstamp_file = linkstamp.file()
stamp_output_path = (
stamp_output_dir +
linkstamp_file.short_path[:-len(linkstamp_file.extension)].rstrip(".") + ".o"
stamp_output_path = paths.join(
stamp_output_dir,
linkstamp_file.short_path[:-len(linkstamp_file.extension)].rstrip(".") + ".o",
)
stamp_output_file = ctx.actions.declare_shareable_artifact(
stamp_output_path,
Expand Down Expand Up @@ -851,12 +856,12 @@ def _register_configuration_specific_link_actions(
if (ctx.fragments.cpp.objc_enable_binary_stripping() and
ctx.fragments.cpp.compilation_mode() == "opt"):
binary = ctx.actions.declare_shareable_artifact(
ctx.label.package + "/" + name + "_unstripped",
paths.join(ctx.label.package, name + "_unstripped"),
build_config.bin_dir,
)
else:
binary = ctx.actions.declare_shareable_artifact(
ctx.label.package + "/" + name,
paths.join(ctx.label.package, name),
build_config.bin_dir,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@ def my_rule_impl(ctx):
.contains("test_starlark/apple_starlark/liblib.a");
}

@Test
public void testStarlarkLinkBinaryInRootPackage() throws Exception {
scratch.file("a.m");
addAppleBinaryStarlarkRule(scratch);
scratch.file(
"BUILD",
"""
load("//test_starlark:apple_binary_starlark.bzl", "apple_binary_starlark")

package(default_visibility = ["//visibility:public"])

objc_library(
name = "lib",
srcs = ["a.m"],
)

apple_binary_starlark(
name = "bin",
platform_type = "macos",
deps = [":lib"],
)
""");

assertThat(getConfiguredTarget("//:bin")).isNotNull();
}

@Test
public void testObjcRuleCanDependOnArbitraryStarlarkRuleThatProvidesCcInfo() throws Exception {
scratch.file("test_starlark/rule/BUILD");
Expand Down
Loading