Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bzlmod support to all extension rules. #3037

Merged
merged 2 commits into from
Dec 4, 2024
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
4 changes: 4 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,11 @@ tasks:
build_targets:
- "//..."
test_targets:
- "--"
- "//..."
# TODO: https://github.com/bazelbuild/rules_rust/issues/3039
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

- "-//rules_js/test:hello_world_wasm_lib_test"
- "-//rules_js/test:hello_world_wasm_direct_test"
extensions_wasm_bindgen_macos:
platform: macos_arm64
name: Extensions wasm-bindgen
Expand Down
7 changes: 0 additions & 7 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,6 @@ stardoc(
deps = ["@rules_rust_wasm_bindgen//rules_js:bzl_lib"],
)

stardoc(
name = "rust_wasm_bindgen_rules_nodejs",
out = "rust_wasm_bindgen_rules_nodejs.md",
input = "@rules_rust_wasm_bindgen//rules_nodejs:defs.bzl",
deps = ["@rules_rust_wasm_bindgen//rules_nodejs:bzl_lib"],
)

sh_binary(
name = "update_docs",
srcs = ["update_docs.sh"],
Expand Down
17 changes: 11 additions & 6 deletions docs/src/rust_wasm_bindgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

Bazel rules for generating wasm modules for Javascript using [wasm-bindgen][wb].

## Rules

- [rust_wasm_bindgen](#rust_wasm_bindgen)
- [rust_wasm_bindgen_toolchain](#rust_wasm_bindgen_toolchain)

## Setup

To begin using the `wasm-bindgen` rules, users can load the necessary dependencies
Expand All @@ -24,15 +29,15 @@ 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
## 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).
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).


[wb]: https://github.com/rustwasm/wasm-bindgen
Expand Down
29 changes: 0 additions & 29 deletions docs/src/rust_wasm_bindgen_rules_nodejs.md

This file was deleted.

2 changes: 1 addition & 1 deletion extensions/bindgen/.bazelignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
examples
bazel-out
bazel-testlogs
bazel-extensions
bazel-bindgen
bazel-bin
5 changes: 2 additions & 3 deletions extensions/bindgen/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ build --incompatible_merge_fixed_and_default_shell_env
## Bzlmod
###############################################################################

# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/bazelbuild/rules_rust/issues/2181
common --noenable_bzlmod --enable_workspace
# A configuration for disabling bzlmod.
common:no-bzlmod --noenable_bzlmod --enable_workspace

# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off
Expand Down
28 changes: 28 additions & 0 deletions extensions/bindgen/3rdparty/BUILD.zstd.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

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

cc_library(
name = "zstd",
srcs = glob([
"lib/common/*.c",
"lib/common/*.h",
"lib/compress/*.c",
"lib/compress/*.h",
"lib/decompress/*.c",
"lib/decompress/*.h",
"lib/decompress/*.S",
"lib/dictBuilder/*.c",
"lib/dictBuilder/*.h",
]),
hdrs = [
"lib/zdict.h",
"lib/zstd.h",
"lib/zstd_errors.h",
],
defines = [
"LLVM_ENABLE_ZSTD=1",
"ZSTD_MULTITHREAD",
],
strip_include_prefix = "lib",
)
17 changes: 2 additions & 15 deletions extensions/bindgen/3rdparty/patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,11 @@

All patches pair with the versions of the referenced repositories defined in `@rules_rust_bindgen//:repositories.bzl`.

## [llvm-project.cxx17](./llvm-project.cxx17.patch)

The llvm-project requires a compiler that builds with at least C++14 but there's no configuration
for this on the targets defined in the repo. This patch plumbs through flags for setting the C++
version on targets to avoid any need for bazel configuration flags. If this patch causes issues
for users with their current toolchain or toolchain definitions then simply defining the `llvm-raw`
repository before loading `rust_bindgen_dependencies` should avoid this.

## [llvm-project.incompatible_disallow_empty_glob](./llvm-project.incompatible_disallow_empty_glob.patch)

Uses of `glob` are updated to have `allow_empty = True` added so the llvm-project repo is compatible
with consumers building with [--incompatible_disallow_empty_glob](https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob).

Most of this patch is generated using the following regex and replace patterns. There are a handful
of additional modifications for more extravagant globs.
## [llvm-raw.incompatible_disallow_empty_glob](./llvm-raw.incompatible_disallow_empty_glob.patch)

| regex | replace |
| --- | --- |
| `glob\(([\[\w\d_\-\*\/\.\],=\n\s"]+)\) \+` | `glob($1, allow_empty = True) +` |
| `glob\(([\[\w\d_\-\*\/\.\],=\n\s"]+)\),` | `glob($1, allow_empty = True),` |
| `(,[\s\n]+), ` | `$1` |
Similar to the `llvm-project` variant but is used outside of bzlmod.
Loading
Loading