This migrates the bazel integration to the new Bazel dependency system
"bzlmod". bzlmod is becoming mandatory this year (see second sentence
here: https://bazel.build/external/migration).
This is a backwards incompatible migration, directly removing the old
WORKSPACE based approach. Users will have to change how they depend on
bzlmod, however I assume pretty much every user will be happy about it,
because they are forced to use bzlmod anyway or add extra flags to
continue to build with newer Bazel versions. Given that users normally
depend on specific git commits in the old system, they won't be hit with
this until they decide to upgrade emsdk.
The basic principle here is simple: I took everything that WORKSPACE did
and searched an alternative in bzlmod. Some interesting bits:
- We have less worries about multiple versions and people depending on
emscripten multiple times in different ways. This is resolved by the new
system: Bazel first iterates through the MODULE.bazel files recursively,
then finds the minimum version needed for each module and then executes
the module extensions that define repos exactly once at that version. So
no more ifs needed to detect multiple inclusions.
- A bunch of nodejs stuff moves to MODULE.bazel, because that is how the
nodejs module works now. As their module extension gets executed only
once you need to declare everything that you could need before that in
the MODULE.bazel file. A side effect of that is that we have to make a
fake repository when emscripten doesn't have an arm64 binary for linux,
because we can't actually figure that out in MODULE.bazel, so we have to
declare that it always exists and then create one in all cases.
There is a bunch of autoformatter changes in here as well, I could try
to revert them if you prefer.
Closes#1509
local=True marks a repository rule to unconditionally re-execute anytime
bazel re-evaluates the workspace (almost every invocation) It works well
for processes that execute in <10ms, not large ones like the embuilder
cache generation.
I have tested this locally and it seems to work fine, but I'll be honest
that I don't understand the nuances of repository rules that well, nor
do I know much of anything about emscripten or the circumstances in
which the cache ought to be rebuilt.
I checked the `external/@emscripten_cache.marker` file that Bazel uses
to store the cache key for if it needs to re-evaluate, and changing any
of the options passed into register_emscripten_toolchains resulted in
the cache key changing, and it correctly resulted in the cache being
regenerated.
The big question I don't have the context to answer: are there files on
disk other than these two that need to be watched for changes, so the
repository rule should change if they change:
```
FILE:@@emscripten_bin_linux//BUILD.bazel
FILE:@@emsdk//emscripten_toolchain/default_config
```
The current way to derive the binary path relies on a specific name for
the nodejs repository. This blocks migrating to bzlmod, as bzlmod
prefixes repository directories with the module name that created them.
By asking bazel for the path instead we always get the correct path, so
we can work with both bzlmod and WORKSPACE based dependencies at the
same time.
The repository @nodejs, used in the build label, refers to nodejs for
the host platform and is generated by the following macro (wasn't too
obvious to me):
d19d695275/nodejs/repositories.bzl (L452)
This is some work towards solving #1509.
This finishes the work started in
https://github.com/emscripten-core/emsdk/pull/1388 by fixing CI. It
avoids a breaking change by:
* Using the latest rules_js 1.x.x version, instead of updating to
rules_js 2 (which removes support for bazel 5).
* Copying the contents of
[rules_js_dependencies](https://github.com/aspect-build/rules_js/blob/main/js/repositories.bzl)
instead of calling it, as the call would need to be added by users in
their `WORKSPACE` files
Context from the previous PR:
> Bazel's Node.js dependency comes from
[rules_nodejs](https://github.com/bazelbuild/rules_nodejs/). Previously,
bazel/deps.bzl was using rules_nodejs 5.8.0, released in 2022 and only
supported Node.js toolchains up to 18.12.1.
> This PR bumps rules_nodejs to latest 6.1.1. It also replaces
build_bazel_rules_nodejs with
[rules_js](https://github.com/aspect-build/rules_js), since npm_install
that bazel/emscripten_deps.bzl used was deprecated. The README of
rules_nodejs now recommends migrating to rules_js for everything other
than the Node.js toolchain:
(371e8cab15)
> Impetus
Our repo builds with Bazel and uses Emscripten and Node.js. Tried to
upgrade Node.js 18 to Node.js 20 and saw that emsdk didn't support
rules_nodejs 6+ in the same workspace.
Similarly, it's not possible to update to rules_js v2 in a workspace
that also references `emsdk`.
Update Node from 18.20.3 LTS to 20.18.0 in precompiled releases. This
does have an effect of retroactively updating Node version also to old
releases, but this is expected to be fine.
Earlier Node 18.20.3 LTS did not yet support Windows on ARM64 builds.
Node 20.18.0 LTS is released on
https://nodejs.org/en/blog/release/v20.18.0.
This update currently only affects the "compiled from source" builds,
and not the Google precompiled releases.
Without this, emrun web server will be left running after user code
quits the page abnormally without calling `exit()` (e.g. due to a page
awwsnap crash), and there are multiple processes in use by the browser.
emrun has a graceful fallback to weaker browser process detection when
psutil is not available, so this is easy to miss if not running emrun
with --verbose:
814ec05f74/emrun.py (L330-L339)
This PR add several features to release automation:
1. The existing tag-release job has an output that indicates whether the
triggering commit
is a release (i.e. whether it matches the regex)
2. The new followup job runs a new script which fetches the recent
emscripten-releases
revisions, reads the DEPS file from the 'latest' release in
emscripten-releases-tags.json
to find the corresponding emscripten revision and writes it into the
environment
2. The final step reads the emscripten revision from the environment and
creates a
workflow_dispatch event to run the tag-release.yml job on the emscripten
repo
For commits created by the new create-release.yml workflow, we can add
the corresponding release tag. This only runs for changes to the tag
JSON file (and the workflow itself) and only acts on changes created by
the automation (so that it won't interfere if we want to do things
manually).
The action runs the existing create_release.py script in a new mode
created for github actions. Rather than using local git commands, it
uses a public action for creating a PR in the repository. The action can
be triggered from the website or via the CLI tool, for example
gh workflow run create-release.yml -R emscripten-core/emsdk -F
lto-sha=abc123 -F nonlto-sha=234567