fork/rules_rust

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

UebelAndreMoved rust extension rules into a separate `rules_rust_ext` workspace. (#3007)2bad96d9

cleanup
3.2 KiB86 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():
25    """Declare dependencies needed for bindgen.
26
27    Returns:
28        list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
29        defined by this macro.
30    """
31
32    maybe(
33        http_archive,
34        name = "llvm-raw",
35        urls = ["https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/llvm-project-14.0.6.src.tar.xz"],
36        strip_prefix = "llvm-project-14.0.6.src",
37        sha256 = "8b3cfd7bc695bd6cea0f37f53f0981f34f87496e79e2529874fd03a2f9dd3a8a",
38        build_file_content = "# empty",
39        patch_args = ["-p1"],
40        patches = [
41            Label("//3rdparty/patches:llvm-project.cxx17.patch"),
42            Label("//3rdparty/patches:llvm-project.incompatible_disallow_empty_glob.patch"),
43        ],
44    )
45
46    maybe(
47        http_archive,
48        name = "zlib",
49        build_file = Label("//3rdparty:BUILD.zlib.bazel"),
50        sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
51        strip_prefix = "zlib-1.2.11",
52        urls = [
53            "https://zlib.net/zlib-1.2.11.tar.gz",
54            "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz",
55        ],
56    )
57
58    bindgen_name = "rules_rust_bindgen__bindgen-cli-{}".format(BINDGEN_VERSION)
59    maybe(
60        http_archive,
61        name = bindgen_name,
62        integrity = "sha256-Mz+eRtWNh1r7irkjwi27fmF4j1WtKPK12Yv5ENkL1ao=",
63        type = "tar.gz",
64        urls = ["https://static.crates.io/crates/bindgen-cli/bindgen-cli-{}.crate".format(BINDGEN_VERSION)],
65        strip_prefix = "bindgen-cli-{}".format(BINDGEN_VERSION),
66        build_file = Label("//3rdparty:BUILD.bindgen-cli.bazel"),
67    )
68
69    direct_deps = [
70        struct(repo = "llvm-raw", is_dev_dep = False),
71        struct(repo = bindgen_name, is_dev_dep = False),
72    ]
73    direct_deps.extend(crate_repositories())
74    return direct_deps
75
76# buildifier: disable=unnamed-macro
77def rust_bindgen_register_toolchains(register_toolchains = True):
78    """Registers the default toolchains for the `rules_rust` [bindgen][bg] rules.
79
80    [bg]: https://rust-lang.github.io/rust-bindgen/
81
82    Args:
83        register_toolchains (bool, optional): Whether or not to register toolchains.
84    """
85    if register_toolchains:
86        native.register_toolchains(str(Label("//:default_bindgen_toolchain")))