Skip to content

Commit

Permalink
feat: make node toolchain_type public so new toolchains can be added (#…
Browse files Browse the repository at this point in the history
…2591)

Enables rules_nodejs to be used in cross-compilation contexts, where
the target architecture is not supported by rules_nodejs.

rules_nodejs's default toolchains are limited via target_compatible_with,
which means they will not work when cross-compiling to Android or iOS
with --platforms for example. With this change, users can define their
own toolchain that is limited by execution platform instead of target
platform.

For example, if you're targeting an unsupported platform, but building
on a Mac, you can place the following in the local WORKSPACE:

    register_toolchains("//ts/node_toolchain")

And the following in ts/node_toolchain/BUILD.bazel:

    toolchain(
        name = "node_toolchain",
        exec_compatible_with = [
            "@platforms//os:osx",
            "@platforms//cpu:x86_64",
        ],
        toolchain = "@nodejs_darwin_amd64_config//:toolchain",
        toolchain_type = "@build_bazel_rules_nodejs//toolchains/node:toolchain_type",
    )

Closes #2565
  • Loading branch information
dae authored Apr 7, 2021
1 parent 472ed62 commit b606b79
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion toolchains/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ filegroup(
)

# node toolchain type
toolchain_type(name = "toolchain_type")
toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
)

# Allow targets to use a toolchains attribute, such as sh_binary and genrule
# This way they can reference the NODE_PATH make variable.
Expand Down

0 comments on commit b606b79

Please sign in to comment.