Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Jun 21, 2022
1 parent 7bbf450 commit 4f82a94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ swc_register_toolchains(
name = "default_swc",
integrity_hashes = {
"darwin-arm64": "sha512-DuBBKIyk0iUGPmq6RQc7/uOCkGnvB0JDWQbWxA2NGAEcK0ZtI9J0efG9M1/gLIb0QD+d2DVS5Lx7VRIUFTx9lA==",
"darwin-x64": "sha512-WvDN6tRjQ/p+4gNvT4UVU4VyJLXy6hT4nT6mGgrtftG/9pP5dDPwwtTm86ISfqGUs8/LuZvrr4Nhwdr3j+0uAA==",
},
swc_version = "v1.2.204",
)
Expand Down
24 changes: 14 additions & 10 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Internal implementation details"

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_file_to_bin_action", "copy_files_to_bin_actions")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_file_to_bin_action")

_attrs = {
"srcs": attr.label_list(
Expand Down Expand Up @@ -97,19 +97,21 @@ def _impl(ctx):
out = ctx.actions.declare_directory(ctx.label.name)
outputs.append(out)
args.add_all([
ctx.files.srcs[0].short_path,
ctx.files.srcs[0].path,
"--out-dir",
out.short_path,
out.path,
#"--no-swcrc",
#"-q",
])

ctx.actions.run(
inputs = copy_files_to_bin_actions(ctx, ctx.files.srcs) + ctx.toolchains["@aspect_rules_swc//swc:toolchain_type"].swcinfo.tool_files,
inputs = ctx.files.srcs + ctx.toolchains["@aspect_rules_swc//swc:toolchain_type"].swcinfo.tool_files,
arguments = [args],
outputs = [out],
executable = binary,
progress_message = "Transpiling with swc %s" % ctx.label,
# sandboxing is unnecessary with swc which takes an explilit list of srcs via args
execution_requirements = {"no-sandbox": "1"},
)

else:
Expand All @@ -129,14 +131,14 @@ def _impl(ctx):
src_args = ctx.actions.args()

js_out = js_outs[i]
inputs = [copy_file_to_bin_action(ctx, src)] + ctx.toolchains["@aspect_rules_swc//swc:toolchain_type"].swcinfo.tool_files
inputs = [src] + ctx.toolchains["@aspect_rules_swc//swc:toolchain_type"].swcinfo.tool_files
outs = [js_out]
if ctx.attr.source_maps in ["true", "both"]:
outs.append(map_outs[i])

# Pass in the swcrc config if it is set
if ctx.file.swcrc:
swcrc_path = ctx.file.swcrc.short_path
swcrc_path = ctx.file.swcrc.path
swcrc_directory = paths.dirname(swcrc_path)
src_args.add_all([
"--config-file",
Expand All @@ -148,7 +150,7 @@ def _impl(ctx):
#src_args.add("--no-swcrc")

src_args.add_all([
# src.short_path,
# src.path,
"--out-file",
js_out.path,
#"-q",
Expand All @@ -160,19 +162,21 @@ def _impl(ctx):
args,
src_args,
"-f ",
src.short_path,
src.path,
],
outputs = outs,
# Workaround swc cli bug:
# https://github.com/swc-project/swc/blob/main/crates/swc_cli/src/commands/compile.rs#L241-L254
# under Bazel it will think there's no tty and so it always errors here
# https://github.com/swc-project/swc/blob/main/crates/swc_cli/src/commands/compile.rs#L301
command = binary + " $@ < " + src.short_path,
command = binary + " $@ < " + src.path,
mnemonic = "SWCTranspile",
progress_message = "Transpiling with swc %s [swc %s]" % (
ctx.label,
src.short_path,
src.path,
),
# sandboxing is unnecessary with swc which takes an explilit list of srcs via args
execution_requirements = {"no-sandbox": "1"},
)

# See https://docs.bazel.build/versions/main/skylark/rules.html#runfiles
Expand Down

0 comments on commit 4f82a94

Please sign in to comment.