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