blob: f6063a04147e7425818c9ee3ac371896d9a14705 [file] [log] [blame]
Brian Silvermancc09f182022-03-09 15:40:20 -08001# 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
17This module is meant to be used by custom rules that need to compile Rust code
18and cannot simply rely on writing a macro that wraps `rust_library`. This module
19provides the lower-level interface to Rust providers, actions, and functions.
20Do not load this file directly; instead, load the top-level `defs.bzl` file,
21which exports the `rust_common` struct.
22
23In the Bazel lingo, `rust_common` gives the access to the Rust Sandwich API.
24"""
25
Adam Snaider1c095c92023-07-08 02:09:58 -040026load(":providers.bzl", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo", "StdLibInfo", "TestCrateInfo")
Brian Silvermancc09f182022-03-09 15:40:20 -080027
Brian Silverman5f6f2762022-08-13 19:30:05 -070028# 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 Silvermancc09f182022-03-09 15:40:20 -080031#
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 Snaider1c095c92023-07-08 02:09:58 -040034DEFAULT_RUST_VERSION = "1.70.0"
35
36DEFAULT_NIGHTLY_ISO_DATE = "2023-06-01"
Brian Silvermancc09f182022-03-09 15:40:20 -080037
38def _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 Silverman5f6f2762022-08-13 19:30:05 -070052 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 Silvermancc09f182022-03-09 15:40:20 -080056 return CrateInfo(**kwargs)
57
58rust_common = struct(
59 create_crate_info = _create_crate_info,
60 crate_info = CrateInfo,
61 dep_info = DepInfo,
Adam Snaider1c095c92023-07-08 02:09:58 -040062 dep_variant_info = DepVariantInfo,
Brian Silvermancc09f182022-03-09 15:40:20 -080063 stdlib_info = StdLibInfo,
Brian Silverman5f6f2762022-08-13 19:30:05 -070064 test_crate_info = TestCrateInfo,
Adam Snaider1c095c92023-07-08 02:09:58 -040065 crate_group_info = CrateGroupInfo,
Brian Silvermancc09f182022-03-09 15:40:20 -080066 default_version = DEFAULT_RUST_VERSION,
67)