From a22bb45df29a933d8603cccbf9e4942c6775bec6 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 5 Apr 2026 15:38:26 +0200 Subject: [PATCH 1/4] feat: use pre-built Cargo target in CI Signed-off-by: David Dal Busco --- src/constants/dev.constants.ts | 3 ++- .../functions/build/build.rust.services.ts | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/constants/dev.constants.ts b/src/constants/dev.constants.ts index e11e265..3c8ce91 100644 --- a/src/constants/dev.constants.ts +++ b/src/constants/dev.constants.ts @@ -54,7 +54,8 @@ export const SPUTNIK_INDEX_RS = 'sputnik_index.rs'; export const DEPLOY_SPUTNIK_SCRIPT_PATH = join(DEPLOY_LOCAL_REPLICA_PATH, SPUTNIK_INDEX_MJS); export const DEPLOY_SPUTNIK_FUNCTIONS_PATH = join(DEPLOY_LOCAL_REPLICA_PATH, SPUTNIK_INDEX_RS); -export const JUNO_ACTION_SPUTNIK_PATH = '/juno/src/sputnik'; +export const JUNO_ACTION_PROJECT_PATH = '/juno'; +export const JUNO_ACTION_SPUTNIK_PATH = join(JUNO_ACTION_PROJECT_PATH, 'src', 'sputnik'); export const SPUTNIK_CARGO_TOML = join(JUNO_ACTION_SPUTNIK_PATH, CARGO_TOML); export const SATELLITE_WASM = 'satellite.wasm'; diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index ef12a19..424b030 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -14,12 +14,14 @@ import { } from '../../../constants/build.constants'; import { DEPLOY_SPUTNIK_SCRIPT_PATH, + JUNO_ACTION_PROJECT_PATH, JUNO_PACKAGE_JSON_PATH, SATELLITE_OUTPUT, SATELLITE_PROJECT_NAME, SPUTNIK_PROJECT_NAME, TARGET_PATH } from '../../../constants/dev.constants'; +import {ENV} from '../../../env'; import type {BuildArgs, BuildType} from '../../../types/build'; import {checkIcpBindgen} from '../../../utils/build.bindgen.utils'; import {checkCandidExtractor, checkIcWasm, checkWasi2ic} from '../../../utils/build.cargo.utils'; @@ -69,8 +71,10 @@ export const buildRust = async ({ const defaultProjectArgs = ['-p', SATELLITE_PROJECT_NAME]; const cargoTarget = target ?? 'wasm32-unknown-unknown'; - const cargoReleaseDir = join(process.cwd(), 'target'); - const cargoOutputWasm = join(cargoReleaseDir, cargoTarget, 'release', 'satellite.wasm'); + const cargoReleaseDir = join(ENV.ci ? JUNO_ACTION_PROJECT_PATH : process.cwd(), 'target'); + + const cargoOutputPath = join(process.cwd(), 'target', cargoTarget, 'release'); + const cargoOutputWasm = join(cargoOutputPath, `${SATELLITE_PROJECT_NAME}.wasm`); const args = [ 'build', @@ -108,6 +112,10 @@ export const buildRust = async ({ return; } + if (ENV.ci) { + await mkdir(cargoOutputPath, {recursive: true}); + } + switch (target) { case 'wasm32-wasip1': { spinner.text = 'Converting WASI to IC...'; @@ -130,6 +138,15 @@ export const buildRust = async ({ break; } default: { + if (ENV.ci) { + // When build in the CI the satellite.wasm needs to be copied as if had been buildin the projects target + // to comply with the next steps of the tooling + await copyFile( + join(cargoReleaseDir, cargoTarget, 'release', `${SATELLITE_PROJECT_NAME}.wasm`), + cargoOutputWasm + ); + } + await prepareJunoPkgForSatellite({buildType}); } } From 1eed819980554aba4724148335ccf4f8c8deaaa4 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 6 Apr 2026 16:47:43 +0200 Subject: [PATCH 2/4] feat: same RUSTFLAGS as on Juno main repo Signed-off-by: David Dal Busco --- src/services/functions/build/build.rust.services.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index 424b030..a52ed6c 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -87,9 +87,17 @@ export const buildRust = async ({ cargoReleaseDir ]; + const baseRustFlags = + '--cfg getrandom_backend="custom" -A deprecated -C link-args=-zstack-size=3000000'; + + // In CI, RUSTFLAGS must exactly match those used during the pre-build step in the Docker image + // (see ./docker/build-canister in the Juno repo). Any difference invalidates Cargo's fingerprints + // and causes a full recompile of all dependencies. In other words, it would slow down the build. + const rustFlags = `${baseRustFlags}${ENV.ci ? ' --remap-path-prefix /home/apprunner/.cargo=/cargo' : ''}`; + const env = { ...process.env, - RUSTFLAGS: '--cfg getrandom_backend="custom" -A deprecated', + RUSTFLAGS: rustFlags, ...(target === 'wasm32-wasip1' && {DEV_SCRIPT_PATH: DEPLOY_SPUTNIK_SCRIPT_PATH}) }; From 5477c560e9c586465586291d48cf6444d3eec523 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 6 Apr 2026 17:48:22 +0200 Subject: [PATCH 3/4] feat: flags order Signed-off-by: David Dal Busco --- src/services/functions/build/build.rust.services.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index a52ed6c..35382a0 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -87,13 +87,18 @@ export const buildRust = async ({ cargoReleaseDir ]; - const baseRustFlags = - '--cfg getrandom_backend="custom" -A deprecated -C link-args=-zstack-size=3000000'; + const REMAP_PATH_PREFIX = '{REMAP_PATH_PREFIX}'; + + const baseRustFlags = `-A deprecated ${REMAP_PATH_PREFIX} -C link-args=-zstack-size=3000000 --cfg getrandom_backend="custom"`; // In CI, RUSTFLAGS must exactly match those used during the pre-build step in the Docker image // (see ./docker/build-canister in the Juno repo). Any difference invalidates Cargo's fingerprints // and causes a full recompile of all dependencies. In other words, it would slow down the build. - const rustFlags = `${baseRustFlags}${ENV.ci ? ' --remap-path-prefix /home/apprunner/.cargo=/cargo' : ''}`; + // ⚠️ To get the same fingerprints the order of the flags must be similar as well. + const rustFlags = baseRustFlags.replace( + REMAP_PATH_PREFIX, + ENV.ci ? ' --remap-path-prefix /home/apprunner/.cargo=/cargo' : '' + ); const env = { ...process.env, From 966cc1cf23085d3e448908840eb9959a9a7e613f Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 6 Apr 2026 18:16:20 +0200 Subject: [PATCH 4/4] docs: move comment Signed-off-by: David Dal Busco --- src/services/functions/build/build.rust.services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index 35382a0..616f36e 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -89,12 +89,12 @@ export const buildRust = async ({ const REMAP_PATH_PREFIX = '{REMAP_PATH_PREFIX}'; + // ⚠️ To get the same fingerprints for the Cargo build, the order of the flags must be similar between the CLI and the Docker scripts. const baseRustFlags = `-A deprecated ${REMAP_PATH_PREFIX} -C link-args=-zstack-size=3000000 --cfg getrandom_backend="custom"`; // In CI, RUSTFLAGS must exactly match those used during the pre-build step in the Docker image // (see ./docker/build-canister in the Juno repo). Any difference invalidates Cargo's fingerprints // and causes a full recompile of all dependencies. In other words, it would slow down the build. - // ⚠️ To get the same fingerprints the order of the flags must be similar as well. const rustFlags = baseRustFlags.replace( REMAP_PATH_PREFIX, ENV.ci ? ' --remap-path-prefix /home/apprunner/.cargo=/cargo' : ''