From aa77dc127113a40bbeb2017d59bff388b1ff751e Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 22 Oct 2020 23:44:08 -0500 Subject: [PATCH 1/2] Migrate to the modern linker input API. See https://github.com/bazelbuild/bazel/issues/10860. --- bindgen/bindgen.bzl | 3 +- rust/private/legacy_cc_starlark_api_shim.bzl | 34 -------------------- rust/private/rustc.bzl | 3 +- rust/private/utils.bzl | 29 +++++++++++++++++ 4 files changed, 31 insertions(+), 38 deletions(-) delete mode 100644 rust/private/legacy_cc_starlark_api_shim.bzl diff --git a/bindgen/bindgen.bzl b/bindgen/bindgen.bzl index 41603c8ac2..7a86e264ff 100644 --- a/bindgen/bindgen.bzl +++ b/bindgen/bindgen.bzl @@ -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( diff --git a/rust/private/legacy_cc_starlark_api_shim.bzl b/rust/private/legacy_cc_starlark_api_shim.bzl deleted file mode 100644 index c94cc63dc6..0000000000 --- a/rust/private/legacy_cc_starlark_api_shim.bzl +++ /dev/null @@ -1,34 +0,0 @@ -""" -Part of --incompatible_disable_legacy_cc_provider migration (https://github.com/bazelbuild/bazel/issues/7036) -""" - -def get_libs_for_static_executable(dep): - """This replaces dep.cc.libs, which found the libraries used for linking a static executable. - - Args: - dep (Target): A cc_library target. - - Returns: - depset: A depset[File] - """ - libraries_to_link = dep[CcInfo].linking_context.libraries_to_link - return depset([_get_preferred_artifact(lib) for lib in libraries_to_link.to_list()]) - -def _get_preferred_artifact(library_to_link): - """Gets the first available library to link from a CcInfo provider's deprecated libraries_to_link field - - Args: - library_to_link (unknown): The object passed here is from a deprecated field. See the following - links for additional details: - https://docs.bazel.build/versions/master/skylark/lib/LinkingContext.html#libraries_to_link - https://github.com/bazelbuild/bazel/issues/8118 - - 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 - ) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 55b99355e2..1acab5c7d1 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -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.", diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index 9c18b10cd4..cee3754387 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -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 + ) From a8dd4afb57c74e035fcd8ac2d8e22771e4531c57 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 23 Oct 2020 08:56:45 -0500 Subject: [PATCH 2/2] Bump required Bazel version to 3.0.0. --- docs/index.md | 2 +- workspace.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 40ad8986cb..394587e0bd 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. ## Rules diff --git a/workspace.bzl b/workspace.bzl index 57ca95d4c3..dcbcb251c8 100644 --- a/workspace.bzl +++ b/workspace.bzl @@ -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