-
Notifications
You must be signed in to change notification settings - Fork 6
Allow easier customization of rust plugins #222
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: main
Are you sure you want to change the base?
Changes from all commits
a2c50af
5eb9658
48467e8
122da35
c65e623
a402320
0066081
005e0bf
965c8f1
ad30162
9e057c8
7fa942e
3afde3e
f391dcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| dist/ | ||
| target/ | ||
| Cargo.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "alpha" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [lib] | ||
| crate-type = ["lib"] | ||
|
|
||
| [dependencies] | ||
| cre_wasm_exports = { path = "../cre-sdk-javy-plugin/src/cre_wasm_exports" } | ||
| javy-plugin-api = "6.0.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Build alpha.plugin.wasm using the workspace @chainlink/cre-sdk-javy-plugin. | ||
| JAVY_PLUGIN := $(abspath ../cre-sdk-javy-plugin) | ||
|
|
||
| .PHONY: build clean | ||
|
|
||
| build: dist/alpha.plugin.wasm | ||
|
|
||
| dist/alpha.plugin.wasm: Cargo.toml src/lib.rs | ||
| mkdir -p dist | ||
| CRE_SDK_JAVY_PLUGIN_HOME="$(JAVY_PLUGIN)" bun "$(JAVY_PLUGIN)/scripts/build-plugin.ts" \ | ||
| --cre-exports . \ | ||
| -o ./dist/alpha.plugin.wasm | ||
|
|
||
| clean: | ||
| rm -rf dist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "$schema": "https://biomejs.dev/schemas/2.3.14/schema.json", | ||
| "vcs": { | ||
| "enabled": false, | ||
| "clientKind": "git", | ||
| "useIgnoreFile": false | ||
| }, | ||
| "files": { | ||
| "ignoreUnknown": false, | ||
| "includes": ["**/*.ts", "**/*.json"] | ||
| }, | ||
| "formatter": { | ||
| "enabled": true, | ||
| "indentStyle": "tab", | ||
| "lineWidth": 100 | ||
| }, | ||
| "assist": { | ||
| "enabled": true | ||
| }, | ||
| "linter": { | ||
| "enabled": true, | ||
| "rules": { | ||
| "recommended": true, | ||
| "correctness": { | ||
| "noUnusedVariables": "error" | ||
| }, | ||
| "suspicious": { | ||
| "noExplicitAny": "warn" | ||
| }, | ||
| "style": { | ||
| "useConst": "error" | ||
| } | ||
| } | ||
| }, | ||
| "javascript": { | ||
| "formatter": { | ||
| "quoteStyle": "single", | ||
| "semicolons": "asNeeded" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { createExtensionAccessor } from '@chainlink/cre-sdk-javy-plugin/runtime/validate-extension' | ||
| import { z } from 'zod' | ||
|
|
||
| const rustAlphaSchema = z.object({ | ||
| greet: z.function().args().returns(z.string()), | ||
| }) | ||
|
|
||
| export type RustAlpha = z.infer<typeof rustAlphaSchema> | ||
|
|
||
| declare global { | ||
| var rustAlpha: RustAlpha | ||
| } | ||
|
|
||
| // biome-ignore lint/suspicious/noRedeclare: global augmentation declares rustAlpha; this export is the validated accessor | ||
| export const rustAlpha = createExtensionAccessor('rustAlpha', rustAlphaSchema) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "@chainlink/cre-rust-inject-alpha", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this probably doesn't matter for the purpose of this demo, but monorepo would only be able to resolve the path
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused by that, I have this library packed and imported in the test and it works. I'll tell cursor your comment and see what it does with it. |
||
| "version": "0.1.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "Example Rust extension (alpha) for CRE rust-inject demos — packaged plugin wasm + crate source.", | ||
| "scripts": { | ||
| "check": "biome check --write ${BIOME_PATHS:-.}", | ||
| "check:ci": "biome ci .", | ||
| "typecheck": "tsc" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "src", | ||
| "Cargo.toml", | ||
| "index.ts" | ||
| ], | ||
| "keywords": [], | ||
| "license": "BUSL-1.1", | ||
| "peerDependencies": { | ||
| "@chainlink/cre-sdk-javy-plugin": ">=1.0.0", | ||
| "zod": ">=3.0.0" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| use cre_wasm_exports::extend_wasm_exports; | ||
| use javy_plugin_api::javy::quickjs::prelude::*; | ||
| use javy_plugin_api::javy::quickjs::{Ctx, Object}; | ||
|
|
||
| pub fn register(ctx: &Ctx<'_>) { | ||
| let obj = Object::new(ctx.clone()).unwrap(); | ||
| obj.set( | ||
| "greet", | ||
| Func::from(|| -> String { "Hello from alpha".to_string() }), | ||
| ) | ||
| .unwrap(); | ||
| extend_wasm_exports(ctx, "rustAlpha", obj); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "lib": ["ESNext"], | ||
| "target": "ESNext", | ||
| "module": "ESNext", | ||
| "moduleDetection": "force", | ||
| "allowJs": true, | ||
| "moduleResolution": "bundler", | ||
| "allowImportingTsExtensions": true, | ||
| "verbatimModuleSyntax": true, | ||
| "noEmit": true, | ||
| "strict": true, | ||
| "skipLibCheck": true, | ||
| "types": [] | ||
| }, | ||
| "include": ["index.ts"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| target/ | ||
| Cargo.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "lib_beta" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [lib] | ||
| crate-type = ["lib"] | ||
|
|
||
| [dependencies] | ||
| cre_wasm_exports = { path = "../cre-sdk-javy-plugin/src/cre_wasm_exports" } | ||
| javy-plugin-api = "6.0.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "$schema": "https://biomejs.dev/schemas/2.3.14/schema.json", | ||
| "vcs": { | ||
| "enabled": false, | ||
| "clientKind": "git", | ||
| "useIgnoreFile": false | ||
| }, | ||
| "files": { | ||
| "ignoreUnknown": false, | ||
| "includes": ["**/*.ts", "**/*.json"] | ||
| }, | ||
| "formatter": { | ||
| "enabled": true, | ||
| "indentStyle": "tab", | ||
| "lineWidth": 100 | ||
| }, | ||
| "assist": { | ||
| "enabled": true | ||
| }, | ||
| "linter": { | ||
| "enabled": true, | ||
| "rules": { | ||
| "recommended": true, | ||
| "correctness": { | ||
| "noUnusedVariables": "error" | ||
| }, | ||
| "suspicious": { | ||
| "noExplicitAny": "warn" | ||
| }, | ||
| "style": { | ||
| "useConst": "error" | ||
| } | ||
| } | ||
| }, | ||
| "javascript": { | ||
| "formatter": { | ||
| "quoteStyle": "single", | ||
| "semicolons": "asNeeded" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||
| import { createExtensionAccessor } from '@chainlink/cre-sdk-javy-plugin/runtime/validate-extension' | ||||||
| import { z } from 'zod' | ||||||
|
|
||||||
| const rustBetaSchema = z.object({ | ||||||
| greet: z.function().args().returns(z.string()), | ||||||
| }) | ||||||
|
|
||||||
| export type RustBeta = z.infer<typeof rustBetaSchema> | ||||||
|
|
||||||
| declare global { | ||||||
| var rustBeta: RustBeta | ||||||
| } | ||||||
|
|
||||||
| // biome-ignore lint/suspicious/noRedeclare: global augmentation declares rustBeta; this export is the validated accessor | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I see an error in Cursor without it. |
||||||
| export const rustBeta = createExtensionAccessor('rustBeta', rustBetaSchema) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "@chainlink/cre-rust-inject-beta", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "description": "Example Rust extension (beta) for CRE rust-inject demos — crate source.", | ||
| "scripts": { | ||
| "check": "biome check --write ${BIOME_PATHS:-.}", | ||
| "check:ci": "biome ci .", | ||
| "typecheck": "tsc" | ||
| }, | ||
| "files": [ | ||
| "src", | ||
| "Cargo.toml", | ||
| "index.ts" | ||
| ], | ||
| "keywords": [], | ||
| "license": "BUSL-1.1", | ||
| "peerDependencies": { | ||
| "@chainlink/cre-sdk-javy-plugin": ">=1.0.0", | ||
| "zod": ">=3.0.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| use cre_wasm_exports::extend_wasm_exports; | ||
| use javy_plugin_api::javy::quickjs::prelude::*; | ||
| use javy_plugin_api::javy::quickjs::{Ctx, Object}; | ||
|
|
||
| pub fn register(ctx: &Ctx<'_>) { | ||
| let obj = Object::new(ctx.clone()).unwrap(); | ||
| obj.set( | ||
| "greet", | ||
| Func::from(|| -> String { "Hello from beta".to_string() }), | ||
| ) | ||
| .unwrap(); | ||
| extend_wasm_exports(ctx, "rustBeta", obj); | ||
| } |
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.
Same here.
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 see
"Shouldn't redeclare 'rustAlpha'. Consider to delete it or rename it.biomelint/suspicious/noRedeclare" if I remove this one.