aspect-build / rules_swc

Bazel rules for the swc toolchain https://swc.rs/
https://docs.aspect.build/rules/aspect_rules_swc
Apache License 2.0
41 stars 21 forks source link

run bare rust CLI binary, no node #57

Closed alexeagle closed 1 year ago

alexeagle commented 1 year ago

BREAKING CHANGES:

alexeagle commented 1 year ago

Okay this has been hard and I haven't found much focus time for it.

As far as I know, https://github.com/swc-project/swc/issues/5171 was the last bug preventing Bazel from using the pure-rust CLI.

We will have some rules_swc API changes:

alexeagle commented 1 year ago

Update: it's still necessary to provide a fake tty to make the swcx binary accept a folder, now trying to make a tty_binary rule in https://github.com/aspect-build/bazel-lib/pull/251

This keeps getting stuck because it's a side-project for me. We need some sponsorship for this work. Filed #88 so that the PR has an associated issue.

realtimetodie commented 1 year ago

I'm working on this

realtimetodie commented 1 year ago

Fixed an upstream bug, see https://github.com/aspect-build/rules_swc/issues/88

alexeagle commented 1 year ago

awesome, LMK if you'd like some help getting this rebased or anything

realtimetodie commented 1 year ago

Yes, I already made a rebase in https://github.com/realtimetodie/rules_swc/tree/swc_rust and got bazel build //... running with a custom swc cli and the changes from https://github.com/swc-project/swc/pull/6708. In addition, I found new bugs in the swc cli and will create subsequent PRs upstream.

bazel test //... 13 tests pass and 3 fail locally. All failed tests are related to the --output-dir option of the swc cli compile command. It is due to the cwd. The cwd is set to the execroot directory and the swc cli can not find the auto-generated mock test files that are written into the bazel-out directory. But I think this might be related to my custom binary location, see

https://github.com/realtimetodie/rules_swc/commit/ac516ac2256f9a273c862a966d8485a19649b802#diff-1444361579758fc6be4458b5105b2ee3ee623d72154094c3fa1fd9056845903eR154

Test summary

//docs:update_test                                              (cached) PASSED in 0.0s
//examples/custom_outs:tests_0_test                             (cached) PASSED in 0.1s
//examples/custom_outs:tests_1_test                             (cached) PASSED in 0.0s
//examples/macro:test_test                                      (cached) PASSED in 0.0s
//examples/opaque_src:test_test                                 (cached) PASSED in 0.1s
//examples/out_dir:check_outputs                                (cached) PASSED in 0.1s
//examples/paths:test_test                                      (cached) PASSED in 0.1s
//examples/rc/src:tests_0_test                                  (cached) PASSED in 0.1s
//examples/rc/src:tests_1_test                                  (cached) PASSED in 0.0s
//examples/root_dir:check_outputs                               (cached) PASSED in 0.1s
//examples/simple:test_test                                     (cached) PASSED in 0.1s
//examples/transitive:assertion_test                            (cached) PASSED in 0.0s
//swc/tests:versions_test_test_0                                (cached) PASSED in 0.1s
//examples/directory:minify_test                                         FAILED in 0.0s
//examples/directory:out_dir_test                                        FAILED in 0.0s
//examples/filegroup:check_outputs                                       FAILED in 0.0s

merry christmas

realtimetodie commented 1 year ago

Fixed an upstream bug, see https://github.com/aspect-build/rules_swc/issues/88

realtimetodie commented 1 year ago

The tests are now passing 🎉

realtimetodie commented 1 year ago

https://github.com/aspect-build/rules_swc/issues/61

alexeagle commented 1 year ago

hey @realtimetodie this is fantastic, I'm watching those upstream PRs. In theory we could use rules_rust to allow a from-source swc toolchain here, then users could point to an unreleased branch of swc (or they could vendor swc sources into their monorepo so they can make local modifications, though that's essentially a fork) That's probably not worth it though, the upstream maintainers are active and responsive so I bet you'll be able to get an official swc release that works 100% with Bazel.

realtimetodie commented 1 year ago

Yes, the swc team is very responsive. The changes for symbolic links were merged upstream.

realtimetodie commented 1 year ago

As this is a breaking change, I used the opportunity to do some house cleaning (please bear with me). I renamed the underlying rule from swc_transpile -> swc_compile. This matches the wording of the SWC project (I think the word "transpile" was originally inspired by the Node-based TypeScript compiler, but this is different in the SWC world).

Checklist

Breaking changes will be documented in the final PR.

Blocked by https://github.com/swc-project/swc/pull/6714

alexeagle commented 1 year ago

@realtimetodie SWC just cut a release that includes your last fix, so I think it's time to merge this!

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

alexeagle commented 1 year ago

@realtimetodie do you mind signing that CLA so I can include your commits without any fear of licensing issues?

realtimetodie commented 1 year ago

signed

realtimetodie commented 1 year ago

wow nice, the build is green let's goo

alexeagle commented 1 year ago

I'm doing another review/cleanup pass on it. The k8-fastbuild is going to be a portability problem https://github.com/aspect-build/rules_swc/pull/57/files#diff-d1df27564968f40aec96caf8b7e3f176263984b5c8f12dc418a9ea61a19f5073R18

realtimetodie commented 1 year ago

The solution to obtain the bazel runfiles directory as an environment variable is very elegant, I like it

alexeagle commented 1 year ago

look for .swcrc in the package and use it if present, like we do for tsconfig.json in ts_project

This doesn't actually seem to work, if I drop the swcrc = ".swcrc" attribute from an swc_compile then it stops using the config file. I'll fix in a follow-up, doesn't really have to be in-scope here as it wasn't a feature before either.