Skip to content

Commit e46c96b

Browse files
committed
Fix determinism
1 parent f391dcf commit e46c96b

File tree

9 files changed

+936
-24
lines changed

9 files changed

+936
-24
lines changed

.github/workflows/ci.yml

Lines changed: 3 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

packages/cre-sdk-javy-plugin/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ./scripts/build-plugin-docker.sh
77

88
# --- Javy CLI + host crate generation (same code path as user builds) ---
9-
FROM oven/bun:slim AS javy-cli
9+
FROM oven/bun:slim@sha256:1848dc9f700b93aa7b47f496355f4edd9015ad54db5f5ca03661c56b7ddcb72a AS javy-cli
1010

1111
ARG CRE_JAVY_VERSION=v8.1.0
1212
ENV CRE_JAVY_VERSION=${CRE_JAVY_VERSION}
@@ -46,10 +46,11 @@ COPY src/javy_chainlink_sdk/rust-toolchain.toml src/javy_chainlink_sdk/Cargo.tom
4646
RUN mkdir -p /build/src/javy_chainlink_sdk/src && echo '' > /build/src/javy_chainlink_sdk/src/lib.rs
4747

4848
COPY --from=javy-cli /build/cre_generated_host /build/cre_generated_host
49+
COPY src/cre_generated_host.Cargo.lock /build/cre_generated_host/Cargo.lock
4950

5051
WORKDIR /build/cre_generated_host
5152
RUN --mount=type=cache,target=/usr/local/cargo/registry \
52-
cargo build --target wasm32-wasip1 --release 2>/dev/null || true
53+
cargo build --locked --target wasm32-wasip1 --release 2>/dev/null || true
5354

5455
COPY src/cre_wasm_exports/src /build/src/cre_wasm_exports/src
5556
RUN touch /build/src/cre_wasm_exports/src/lib.rs
@@ -58,7 +59,7 @@ COPY src/javy_chainlink_sdk/src /build/src/javy_chainlink_sdk/src
5859
RUN touch /build/src/javy_chainlink_sdk/src/lib.rs
5960

6061
RUN --mount=type=cache,target=/usr/local/cargo/registry \
61-
cargo build --target wasm32-wasip1 --release
62+
cargo build --locked --target wasm32-wasip1 --release
6263

6364
RUN javy init-plugin --deterministic \
6465
target/wasm32-wasip1/release/cre_generated_host.wasm \

packages/cre-sdk-javy-plugin/bin/compile-workflow.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bun
2-
import { existsSync, mkdtempSync, rmSync } from 'node:fs'
2+
import { copyFileSync, existsSync, mkdtempSync, rmSync } from 'node:fs'
33
import { tmpdir } from 'node:os'
44
import { dirname, join, resolve } from 'node:path'
55
import { fileURLToPath } from 'node:url'
@@ -23,14 +23,15 @@ function findBuiltWasm(targetDir: string): string {
2323

2424
async function main() {
2525
const argv = process.argv.slice(2)
26-
const { creExports, plugin: pluginArg, rest } = parseCompileFlags(argv)
26+
const { creExports, plugin: pluginArg, lockfile: lockfileArg, rest } = parseCompileFlags(argv)
2727

2828
if (rest.length < 2) {
2929
console.error(
30-
'Usage: compile-workflow.ts [--plugin <path>] [--cre-exports <crate-dir>]... <input.js> <output.wasm>',
30+
'Usage: compile-workflow.ts [--plugin <path>] [--cre-exports <crate-dir>]... [--lockfile <path>] <input.js> <output.wasm>',
3131
)
3232
console.error(' --plugin: use pre-built .plugin.wasm (mutually exclusive with --cre-exports)')
3333
console.error(' --cre-exports: path to a Rust extension crate directory (repeat for multiple)')
34+
console.error(' --lockfile: Cargo.lock to use for reproducible builds')
3435
console.error(' If neither given, uses default pre-built plugin from dist/')
3536
process.exit(1)
3637
}
@@ -64,15 +65,21 @@ async function main() {
6465
const tmpDir = mkdtempSync(join(tmpdir(), 'cre-host-'))
6566
const sharedTargetDir = resolve(pluginDir, '.cargo-target')
6667
try {
67-
const extensions = resolveExtensions(creExports)
68-
generateHostCrate(tmpDir, pluginDir, extensions)
69-
70-
const [, javyPath] = await Promise.all([
71-
run('cargo', ['build', '--target', 'wasm32-wasip1', '--release'], tmpDir, {
72-
CARGO_TARGET_DIR: sharedTargetDir,
73-
}),
74-
ensureJavy({ version: JAVY_VERSION }),
75-
])
68+
const extensions = resolveExtensions(creExports)
69+
generateHostCrate(tmpDir, pluginDir, extensions)
70+
71+
const cargoArgs = ['build', '--target', 'wasm32-wasip1', '--release']
72+
if (lockfileArg) {
73+
copyFileSync(resolve(lockfileArg), join(tmpDir, 'Cargo.lock'))
74+
cargoArgs.splice(1, 0, '--locked')
75+
}
76+
77+
const [, javyPath] = await Promise.all([
78+
run('cargo', cargoArgs, tmpDir, {
79+
CARGO_TARGET_DIR: sharedTargetDir,
80+
}),
81+
ensureJavy({ version: JAVY_VERSION }),
82+
])
7683

7784
const builtWasm = findBuiltWasm(sharedTargetDir)
7885
pluginPath = resolve(tmpDir, 'cre.plugin.wasm')
0 Bytes
Binary file not shown.

packages/cre-sdk-javy-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"cre-compile-workflow": "bin/compile-workflow.ts"
88
},
99
"scripts": {
10-
"build": "bun run clean && bun scripts/compile-javy-sdk-plugin.ts",
10+
"build": "bun run clean && bun scripts/compile-javy-sdk-plugin.ts --lockfile src/cre_generated_host.Cargo.lock",
1111
"build:plugin-wasm": "./scripts/build-plugin-docker.sh",
1212
"clean": "rm -rf dist",
1313
"check": "biome check --write ${BIOME_PATHS:-.}",

packages/cre-sdk-javy-plugin/scripts/build-plugin.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Builds a Javy plugin .plugin.wasm from extension crates.
44
* Used by examples that need a pre-built plugin (e.g. lib_alpha).
55
*/
6-
import { existsSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs'
6+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs'
77
import { tmpdir } from 'node:os'
88
import path, { dirname, join, resolve } from 'node:path'
99
import { fileURLToPath } from 'node:url'
@@ -27,17 +27,23 @@ async function main() {
2727
const argv = process.argv.slice(2)
2828
const creExports: string[] = []
2929
let outputPath: string | null = null
30+
let lockfilePath: string | null = null
3031
for (let i = 0; i < argv.length; i++) {
3132
if (argv[i] === '--cre-exports' && i + 1 < argv.length) {
3233
creExports.push(argv[i + 1])
3334
i++
3435
} else if (argv[i] === '-o' && i + 1 < argv.length) {
3536
outputPath = argv[i + 1]
3637
i++
38+
} else if (argv[i] === '--lockfile' && i + 1 < argv.length) {
39+
lockfilePath = resolve(argv[i + 1])
40+
i++
3741
}
3842
}
3943
if (creExports.length === 0 || outputPath === null) {
40-
console.error('Usage: build-plugin.ts --cre-exports <path>... -o <output.plugin.wasm>')
44+
console.error(
45+
'Usage: build-plugin.ts --cre-exports <path>... -o <output.plugin.wasm> [--lockfile <path>]',
46+
)
4147
process.exit(1)
4248
}
4349

@@ -47,8 +53,14 @@ async function main() {
4753
const extensions = resolveExtensions(creExports)
4854
generateHostCrate(tmpDir, pluginDir, extensions)
4955

56+
const cargoArgs = ['build', '--target', 'wasm32-wasip1', '--release']
57+
if (lockfilePath) {
58+
copyFileSync(lockfilePath, join(tmpDir, 'Cargo.lock'))
59+
cargoArgs.splice(1, 0, '--locked')
60+
}
61+
5062
const [, javyPath] = await Promise.all([
51-
run('cargo', ['build', '--target', 'wasm32-wasip1', '--release'], tmpDir, {
63+
run('cargo', cargoArgs, tmpDir, {
5264
CARGO_TARGET_DIR: sharedTargetDir,
5365
}),
5466
ensureJavy({ version: JAVY_VERSION }),

packages/cre-sdk-javy-plugin/scripts/compile-javy-sdk-plugin.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,34 @@ function findBuiltWasm(targetDir: string): string {
2121
throw new Error(`Build succeeded but WASM not found in ${releaseDir}`)
2222
}
2323

24+
function parseLockfileArg(): string | null {
25+
const argv = process.argv.slice(2)
26+
for (let i = 0; i < argv.length; i++) {
27+
if (argv[i] === '--lockfile' && i + 1 < argv.length) {
28+
return resolve(argv[i + 1])
29+
}
30+
}
31+
return null
32+
}
33+
2434
export const main = async () => {
2535
console.info('\n\n---> Compiling Chainlink SDK Javy plugin (Rust) \n\n')
2636

37+
const lockfilePath = parseLockfileArg()
2738
const tmpDir = mkdtempSync(join(tmpdir(), 'cre-plugin-'))
2839
const sharedTargetDir = resolve(pluginDir, '.cargo-target')
2940

3041
try {
3142
generateHostCrate(tmpDir, pluginDir, [])
3243

44+
const cargoArgs = ['build', '--target', 'wasm32-wasip1', '--release']
45+
if (lockfilePath) {
46+
copyFileSync(lockfilePath, join(tmpDir, 'Cargo.lock'))
47+
cargoArgs.splice(1, 0, '--locked')
48+
}
49+
3350
const [, javyPath] = await Promise.all([
34-
run('cargo', ['build', '--target', 'wasm32-wasip1', '--release'], tmpDir, {
51+
run('cargo', cargoArgs, tmpDir, {
3552
CARGO_TARGET_DIR: sharedTargetDir,
3653
}),
3754
ensureJavy({ version: JAVY_VERSION }),
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
export function parseCompileFlags(argv: string[]): {
22
creExports: string[]
33
plugin: string | null
4+
lockfile: string | null
45
rest: string[]
56
} {
67
const creExports: string[] = []
78
let plugin: string | null = null
9+
let lockfile: string | null = null
810
const rest: string[] = []
911
for (let i = 0; i < argv.length; i++) {
1012
if (argv[i] === '--cre-exports' && i + 1 < argv.length) {
@@ -13,9 +15,12 @@ export function parseCompileFlags(argv: string[]): {
1315
} else if (argv[i] === '--plugin' && i + 1 < argv.length) {
1416
plugin = argv[i + 1]
1517
i++
18+
} else if (argv[i] === '--lockfile' && i + 1 < argv.length) {
19+
lockfile = argv[i + 1]
20+
i++
1621
} else {
1722
rest.push(argv[i])
1823
}
1924
}
20-
return { creExports, plugin, rest }
25+
return { creExports, plugin, lockfile, rest }
2126
}

0 commit comments

Comments
 (0)