Skip to content

Commit d99e862

Browse files
committed
chore: simplify WORKSPACE
This means we don't have to mirror hashes an extra time when we add a new swc version. Move this to the documentation instead. Note, this means we don't have test coverage for these two attributes anymore. If we really want that we could add another e2e for it.
1 parent 6174b08 commit d99e862

File tree

4 files changed

+96
-19
lines changed

4 files changed

+96
-19
lines changed

WORKSPACE

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,11 @@ load("//swc:dependencies.bzl", "rules_swc_dependencies")
1212
# Fetch our "runtime" dependencies which users need as well
1313
rules_swc_dependencies()
1414

15-
load("//swc:repositories.bzl", "swc_register_toolchains")
15+
load("//swc:repositories.bzl", "LATEST_VERSION", "swc_register_toolchains")
1616

1717
swc_register_toolchains(
1818
name = "swc",
19-
# Demonstrates how users can choose ANY swc version, not just the ones we mirrored
20-
integrity_hashes = {
21-
"darwin-arm64": "sha384-IhP/76Zi5PEfsrGwPJj/CLHu2afxSBO2Fehp/qo4uHVXez08dcfyd9UzrcUI1z1q",
22-
"darwin-x64": "sha384-s2wH7hzaMbTbIkgPpP5rAYThH/+H+RBQ/5xKbpM4lfwPMS6cNBIpjKVnathrENm/",
23-
"linux-arm64-gnu": "sha384-iaBhMLrnHTSfXa86AVHM6zHqYbH3Fh1dWwDeH7sW9HKvX2gbQb6LOpWN6Wp4ddud",
24-
"linux-x64-gnu": "sha384-R/y9mcodpNt8l6DulUCG5JsNMrApP+vOAAh3bTRChh6LQKP0Z3Fwq86ztfObpAH8",
25-
},
26-
swc_version_from = "//:package.json",
19+
swc_version = LATEST_VERSION,
2720
)
2821

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

docs/repositories.md

Lines changed: 47 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

swc/repositories.bzl

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
"""Repository rules for fetching the swc toolchain.
22
33
For typical usage, see the snippets provided in the rules_swc release notes.
4+
5+
### Version matching
6+
7+
To keep the swc version in sync with non-Bazel tooling, use `swc_version_from`.
8+
9+
Currently this only works when a single, pinned version appears, see:
10+
https://github.com/aspect-build/rules_ts/issues/308
11+
12+
For example, `package.json`:
13+
14+
```json
15+
{
16+
"devDependencies": {
17+
"@swc/core": "1.3.37"
18+
}
19+
}
20+
```
21+
22+
Allows this in `WORKSPACE`:
23+
24+
```starlark
25+
swc_register_toolchains(
26+
name = "swc",
27+
swc_version_from = "//:package.json",
28+
)
29+
```
30+
31+
### Other versions
32+
33+
To use an swc version which is not mirrored to rules_swc, use `integrity_hashes`.
34+
35+
For example in `WORKSPACE`:
36+
37+
```starlark
38+
swc_register_toolchains(
39+
name = "swc",
40+
integrity_hashes = {
41+
"darwin-arm64": "sha384-IhP/76Zi5PEfsrGwPJj/CLHu2afxSBO2Fehp/qo4uHVXez08dcfyd9UzrcUI1z1q",
42+
"darwin-x64": "sha384-s2wH7hzaMbTbIkgPpP5rAYThH/+H+RBQ/5xKbpM4lfwPMS6cNBIpjKVnathrENm/",
43+
"linux-arm64-gnu": "sha384-iaBhMLrnHTSfXa86AVHM6zHqYbH3Fh1dWwDeH7sW9HKvX2gbQb6LOpWN6Wp4ddud",
44+
"linux-x64-gnu": "sha384-R/y9mcodpNt8l6DulUCG5JsNMrApP+vOAAh3bTRChh6LQKP0Z3Fwq86ztfObpAH8",
45+
},
46+
swc_version = "1.3.37",
47+
)
48+
```
449
"""
550

651
load("@bazel_skylib//lib:versions.bzl", "versions")
@@ -13,9 +58,9 @@ LATEST_VERSION = TOOL_VERSIONS.keys()[0]
1358
_DOC = "Fetch external dependencies needed to run the SWC cli"
1459
_ATTRS = {
1560
"swc_version": attr.string(doc = "Explicit version. If provided, the package.json is not read."),
16-
"swc_version_from": attr.label(doc = "Location of package.json which may have a version for @swc/core."),
61+
"swc_version_from": attr.label(doc = "Location of package.json which has a version for @swc/core."),
1762
"platform": attr.string(mandatory = True, values = PLATFORMS.keys()),
18-
"integrity_hashes": attr.string_dict(),
63+
"integrity_hashes": attr.string_dict(doc = "A mapping from platform to integrity hash."),
1964
}
2065

2166
# This package is versioned the same as the underlying rust binary we download

0 commit comments

Comments
 (0)