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"""Dependency definitions for wasm-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("//wasm_bindgen/3rdparty/crates:defs.bzl", "crate_repositories") 20*d4726bddSHONG Yifan 21*d4726bddSHONG YifanWASM_BINDGEN_VERSION = "0.2.92" 22*d4726bddSHONG Yifan 23*d4726bddSHONG Yifan# buildifier: disable=unnamed-macro 24*d4726bddSHONG Yifandef rust_wasm_bindgen_dependencies(): 25*d4726bddSHONG Yifan """Declare dependencies needed for the `rules_rust` [wasm-bindgen][wb] rules. 26*d4726bddSHONG Yifan 27*d4726bddSHONG Yifan [wb]: https://github.com/rustwasm/wasm-bindgen 28*d4726bddSHONG Yifan 29*d4726bddSHONG Yifan Returns: 30*d4726bddSHONG Yifan list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories 31*d4726bddSHONG Yifan defined by this macro. 32*d4726bddSHONG Yifan """ 33*d4726bddSHONG Yifan 34*d4726bddSHONG Yifan direct_deps = [ 35*d4726bddSHONG Yifan struct(repo = "rules_rust_wasm_bindgen_cli", is_dev_dep = False), 36*d4726bddSHONG Yifan ] 37*d4726bddSHONG Yifan maybe( 38*d4726bddSHONG Yifan http_archive, 39*d4726bddSHONG Yifan name = "rules_rust_wasm_bindgen_cli", 40*d4726bddSHONG Yifan sha256 = "08f61e21873f51e3059a8c7c3eef81ede7513d161cfc60751c7b2ffa6ed28270", 41*d4726bddSHONG Yifan urls = ["https://static.crates.io/crates/wasm-bindgen-cli/wasm-bindgen-cli-{}.crate".format(WASM_BINDGEN_VERSION)], 42*d4726bddSHONG Yifan type = "tar.gz", 43*d4726bddSHONG Yifan strip_prefix = "wasm-bindgen-cli-{}".format(WASM_BINDGEN_VERSION), 44*d4726bddSHONG Yifan build_file = Label("//wasm_bindgen/3rdparty:BUILD.wasm-bindgen-cli.bazel"), 45*d4726bddSHONG Yifan patch_args = ["-p1"], 46*d4726bddSHONG Yifan patches = [Label("//wasm_bindgen/3rdparty/patches:resolver.patch")], 47*d4726bddSHONG Yifan ) 48*d4726bddSHONG Yifan 49*d4726bddSHONG Yifan direct_deps.extend(crate_repositories()) 50*d4726bddSHONG Yifan return direct_deps 51*d4726bddSHONG Yifan 52*d4726bddSHONG Yifan# buildifier: disable=unnamed-macro 53*d4726bddSHONG Yifandef rust_wasm_bindgen_register_toolchains(register_toolchains = True): 54*d4726bddSHONG Yifan """Registers the default toolchains for the `rules_rust` [wasm-bindgen][wb] rules. 55*d4726bddSHONG Yifan 56*d4726bddSHONG Yifan [wb]: https://github.com/rustwasm/wasm-bindgen 57*d4726bddSHONG Yifan 58*d4726bddSHONG Yifan Args: 59*d4726bddSHONG Yifan register_toolchains (bool, optional): Whether or not to register toolchains. 60*d4726bddSHONG Yifan """ 61*d4726bddSHONG Yifan 62*d4726bddSHONG Yifan if register_toolchains: 63*d4726bddSHONG Yifan native.register_toolchains(str(Label("//wasm_bindgen:default_wasm_bindgen_toolchain"))) 64*d4726bddSHONG Yifan 65*d4726bddSHONG Yifan# buildifier: disable=unnamed-macro 66*d4726bddSHONG Yifandef rust_wasm_bindgen_repositories(register_default_toolchain = True): 67*d4726bddSHONG Yifan """Declare dependencies needed for [rust_wasm_bindgen](#rust_wasm_bindgen). 68*d4726bddSHONG Yifan 69*d4726bddSHONG Yifan **Deprecated**: Use [rust_wasm_bindgen_dependencies](#rust_wasm_bindgen_depednencies) and [rust_wasm_bindgen_register_toolchains](#rust_wasm_bindgen_register_toolchains). 70*d4726bddSHONG Yifan 71*d4726bddSHONG Yifan Args: 72*d4726bddSHONG Yifan register_default_toolchain (bool, optional): If True, the default [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain) 73*d4726bddSHONG Yifan (`@rules_rust//wasm_bindgen:default_wasm_bindgen_toolchain`) is registered. This toolchain requires a set of dependencies 74*d4726bddSHONG Yifan that were generated using [crate_universe](https://github.com/bazelbuild/rules_rust/tree/main/crate_universe). These will also be loaded. 75*d4726bddSHONG Yifan """ 76*d4726bddSHONG Yifan 77*d4726bddSHONG Yifan rust_wasm_bindgen_dependencies() 78*d4726bddSHONG Yifan 79*d4726bddSHONG Yifan rust_wasm_bindgen_register_toolchains(register_toolchains = register_default_toolchain) 80