Skip to content

Commit cec8f75

Browse files
authored
Merge pull request #222 from smartcontractkit/rtinianov_multi_javy_2
Allow easier customization of rust plugins
2 parents f6edcee + e8929d8 commit cec8f75

66 files changed

Lines changed: 2960 additions & 373 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Bun
2222
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
2323
with:
24-
bun-version: latest
24+
bun-version: 1.3.12
2525

2626
- name: Install dependencies
2727
run: bun install --frozen-lockfile
@@ -78,7 +78,7 @@ jobs:
7878
- name: Setup Bun
7979
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
8080
with:
81-
bun-version: latest
81+
bun-version: 1.3.12
8282

8383
- name: Cache Bun dependencies
8484
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
@@ -94,7 +94,7 @@ jobs:
9494
~/.cargo/registry
9595
~/.cargo/git
9696
~/.cache/javy
97-
key: ${{ runner.os }}-cre-plugin-v8.1.0-${{ hashFiles('packages/cre-sdk-javy-plugin/src/javy_chainlink_sdk/Cargo.lock', 'packages/cre-sdk-javy-plugin/src/javy_chainlink_sdk/rust-toolchain.toml', 'packages/cre-sdk-javy-plugin/scripts/build-plugin-local.sh', 'packages/cre-sdk-javy-plugin/scripts/print-javy-path-for-build.ts', 'packages/cre-sdk-javy-plugin/scripts/ensure-javy.ts', 'packages/cre-sdk-javy-plugin/Dockerfile') }}
97+
key: ${{ runner.os }}-cre-plugin-v8.1.0-${{ hashFiles('packages/cre-sdk-javy-plugin/src/javy_chainlink_sdk/Cargo.lock', 'packages/cre-sdk-javy-plugin/src/cre_generated_host.Cargo.lock', 'packages/cre-sdk-javy-plugin/src/javy_chainlink_sdk/rust-toolchain.toml', 'packages/cre-sdk-javy-plugin/scripts/build-plugin-local.sh', 'packages/cre-sdk-javy-plugin/scripts/print-javy-path-for-build.ts', 'packages/cre-sdk-javy-plugin/scripts/ensure-javy.ts', 'packages/cre-sdk-javy-plugin/Dockerfile') }}
9898

9999
- name: Install dependencies
100100
run: bun install --frozen-lockfile
@@ -141,3 +141,9 @@ jobs:
141141
env:
142142
CRE_API_KEY: ${{ secrets.CRE_CLI_API_KEY }}
143143
run: ./scripts/e2e/simulate-log-trigger.sh
144+
145+
# Rust extension examples: build cre-rust-inject-alpha, compile workflows, simulate.
146+
- name: E2E - Simulate rust-inject workflows
147+
env:
148+
CRE_API_KEY: ${{ secrets.CRE_CLI_API_KEY }}
149+
run: ./scripts/e2e/simulate-rust-inject.sh

bun.lock

Lines changed: 57 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
target/
3+
Cargo.lock
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "alpha"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
crate-type = ["lib"]
8+
9+
[dependencies]
10+
cre_wasm_exports = { path = "../cre-sdk-javy-plugin/src/cre_wasm_exports" }
11+
javy-plugin-api = "6.0.0"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Build alpha.plugin.wasm using the workspace @chainlink/cre-sdk-javy-plugin.
2+
JAVY_PLUGIN := $(abspath ../cre-sdk-javy-plugin)
3+
4+
.PHONY: build clean
5+
6+
build: dist/alpha.plugin.wasm
7+
8+
dist/alpha.plugin.wasm: Cargo.toml src/lib.rs
9+
mkdir -p dist
10+
CRE_SDK_JAVY_PLUGIN_HOME="$(JAVY_PLUGIN)" bun "$(JAVY_PLUGIN)/scripts/build-plugin.ts" \
11+
--cre-exports . \
12+
-o ./dist/alpha.plugin.wasm
13+
14+
clean:
15+
rm -rf dist
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.3.14/schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"includes": ["**/*.ts", "**/*.json"]
11+
},
12+
"formatter": {
13+
"enabled": true,
14+
"indentStyle": "tab",
15+
"lineWidth": 100
16+
},
17+
"assist": {
18+
"enabled": true
19+
},
20+
"linter": {
21+
"enabled": true,
22+
"rules": {
23+
"recommended": true,
24+
"correctness": {
25+
"noUnusedVariables": "error"
26+
},
27+
"suspicious": {
28+
"noExplicitAny": "warn"
29+
},
30+
"style": {
31+
"useConst": "error"
32+
}
33+
}
34+
},
35+
"javascript": {
36+
"formatter": {
37+
"quoteStyle": "single",
38+
"semicolons": "asNeeded"
39+
}
40+
}
41+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createExtensionAccessor } from '@chainlink/cre-sdk-javy-plugin/runtime/validate-extension'
2+
import { z } from 'zod'
3+
4+
const rustAlphaSchema = z.object({
5+
greet: z.function().args().returns(z.string()),
6+
})
7+
8+
export type RustAlpha = z.infer<typeof rustAlphaSchema>
9+
10+
declare global {
11+
var rustAlpha: RustAlpha
12+
}
13+
14+
// biome-ignore lint/suspicious/noRedeclare: global augmentation declares rustAlpha; this export is the validated accessor
15+
export const rustAlpha = createExtensionAccessor('rustAlpha', rustAlphaSchema)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@chainlink/cre-rust-inject-alpha",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"description": "Example Rust extension (alpha) for CRE rust-inject demos — packaged plugin wasm + crate source.",
7+
"scripts": {
8+
"check": "biome check --write ${BIOME_PATHS:-.}",
9+
"check:ci": "biome ci .",
10+
"typecheck": "tsc"
11+
},
12+
"files": [
13+
"dist",
14+
"src",
15+
"Cargo.toml",
16+
"index.ts"
17+
],
18+
"keywords": [],
19+
"license": "BUSL-1.1",
20+
"peerDependencies": {
21+
"@chainlink/cre-sdk-javy-plugin": ">=1.0.0",
22+
"zod": ">=3.0.0"
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use cre_wasm_exports::extend_wasm_exports;
2+
use javy_plugin_api::javy::quickjs::prelude::*;
3+
use javy_plugin_api::javy::quickjs::{Ctx, Object};
4+
5+
pub fn register(ctx: &Ctx<'_>) {
6+
let obj = Object::new(ctx.clone()).unwrap();
7+
obj.set(
8+
"greet",
9+
Func::from(|| -> String { "Hello from alpha".to_string() }),
10+
)
11+
.unwrap();
12+
extend_wasm_exports(ctx, "rustAlpha", obj);
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["ESNext"],
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
"moduleDetection": "force",
7+
"allowJs": true,
8+
"moduleResolution": "bundler",
9+
"allowImportingTsExtensions": true,
10+
"verbatimModuleSyntax": true,
11+
"noEmit": true,
12+
"strict": true,
13+
"skipLibCheck": true,
14+
"types": []
15+
},
16+
"include": ["index.ts"]
17+
}

0 commit comments

Comments
 (0)