fork/rules_rust

git clone https://git.julia.blue/fork/rules_rust

UebelAndreAdded bzlmod support to all extension rules. (#3037)a7aba2d0

main
3.7 KiB100 linesraw
1# Copyright 2019 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"""Dependencies for the Rust `bindgen` rules"""
16
17load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
19load("//3rdparty/crates:defs.bzl", "crate_repositories")
20
21BINDGEN_VERSION = "0.70.1"
22
23# buildifier: disable=unnamed-macro
24def rust_bindgen_dependencies(is_bzlmod = False):
25    """Declare dependencies needed for bindgen.
26
27    Args:
28        is_bzlmod (bool): Whether or not this macro is called in a bzlmod context.
29
30    Returns:
31        list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
32        defined by this macro.
33    """
34
35    if not is_bzlmod:
36        maybe(
37            http_archive,
38            name = "llvm-raw",
39            urls = ["https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.3/llvm-project-17.0.3.src.tar.xz"],
40            strip_prefix = "llvm-project-17.0.3.src",
41            integrity = "sha256-vloeRNZPMGu0T859NuOzmTaU6OYSKyNIYIkGKDwXbbg=",
42            build_file_content = "# empty",
43            patch_args = ["-p1"],
44            patches = [
45                # Label("//3rdparty/patches:llvm-project.cxx17.patch"),
46                Label("//3rdparty/patches:llvm-raw.incompatible_disallow_empty_glob.patch"),
47            ],
48        )
49
50        maybe(
51            http_archive,
52            name = "zlib",
53            build_file = Label("//3rdparty:BUILD.zlib.bazel"),
54            sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
55            strip_prefix = "zlib-1.2.11",
56            urls = [
57                "https://zlib.net/zlib-1.2.11.tar.gz",
58                "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz",
59            ],
60        )
61
62        maybe(
63            http_archive,
64            name = "zstd",
65            build_file = Label("//3rdparty:BUILD.zstd.bazel"),
66            sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
67            strip_prefix = "zstd-1.5.2",
68            urls = [
69                "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
70            ],
71        )
72
73    bindgen_name = "rules_rust_bindgen__bindgen-cli-{}".format(BINDGEN_VERSION)
74    maybe(
75        http_archive,
76        name = bindgen_name,
77        integrity = "sha256-Mz+eRtWNh1r7irkjwi27fmF4j1WtKPK12Yv5ENkL1ao=",
78        type = "tar.gz",
79        urls = ["https://static.crates.io/crates/bindgen-cli/bindgen-cli-{}.crate".format(BINDGEN_VERSION)],
80        strip_prefix = "bindgen-cli-{}".format(BINDGEN_VERSION),
81        build_file = Label("//3rdparty:BUILD.bindgen-cli.bazel"),
82    )
83
84    direct_deps = [
85        struct(repo = bindgen_name, is_dev_dep = False),
86    ]
87    direct_deps.extend(crate_repositories())
88    return direct_deps
89
90# buildifier: disable=unnamed-macro
91def rust_bindgen_register_toolchains(register_toolchains = True):
92    """Registers the default toolchains for the `rules_rust` [bindgen][bg] rules.
93
94    [bg]: https://rust-lang.github.io/rust-bindgen/
95
96    Args:
97        register_toolchains (bool, optional): Whether or not to register toolchains.
98    """
99    if register_toolchains:
100        native.register_toolchains(str(Label("//:default_bindgen_toolchain")))