-
-
Notifications
You must be signed in to change notification settings - Fork 576
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
base: master
Are you sure you want to change the base?
Reenable Specta integration #2432
Conversation
Thank you for writing the library and helping us restore this! I'm eager to do the refactor which replaces |
aa7ff13
to
e11b57a
Compare
Back to reviewing this now! Could you please help me understand the purpose of |
@@ -34,6 +34,18 @@ pub fn init_graphite() { | |||
log::set_max_level(log::LevelFilter::Debug); | |||
} | |||
|
|||
#[cfg(debug_assertions)] |
There was a problem hiding this comment.
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(() => |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)
I also removed the |
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:
Part of #1148