Skip to content

Commit

Permalink
additional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimetodie committed Dec 24, 2022
1 parent 723f824 commit ac516ac
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 54 deletions.
19 changes: 10 additions & 9 deletions docs/swc.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/custom_outs/expected.cjs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export var a = "a";
export var a = "a";
2 changes: 1 addition & 1 deletion examples/custom_outs/expected.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export var a = "a";
export var a = "a";
3 changes: 0 additions & 3 deletions examples/opaque_src/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export var a = "simple";


//# sourceMappingURL=in.js.map
2 changes: 1 addition & 1 deletion examples/paths/expected.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
const _moduleA = require("../../../../../../../shared/cache/bazel/user_base/09a27d1eeea3b44d1580773090924b4d/execroot/aspect_rules_swc/src/modules/moduleA");
const _moduleA = require("../../../../../../../../.cache/bazel/_bazel_kyoko/ff577c076cf6a317d57071fc46ad7397/execroot/aspect_rules_swc/src/modules/moduleA");
(0, _moduleA.moduleA)();
2 changes: 1 addition & 1 deletion examples/rc/src/expected.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 16 additions & 38 deletions swc/private/swc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _impl(ctx):
args.add_all(ctx.attr.args)

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

if ctx.attr.output_dir:
if len(ctx.attr.srcs) != 1:
Expand All @@ -144,62 +144,43 @@ def _impl(ctx):
ctx.files.srcs[0].short_path,
"--out-dir",
output_dir.path,
# There is no longer such an option - the rust CLI doesn't go looking for it though
#"--no-swcrc",
# There is no "quiet" flag to the rust CLI.
#"-q",
])

ctx.actions.run_shell(
inputs = ctx.files.srcs + ctx.toolchains["@aspect_rules_swc//swc:toolchain_type"].swcinfo.tool_files,
inputs = ctx.files.srcs,
arguments = [args],
outputs = output_sources,

# command = "pwd > {}/help".format(output_dir.path), # /shared/cache/bazel/user_base/09a27d1eeea3b44d1580773090924b4d/sandbox/linux-sandbox/90/execroot/aspect_rules_swc
# command = "socat - SYSTEM:\"pwd > {}/help\",pty".format(output_dir.path),

#command = "socat - SYSTEM:\"pwd; ls --color\",pty,setsid,ctty > {}/help".format(output_dir.path),
# command = "(pwd; ls) > {}/help".format(output_dir.path),
command = "socat - SYSTEM:\"{} compile {} --out-dir {}\",pty".format(binary, ctx.files.srcs[0].path, output_dir.path),
#command = "python -c 'import os\n_, slave = os.openpty()\nsubprocess.run(\"{} compile {} --out-dir {}\", check=True, shell=True, stdin=slave, stdout=subprocess.PIPE)'".format(binary, ctx.files.srcs[0].path, output_dir.path),
#command = "python -c 'import os\n_, slave = os.openpty()'".format(binary, ctx.files.srcs[0].path, output_dir.path),

# /bin/bash -c 'socat - EXEC:"external/default_swc_linux-x64-gnu/package/swc --help",pty,setsid,ctty 2>&1 >bazel-out/k8-fastbuild/bin/examples/directory/minify/help' '' compile examples/directory/split_app --out-dir bazel-out/k8-fastbuild/bin/examples/directory/minify
# command = "socat - EXEC:\"{0} --help\",pty,setsid,ctty 2>&1 >{2}/help".format(binary, ctx.files.srcs[0].short_path, output_dir.path),

#command = binary + " $@",
#use_default_shell_env = True,
command = "/home/kyoko/.local/bin/swc $@",
mnemonic = "SWCTranspile",
progress_message = "Transpiling with swc %s" % ctx.label,
)
else:
output_sources = []

for src in ctx.files.srcs:
inputs = [copy_file_to_bin_action(ctx, src)] + swcinfo.tool_files

src_args = ctx.actions.args()
src_path = _relative_to_package(src.path, ctx)

js_out_path = _calculate_js_out(src_path, ctx.attr.out_dir, ctx.attr.root_dir, [_relative_to_package(f.path, ctx) for f in ctx.outputs.js_outs])
if not js_out_path:
# This source file is not a supported src
continue
js_out = ctx.actions.declare_file(js_out_path)
outputs = [js_out]
map_out_path = _calculate_map_out(src_path, ctx.attr.source_maps, ctx.attr.out_dir, ctx.attr.root_dir)

if map_out_path:
outputs.append(ctx.actions.declare_file(map_out_path))
js_map_out = ctx.actions.declare_file(map_out_path)
outputs.append(js_map_out)

src_args = ctx.actions.args()
if ctx.attr.source_maps in ["true", "both"]:
src_args.add_all([
"--source-map-target",
js_map_out.path,
])

js_out = js_outs[i]
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])
src_args.add_all([
"--source-map-target",
map_outs[i].path,
])

if ctx.attr.swcrc:
swcrc_path = ctx.file.swcrc.path
Expand All @@ -224,12 +205,9 @@ def _impl(ctx):
"--filename",
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.path,
outputs = outputs,
#command = binary + " $@ < " + src.path,
command = "/home/kyoko/.local/bin/swc $@ < " + src.path,
mnemonic = "SWCTranspile",
progress_message = "Transpiling with swc %s [swc %s]" % (
ctx.label,
Expand Down

0 comments on commit ac516ac

Please sign in to comment.