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

Migrate to the modern linker input API. #463

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
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
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
rust_workspace()
```

The rules are under active development, as such the lastest commit on the master branch should be used. `master` currently requires Bazel >= 0.26.0.
The rules are under active development, as such the lastest commit on the master branch should be used. `master` currently requires Bazel >= 3.0.0.
benjaminp marked this conversation as resolved.
Show resolved Hide resolved

## Rules

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
)
2 changes: 1 addition & 1 deletion workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@bazel_skylib//lib:versions.bzl", "versions")

_MINIMUM_SUPPORTED_BAZEL_VERSION = "0.17.1"
_MINIMUM_SUPPORTED_BAZEL_VERSION = "3.0.0"

def _bazel_version_impl(repository_ctx):
"""The implementation for the `bazel_version` rule
Expand Down