Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 1 | # Copyright 2021 The Bazel Authors. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """A resilient API layer wrapping compilation and other logic for Rust rules. |
| 16 | |
| 17 | This module is meant to be used by custom rules that need to compile Rust code |
| 18 | and cannot simply rely on writing a macro that wraps `rust_library`. This module |
| 19 | provides the lower-level interface to Rust providers, actions, and functions. |
| 20 | Do not load this file directly; instead, load the top-level `defs.bzl` file, |
| 21 | which exports the `rust_common` struct. |
| 22 | |
| 23 | In the Bazel lingo, `rust_common` gives the access to the Rust Sandwich API. |
| 24 | """ |
| 25 | |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 26 | load(":providers.bzl", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo", "StdLibInfo", "TestCrateInfo") |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 27 | |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 28 | # This constant only represents the default value for attributes and macros |
| 29 | # defined in `rules_rust`. Like any attribute public attribute, it can be |
| 30 | # overwritten by the user on the rules they're defined on. |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 31 | # |
| 32 | # Note: Code in `.github/workflows/crate_universe.yaml` looks for this line, if |
| 33 | # you remove it or change its format, you will also need to update that code. |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 34 | DEFAULT_RUST_VERSION = "1.70.0" |
| 35 | |
| 36 | DEFAULT_NIGHTLY_ISO_DATE = "2023-06-01" |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 37 | |
| 38 | def _create_crate_info(**kwargs): |
| 39 | """A constructor for a `CrateInfo` provider |
| 40 | |
| 41 | This function should be used in place of directly creating a `CrateInfo` |
| 42 | provider to improve API stability. |
| 43 | |
| 44 | Args: |
| 45 | **kwargs: An inital set of keyword arguments. |
| 46 | |
| 47 | Returns: |
| 48 | CrateInfo: A provider |
| 49 | """ |
| 50 | if not "wrapped_crate_type" in kwargs: |
| 51 | kwargs.update({"wrapped_crate_type": None}) |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 52 | if not "metadata" in kwargs: |
| 53 | kwargs.update({"metadata": None}) |
| 54 | if not "rustc_env_files" in kwargs: |
| 55 | kwargs.update({"rustc_env_files": []}) |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 56 | return CrateInfo(**kwargs) |
| 57 | |
| 58 | rust_common = struct( |
| 59 | create_crate_info = _create_crate_info, |
| 60 | crate_info = CrateInfo, |
| 61 | dep_info = DepInfo, |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 62 | dep_variant_info = DepVariantInfo, |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 63 | stdlib_info = StdLibInfo, |
Brian Silverman | 5f6f276 | 2022-08-13 19:30:05 -0700 | [diff] [blame] | 64 | test_crate_info = TestCrateInfo, |
Adam Snaider | 1c095c9 | 2023-07-08 02:09:58 -0400 | [diff] [blame^] | 65 | crate_group_info = CrateGroupInfo, |
Brian Silverman | cc09f18 | 2022-03-09 15:40:20 -0800 | [diff] [blame] | 66 | default_version = DEFAULT_RUST_VERSION, |
| 67 | ) |