-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(esbuild): add support for toolchains
- Loading branch information
Showing
26 changed files
with
277 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
""" | ||
Helper macro for fetching esbuild versions for internal tests and examples in rules_nodejs | ||
""" | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@build_bazel_rules_nodejs//internal/common:check_version.bzl", "parse_version") | ||
|
||
_VERSION = "0.12.1" | ||
_MIN_VERSION = "0.12.0" | ||
_MAX_VERSION = "0.13.0" | ||
|
||
DARWIN_AMD64 = "darwin_amd64" | ||
LINUX_AMD64 = "linux_amd64" | ||
WINDOWS_AMD64 = "windows_amd64" | ||
|
||
ESBUILD_SHAS = dict({ | ||
DARWIN_AMD64: "efb34692bfa34db61139eb8e46cd6cf767a42048f41c8108267279aaf58a948f", | ||
LINUX_AMD64: "de8409b90ec3c018ffd899b49ed5fc462c61b8c702ea0f9da013e0e1cd71549a", | ||
WINDOWS_AMD64: "10439647b11c7fd1d9647fd98d022fe2188b4877d2d0b4acbe857f4e764b17a9", | ||
}) | ||
|
||
def _maybe(repo_rule, name, **kwargs): | ||
if name not in native.existing_rules(): | ||
repo_rule(name = name, **kwargs) | ||
|
||
def _esbuild_toolchain_repository_impl(repository_ctx): | ||
content = "SUPPORTED_PLATFORMS = %s" % str(repository_ctx.attr.platforms) | ||
repository_ctx.file("index.bzl", content = content) | ||
repository_ctx.file("BUILD.bazel") | ||
|
||
_esbuild_toolchain_repository = repository_rule( | ||
implementation = _esbuild_toolchain_repository_impl, | ||
attrs = { | ||
"platforms": attr.string_list( | ||
mandatory = True, | ||
), | ||
}, | ||
) | ||
|
||
def esbuild_repositories(name = "esbuild_repositories", version = _VERSION, shas = ESBUILD_SHAS): | ||
"""Helper for fetching and setting up the esbuild versions and toolchains | ||
Args: | ||
name: currently unused | ||
version: version of esbuild to use | ||
shas: mapping of platform_arch to the sha256 sum of the esbuild package for that platform | ||
""" | ||
|
||
current_version = parse_version(version) | ||
if not (current_version >= parse_version(_MIN_VERSION) and current_version < parse_version(_MAX_VERSION)): | ||
fail("Expected esbuild version to be >= %s and < %s, but got %s" % (_MIN_VERSION, _MAX_VERSION, version)) | ||
|
||
shas = dict({}, **shas) | ||
platforms = [] | ||
|
||
if DARWIN_AMD64 in shas: | ||
_maybe( | ||
http_archive, | ||
name = "esbuild_darwin_amd64", | ||
urls = [ | ||
"https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-%s.tgz" % version, | ||
], | ||
strip_prefix = "package", | ||
build_file_content = """exports_files(["bin/esbuild"])""", | ||
sha256 = shas.pop(DARWIN_AMD64), | ||
) | ||
platforms.append(DARWIN_AMD64) | ||
|
||
if WINDOWS_AMD64 in shas: | ||
_maybe( | ||
http_archive, | ||
name = "esbuild_windows_amd64", | ||
urls = [ | ||
"https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-%s.tgz" % version, | ||
], | ||
strip_prefix = "package", | ||
build_file_content = """exports_files(["esbuild.exe"])""", | ||
sha256 = shas.pop(WINDOWS_AMD64), | ||
) | ||
platforms.append(WINDOWS_AMD64) | ||
|
||
if LINUX_AMD64 in shas: | ||
_maybe( | ||
http_archive, | ||
name = "esbuild_linux_amd64", | ||
urls = [ | ||
"https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-%s.tgz" % version, | ||
], | ||
strip_prefix = "package", | ||
build_file_content = """exports_files(["bin/esbuild"])""", | ||
sha256 = shas.pop(LINUX_AMD64), | ||
) | ||
platforms.append(LINUX_AMD64) | ||
|
||
if len(shas.keys()) > 0: | ||
fail( | ||
"Unsupported platforms defined for esbuild repositories: %s\n" % ", ".join(shas.keys()) + | ||
"To define a custom esbuild toolchain, see the rules_nodejs esbuild documentation pages", | ||
) | ||
|
||
_esbuild_toolchain_repository( | ||
name = "esbuild_toolchains", | ||
platforms = platforms, | ||
) | ||
|
||
for platform in platforms: | ||
toolchain_label = Label("@build_bazel_rules_nodejs//packages/esbuild/toolchain:esbuild_%s_toolchain" % platform) | ||
native.register_toolchains("@%s//%s:%s" % (toolchain_label.workspace_name, toolchain_label.package, toolchain_label.name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.