Skip to content

Commit

Permalink
feat: import toolchains to use for copy actions (#165)
Browse files Browse the repository at this point in the history
* feat: import toolchains to use for copy actions

upport bazel-lib 1.x and 2.x.

This is analogous to aspect-build/rules_js#1355 for rules_js.

* chore: use bazel-lib 2.0 locally

* chore: update e2e to work with newer rules_js

* chore: green up

---------

Co-authored-by: Alex Eagle <[email protected]>
  • Loading branch information
ralimi and alexeagle authored Nov 20, 2023
1 parent a4ffe24 commit b388fb7
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ jobs:
# Don't test Windows with Bazel 5 to minimize Windows minutes (billed at 2X)
- bazelversion: 5.3.2
os: windows-latest
# Don't run the root workspace with Bazel 5, it uses bazel-lib 2.0 which doesn't work.
- bazelversion: 5.3.2
folder: '.'

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ http_archive(
EOF
awk 'f;/--SNIP--/{f=1}' e2e/smoke/WORKSPACE.bazel
echo "\`\`\`"

cat << EOF
To use rules_esbuild with bazel-lib 2.0, you must additionally register the coreutils toolchain.
\`\`\`starlark
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")
register_coreutils_toolchains()
\`\`\`
EOF
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.29.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "buildifier_prebuilt", version = "6.0.0.1", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "1.29.2")
bazel_dep(name = "aspect_bazel_lib", version = "1.38.1")
bazel_dep(name = "aspect_rules_js", version = "1.29.2")
bazel_dep(name = "rules_nodejs", version = "5.8.2")
bazel_dep(name = "platforms", version = "0.0.5")
Expand Down
6 changes: 4 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "aspect_bazel_lib_dependencies", "register_yq_toolchains")
load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains", "register_yq_toolchains")

aspect_bazel_lib_dependencies(override_local_config_platform = True)
aspect_bazel_lib_dependencies()

register_coreutils_toolchains()

register_yq_toolchains(
version = DEFAULT_YQ_VERSION,
Expand Down
8 changes: 8 additions & 0 deletions e2e/bundle/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

Expand Down
8 changes: 8 additions & 0 deletions e2e/npm-links/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
Expand Down
8 changes: 8 additions & 0 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

Expand Down
10 changes: 10 additions & 0 deletions e2e/sourcemaps/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

# For convenience, npm_translate_lock does this call automatically.
# You can omit this if you have any npm_translate_lock calls.
load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

# If you didn't already register a toolchain providing nodejs, do that:
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

Expand Down
8 changes: 8 additions & 0 deletions e2e/tsconfig/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependenc

rules_esbuild_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
Expand Down
12 changes: 6 additions & 6 deletions esbuild/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def rules_esbuild_dependencies():

http_archive(
name = "aspect_bazel_lib",
sha256 = "ee95bbc80f9ca219b93a8cc49fa19a2d4aa8649ddc9024f46abcdd33935753ca",
strip_prefix = "bazel-lib-1.29.2",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.29.2/bazel-lib-v1.29.2.tar.gz",
sha256 = "262e3d6693cdc16dd43880785cdae13c64e6a3f63f75b1993c716295093d117f",
strip_prefix = "bazel-lib-1.38.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.38.1/bazel-lib-v1.38.1.tar.gz",
)

http_archive(
name = "aspect_rules_js",
sha256 = "7cb2d84b7d5220194627c9a0267ae599e357350e75ea4f28f337a25ca6219b83",
strip_prefix = "rules_js-1.29.2",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.29.2/rules_js-v1.29.2.tar.gz",
sha256 = "d9ceb89e97bb5ad53b278148e01a77a3e9100db272ce4ebdcd59889d26b9076e",
strip_prefix = "rules_js-1.34.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.0/rules_js-v1.34.0.tar.gz",
)

http_archive(
Expand Down
4 changes: 2 additions & 2 deletions esbuild/private/esbuild.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"# esbuild rule"

load("@aspect_bazel_lib//lib:expand_make_vars.bzl", "expand_variables")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_file_to_bin_action", "copy_files_to_bin_actions")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS", "copy_file_to_bin_action", "copy_files_to_bin_actions")
load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers")
load("@aspect_rules_js//js:providers.bzl", "JsInfo", "js_info")
load(":helpers.bzl", "desugar_entry_point_names", "write_args_file")
Expand Down Expand Up @@ -422,7 +422,7 @@ lib = struct(
toolchains = [
"@rules_nodejs//nodejs:toolchain_type",
"@aspect_rules_esbuild//esbuild:toolchain_type",
],
] + COPY_FILE_TO_BIN_TOOLCHAINS,
)

esbuild_bundle = rule(
Expand Down
9 changes: 9 additions & 0 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ load("//esbuild/private:maybe.bzl", http_archive = "maybe_http_archive")

def rules_esbuild_internal_deps():
"Fetch deps needed for local development"

# opt-in to 2.0 without forcing users to do so
http_archive(
name = "aspect_bazel_lib",
sha256 = "4b32cf6feab38b887941db022020eea5a49b848e11e3d6d4d18433594951717a",
strip_prefix = "bazel-lib-2.0.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.0.1/bazel-lib-v2.0.1.tar.gz",
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
Expand Down

0 comments on commit b388fb7

Please sign in to comment.