diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 422b72dcd5..d2b254b25c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,8 +38,3 @@ repos: exclude_types: - json - javascript - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 - hooks: - - id: prettier - files: ".*\\.(js|mjs|cjs|jsx|ts|tsx)$" diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index be2c0fe3d8..4b6a8fb9c4 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -249,13 +249,6 @@ stardoc( deps = ["@rules_rust_wasm_bindgen//:bzl_lib"], ) -stardoc( - name = "rust_wasm_bindgen_rules_js", - out = "src/rust_wasm_bindgen_rules_js.md", - input = "@rules_rust_wasm_bindgen//rules_js:defs.bzl", - deps = ["@rules_rust_wasm_bindgen//rules_js:bzl_lib"], -) - stardoc( name = "rust_settings", out = "src/rust_settings.md", @@ -295,7 +288,6 @@ mdbook( ":rust_toolchains", ":rust_unpretty", ":rust_wasm_bindgen", - ":rust_wasm_bindgen_rules_js", ], book = "book.toml", ) diff --git a/extensions/wasm_bindgen/.bazelrc b/extensions/wasm_bindgen/.bazelrc index 8f0bfe2b35..e459b2c912 100644 --- a/extensions/wasm_bindgen/.bazelrc +++ b/extensions/wasm_bindgen/.bazelrc @@ -5,9 +5,6 @@ ## https://bazel.build/docs/best-practices#bazelrc-file ############################################################################### -# TODO: https://github.com/bazelbuild/rules_rust/issues/3319 -common --deleted_packages=rules_js,rules_js/test - # An alias for the test browser setting. common --flag_alias=test_browser=//settings:test_browser diff --git a/extensions/wasm_bindgen/MODULE.bazel b/extensions/wasm_bindgen/MODULE.bazel index 4126905480..dead2decab 100644 --- a/extensions/wasm_bindgen/MODULE.bazel +++ b/extensions/wasm_bindgen/MODULE.bazel @@ -10,7 +10,6 @@ bazel_dep(name = "bazel_features", version = "1.32.0") bazel_dep(name = "bazel_skylib", version = "1.8.1") bazel_dep(name = "platforms", version = "1.0.0") bazel_dep(name = "rules_cc", version = "0.2.4") -bazel_dep(name = "aspect_rules_js", version = "2.1.2") bazel_dep(name = "apple_support", version = "1.23.0") rust_ext = use_extension("//:extensions.bzl", "rust_ext") diff --git a/extensions/wasm_bindgen/defs.bzl b/extensions/wasm_bindgen/defs.bzl index 832c27c717..cd57b75ce4 100644 --- a/extensions/wasm_bindgen/defs.bzl +++ b/extensions/wasm_bindgen/defs.bzl @@ -29,13 +29,7 @@ toolchains to register in the workspace. ## Interfacing with Javascript rules -While it's recommended for users to maintain their own , in the -`@rules_rust_wasm_bindgen` package there exists interface sub-packages for various -Javascript Bazel rules. E.g. `aspect_rules_js`. The rules defined there are a more -convenient way to use `rust_wasm_bindgen` with the associated javascript rules due -to the inclusion of additional providers. Each directory contains a `defs.bzl` file -that defines the different variants of `rust_wasm_bindgen`. (e.g. `js_rust_wasm_bindgen` -for the `rules_js` submodule). +Rules for doing so can be found at [rules_js_rust_wasm_bindgen](https://github.com/UebelAndre/rules_js_rust_wasm_bindgen) [wb]: https://github.com/rustwasm/wasm-bindgen diff --git a/extensions/wasm_bindgen/rules_js/BUILD.bazel b/extensions/wasm_bindgen/rules_js/BUILD.bazel deleted file mode 100644 index 8b503ab748..0000000000 --- a/extensions/wasm_bindgen/rules_js/BUILD.bazel +++ /dev/null @@ -1,17 +0,0 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -package(default_visibility = ["//visibility:public"]) - -exports_files([ - "defs.bzl", -]) - -bzl_library( - name = "bzl_lib", - srcs = glob(["**/*.bzl"]), - deps = [ - "//:bzl_lib", - "@aspect_rules_js//js:defs", - "@aspect_rules_js//js:providers", - ], -) diff --git a/extensions/wasm_bindgen/rules_js/defs.bzl b/extensions/wasm_bindgen/rules_js/defs.bzl deleted file mode 100644 index 1da939c52f..0000000000 --- a/extensions/wasm_bindgen/rules_js/defs.bzl +++ /dev/null @@ -1,59 +0,0 @@ -"""Rust WASM-bindgen rules for interfacing with aspect-build/rules_js""" - -load("@aspect_rules_js//js:providers.bzl", "js_info") - -# buildifier: disable=bzl-visibility -load("@rules_rust//rust/private:providers.bzl", "ClippyInfo", "RustAnalyzerGroupInfo", "RustAnalyzerInfo") -load("//private:wasm_bindgen.bzl", "WASM_BINDGEN_ATTR", "rust_wasm_bindgen_action") - -def _js_rust_wasm_bindgen_impl(ctx): - toolchain = ctx.toolchains[Label("//:toolchain_type")] - - info = rust_wasm_bindgen_action( - ctx = ctx, - toolchain = toolchain, - wasm_file = ctx.attr.wasm_file, - target_output = ctx.attr.target, - flags = ctx.attr.bindgen_flags, - ) - - providers = [ - 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( - target = ctx.label, - sources = info.js, - transitive_sources = info.js, - types = info.ts, - transitive_types = info.ts, - ), - ] - - crate = ctx.attr.wasm_file[0] - if RustAnalyzerGroupInfo in crate: - providers.append(crate[RustAnalyzerGroupInfo]) - - if RustAnalyzerInfo in crate: - providers.append(crate[RustAnalyzerInfo]) - - if ClippyInfo in crate: - providers.append(crate[ClippyInfo]) - - return providers - -js_rust_wasm_bindgen = rule( - doc = """\ -Generates javascript and typescript bindings for a webassembly module using [wasm-bindgen][ws] that interface with [aspect-build/rules_js][abjs]. - -[ws]: https://rustwasm.github.io/docs/wasm-bindgen/ -[abjs]: https://github.com/aspect-build/rules_js -""", - implementation = _js_rust_wasm_bindgen_impl, - attrs = WASM_BINDGEN_ATTR, - toolchains = [ - str(Label("//:toolchain_type")), - ], -) diff --git a/extensions/wasm_bindgen/rules_js/repositories.bzl b/extensions/wasm_bindgen/rules_js/repositories.bzl deleted file mode 100644 index 8267da9b1f..0000000000 --- a/extensions/wasm_bindgen/rules_js/repositories.bzl +++ /dev/null @@ -1,23 +0,0 @@ -"""Rust wasm-bindgen rules_js dependencies.""" - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load( - "//:repositories.bzl", - _rust_wasm_bindgen_dependencies = "rust_wasm_bindgen_dependencies", - _rust_wasm_bindgen_register_toolchains = "rust_wasm_bindgen_register_toolchains", -) - -def js_rust_wasm_bindgen_dependencies(): - _rust_wasm_bindgen_dependencies() - - maybe( - http_archive, - name = "aspect_rules_js", - 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): - _rust_wasm_bindgen_register_toolchains(**kwargs) diff --git a/extensions/wasm_bindgen/rules_js/test/BUILD.bazel b/extensions/wasm_bindgen/rules_js/test/BUILD.bazel deleted file mode 100644 index 967b8f2de4..0000000000 --- a/extensions/wasm_bindgen/rules_js/test/BUILD.bazel +++ /dev/null @@ -1,104 +0,0 @@ -load("@aspect_rules_js//js:defs.bzl", "js_library", "js_test") -load("@bazel_skylib//rules:build_test.bzl", "build_test") -load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_shared_library") -load("@rules_rust_wasm_bindgen//rules_js:defs.bzl", "js_rust_wasm_bindgen") - -rust_binary( - name = "hello_world_bin_wasm", - srcs = ["//test:main.rs"], - edition = "2018", - deps = [ - "@rules_rust_wasm_bindgen//3rdparty:wasm_bindgen", - ], -) - -rust_shared_library( - name = "hello_world_lib_wasm", - srcs = ["//test:main.rs"], - edition = "2018", - deps = [ - "@rules_rust_wasm_bindgen//3rdparty:wasm_bindgen", - ], -) - -js_rust_wasm_bindgen( - name = "hello_world_bundler_wasm_bindgen", - wasm_file = ":hello_world_bin_wasm", -) - -js_rust_wasm_bindgen( - name = "hello_world_web_wasm_bindgen", - target = "web", - wasm_file = ":hello_world_lib_wasm", -) - -js_rust_wasm_bindgen( - name = "hello_world_deno_wasm_bindgen", - target = "deno", - wasm_file = ":hello_world_lib_wasm", -) - -js_rust_wasm_bindgen( - name = "hello_world_nomodules_wasm_bindgen", - target = "no-modules", - wasm_file = ":hello_world_lib_wasm", -) - -js_rust_wasm_bindgen( - name = "hello_world_nodejs_wasm_bindgen", - target = "nodejs", - wasm_file = ":hello_world_lib_wasm", -) - -js_rust_wasm_bindgen( - name = "hello_world_nodejs_no_typescript_wasm_bindgen", - bindgen_flags = [ - "--no-typescript", - ], - target = "nodejs", - wasm_file = ":hello_world_lib_wasm", -) - -_WASM_DATA = [ - ":hello_world_bundler_wasm_bindgen", - ":hello_world_deno_wasm_bindgen", - ":hello_world_nodejs_wasm_bindgen", - ":hello_world_nomodules_wasm_bindgen", - ":hello_world_web_wasm_bindgen", -] - -js_test( - name = "hello_world_wasm_direct_test", - data = _WASM_DATA, - entry_point = "hello_world_wasm_test.js", - tags = [ - # TODO: https://github.com/bazelbuild/rules_rust/issues/3266 - "manual", - ], -) - -js_library( - name = "hello_world_wasm_lib", - srcs = [ - "hello_world_wasm_test.js", - ], - data = _WASM_DATA, - deps = [], -) - -js_test( - name = "hello_world_wasm_lib_test", - data = [ - ":hello_world_wasm_lib", - ], - entry_point = ":hello_world_wasm_lib", - tags = [ - # TODO: https://github.com/bazelbuild/rules_rust/issues/3266 - "manual", - ], -) - -build_test( - name = "build_test", - targets = _WASM_DATA, -) diff --git a/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.js b/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.js deleted file mode 100644 index be829ddabb..0000000000 --- a/extensions/wasm_bindgen/rules_js/test/hello_world_wasm_test.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -const fs = require("fs"); -const path = require("path"); -const assert = require("assert"); - -const main = async function (kind, dir) { - const wasm_file = path.join( - __dirname, - "..", - dir, - "test", - "hello_world_" + kind + "_wasm_bindgen", - "hello_world_" + kind + "_wasm_bindgen_bg.wasm", - ); - const buf = fs.readFileSync(wasm_file); - assert.ok(buf); - - const res = await WebAssembly.instantiate(buf); - assert.ok(res); - assert.strictEqual(res.instance.exports.double(2), 4); -}; - -["bundler", "web", "deno", "nomodules", "nodejs"].forEach((kind) => { - main(kind, process.argv.length > 2 ? process.argv[2] : "").catch( - function (err) { - console.error(err); - process.exit(1); - }, - ); -});