Skip to content

Is there a way to use emsdk using bzlmod? #1509

Closed

Description

@ShapeLayer

I am now trying to use emsdk/bazel with bzlmod. However, the contents of /bazel seem to not support bzlmod. In more detail, I'm trying to use emsdk using only MODULE.bazel, but it is not working well.

Is there a way to use emsdk with MODULE.bazel not WORKSPACE?

Ref:

ERROR: Skipping '//includes:libgfm2pst-wasm.js': error loading package 'includes': Unable to find package for
 @@[unknown repo 'emsdk' requested from @@]//emscripten_toolchain:wasm_rules.bzl: The repository '@@
[unknown repo 'emsdk' requested from @@]' could not be resolved: No repository visible as '@emsdk' from 
main repository. Was the repository introduced in WORKSPACE? The WORKSPACE file is disabled by default in 
Bazel 8 (late 2024) and will be removed in Bazel 9 (late 2025), please migrate to Bzlmod. See https://bazel.build/external/migration.
ERROR: error loading package 'includes': Unable to find package for @@[unknown repo 'emsdk' requested from 
@@]//emscripten_toolchain:wasm_rules.bzl: The repository '@@[unknown repo 'emsdk' requested from @@]' 
could not be resolved: No repository visible as '@emsdk' from main repository. Was the repository introduced in 
WORKSPACE? The WORKSPACE file is disabled by default in Bazel 8 (late 2024) and will be removed in Bazel 9 
(late 2025), please migrate to Bzlmod. See https://bazel.build/external/migration.

Activity

  1. sbc100 commented on Jan 9, 2025

    @sbc100
    Collaborator
  2. changed the title [-]Is there a way to emsdk using bzlmod?[/-] [+]Is there a way to use emsdk using bzlmod?[/+] on Jan 10, 2025
  3. Vertexwahn commented on Jan 17, 2025

    @Vertexwahn

    https://github.com/emscripten-core/emsdk/blob/main/bazel/deps.bzl can be replaced by adding to the MODULE.bazel file:

    bazel_dep(name = "bazel_skylib", version = "1.1.1")
    bazel_dep(name = "bazel_features", version = "0.1.0")
    bazel_dep(name = "rules_nodejs", version = "6.3.2")
    bazel_dep(name = "aspect_bazel_lib", version = "2.7.8")
    bazel_dep(name = "aspect_rules_js", version = "1.42.0")
    

    next stop https://github.com/emscripten-core/emsdk/blob/main/bazel/emscripten_deps.bzl

    Maybe we can do an incremental migration here...?

  4. ShapeLayer commented on Jan 20, 2025

    @ShapeLayer
    Author

    Add: I want to know if there is an official manual, procedure, or works in progress about migration to bzlmod.

    I've been trying to migrate, and it seems to be increasing works. So I want to check other answers before going any further.

  5. sbc100 commented on Jan 20, 2025

    @sbc100
    Collaborator

    No plans that I know off. I have no idea what bzlmod even is though.

    The bazel support for emsdk it mostly a best effort by interested parties so if you would like to contribute please go ahead.

  6. xalteropsx commented on Jan 24, 2025

    @xalteropsx

    same error

    WARNING: Target pattern parsing failed.
    ERROR: Skipping '//:hello-world-wasm': error loading package '': Unable to find package for @@[unknown repo 'emsdk' requested from @@]//emscripten_toolchain:wasm_rules.bzl: The repository '@@[unknown repo 'emsdk' requested from @@]' could not be resolved: No repository visible as '@emsdk' from main repository. Was the repository introduced in WORKSPACE? The WORKSPACE file is disabled by default in Bazel 8 (late 2024) and will be removed in Bazel 9 (late 2025), please migrate to Bzlmod. See https://bazel.build/external/migration.
    ERROR: error loading package '': Unable to find package for @@[unknown repo 'emsdk' requested from @@]//emscripten_toolchain:wasm_rules.bzl: The repository '@@[unknown repo 'emsdk' requested from @@]' could not be resolved: No repository visible as '@emsdk' from main repository. Was the repository introduced in WORKSPACE? The WORKSPACE file is disabled by default in Bazel 8 (late 2024) and will be removed in Bazel 9 (late 2025), please migrate to Bzlmod. See https://bazel.build/external/migration.

  7. cburchert commented on Jan 31, 2025

    @cburchert
    Contributor

    I was also hit by this, so I spent some time investigating. I hacked through emsdk to make it work and can build my project with my emsdk fork now with pure bzlmod, here is the fork: https://github.com/cburchert/emsdk/tree/main/bazel

    In theory you could use that, but I didn't even look into fixing the tests, any other host platform than linux and this would break all existing users that don't use bzlmod right now, if merged upstream.

    I think it isn't too much work to implement this more properly and would be highly beneficial, given that Bazel now doesn't build without it anymore by default. As this is a free time project I don't have much time, but I could probably look into it soon.

    Before that, it would be good to get some opinions how to proceed though.

    General strategy

    We have two options:

    1. Migrate everything to bzlmod and remove WORKSPACE support in one go. That makes things easy and can probably be reached quickly. However it would require all users to change how they import emsdk when they update it the next time. Given that Bazel is already disabling WORKSPACE support by default, this might actually be ok?

    2. We could give users more time to migrate by supporting both for some time. That needs a little bit of extra work and possibly leads to some code duplication.

    Is there any policy on this and what do other users think?

    I am leaning towards option 1, because users will have to migrate to bzlmod probably within this year anyway and most people only do it when they have to. We could make it slightly easier by also making emsdk available through the bazel central registry. On the other hand I am biased, because this saves me work.

    Implementation

    I think it is roughly:

    • Add a bunch of deps to MODULE.bazel
    • Convert the deps.bzl and emscripten_deps.bzl files to module extensions
    • Fix a bunch of bugs that occur, because the repository names are different now and were hardcoded where they shouldn't be

    There is a small design question about how to represent custom emscripten cache settings, but I think there are some nice ways to do it with tags on the module extensions. My prototype should allow a syntax like this:

    bazel_dep(name = "emsdk", version = "4.0.1")
    emscripten_cache = use_extension("@emsdk//:extensions.bzl", "emscripten_cache")
    emscripten_cache.configuration(flags = [
            "--lto"
    ])
    emscripten_cache.targets(targets = [
            "crtbegin",
            "libprintf_long_double-debug",
            "libstubs-debug",
            "libnoexit"
    ])
    

    These can be specified multiple times (also across different bazel modules) and will get joined together before creating the cache. Any thoughts on this?

  8. xalteropsx commented on Jan 31, 2025

    @xalteropsx

    will check soon thnx for sharing it bro

  9. walkingeyerobot commented on Feb 3, 2025

    @walkingeyerobot
    Collaborator

    I support option 1 here: Migrate everything to bzlmod and remove WORKSPACE support in one go. As sbc100 said, bazel support in emsdk is best effort. I'm happy to review and merge changes that update emsdk to bzlmod. However, I will ask that we keep the mac and windows versions working; hopefully this does not add too much complexity.

  10. added a commit that references this issue on Apr 9, 2025
    ed2035a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions