Skip to content

Commit

Permalink
demonstrate integrity hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Sep 2, 2022
1 parent 2416993 commit 6813d28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
11 changes: 8 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ load("//swc:dependencies.bzl", "rules_swc_dependencies")
# Fetch our "runtime" dependencies which users need as well
rules_swc_dependencies()

load("//swc:repositories.bzl", "LATEST_VERSION", "swc_register_toolchains")
load("//swc:repositories.bzl", "swc_register_toolchains")

swc_register_toolchains(
name = "default_swc",
# FIXME: demonstrate pulling whatever version we like, with manual hashes
swc_version = LATEST_VERSION,
# Demonstrates how users can choose ANY swc version, not just the ones we mirrored
integrity_hashes = {
"darwin-arm64": "sha512-0qn4H9h6otyW3L+sFSCZ7pgp93fxizFIkBscxShjX1160zs4AScnK5hp4kNYfyjxr2tMCIA5WVttfL6NIYp6Uw==",
"darwin-x64": "sha512-DkJHcGZi3pZkH+jl6QCWcXB00xP9Ntp8btpUuqsiRhtNkbQhTOk+2d8M3AzSJs/p2Jlr3Z24tBIq52q3CQJiCg==",
"linux-x64-gnu": "sha512-NAgd4ImnWubYKdZE1sQi9hNvsSw8+z3nVm7WrZqhBx3OVQx/XQ2OQxUKIYvTe3LInUDxywX+ifRQ/syR/pFHUQ==",
},
swc_version = "1.2.245",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
Expand Down
1 change: 1 addition & 0 deletions scripts/mirror_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

set -o errexit -o nounset -o pipefail


pkgs=$(curl --silent https://registry.npmjs.org/@swc/core/latest | jq --raw-output '.dependencies | keys[]')
version=$(curl --silent https://registry.npmjs.org/@swc/core/latest | jq --raw-output '.version')
echo " \"v$version\": {"
Expand Down
14 changes: 11 additions & 3 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ _attrs = {
mandatory = True,
),
"args": attr.string_list(
doc = "additional arguments to pass to swc cli, see https://swc.rs/docs/usage/cli",
doc = """Additional arguments to pass to swcx cli (NOT swc!).
NB: this is not the same as the CLI arguments for @swc/cli npm package.
For performance, rules_swc does not call a Node.js program wrapping the swc rust binding.
Instead, we directly spawn the (somewhat experimental) native Rust binary shipped inside the
@swc/core npm package, which the swc project calls "swcx"
Tracking issue for feature parity: https://github.com/swc-project/swc/issues/4017
""",
),
"source_maps": attr.string(
doc = "see https://swc.rs/docs/usage/cli#--source-maps--s",
Expand All @@ -25,7 +32,6 @@ _attrs = {
"swcrc": attr.label(
doc = "label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc",
allow_single_file = True,
# mandatory = True,
),
"out_dir": attr.string(
doc = "base directory for output files",
Expand Down Expand Up @@ -91,7 +97,9 @@ def _impl(ctx):

# Add user specified arguments *before* rule supplied arguments
args.add_all(ctx.attr.args)
args.add_all(["--source-maps", ctx.attr.source_maps])

# FIXME: swcx ignores this, it MUST be in the config file...
# args.add_all(["--source-maps", ctx.attr.source_maps])

if ctx.attr.output_dir:
if len(ctx.attr.srcs) != 1:
Expand Down
7 changes: 7 additions & 0 deletions swc/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def _swc_repo_impl(repository_ctx):
None,
)
if not integrity:
if repository_ctx.attr.swc_version not in TOOL_VERSIONS.keys():
fail("""\
swc version {} does not have hashes mirrored in rules_swc, please either
- Set the integrity_hashes attribute to a dictionary of platform/hash
- Choose one of the mirrored versions: {}
""".format(repository_ctx.attr.swc_version, TOOL_VERSIONS.keys()))

integrity = TOOL_VERSIONS[repository_ctx.attr.swc_version][repository_ctx.attr.platform]
bin = "package/swc{ext}".format(ext = ".exe" if False else "") # FIXME: check for windows

Expand Down

0 comments on commit 6813d28

Please sign in to comment.