Skip to content

Commit

Permalink
Update wasm_bindgen to non-deprecated rules_js API (#2934)
Browse files Browse the repository at this point in the history
`js_info` needs to jump through some hoops to support the legacy names.
The new ones are shorter and clearer.
Also, set the toolchain on the action to support Auto Exec Groups while
I'm here.

Co-authored-by: UebelAndre <[email protected]>
  • Loading branch information
dzbarsky and UebelAndre authored Oct 15, 2024
1 parent 390c998 commit ded96a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
19 changes: 8 additions & 11 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ load("@rules_rust//wasm_bindgen/rules_js:repositories.bzl", "js_rust_wasm_bindge

js_rust_wasm_bindgen_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

###############################################################################
# Workspace examples
###############################################################################
Expand Down Expand Up @@ -106,17 +114,6 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")

node_repositories()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()
Expand Down
1 change: 1 addition & 0 deletions wasm_bindgen/private/wasm_bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def rust_wasm_bindgen_action(ctx, toolchain, wasm_file, target_output, bindgen_f
mnemonic = "RustWasmBindgen",
progress_message = "Generating WebAssembly bindings for {}...".format(progress_message_label),
arguments = [args],
toolchain = str(Label("//wasm_bindgen:toolchain_type")),
)

return RustWasmBindgenInfo(
Expand Down
14 changes: 6 additions & 8 deletions wasm_bindgen/rules_js/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ def _js_rust_wasm_bindgen_impl(ctx):
bindgen_flags = ctx.attr.bindgen_flags,
)

# Return a structure that is compatible with the deps[] of a ts_library.
declarations = info.ts
es5_sources = info.js

return [
DefaultInfo(
files = depset([info.wasm], transitive = [info.js, info.ts]),
),
info,
# Return a structure that is compatible with the deps[] of a ts_library.
js_info(
declarations = declarations,
sources = es5_sources,
transitive_declarations = declarations,
transitive_sources = es5_sources,
target = ctx.label,
sources = info.js,
transitive_sources = info.js,
types = info.ts,
transitive_types = info.ts,
),
]

Expand Down
6 changes: 3 additions & 3 deletions wasm_bindgen/rules_js/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def js_rust_wasm_bindgen_dependencies():
maybe(
http_archive,
name = "aspect_rules_js",
sha256 = "7b2a4d1d264e105eae49a27e2e78065b23e2e45724df2251eacdd317e95bfdfd",
strip_prefix = "rules_js-1.31.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.31.0/rules_js-v1.31.0.tar.gz",
sha256 = "75c25a0f15a9e4592bbda45b57aa089e4bf17f9176fd735351e8c6444df87b52",
strip_prefix = "rules_js-2.1.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v2.1.0/rules_js-v2.1.0.tar.gz",
)

def js_rust_wasm_bindgen_register_toolchains(**kwargs):
Expand Down

0 comments on commit ded96a9

Please sign in to comment.