fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
6d8009db
0.8.1
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 28crate_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 36Args: 37register_toolchains (bool, optional): Whether or not to register toolchains. 38""" 39if register_toolchains : 40native . 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 46rust_bindgen_dependencies () 47rust_bindgen_register_toolchains () 48 49_COMMON_WORKSPACE = """\ 50workspace(name = "{}") 51 52load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 53 54http_archive( 55name = "rules_cc", 56urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"], 57sha256 = "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( 67name = "clang", 68srcs = ["bin/clang"], 69) 70 71cc_import( 72name = "libclang", 73shared_library = "lib/libclang.{suffix}", 74) 75 76alias( 77name = "libclang.so", 78actual = ":libclang", 79deprecation = "Use :libclang instead", 80) 81 82cc_import( 83name = "libc++", 84shared_library = "lib/libc++.{suffix}" 85) 86""" 87 88def _bindgen_clang_repositories (): 89# Releases @ http://releases.llvm.org/download.html 90maybe ( 91http_archive , 92name = "bindgen_clang_linux" , 93urls = [ "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" ], 94strip_prefix = "clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04" , 95sha256 = "b25f592a0c00686f03e3b7db68ca6dc87418f681f4ead4df4745a01d9be63843" , 96build_file_content = _CLANG_BUILD_FILE . format ( suffix = "so" ), 97workspace_file_content = _COMMON_WORKSPACE . format ( "bindgen_clang_linux" ), 98) 99 100maybe ( 101http_archive , 102name = "bindgen_clang_osx" , 103urls = [ "https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz" ], 104strip_prefix = "clang+llvm-10.0.0-x86_64-apple-darwin" , 105sha256 = "633a833396bf2276094c126b072d52b59aca6249e7ce8eae14c728016edb5e61" , 106build_file_content = _CLANG_BUILD_FILE . format ( suffix = "dylib" ), 107workspace_file_content = _COMMON_WORKSPACE . format ( "bindgen_clang_osx" ), 108)