Skip to content

Restructure the CLI #702

Open
Open
@saulecabrera

Description

@saulecabrera

This proposal suggests a restructuring of Javy's CLI interface to:

  • Enhance flexibility in specifying code generation options and JavaScript engine features.
  • Provide semantically meaningful command and sub-command names where applicable.

Command Flexibility

Javy currently offers a wide range of configuration options that control the JavaScript language features available to the generated code. However, there are limitations:

  • There is currently no way to specify these options directly from the CLI.
  • Other code-generation options, such as name section generation and optimization options, cannot be specified through the CLI. These options are crucial for profiling Javy-generated modules using tools like wasmprof. Currently, users must manually update these options, which is not ideal.
  • The current default settings are not well-suited to all use cases, as highlighted in issue #628.

Semantically Meaningful Commands, Sub-Commands and Options

The CLI currently features two main commands: compile and emit-provider. The compile command does not accurately reflect its actions and could be better named to represent actual AOT compilation of JavaScript, a feature we plan to explore in the future.

Proposal

The high-level proposal includes:

  • Deprecating the compile command in favor of a new command, tentatively named build. Avoid introducing breaking changes or new features through the compile command.
  • Enhance the build command with meaningful options to control JavaScript and code generation features as described above.
  • Updating the compile command to emit a deprecation notice, indicating that it will be deprecated in the next major release of the CLI.
    • The ideal timeline for transitioning from issuing a deprecation notice to actual deprecation is not clear. I propose to discuss this issue on our Zulip stream and make a decision based on the feedback received.

CLI Interface

The proposal suggests, according to the bullet points above, to have the new build command look like:

$ javy build --help

Builds a Wasm module from a JS source
Usage: javy build <OPTIONS> <JS>

Arguments:
  <JS> The JavaScript source to be used as input for building the WebAssembly module.

Options:

-J, --js <KEY[=VAL[,..]]> JavaScript runtime options.
-D, --debug <KEY[=VAL[,..]]> Debug options.
-C, --codegen <KEY[=VAL[,..]]> Code generation options (the current `-d` and `wit` options)
-o, --output The path of the Wasm module.

For example, in order to control the name section generation, one could do:

javy build -D generate-name-section=true -o index.wasm index.js

The suggested CLI layout, takes inspiration from Wasmtime's CLI layout, which, I think offers multiple benefits, notably:

  • Ability to have option groups, that make it easier to share such groups across commands where applicable (e.g., it might make sense to share the -D group, across the build and emit-provider commands, for cases in which the user wants to control walrus/wasm-opt options.
  • Reduced option verbosity. I can think of at least one alternative way of presenting command options, by using enable-<group>-<option> and disable-<group>-<option>. Aside from the verbosity, with this approach, we need to introduce at least two options per group (assuming each option allows at least enabling or disabling).

Proposed order of operations

  • Introduce the new build command, which will initially behave similar to the current compile command.
  • Introduce a deprecation notice under the current compile command.
  • Land CLI: Allow Input from stdin and Output to stdout #701
  • Release version 3.1.0 of the CLI
  • Introduce the -J options group
  • Introduce the -D options group
  • Introduce the -C options group
  • Release version 4 of the CLI with the deprecated compile command. (After having collected feedback / agreed on the deprecation timeline)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions