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

feat: import toolchains to use for copy actions (2.x) #485

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 10 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ EOF

awk 'f;/--SNIP--/{f=1}' e2e/workspace/WORKSPACE
echo "\`\`\`"

cat << EOF

To use rules_ts with bazel-lib 2.0, you must additionally register the coreutils toolchain.

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

register_coreutils_toolchains()

EOF
16 changes: 15 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ module(
)

bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "aspect_rules_js", version = "1.29.2")
bazel_dep(name = "aspect_rules_js", version = "1.33.3")
bazel_dep(name = "aspect_bazel_lib", version = "1.29.2")

# TODO: remove before landing
archive_override(
module_name = "aspect_bazel_lib",
patches = ["//:version.patch"],
strip_prefix = "bazel-lib-14f685015cb1219a9ee2c83859a5c1e79fa0ca27",
urls = ["https://github.com/kormide/bazel-lib/archive/14f685015cb1219a9ee2c83859a5c1e79fa0ca27.zip"],
)

archive_override(
module_name = "aspect_rules_js",
strip_prefix = "rules_js-0085348f221540e9c1712db1ca944d2fd8ae7666",
urls = ["https://github.com/kormide/rules_js/archive/0085348f221540e9c1712db1ca944d2fd8ae7666.zip"],
)

# Similar to rules_python/MODULE.bazel, see https://github.com/bazelbuild/rules_python/pull/832
# These are loaded only when using ts_proto_library
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
Expand Down
6 changes: 4 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

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

aspect_bazel_lib_dependencies(override_local_config_platform = True)
aspect_bazel_lib_dependencies()

register_coreutils_toolchains()

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

Expand Down
14 changes: 14 additions & 0 deletions e2e/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ local_path_override(
path = "../..",
)

# TODO: remove before landing
archive_override(
module_name = "aspect_bazel_lib",
patches = ["//:version.patch"],
strip_prefix = "bazel-lib-14f685015cb1219a9ee2c83859a5c1e79fa0ca27",
urls = ["https://github.com/kormide/bazel-lib/archive/14f685015cb1219a9ee2c83859a5c1e79fa0ca27.zip"],
)

archive_override(
module_name = "aspect_rules_js",
strip_prefix = "rules_js-0085348f221540e9c1712db1ca944d2fd8ae7666",
urls = ["https://github.com/kormide/rules_js/archive/0085348f221540e9c1712db1ca944d2fd8ae7666.zip"],
)

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
Expand Down
12 changes: 12 additions & 0 deletions e2e/bzlmod/version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git tools/version.bzl tools/version.bzl
index cd62824..486d94f 100755
--- tools/version.bzl
+++ tools/version.bzl
@@ -2,6 +2,6 @@

# This is automagically replace by git during git archive using `git export-subst`
# See https://git-scm.com/docs/git-archive#Documentation/git-archive.txt-export-subst
-_VERSION_PRIVATE = "v0.8.1-485-g14f68501"
+_VERSION_PRIVATE = "v2.0.0"

VERSION = "0.0.0" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE.replace("v", "", 1)
5 changes: 5 additions & 0 deletions e2e/external_dep/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

# TODO: remove after landing
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")

register_coreutils_toolchains()

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

Expand Down
5 changes: 5 additions & 0 deletions e2e/external_dep/app/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

# TODO: remove after landing
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")

register_coreutils_toolchains()

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

Expand Down
7 changes: 6 additions & 1 deletion e2e/test/common.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

# TODO: remove after landing
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")

register_coreutils_toolchains()

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

bazel_features_deps()
Expand Down Expand Up @@ -225,4 +230,4 @@ npm_package(
srcs = [${srcs_joined}]
)
EOF
}
}
5 changes: 5 additions & 0 deletions e2e/worker/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

# TODO: remove after landing
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")

register_coreutils_toolchains()

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

Expand Down
9 changes: 5 additions & 4 deletions e2e/workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

# TODO: remove after landing
load("@aspect_bazel_lib//lib:repositories.bzl", "register_copy_directory_toolchains", "register_copy_to_directory_toolchains", "register_coreutils_toolchains")

register_coreutils_toolchains()

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

bazel_features_deps()
Expand All @@ -41,10 +46,6 @@ nodejs_register_toolchains(
node_version = DEFAULT_NODE_VERSION,
)

# Register aspect_bazel_lib toolchains;
# If you use npm_translate_lock or npm_import from aspect_rules_js you can omit this block.
load("@aspect_bazel_lib//lib:repositories.bzl", "register_copy_directory_toolchains", "register_copy_to_directory_toolchains")

register_copy_directory_toolchains()

register_copy_to_directory_toolchains()
2 changes: 2 additions & 0 deletions ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The most commonly used is the [ts_project](#ts_project) macro which accepts Type
inputs and produces JavaScript or declaration (.d.ts) outputs.
"""

load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS")
load("@aspect_bazel_lib//lib:utils.bzl", "to_label")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@bazel_skylib//lib:partial.bzl", "partial")
Expand All @@ -21,6 +22,7 @@ validate_options = rule(
See the documentation of [`ts_project`](#ts_project) for more information.""",
implementation = validate_lib.implementation,
attrs = validate_lib.attrs,
toolchains = COPY_FILE_TO_BIN_TOOLCHAINS,
)

ts_project_rule = _ts_project
Expand Down
3 changes: 2 additions & 1 deletion ts/private/ts_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"tsconfig.json files using extends"

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_bazel_lib//lib:paths.bzl", "relative_file")
load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers")
load("@aspect_rules_js//js:providers.bzl", "js_info")
Expand Down Expand Up @@ -111,6 +111,7 @@ of a `ts_library` or `ts_project` rule. However, if your `tsconfig.json` uses th
feature from TypeScript, then the Bazel implementation needs to know about that
extended configuration file as well, to pass them both to the TypeScript compiler.
""",
toolchains = COPY_FILE_TO_BIN_TOOLCHAINS,
)

def _filter_input_files(files, allow_js, resolve_json_module):
Expand Down
3 changes: 2 additions & 1 deletion ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"ts_project rule"

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_bazel_lib//lib:paths.bzl", "to_output_relative_path")
load("@aspect_bazel_lib//lib:platform_utils.bzl", "platform_utils")
load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers")
Expand Down Expand Up @@ -325,4 +325,5 @@ ts_project = rule(
""",
implementation = lib.implementation,
attrs = lib.attrs,
toolchains = COPY_FILE_TO_BIN_TOOLCHAINS,
)
2 changes: 2 additions & 0 deletions ts/private/ts_proto_library.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"Private implementation details for ts_proto_library"

load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS")
load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers")
load("@aspect_rules_js//js:providers.bzl", "JsInfo", "js_info")
load("@rules_proto//proto:defs.bzl", "ProtoInfo", "proto_common")
Expand Down Expand Up @@ -118,4 +119,5 @@ ts_proto_library = rule(
cfg = "exec",
),
},
toolchains = COPY_FILE_TO_BIN_TOOLCHAINS,
)
30 changes: 24 additions & 6 deletions ts/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,43 @@ def http_archive(**kwargs):
# ours took precedence. Such breakages are challenging for users, so any
# changes in this function should be marked as BREAKING in the commit message
# and released only in semver majors.
# buildifier: disable=function-docstring
def rules_ts_bazel_dependencies():
http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz"],
)

# 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",
# )

# TODO: remove before landing
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",
strip_prefix = "bazel-lib-14f685015cb1219a9ee2c83859a5c1e79fa0ca27",
url = "https://github.com/kormide/bazel-lib/archive/14f685015cb1219a9ee2c83859a5c1e79fa0ca27.zip",
patches = [
"@aspect_rules_ts//:version.patch",
],
)

# http_archive(
# name = "aspect_rules_js",
# sha256 = "295a73d963bad4b04a3c488d60dc8a76a659ee64708be3a66be75726e6277c7e",
# strip_prefix = "rules_js-1.33.3",
# url = "https://github.com/aspect-build/rules_js/releases/download/v1.33.3/rules_js-v1.33.3.tar.gz",
# )

# TODO: remove before landing
http_archive(
name = "aspect_rules_js",
sha256 = "bdbd6df52fc7963f55281fe0a140e21de8ec587ab711a8a2fff0715b6710a4f8",
strip_prefix = "rules_js-1.32.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.32.0/rules_js-v1.32.0.tar.gz",
strip_prefix = "rules_js-0085348f221540e9c1712db1ca944d2fd8ae7666",
url = "https://github.com/kormide/rules_js/archive/0085348f221540e9c1712db1ca944d2fd8ae7666.zip",
)

http_archive(
Expand Down
12 changes: 12 additions & 0 deletions version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git tools/version.bzl tools/version.bzl
index cd62824..486d94f 100755
--- tools/version.bzl
+++ tools/version.bzl
@@ -2,6 +2,6 @@

# This is automagically replace by git during git archive using `git export-subst`
# See https://git-scm.com/docs/git-archive#Documentation/git-archive.txt-export-subst
-_VERSION_PRIVATE = "v0.8.1-485-g14f68501"
+_VERSION_PRIVATE = "v2.0.0"

VERSION = "0.0.0" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE.replace("v", "", 1)
Loading