fork/rules_rust

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

UebelAndreUpdate `//bindgen` to use `crate_universe` (#1440)6d8009db

0.8.1
3.7 KiB108 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("//bindgen/3rdparty/crates:defs.bzl", "crate_repositories")
20
21# buildifier: disable=unnamed-macro
22def rust_bindgen_dependencies():
23    """Declare dependencies needed for bindgen."""
24
25    # nb. The bindgen rule itself should work on any platform.
26    _bindgen_clang_repositories()
27
28    crate_repositories()
29
30# buildifier: disable=unnamed-macro
31def rust_bindgen_register_toolchains(register_toolchains = True):
32    """Registers the default toolchains for the `rules_rust` [bindgen][bg] rules.
33
34    [bg]: https://rust-lang.github.io/rust-bindgen/
35
36    Args:
37        register_toolchains (bool, optional): Whether or not to register toolchains.
38    """
39    if register_toolchains:
40        native.register_toolchains(str(Label("//bindgen:default_bindgen_toolchain")))
41
42# buildifier: disable=unnamed-macro
43def rust_bindgen_repositories():
44    """**Deprecated**: Instead use [rust_bindgen_dependencies](#rust_bindgen_dependencies) and [rust_bindgen_register_toolchains](#rust_bindgen_register_toolchains)"""
45
46    rust_bindgen_dependencies()
47    rust_bindgen_register_toolchains()
48
49_COMMON_WORKSPACE = """\
50workspace(name = "{}")
51
52load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
53
54http_archive(
55    name = "rules_cc",
56    urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"],
57    sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
58)
59"""
60
61_CLANG_BUILD_FILE = """\
62load("@rules_cc//cc:defs.bzl", "cc_import")
63
64package(default_visibility = ["//visibility:public"])
65
66sh_binary(
67    name = "clang",
68    srcs = ["bin/clang"],
69)
70
71cc_import(
72    name = "libclang",
73    shared_library = "lib/libclang.{suffix}",
74)
75
76alias(
77    name = "libclang.so",
78    actual = ":libclang",
79    deprecation = "Use :libclang instead",
80)
81
82cc_import(
83    name = "libc++",
84    shared_library = "lib/libc++.{suffix}"
85)
86"""
87
88def _bindgen_clang_repositories():
89    # Releases @ http://releases.llvm.org/download.html
90    maybe(
91        http_archive,
92        name = "bindgen_clang_linux",
93        urls = ["https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz"],
94        strip_prefix = "clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04",
95        sha256 = "b25f592a0c00686f03e3b7db68ca6dc87418f681f4ead4df4745a01d9be63843",
96        build_file_content = _CLANG_BUILD_FILE.format(suffix = "so"),
97        workspace_file_content = _COMMON_WORKSPACE.format("bindgen_clang_linux"),
98    )
99
100    maybe(
101        http_archive,
102        name = "bindgen_clang_osx",
103        urls = ["https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz"],
104        strip_prefix = "clang+llvm-10.0.0-x86_64-apple-darwin",
105        sha256 = "633a833396bf2276094c126b072d52b59aca6249e7ce8eae14c728016edb5e61",
106        build_file_content = _CLANG_BUILD_FILE.format(suffix = "dylib"),
107        workspace_file_content = _COMMON_WORKSPACE.format("bindgen_clang_osx"),
108    )