Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ tasks:
- "//..."
# The proto rules do not work on windows
- "-//proto/..."
# The wasm rules do not work on windows
- "-//wasm/..."
# The bindgen rules are currently broken on windows
# https://github.com/bazelbuild/rules_rust/issues/2009
- "-//bindgen/..."
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- synchronize

jobs:
clang-format-checking:
code-format-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -19,3 +19,13 @@ jobs:
source: '.'
extensions: 'h,c,cc,proto'
clangFormatVersion: 14
- uses: actionsx/prettier@v2
with:
args: --config "${{ github.workspace }}/.prettierrc.toml" --write "**/*.{js,ts}"
# Prettier has no diff view so we must make one ourselves
# https://github.com/prettier/prettier/issues/6885
- run: |
git diff
if [[ -n "$(git status --porcelain)" ]]; then
exit 1
fi
3 changes: 3 additions & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Prettier config file. For more opitons see https://prettier.io/docs/en/options
tabWidth = 4
trailingComma = "all"
2 changes: 1 addition & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ bzl_library(
srcs = [
"@bazel_tools//tools:bzl_srcs",
"@com_google_protobuf//:bzl_srcs",
"@rules_nodejs//nodejs:bzl",
],
deps = [
"@bazel_skylib//lib:paths",
Expand Down Expand Up @@ -152,6 +151,7 @@ PAGES = dict([
"rust_wasm_bindgen_register_toolchains",
"rust_wasm_bindgen_toolchain",
"rust_wasm_bindgen",
"RustWasmBindgenInfo",
],
),
page(
Expand Down
32 changes: 21 additions & 11 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [CrateInfo](#CrateInfo)
* [DepInfo](#DepInfo)
* [RustWasmBindgenInfo](#RustWasmBindgenInfo)
* [StdLibInfo](#StdLibInfo)
* [capture_clippy_output](#capture_clippy_output)
* [cargo_bootstrap_repository](#cargo_bootstrap_repository)
Expand Down Expand Up @@ -1330,17 +1331,6 @@ Generates javascript and typescript bindings for a webassembly module using [was

[ws]: https://rustwasm.github.io/docs/wasm-bindgen/

To use the Rust WebAssembly bindgen rules, add the following to your `WORKSPACE` file to add the
external repositories for the Rust bindgen toolchain (in addition to the Rust rules setup):

```python
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")

rust_wasm_bindgen_repositories()
```

For more details on `rust_wasm_bindgen_repositories`, see [here](#rust_wasm_bindgen_repositories).

An example of this rule in use can be seen at [@rules_rust//examples/wasm](../examples/wasm)


Expand Down Expand Up @@ -1509,6 +1499,26 @@ A provider containing information about a Crate's dependencies.
| <a id="DepInfo-transitive_proc_macro_data"></a>transitive_proc_macro_data | depset[File]: Data of all transitive proc-macro dependencies, and non-macro dependencies of those macros. |


<a id="RustWasmBindgenInfo"></a>

## RustWasmBindgenInfo

<pre>
RustWasmBindgenInfo(<a href="#RustWasmBindgenInfo-js">js</a>, <a href="#RustWasmBindgenInfo-ts">ts</a>, <a href="#RustWasmBindgenInfo-wasm">wasm</a>)
</pre>

Info about wasm-bindgen outputs.

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="RustWasmBindgenInfo-js"></a>js | Depset[File]: The Javascript files produced by <code>wasm-bindgen</code>. |
| <a id="RustWasmBindgenInfo-ts"></a>ts | Depset[File]: The Typescript files produced by <code>wasm-bindgen</code>. |
| <a id="RustWasmBindgenInfo-wasm"></a>wasm | File: The <code>.wasm</code> file generated by <code>wasm-bindgen</code>. |


<a id="StdLibInfo"></a>

## StdLibInfo
Expand Down
70 changes: 50 additions & 20 deletions docs/rust_wasm_bindgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,45 @@
* [rust_wasm_bindgen_register_toolchains](#rust_wasm_bindgen_register_toolchains)
* [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain)
* [rust_wasm_bindgen](#rust_wasm_bindgen)
* [RustWasmBindgenInfo](#RustWasmBindgenInfo)


## Overview

To build a `rust_binary` for `wasm32-unknown-unknown` target add the `--platforms=@rules_rust//rust/platform:wasm` flag.
Bazel rules for generating wasm modules for Javascript using [wasm-bindgen][wb].

```command
bazel build @examples//hello_world_wasm --platforms=@rules_rust//rust/platform:wasm
```
## Setup

To begin using the `wasm-bindgen` rules, users can load the necessary dependencies
in their workspace by adding the following to their `WORKSPACE.bazel` file.

To build a `rust_binary` for `wasm32-wasi` target add the `--platforms=@rules_rust//rust/platform:wasi` flag.
```starlark
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains")

rust_wasm_bindgen_dependencies()

```command
bazel build @examples//hello_world_wasm --platforms=@rules_rust//rust/platform:wasi
rust_wasm_bindgen_register_toolchains()
```

`rust_wasm_bindgen` will automatically transition to the `wasm` platform and can be used when
building WebAssembly code for the host target.
This should enable users to start using the [rust_wasm_bindgen](#rust_wasm_bindgen)
rule. However, it's common to want to control the version of `wasm-bindgen` in the
workspace instead of relying on the one provided by `rules_rust`. In this case, users
should avoid calling `rust_wasm_bindgen_register_toolchains` and instead use the
[rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain) rule to define their own
toolchains to register in the workspace.

### Interfacing with Javascript rules

While it's recommended for users to mantain their own , in the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing word after "own"?

`@rules_rust//wasm_bindgen` package there exists interface sub-packages for various
Javascript Bazel rules. E.g. `build_bazel_rules_nodejs` or `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. `nodejs_rust_wasm_bindgen` for the `rules_nodejs` submodule).


[wb]: https://github.com/rustwasm/wasm-bindgen


<a id="rust_wasm_bindgen"></a>
Expand All @@ -37,17 +58,6 @@ Generates javascript and typescript bindings for a webassembly module using [was

[ws]: https://rustwasm.github.io/docs/wasm-bindgen/

To use the Rust WebAssembly bindgen rules, add the following to your `WORKSPACE` file to add the
external repositories for the Rust bindgen toolchain (in addition to the Rust rules setup):

```python
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories")

rust_wasm_bindgen_repositories()
```

For more details on `rust_wasm_bindgen_repositories`, see [here](#rust_wasm_bindgen_repositories).

An example of this rule in use can be seen at [@rules_rust//examples/wasm](../examples/wasm)


Expand Down Expand Up @@ -110,6 +120,26 @@ For additional information, see the [Bazel toolchains documentation][toolchains]
| <a id="rust_wasm_bindgen_toolchain-bindgen"></a>bindgen | The label of a <code>wasm-bindgen-cli</code> executable. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | <code>None</code> |


<a id="RustWasmBindgenInfo"></a>

## RustWasmBindgenInfo

<pre>
RustWasmBindgenInfo(<a href="#RustWasmBindgenInfo-js">js</a>, <a href="#RustWasmBindgenInfo-ts">ts</a>, <a href="#RustWasmBindgenInfo-wasm">wasm</a>)
</pre>

Info about wasm-bindgen outputs.

**FIELDS**


| Name | Description |
| :------------- | :------------- |
| <a id="RustWasmBindgenInfo-js"></a>js | Depset[File]: The Javascript files produced by <code>wasm-bindgen</code>. |
| <a id="RustWasmBindgenInfo-ts"></a>ts | Depset[File]: The Typescript files produced by <code>wasm-bindgen</code>. |
| <a id="RustWasmBindgenInfo-wasm"></a>wasm | File: The <code>.wasm</code> file generated by <code>wasm-bindgen</code>. |


<a id="rust_wasm_bindgen_dependencies"></a>

## rust_wasm_bindgen_dependencies
Expand Down
38 changes: 29 additions & 9 deletions docs/rust_wasm_bindgen.vm
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
#[[
## Overview

To build a `rust_binary` for `wasm32-unknown-unknown` target add the `--platforms=@rules_rust//rust/platform:wasm` flag.
Bazel rules for generating wasm modules for Javascript using [wasm-bindgen][wb].

```command
bazel build @examples//hello_world_wasm --platforms=@rules_rust//rust/platform:wasm
```
## Setup

To begin using the `wasm-bindgen` rules, users can load the necessary dependencies
in their workspace by adding the following to their `WORKSPACE.bazel` file.

To build a `rust_binary` for `wasm32-wasi` target add the `--platforms=@rules_rust//rust/platform:wasi` flag.
```starlark
load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains")

```command
bazel build @examples//hello_world_wasm --platforms=@rules_rust//rust/platform:wasi
rust_wasm_bindgen_dependencies()

rust_wasm_bindgen_register_toolchains()
```

`rust_wasm_bindgen` will automatically transition to the `wasm` platform and can be used when
building WebAssembly code for the host target.
This should enable users to start using the [rust_wasm_bindgen](#rust_wasm_bindgen)
rule. However, it's common to want to control the version of `wasm-bindgen` in the
workspace instead of relying on the one provided by `rules_rust`. In this case, users
should avoid calling `rust_wasm_bindgen_register_toolchains` and instead use the
[rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain) rule to define their own
toolchains to register in the workspace.

### Interfacing with Javascript rules

While it's recommended for users to mantain their own , in the
`@rules_rust//wasm_bindgen` package there exists interface sub-packages for various
Javascript Bazel rules. E.g. `build_bazel_rules_nodejs` or `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. `nodejs_rust_wasm_bindgen` for the `rules_nodejs` submodule).


[wb]: https://github.com/rustwasm/wasm-bindgen
]]#
12 changes: 7 additions & 5 deletions docs/symbols.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ load(
"@rules_rust//rust/settings:incompatible.bzl",
_incompatible_flag = "incompatible_flag",
)
load(
"@rules_rust//wasm_bindgen:defs.bzl",
_RustWasmBindgenInfo = "RustWasmBindgenInfo",
_rust_wasm_bindgen = "rust_wasm_bindgen",
_rust_wasm_bindgen_toolchain = "rust_wasm_bindgen_toolchain",
)
load(
"@rules_rust//wasm_bindgen:repositories.bzl",
_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",
_rust_wasm_bindgen = "rust_wasm_bindgen",
_rust_wasm_bindgen_toolchain = "rust_wasm_bindgen_toolchain",
)

rust_binary = _rust_binary
rust_library = _rust_library
Expand Down Expand Up @@ -161,6 +162,7 @@ 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
RustWasmBindgenInfo = _RustWasmBindgenInfo

rules_rust_dependencies = _rules_rust_dependencies
rust_register_toolchains = _rust_register_toolchains
Expand Down
27 changes: 25 additions & 2 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ rust_wasm_bindgen_dependencies()

rust_wasm_bindgen_register_toolchains()

load("@rules_rust//wasm_bindgen/rules_nodejs:repositories.bzl", "nodejs_rust_wasm_bindgen_dependencies")

nodejs_rust_wasm_bindgen_dependencies()

load("@rules_rust//wasm_bindgen/rules_js:repositories.bzl", "js_rust_wasm_bindgen_dependencies")

js_rust_wasm_bindgen_dependencies()

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

###############################################################################
Expand Down Expand Up @@ -81,14 +89,29 @@ rust_repository_set(

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "c78216f5be5d451a42275b0b7dc809fb9347e2b04a68f68bad620a2b01f5c774",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.2/rules_nodejs-5.5.2.tar.gz"],
sha256 = "709cc0dcb51cf9028dd57c268066e5bc8f03a119ded410a13b5c3925d6e43c48",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.4/rules_nodejs-5.8.4.tar.gz"],
)

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()

http_archive(
name = "rules_foreign_cc",
sha256 = "69023642d5781c68911beda769f91fcbc8ca48711db935a75da7f6536b65047f",
Expand Down
23 changes: 0 additions & 23 deletions examples/wasm/hello_world_wasm_test.js

This file was deleted.

22 changes: 7 additions & 15 deletions examples/wasm/BUILD.bazel → examples/wasm_bindgen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_shared_library")
load("@rules_rust//wasm_bindgen:wasm_bindgen.bzl", "rust_wasm_bindgen")
load("@rules_rust//wasm_bindgen:defs.bzl", "rust_wasm_bindgen")

package(default_visibility = ["//visibility:public"])
package(default_visibility = ["//wasm_bindgen:__subpackages__"])

exports_files([
"hello_world_wasm_test.js",
"main.rs",
])

rust_binary(
name = "hello_world_bin_wasm",
Expand Down Expand Up @@ -64,15 +68,3 @@ rust_wasm_bindgen(
target = "nodejs",
wasm_file = ":hello_world_lib_wasm",
)

nodejs_test(
name = "hello_world_wasm_test",
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",
],
entry_point = "hello_world_wasm_test.js",
)
Loading