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

Propagate runfiles #27

Merged
merged 2 commits into from
Apr 18, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rules_swc_dependencies()
load("@aspect_rules_swc//swc:repositories.bzl", "swc_register_toolchains")
swc_register_toolchains(
name = "swc",
swc_version = "v1.2.118",
swc_version = "v1.2.168",
)

# Fetches a NodeJS interpreter, needed to run the swc CLI.
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load("//swc:repositories.bzl", "swc_register_toolchains")

swc_register_toolchains(
name = "default_swc",
swc_version = "v1.2.141",
swc_version = "v1.2.168",
)

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
Expand Down
21 changes: 21 additions & 0 deletions examples/transitive/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Test transitive dependencies between typescript files
which are transpiled separately as "libraries" but which
have runtime dependencies.
"""

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

genrule(
name = "run",
outs = ["actual"],
cmd = "$(location //examples/transitive/app:bin) > $@",
tools = ["//examples/transitive/app:bin"],
)

# Assert the output of the program matches the expected file
write_source_files(
name = "assertion",
files = {
"expected": "actual",
},
)
24 changes: 24 additions & 0 deletions examples/transitive/app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@aspect_rules_swc//swc:swc.bzl", "swc")
load("@aspect_rules_js//js:nodejs_binary.bzl", "nodejs_binary")

package(default_visibility = ["//:__subpackages__"])

swc(
name = "app",
srcs = ["a.ts"],
args = [
"--config",
"module.type=commonjs",
],
# In Bazel, a "data" dependency is a runtime dependency.
# This file isn't required to transpile b.ts -> b.js
# however any program which depends on lib_b should have
# lib_c available in the "runfiles".
data = ["//examples/transitive/lib_b"],
)

nodejs_binary(
name = "bin",
data = [":app"],
entry_point = "a.js",
)
3 changes: 3 additions & 0 deletions examples/transitive/app/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { b } from "../lib_b/b";

console.log("output of app:", b);
1 change: 1 addition & 0 deletions examples/transitive/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output of app: 3
17 changes: 17 additions & 0 deletions examples/transitive/lib_b/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@aspect_rules_swc//swc:swc.bzl", "swc")

package(default_visibility = ["//:__subpackages__"])

swc(
name = "lib_b",
srcs = ["b.ts"],
args = [
"--config",
"module.type=commonjs",
],
# In Bazel, a "data" dependency is a runtime dependency.
# This file isn't required to transpile b.ts -> b.js
# however any program which depends on lib_b should have
# lib_c available in the "runfiles".
data = ["//examples/transitive/lib_c"],
)
3 changes: 3 additions & 0 deletions examples/transitive/lib_b/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { c } from "../lib_c/c";

export const b = 2 + c;
12 changes: 12 additions & 0 deletions examples/transitive/lib_c/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@aspect_rules_swc//swc:swc.bzl", "swc")

package(default_visibility = ["//:__subpackages__"])

swc(
name = "lib_c",
srcs = ["c.ts"],
args = [
"--config",
"module.type=commonjs",
],
)
1 change: 1 addition & 0 deletions examples/transitive/lib_c/c.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const c = 1;
6 changes: 5 additions & 1 deletion swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ def _impl(ctx):
),
)

# See https://docs.bazel.build/versions/main/skylark/rules.html#runfiles
runfiles = ctx.runfiles(files = outputs + ctx.files.data)
runfiles = runfiles.merge_all([d[DefaultInfo].default_runfiles for d in ctx.attr.data])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it always have a DefaultInfo provider?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yes I think every rule does?


providers = [
DefaultInfo(
files = depset(outputs),
runfiles = ctx.runfiles(outputs, transitive_files = depset(ctx.files.data)),
runfiles = runfiles,
),
]

Expand Down
15 changes: 15 additions & 0 deletions swc/private/versions.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
"Mirror of release info"

TOOL_VERSIONS = {
"v1.2.168": {
"android-arm-eabi": "sha384-eegQUZCJXBzl5Y4IeELJhlVGAUkspDA6cIqHJxEY6nSMRsJ5azxPAYHPMjd/7HcB",
"android-arm64": "sha384-iDGIuT+rMBqEFXynqgqUCEwaEysPNHPgU5zHVrw0ZoTBmbgU7hE/bDI6qtwEuhGB",
"darwin-arm64": "sha384-cC7J5IXEiivWG9fLk70P3/eR3xlC9c6pEQ7eDSLEbUPayV9dzd2sfL6zJNAVzJke",
"darwin-x64": "sha384-cdoeWiAiFuC6trXvaOIKHaghIOgGjE8FYU+ApLIX10uuASykH0KBUls8YzI/z0BF",
"freebsd-x64": "sha384-i/sWnzLH7iq73TnVt0Gc7N1jllFITcKp14PIEB/GPuR2XfH5Lta6N2AtAHlIRJj6",
"linux-arm-gnueabihf": "sha384-JAMYCgrMEUFVmDdXSjJJCnaatsyQ3PXB1UwlGwZ3ggXx3TQ8q6zUjXPcaWPMPDdd",
"linux-arm64-gnu": "sha384-6vN8ks/3LXz1y1Vlt99MZTpieafcdy1E+Umd8Al3v/dPECuhq9r+nOseFzNBCYwK",
"linux-arm64-musl": "sha384-jJhVdadlEqOIKadZBzlMue1t8YYNJ/kdsdbUt0UM+gc6Zbp1DJr1oai3maH6lvTc",
"linux-x64-gnu": "sha384-Of6s4gjX/7JGFpReGFG0lozDS6i7AJcJ3xBOEoYvAo33dXakrg+NTOORTtUvyHQS",
"linux-x64-musl": "sha384-c537PkbC8nkaQP+lMkKWjUZ1Xl2qpCnDW5tc1SMRb1SGgLWuSj4AZ1GjmT5CFVV9",
"win32-arm64-msvc": "sha384-inYv8Ad8efI6sT5nZ9dlGq0aeaBIzo8S2ZcG8MafsdipilHazxm/BYdQWZTsazAP",
"win32-ia32-msvc": "sha384-3Sxwt0BN2W7N/xei9wcONc6MQbEQo9EcnfoeO+pNBGR1e4t0QVAVufpzK4G+ZDHs",
"win32-x64-msvc": "sha384-HJKPVPvKu6nWu6vdXrnVK5ClFoKA7pM1C4fgiQ2eBt0N/syTzD9HRGbB24s1Ru3B",
},
"v1.2.141": {
"android-arm-eabi": "sha384-1Kpl5sj2A50yTtZu5Ae7rGGY+t+0FYvcy/VCUp1IM8lW36RuhERqfahcWdmgtinB",
"android-arm64": "sha384-F/kmewGo2LlmyIeEQBnctRBJULmcSbko/5Gz1AJNxATWS1JUEX8C06AhdTpV7dk0",
Expand Down