Skip to content

Commit

Permalink
Add Starlark implementation of common.linker_scripts.
Browse files Browse the repository at this point in the history
Switch calls from Java to Starlark version.

PiperOrigin-RevId: 504225500
Change-Id: Ic3b6c3c198d331bf474a012722b0a6e4d2feeeec
  • Loading branch information
buildbreaker2021 authored and copybara-github committed Jan 24, 2023
1 parent c213d68 commit fa01235
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,6 @@ public Artifact getDynamicLibrarySymlink(Artifact library, boolean preserveName)
/* prefixConsumer= */ true);
}

@StarlarkMethod(name = "linker_scripts", structField = true, documented = false)
public Sequence<Artifact> getLinkerScriptsForStarlark() {
return StarlarkList.immutableCopyOf(getLinkerScripts());
}

/** Returns any linker scripts found in the "deps" attribute of the rule. */
List<Artifact> getLinkerScripts() {
return ruleContext.getPrerequisiteArtifacts("deps").filter(CppFileTypes.LINKER_SCRIPT).list();
Expand Down
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def _create_transitive_linking_actions(
owner = ctx.label,
libraries = depset(libraries_for_current_cc_linking_context),
user_link_flags = cc_helper.linkopts(ctx, additional_make_variable_substitutions, cc_toolchain) + additional_linkopts,
additional_inputs = depset(common.linker_scripts + compilation_context.transitive_compilation_prerequisites().to_list()),
additional_inputs = depset(cc_helper.linker_scripts(ctx) + compilation_context.transitive_compilation_prerequisites().to_list()),
)
current_cc_linking_context = cc_common.create_linking_context(linker_inputs = depset([linker_inputs]))

Expand Down
13 changes: 13 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ ios_cpus = struct(
MACOS_TARGET_CPUS = ["darwin_x86_64", "darwin_arm64", "darwin_arm64e", "darwin"],
)

cpp_file_types = struct(
LINKER_SCRIPT = ["ld", "lds", "ldscript"],
)

SYSROOT_FLAG = "--sysroot="

def _build_linking_context_from_libraries(ctx, libraries):
Expand Down Expand Up @@ -1283,6 +1287,14 @@ def _defines(ctx, additional_make_variable_substitutions):
def _local_defines(ctx, additional_make_variable_substitutions):
return _defines_attribute(ctx, additional_make_variable_substitutions, "local_defines")

def _linker_scripts(ctx):
result = []
for dep in ctx.attr.deps:
for f in dep.files.to_list():
if f.extension in cpp_file_types.LINKER_SCRIPT:
result.append(f)
return result

cc_helper = struct(
merge_cc_debug_contexts = _merge_cc_debug_contexts,
is_code_coverage_enabled = _is_code_coverage_enabled,
Expand Down Expand Up @@ -1341,4 +1353,5 @@ cc_helper = struct(
linkopts = _linkopts,
defines = _defines,
local_defines = _local_defines,
linker_scripts = _linker_scripts,
)

0 comments on commit fa01235

Please sign in to comment.