Skip to content

Commit

Permalink
Updated wasm_bindgen dependencies API
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed May 6, 2022
1 parent fb4d554 commit f401d65
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ PAGES = dict([
name = "rust_wasm_bindgen",
header_template = ":rust_wasm_bindgen.vm",
symbols = [
"rust_wasm_bindgen_repositories",
"rust_wasm_bindgen_dependencies",
"rust_wasm_bindgen_register_toolchains",
"rust_wasm_bindgen_toolchain",
"rust_wasm_bindgen",
],
Expand Down
10 changes: 8 additions & 2 deletions docs/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_re

rust_proto_transitive_repositories()

load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")
load(
"@rules_rust//wasm_bindgen:repositories.bzl",
"rust_wasm_bindgen_dependencies",
"rust_wasm_bindgen_register_toolchains",
)

rust_wasm_bindgen_dependencies()

rust_wasm_bindgen_repositories()
rust_wasm_bindgen_register_toolchains()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand Down
6 changes: 4 additions & 2 deletions docs/symbols.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ load(
)
load(
"@rules_rust//wasm_bindgen:repositories.bzl",
_rust_wasm_bindgen_repositories = "rust_wasm_bindgen_repositories",
_rust_wasm_bindgen_dependencies = "rust_wasm_bindgen_dependencies",
_rust_wasm_bindgen_register_toolchains = "rust_wasm_bindgen_register_toolchains",
)
load(
"@rules_rust//wasm_bindgen:wasm_bindgen.bzl",
Expand Down Expand Up @@ -125,8 +126,9 @@ cargo_bootstrap_repository = _cargo_bootstrap_repository
cargo_env = _cargo_env

rust_wasm_bindgen = _rust_wasm_bindgen
rust_wasm_bindgen_dependencies = _rust_wasm_bindgen_dependencies
rust_wasm_bindgen_register_toolchains = _rust_wasm_bindgen_register_toolchains
rust_wasm_bindgen_toolchain = _rust_wasm_bindgen_toolchain
rust_wasm_bindgen_repositories = _rust_wasm_bindgen_repositories

rust_repositories = _rust_repositories
rust_repository_set = _rust_repository_set
Expand Down
6 changes: 4 additions & 2 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ load("@rules_rust//proto:transitive_repositories.bzl", "rust_proto_transitive_re

rust_proto_transitive_repositories()

load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains")

rust_wasm_bindgen_repositories()
rust_wasm_bindgen_dependencies()

rust_wasm_bindgen_register_toolchains()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand Down
41 changes: 32 additions & 9 deletions wasm_bindgen/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//wasm_bindgen/raze:crates.bzl", "rules_rust_wasm_bindgen_fetch_remote_crates")

# buildifier: disable=unnamed-macro
def rust_wasm_bindgen_repositories(register_default_toolchain = True):
"""Declare dependencies needed for [rust_wasm_bindgen](#rust_wasm_bindgen).
def rust_wasm_bindgen_dependencies():
"""Declare dependencies needed for the `rules_rust` [wasm-bindgen][wb] rules.
Args:
register_default_toolchain (bool, optional): If True, the default [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain)
(`@rules_rust//wasm_bindgen:default_wasm_bindgen_toolchain`) is registered. This toolchain requires a set of dependencies
that were generated using [cargo raze](https://github.com/google/cargo-raze). These will also be loaded.
[wb]: https://github.com/rustwasm/wasm-bindgen
"""

maybe(
Expand All @@ -34,7 +31,33 @@ def rust_wasm_bindgen_repositories(register_default_toolchain = True):
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.4.2/rules_nodejs-core-5.4.2.tar.gz"],
)

# Load dependencies of the default toolchain and register it.
if register_default_toolchain:
rules_rust_wasm_bindgen_fetch_remote_crates()
rules_rust_wasm_bindgen_fetch_remote_crates()

# buildifier: disable=unnamed-macro
def rust_wasm_bindgen_register_toolchains(register_toolchains = True):
"""Registers the default toolchains for the `rules_rust` [wasm-bindgen][wb] rules.
[wb]: https://github.com/rustwasm/wasm-bindgen
Args:
register_toolchains (bool, optional): Whether or not to register toolchains.
"""

if register_toolchains:
native.register_toolchains(str(Label("//wasm_bindgen:default_wasm_bindgen_toolchain")))

# buildifier: disable=unnamed-macro
def rust_wasm_bindgen_repositories(register_default_toolchain = True):
"""Declare dependencies needed for [rust_wasm_bindgen](#rust_wasm_bindgen).
**Deprecated**: Use [rust_wasm_bindgen_dependencies](#rust_wasm_bindgen_depednencies) and [rust_wasm_bindgen_register_toolchains](#rust_wasm_bindgen_register_toolchains).
Args:
register_default_toolchain (bool, optional): If True, the default [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain)
(`@rules_rust//wasm_bindgen:default_wasm_bindgen_toolchain`) is registered. This toolchain requires a set of dependencies
that were generated using [cargo raze](https://github.com/google/cargo-raze). These will also be loaded.
"""

rust_wasm_bindgen_dependencies()

rust_wasm_bindgen_register_toolchains(register_toolchains = register_default_toolchain)

0 comments on commit f401d65

Please sign in to comment.