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

(bazel) Set @platforms//os:emscripten for platform_wasm #1363

Merged
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
1 change: 1 addition & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ platform(
name = "platform_wasm",
constraint_values = [
"@platforms//cpu:wasm32",
"@platforms//os:emscripten",
],
)

Expand Down
1 change: 1 addition & 0 deletions bazel/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel_dep(name = "platforms", version = "0.0.9")
Copy link

Choose a reason for hiding this comment

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

To properly Bzlmod-ify this so that other Bazel projects can depend on it, you also need to add something like this to the top:

module(
    name = "emsdk",
    version = "<current version>",
)

Instead of manually maintaining <current version>, you can also use the Publish to BCR app to automate the version bump and releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope I understand what you mean xD (I'm still new in bazel).
If it's not a problem, I'll try to do it in the next/separate MR.
Thanks for the tip!

5 changes: 5 additions & 0 deletions bazel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ The SHA1 hash in the above `strip_prefix` and `url` parameters correspond to the
newer versions, you'll need to update those. To make use of older versions, change the
parameter of `emsdk_emscripten_deps()`. Supported versions are listed in `revisions.bzl`

Bazel 7+ additionally requires `platforms` dependencies in the `MODULE.bazel` file.
```starlark
bazel_dep(name = "platforms", version = "0.0.9")
```

Comment on lines +29 to +33
Copy link

Choose a reason for hiding this comment

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

Suggested change
Bazel 7+ additionally requires `platforms` dependencies in the `MODULE.bazel` file.
```starlark
bazel_dep(name = "platforms", version = "0.0.9")
```

This isn't needed: Bzlmod resolves transitive dependencies via Minimum Version Selection, so adding the platforms dep to the emsdk's MODULE.bazel file is sufficient for dependent modules to pick it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand that you are talking about Bazel 7+, but versions 5.4 and/or 6x do not check the MODULE file (by default), so a macro update is needed for older versions.

Should we be concerned about Bazel 5x/6x users? → I have no idea 🤷

Copy link

Choose a reason for hiding this comment

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

I see, this snippet is meant for users pulling in emsdk via WORKSPACE but who do have --enable_bzlmod set, e.g. because it is the default in Bazel 7+? That makes sense if you don't want to fully set up emsdk for Bzlmod.

If you do, then this wouldn't be necessary and such users could just load emsdk via a bazel_dep in MODULE.bazel instead. But that could be done in a separate PR.


## Building

Expand Down
9 changes: 9 additions & 0 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def deps():
maybe(
http_archive,
name = "platforms",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.9/platforms-0.0.9.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.9/platforms-0.0.9.tar.gz",
],
sha256 = "5eda539c841265031c2f82d8ae7a3a6490bd62176e0c038fc469eabf91f6149b",
)
maybe(
http_archive,
name = "bazel_skylib",
Expand Down
1 change: 1 addition & 0 deletions bazel/test_external/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel_dep(name = "platforms", version = "0.0.9")