diff --git a/ts/private/build_test.bzl b/ts/private/build_test.bzl index e0dc0aeb..077da631 100644 --- a/ts/private/build_test.bzl +++ b/ts/private/build_test.bzl @@ -11,12 +11,15 @@ It is used to force Bazel to build some of its dependencies, in the case where """ def _build_test_impl(ctx): - executable = ctx.actions.declare_file(ctx.label.name + ".sh") + # See https://github.com/bazelbuild/bazel-skylib/blob/1.7.1/rules/build_test.bzl#L19-L33 + extension = ".bat" if ctx.attr.is_windows else ".sh" + content = "exit 0" if ctx.attr.is_windows else "#!/usr/bin/env bash\nexit 0" + executable = ctx.actions.declare_file(ctx.label.name + extension) ctx.actions.write( output = executable, is_executable = True, - content = "#!/usr/bin/env bash\nexit 0", + content = content, ) return DefaultInfo( @@ -26,11 +29,22 @@ def _build_test_impl(ctx): runfiles = ctx.runfiles(files = ctx.files.targets), ) -build_test = rule( +_build_test = rule( doc = _DOC, implementation = _build_test_impl, attrs = { "targets": attr.label_list(allow_files = True), + "is_windows": attr.bool(mandatory = True), }, test = True, ) + +def build_test(name, **kwargs): + _build_test( + name = name, + is_windows = select({ + "@bazel_tools//src/conditions:host_windows": True, + "//conditions:default": False, + }), + **kwargs + )