1*d4726bddSHONG Yifan# Copyright 2019 The Bazel Authors. All rights reserved. 2*d4726bddSHONG Yifan# 3*d4726bddSHONG Yifan# Licensed under the Apache License, Version 2.0 (the "License"); 4*d4726bddSHONG Yifan# you may not use this file except in compliance with the License. 5*d4726bddSHONG Yifan# You may obtain a copy of the License at 6*d4726bddSHONG Yifan# 7*d4726bddSHONG Yifan# http://www.apache.org/licenses/LICENSE-2.0 8*d4726bddSHONG Yifan# 9*d4726bddSHONG Yifan# Unless required by applicable law or agreed to in writing, software 10*d4726bddSHONG Yifan# distributed under the License is distributed on an "AS IS" BASIS, 11*d4726bddSHONG Yifan# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*d4726bddSHONG Yifan# See the License for the specific language governing permissions and 13*d4726bddSHONG Yifan# limitations under the License. 14*d4726bddSHONG Yifan 15*d4726bddSHONG Yifan"""Dependencies for the Rust `bindgen` rules""" 16*d4726bddSHONG Yifan 17*d4726bddSHONG Yifanload("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 18*d4726bddSHONG Yifanload("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 19*d4726bddSHONG Yifanload("//bindgen/3rdparty/crates:defs.bzl", "crate_repositories") 20*d4726bddSHONG Yifan 21*d4726bddSHONG YifanBINDGEN_VERSION = "0.69.1" 22*d4726bddSHONG Yifan 23*d4726bddSHONG Yifan# buildifier: disable=unnamed-macro 24*d4726bddSHONG Yifandef rust_bindgen_dependencies(): 25*d4726bddSHONG Yifan """Declare dependencies needed for bindgen. 26*d4726bddSHONG Yifan 27*d4726bddSHONG Yifan Returns: 28*d4726bddSHONG Yifan list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 29*d4726bddSHONG Yifan defined by this macro. 30*d4726bddSHONG Yifan """ 31*d4726bddSHONG Yifan 32*d4726bddSHONG Yifan maybe( 33*d4726bddSHONG Yifan http_archive, 34*d4726bddSHONG Yifan name = "llvm-raw", 35*d4726bddSHONG Yifan urls = ["https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/llvm-project-14.0.6.src.tar.xz"], 36*d4726bddSHONG Yifan strip_prefix = "llvm-project-14.0.6.src", 37*d4726bddSHONG Yifan sha256 = "8b3cfd7bc695bd6cea0f37f53f0981f34f87496e79e2529874fd03a2f9dd3a8a", 38*d4726bddSHONG Yifan build_file_content = "# empty", 39*d4726bddSHONG Yifan patch_args = ["-p1"], 40*d4726bddSHONG Yifan patches = [ 41*d4726bddSHONG Yifan Label("//bindgen/3rdparty/patches:llvm-project.cxx17.patch"), 42*d4726bddSHONG Yifan Label("//bindgen/3rdparty/patches:llvm-project.incompatible_disallow_empty_glob.patch"), 43*d4726bddSHONG Yifan ], 44*d4726bddSHONG Yifan ) 45*d4726bddSHONG Yifan 46*d4726bddSHONG Yifan bindgen_name = "rules_rust_bindgen__bindgen-cli-{}".format(BINDGEN_VERSION) 47*d4726bddSHONG Yifan maybe( 48*d4726bddSHONG Yifan http_archive, 49*d4726bddSHONG Yifan name = bindgen_name, 50*d4726bddSHONG Yifan integrity = "sha256-iFZe4JEQqZ54KZiX+/7VA7mqAwZThu6MGBl/yvIotQE=", 51*d4726bddSHONG Yifan type = "tar.gz", 52*d4726bddSHONG Yifan urls = ["https://static.crates.io/crates/bindgen-cli/bindgen-cli-{}.crate".format(BINDGEN_VERSION)], 53*d4726bddSHONG Yifan strip_prefix = "bindgen-cli-{}".format(BINDGEN_VERSION), 54*d4726bddSHONG Yifan build_file = Label("//bindgen/3rdparty:BUILD.bindgen-cli.bazel"), 55*d4726bddSHONG Yifan ) 56*d4726bddSHONG Yifan 57*d4726bddSHONG Yifan direct_deps = [ 58*d4726bddSHONG Yifan struct(repo = "llvm-raw", is_dev_dep = False), 59*d4726bddSHONG Yifan struct(repo = bindgen_name, is_dev_dep = False), 60*d4726bddSHONG Yifan ] 61*d4726bddSHONG Yifan direct_deps.extend(crate_repositories()) 62*d4726bddSHONG Yifan return direct_deps 63*d4726bddSHONG Yifan 64*d4726bddSHONG Yifan# buildifier: disable=unnamed-macro 65*d4726bddSHONG Yifandef rust_bindgen_register_toolchains(register_toolchains = True): 66*d4726bddSHONG Yifan """Registers the default toolchains for the `rules_rust` [bindgen][bg] rules. 67*d4726bddSHONG Yifan 68*d4726bddSHONG Yifan [bg]: https://rust-lang.github.io/rust-bindgen/ 69*d4726bddSHONG Yifan 70*d4726bddSHONG Yifan Args: 71*d4726bddSHONG Yifan register_toolchains (bool, optional): Whether or not to register toolchains. 72*d4726bddSHONG Yifan """ 73*d4726bddSHONG Yifan if register_toolchains: 74*d4726bddSHONG Yifan native.register_toolchains(str(Label("//bindgen:default_bindgen_toolchain"))) 75