Skip to content

Commit 107e432

Browse files
authored
Migrate to the modern linker input API. (#463)
See bazelbuild/bazel#10860.
1 parent afee872 commit 107e432

File tree

6 files changed

+33
-40
lines changed

6 files changed

+33
-40
lines changed

bindgen/bindgen.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
# limitations under the License.
1414

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

2019
def rust_bindgen_library(

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")
3636
rust_workspace()
3737
```
3838

39-
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.
39+
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.
4040

4141
## Rules
4242

rust/private/legacy_cc_starlark_api_shim.bzl

Lines changed: 0 additions & 34 deletions
This file was deleted.

rust/private/rustc.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ load(
2121
)
2222
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
2323
load("@io_bazel_rules_rust_bazel_version//:def.bzl", "BAZEL_VERSION")
24-
load("@io_bazel_rules_rust//rust:private/legacy_cc_starlark_api_shim.bzl", "get_libs_for_static_executable")
25-
load("@io_bazel_rules_rust//rust:private/utils.bzl", "get_lib_name", "relativize")
24+
load("@io_bazel_rules_rust//rust:private/utils.bzl", "get_lib_name", "get_libs_for_static_executable", "relativize")
2625

2726
CrateInfo = provider(
2827
doc = "A provider containing general Crate information.",

rust/private/utils.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,32 @@ def determine_output_hash(crate_root):
9494
str: A string representation of the hash.
9595
"""
9696
return repr(hash(crate_root.path))
97+
98+
def get_libs_for_static_executable(dep):
99+
"""find the libraries used for linking a static executable.
100+
101+
Args:
102+
dep (Target): A cc_library target.
103+
104+
Returns:
105+
depset: A depset[File]
106+
"""
107+
linker_inputs = dep[CcInfo].linking_context.linker_inputs.to_list()
108+
return depset([_get_preferred_artifact(lib) for li in linker_inputs for lib in li.libraries])
109+
110+
def _get_preferred_artifact(library_to_link):
111+
"""Get the first available library to link from a LibraryToLink object.
112+
113+
Args:
114+
library_to_link (LibraryToLink): See the followg links for additional details:
115+
https://docs.bazel.build/versions/master/skylark/lib/LibraryToLink.html
116+
117+
Returns:
118+
File: Returns the first valid library type (only one is expected)
119+
"""
120+
return (
121+
library_to_link.static_library or
122+
library_to_link.pic_static_library or
123+
library_to_link.interface_library or
124+
library_to_link.dynamic_library
125+
)

workspace.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
33
load("@bazel_skylib//lib:versions.bzl", "versions")
44

5-
_MINIMUM_SUPPORTED_BAZEL_VERSION = "0.17.1"
5+
_MINIMUM_SUPPORTED_BAZEL_VERSION = "3.0.0"
66

77
def _bazel_version_impl(repository_ctx):
88
"""The implementation for the `bazel_version` rule

0 commit comments

Comments
 (0)