fork/rules_rust

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

UebelAndreUpdated rust_bindgen dependencies API (#1354)120f911d

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