Skip to content

Commit

Permalink
Migrate to the modern linker input API.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Nov 5, 2020
1 parent d1d04eb commit aa77dc1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 38 deletions.
3 changes: 1 addition & 2 deletions bindgen/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

# buildifier: disable=module-docstring
load("@io_bazel_rules_rust//rust:private/legacy_cc_starlark_api_shim.bzl", "get_libs_for_static_executable")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain", "get_libs_for_static_executable")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library")

def rust_bindgen_library(
Expand Down
34 changes: 0 additions & 34 deletions rust/private/legacy_cc_starlark_api_shim.bzl

This file was deleted.

3 changes: 1 addition & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ load(
)
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@io_bazel_rules_rust_bazel_version//:def.bzl", "BAZEL_VERSION")
load("@io_bazel_rules_rust//rust:private/legacy_cc_starlark_api_shim.bzl", "get_libs_for_static_executable")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "get_lib_name", "relativize")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "get_lib_name", "get_libs_for_static_executable", "relativize")

CrateInfo = provider(
doc = "A provider containing general Crate information.",
Expand Down
29 changes: 29 additions & 0 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,32 @@ def determine_output_hash(crate_root):
str: A string representation of the hash.
"""
return repr(hash(crate_root.path))

def get_libs_for_static_executable(dep):
"""find the libraries used for linking a static executable.
Args:
dep (Target): A cc_library target.
Returns:
depset: A depset[File]
"""
linker_inputs = dep[CcInfo].linking_context.linker_inputs.to_list()
return depset([_get_preferred_artifact(lib) for li in linker_inputs for lib in li.libraries])

def _get_preferred_artifact(library_to_link):
"""Get the first available library to link from a LibraryToLink object.
Args:
library_to_link (LibraryToLink): See the followg links for additional details:
https://docs.bazel.build/versions/master/skylark/lib/LibraryToLink.html
Returns:
File: Returns the first valid library type (only one is expected)
"""
return (
library_to_link.static_library or
library_to_link.pic_static_library or
library_to_link.interface_library or
library_to_link.dynamic_library
)

0 comments on commit aa77dc1

Please sign in to comment.