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

Rewrite Wing CLI into Rust #7061

Open
Chriscbr opened this issue Aug 30, 2024 · 0 comments
Open

Rewrite Wing CLI into Rust #7061

Chriscbr opened this issue Aug 30, 2024 · 0 comments
Labels
⌨️ cli CLI ✨ enhancement New feature or request ⭐️ epic agile epic refactor

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Aug 30, 2024

Use Case

Debugging the current Wing toolchain when developing changes or features in the compiler can cumbersome because there are many concerns that overlap between the Node.js-based CLI and the Rust-based compiler core. For example, a large responsibility of the Wing compiler is to parse files and emit error information about these files, but the standard libraries for Node.js and Rust provide fairly different sets of APIs which don't always map 1:1.

To use the Rust-based compiler in Node.js, we compile it to WebAssembly and embed the WASM file in our Node package. Besides this requiring a dedicated build process (currently handled by turbo), a large amount of custom wrapper code has to be maintained for mapping functions between Rust and Node.js, and serializing/deserializing the data being passed or returned.

As a concrete example, in this PR I had to spend several hours trying to root cause the reason why a recently introduced CLI command was hanging. In the end, the looping was happening within the WASI file system mapping layer. Though it's possible to have these kinds of looping or file system issues with any compiler that needs to explore file paths and build an internal graph of files, the fact that we have to solve these problems at multiple layers is a burden.

In sum, the separation across language layers both make it a lot harder to contribute to the Wing compiler, and makes it much harder to debug. I believe unifying these under a single language will make it simpler to debug and continuing to stick to Rust will avoid the need to rewrite as many parts of our stack, while ensuring we can continue to scale the language performantly into the future.

Proposed Solution

Rewrite the CLI in Rust, and ship a unified binary (for all major architectures) to users. Initially we will require users to provide their own Node.js installations on their system which our CLI will call through subprocesses, but in the future we may consider embedding and shipping Node within our own CLI.

Implementation Notes

An initial proof of concept for performing just the "compile" command has been prototyped in the wingcli-v2 folder. Further work is needed to bring over more capabilities, including:

  • Diagnostics
  • Testing
  • Doc generation
  • Language server
  • Wing Console integration

Component

CLI

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Discord.
@Chriscbr Chriscbr added ✨ enhancement New feature or request ⌨️ cli CLI ⭐️ epic agile epic refactor labels Aug 30, 2024
@monadabot monadabot added this to Wing Aug 30, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ cli CLI ✨ enhancement New feature or request ⭐️ epic agile epic refactor
Projects
Status: 🆕 New - not properly defined
Development

No branches or pull requests

1 participant