Skip to content

[WIP] Rescript#207

Draft
rofinn wants to merge 4 commits into
specta-rs:mainfrom
rofinn:rf/specta-rescript
Draft

[WIP] Rescript#207
rofinn wants to merge 4 commits into
specta-rs:mainfrom
rofinn:rf/specta-rescript

Conversation

@rofinn

@rofinn rofinn commented Mar 25, 2026

Copy link
Copy Markdown

Work in progress rescript language extension with an example for setting up a tauri + rescript app.

Depends on specta-rs/specta#459 and #206 (rebase once the updates are working correctly).

Screenshot From 2026-03-25 10-57-27

Decided to setup a separate rescript example rather than extending the
default examples/app.

  1. This allows us to keep the setup separate
  2. We can keep the dependencies and vite config separate.

Frontend

  • src/Main.res: Largely the same as main.ts, just converted to rescript
  • src/style.css: Basically copied from the original app
  • index.html: Again, copied from the original app (might have slight
    autoformatting differences)
  • src/assets: vite.svg and tauri.svg were copied from the app and I've
    just added the rescript logo.
  • src/Bindings.res: Our generated bindings file committed for reference
  • src/*.js: I've opted to ignore rescript's compiled .js files for now

NOTE: You may noticed the bindings.res file is a bit different than the
corresponding bindings.ts file.

  1. Rescript has stricter requirements on the order of definitions
  2. Rescript has a different convention regarding modules and importing
  3. Some elements like docstrings and deprecations are unsupported.

Backend

  • src-tauri/src/main.rs: Is just the original app version with updated
    imports and main functions.

NOTE: For dependencies and configuration, we're using rescript v12 with
the experimental webapi lib and a beta version of the
vite-plugin-rescript (so vite automatically compiles the rescript code).

** Exporter **

This export doesn't follow the same pattern as the typescript code since
specta-rescript doesn't implement a FrameworkExporter pattern.

In general, it's a pretty basic export(self, config, path) -> Result method with a
bunch of simpler utility functions for rendering_ (takes a mutable out
string) or format_ functions.

rofinn added 2 commits March 21, 2026 18:06
This export doesn't follow the same pattern as the typescript code since
specta-rescript doesn't implement a similar FrameworkExporter pattern.

In general, we've implement a basic `export(self, config, path) -> Result` method with a
bunch of simpler utility functions for rendering (take a mutable `out`
string) or format functions. Over half of the rescript.rs file is tests.
Decided to setup a separate rescript example rather than extending the
default examples/app.

1. This allows us to keep the setup separate
2. We can keep the dependencies and vite config separate.

**Frontend**

- src/Main.res: Largely the same as main.ts, just converted to rescript
- src/style.css: Basically copied from the original app
- index.html: Again, copied from the original app (might have slight
  autoformatting differences)
- src/assets: vite.svg and tauri.svg were copied from the app and I've
  just added the rescript logo.
- src/Bindings.res: Our generated bindings file committed for reference
- src/*.js: I've opted to ignore rescript's compiled .js files for now

NOTE: You may noticed the bindings.res file is a bit different than the
corresponding bindings.ts file.

1. Rescript has stricter requirements on the order of definitions
2. Rescript has a different convention regarding modules and importing
3. Some elements like docstrings and deprecations are unsupported.

**Backend**

- src-tauri/src/main.rs: Is just the original app version with updated
  imports and main functions.

NOTE: For dependencies and configuration, we're using rescript v12 with
the experimental webapi lib and a beta version of the
vite-plugin-rescript (so vite automatically compiles the rescript code).

** Exporter **

While debugging the new example, I noticed a few issues.

1. Docstrings aren't generated (expected)
2. Constants weren't being included (added)
3. Js.Obj.empty() was producing warnings on rescript v12 (should be
   Object.make())
4. We were just inline the events code rather than following the
   makeEvent function pattern in the typescript implementation.
@rofinn rofinn marked this pull request as draft March 25, 2026 23:13
rofinn and others added 2 commits May 22, 2026 11:31
1. Updated the re-updated the root cargo and pnpm files to sync deps,
   but keep our specta branches.
2. Updated src/lang/rescript.rs to the new api (e.g., r.get(types) ->
   types.get(r), getters replaced with public field access)
3. Added a render_types filter to suppress std::result::Result from
   being exported as a custom type since it conflicts with the Rescript
   `result` type.
4. Reduced some dead code warnings in the example for now.
5. To suppress a build warning with the rescript/webapi package we need
   to patch their rescript.json file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant