Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/constants/dev.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
36 changes: 33 additions & 3 deletions src/services/functions/build/build.rust.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand All @@ -83,9 +87,22 @@ export const buildRust = async ({
cargoReleaseDir
];

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.
const rustFlags = baseRustFlags.replace(
REMAP_PATH_PREFIX,
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})
};

Expand All @@ -108,6 +125,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...';
Expand All @@ -130,6 +151,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});
}
}
Expand Down
Loading