@@ -14,12 +14,14 @@ import {
1414} from '../../../constants/build.constants' ;
1515import {
1616 DEPLOY_SPUTNIK_SCRIPT_PATH ,
17+ JUNO_ACTION_PROJECT_PATH ,
1718 JUNO_PACKAGE_JSON_PATH ,
1819 SATELLITE_OUTPUT ,
1920 SATELLITE_PROJECT_NAME ,
2021 SPUTNIK_PROJECT_NAME ,
2122 TARGET_PATH
2223} from '../../../constants/dev.constants' ;
24+ import { ENV } from '../../../env' ;
2325import type { BuildArgs , BuildType } from '../../../types/build' ;
2426import { checkIcpBindgen } from '../../../utils/build.bindgen.utils' ;
2527import { checkCandidExtractor , checkIcWasm , checkWasi2ic } from '../../../utils/build.cargo.utils' ;
@@ -69,8 +71,10 @@ export const buildRust = async ({
6971 const defaultProjectArgs = [ '-p' , SATELLITE_PROJECT_NAME ] ;
7072
7173 const cargoTarget = target ?? 'wasm32-unknown-unknown' ;
72- const cargoReleaseDir = join ( process . cwd ( ) , 'target' ) ;
73- const cargoOutputWasm = join ( cargoReleaseDir , cargoTarget , 'release' , 'satellite.wasm' ) ;
74+ const cargoReleaseDir = join ( ENV . ci ? JUNO_ACTION_PROJECT_PATH : process . cwd ( ) , 'target' ) ;
75+
76+ const cargoOutputPath = join ( process . cwd ( ) , 'target' , cargoTarget , 'release' ) ;
77+ const cargoOutputWasm = join ( cargoOutputPath , `${ SATELLITE_PROJECT_NAME } .wasm` ) ;
7478
7579 const args = [
7680 'build' ,
@@ -83,9 +87,22 @@ export const buildRust = async ({
8387 cargoReleaseDir
8488 ] ;
8589
90+ const REMAP_PATH_PREFIX = '{REMAP_PATH_PREFIX}' ;
91+
92+ // ⚠️ To get the same fingerprints for the Cargo build, the order of the flags must be similar between the CLI and the Docker scripts.
93+ const baseRustFlags = `-A deprecated ${ REMAP_PATH_PREFIX } -C link-args=-zstack-size=3000000 --cfg getrandom_backend="custom"` ;
94+
95+ // In CI, RUSTFLAGS must exactly match those used during the pre-build step in the Docker image
96+ // (see ./docker/build-canister in the Juno repo). Any difference invalidates Cargo's fingerprints
97+ // and causes a full recompile of all dependencies. In other words, it would slow down the build.
98+ const rustFlags = baseRustFlags . replace (
99+ REMAP_PATH_PREFIX ,
100+ ENV . ci ? ' --remap-path-prefix /home/apprunner/.cargo=/cargo' : ''
101+ ) ;
102+
86103 const env = {
87104 ...process . env ,
88- RUSTFLAGS : '--cfg getrandom_backend="custom" -A deprecated' ,
105+ RUSTFLAGS : rustFlags ,
89106 ...( target === 'wasm32-wasip1' && { DEV_SCRIPT_PATH : DEPLOY_SPUTNIK_SCRIPT_PATH } )
90107 } ;
91108
@@ -108,6 +125,10 @@ export const buildRust = async ({
108125 return ;
109126 }
110127
128+ if ( ENV . ci ) {
129+ await mkdir ( cargoOutputPath , { recursive : true } ) ;
130+ }
131+
111132 switch ( target ) {
112133 case 'wasm32-wasip1' : {
113134 spinner . text = 'Converting WASI to IC...' ;
@@ -130,6 +151,15 @@ export const buildRust = async ({
130151 break ;
131152 }
132153 default : {
154+ if ( ENV . ci ) {
155+ // When build in the CI the satellite.wasm needs to be copied as if had been buildin the projects target
156+ // to comply with the next steps of the tooling
157+ await copyFile (
158+ join ( cargoReleaseDir , cargoTarget , 'release' , `${ SATELLITE_PROJECT_NAME } .wasm` ) ,
159+ cargoOutputWasm
160+ ) ;
161+ }
162+
133163 await prepareJunoPkgForSatellite ( { buildType} ) ;
134164 }
135165 }
0 commit comments