Skip to content

Reenable Specta integration #2432

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

oscartbeaumont
Copy link
Contributor

@oscartbeaumont oscartbeaumont commented Mar 14, 2025

This fixes the commented out Specta integration resolving the TODO comment.

It might be worth moving the type exporting code into the startup of the application if possible when doing a debug build so that you don't need to run cargo test ... to generate the bindings but I don't know enough about Graphite's setup to know where is best. I also suppose any Rust running in wasm would not be a good place for that as it won't have filesystem access so a better place may not exist.

TODO:

  • Decide on approach
  • Fix the errors with linter (we can do that from the Specta side)

Part of #1148

@Keavon
Copy link
Member

Keavon commented Mar 14, 2025

Thank you for writing the library and helping us restore this! I'm eager to do the refactor which replaces messages.ts with these generated bindings.

@Keavon Keavon force-pushed the master branch 4 times, most recently from aa7ff13 to e11b57a Compare April 6, 2025 11:41
@Keavon
Copy link
Member

Keavon commented May 2, 2025

Back to reviewing this now! Could you please help me understand the purpose of pnpm-lock.yaml, bindings_from_node.ts, and export.js?

@@ -34,6 +34,18 @@ pub fn init_graphite() {
log::set_max_level(log::LevelFilter::Debug);
}

#[cfg(debug_assertions)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We expose a wasm function that returns a string with all the Specta types.

This is only enabled in development so Rust can strip more for production builds.

import path from "node:path";
import graphite, { get_specta_types } from "./pkg/graphite_wasm.js";

graphite(fs.readFileSync(path.join(import.meta.dirname, './pkg/graphite_wasm_bg.wasm'))).then(() =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We import the wasm file and then call the get_specta_types function and save the result to the disk.

By doing this we don't need to build a separate x86/ARM binary specially for exporting the types. Commonly this would be done via cargo test. By having it be included in the binary makes it way quicker for Graphite's specific setup.

@@ -0,0 +1,276 @@
// This file has been generated by Specta. DO NOT EDIT.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the result of all the types that Specta generated from Graphite's codebase.

These can be used anywhere in Graphite's frontend.

@@ -1,34 +1,15 @@
/// Running this test will generate a `types.ts` file at the root of the repo,
/// containing every type annotated with `specta::Type`
// #[cfg(all(test, feature = "specta-export"))]
#[ignore]

#[test]
fn generate_ts_types() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this but it's probally not needed with the wasm exporting solution (hence why it's still #[ignore]ed)

@oscartbeaumont
Copy link
Contributor Author

I also removed the pnpm-lock.yaml. It was just from me using pnpm instead of npm.

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.

2 participants