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 @@ -52,4 +52,5 @@ export const DEPLOY_SPUTNIK_PATH = join(DEPLOY_LOCAL_REPLICA_PATH, SPUTNIK_INDEX
export const JUNO_ACTION_SPUTNIK_PATH = '/juno/src/sputnik';
export const SPUTNIK_CARGO_TOML = join(JUNO_ACTION_SPUTNIK_PATH, CARGO_TOML);

export const SATELLITE_OUTPUT = join(DEPLOY_LOCAL_REPLICA_PATH, 'satellite.wasm');
export const SATELLITE_WASM = 'satellite.wasm';
export const SATELLITE_OUTPUT = join(DEPLOY_LOCAL_REPLICA_PATH, SATELLITE_WASM);
3 changes: 3 additions & 0 deletions src/services/functions/build/build.rust.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {formatTime} from '../../../utils/format.utils';
import {readPackageJson} from '../../../utils/pkg.utils';
import {readEmulatorConfigAndCreateDeployTargetDir} from '../../emulator.services';
import {prepareJunoPkgForSatellite, prepareJunoPkgForSputnik} from './build.metadata.services';
import {dispatchEmulatorTouchSatellite} from './touch.services';

export const buildRust = async ({
paths,
Expand Down Expand Up @@ -159,6 +160,8 @@ export const buildRust = async ({
} finally {
spinner.stop();
}

await dispatchEmulatorTouchSatellite();
};

const SATELLITE_DID_FILE = join(DEVELOPER_PROJECT_SATELLITE_PATH, 'satellite.did');
Expand Down
18 changes: 11 additions & 7 deletions src/services/functions/build/build.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {type BuildArgs} from '../../../types/build';
import {buildArgs} from '../../../utils/build.utils';
import {buildJavaScript, buildTypeScript} from './build.javascript.services';
import {buildRust} from './build.rust.services';
import {dispatchEmulatorTouchSputnik} from './touch.services';

export const build = async (args?: string[]) => {
const {watch, ...params} = buildArgs(args);
Expand Down Expand Up @@ -116,14 +117,17 @@ const executeSputnikBuild = async ({

const withToolchain = nonNullish(paths?.cargo) || ENV.ci;

if (withToolchain) {
const rustPaths = {
...paths,
cargo: paths?.cargo ?? SPUTNIK_CARGO_TOML
};

await buildRust({paths: rustPaths, target: 'wasm32-wasip1'});
if (!withToolchain) {
await dispatchEmulatorTouchSputnik();
return;
}

const rustPaths = {
...paths,
cargo: paths?.cargo ?? SPUTNIK_CARGO_TOML
};

await buildRust({paths: rustPaths, target: 'wasm32-wasip1'});
};

export const watchBuild = ({watch, paths, ...params}: BuildArgs) => {
Expand Down
60 changes: 60 additions & 0 deletions src/services/functions/build/touch.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {red} from 'kleur';
import {readEmulatorConfig} from '../../../configs/emulator.config';
import {SATELLITE_WASM, SPUTNIK_INDEX_MJS} from '../../../constants/dev.constants';
import {EMULATOR_SKYLAB} from '../../../constants/emulator.constants';

export const dispatchEmulatorTouchSatellite = async () => {
await dispatchTouch({filename: `${SATELLITE_WASM}.gz`});
};

export const dispatchEmulatorTouchSputnik = async () => {
await dispatchTouch({filename: SPUTNIK_INDEX_MJS});
};

/**
* Workaround Podman and Apple container issues on macOS:
* - https://github.com/containers/podman/issues/22343
* - https://github.com/apple/container/issues/141
*/
const dispatchTouch = async ({filename}: {filename: string}) => {
if (process.platform !== 'darwin') {
// Workaround only required on macOS. Not sure if it's required on old Intel process, maybe not but
// for simplicity reasons let's consider all Apple devices require the workaround.
return;
}

const parsedResult = await readEmulatorConfig();

if (!parsedResult.success) {
return;
}

const {
config: {
config,
derivedConfig: {emulatorType, runner}
}
} = parsedResult;

if (runner === 'docker') {
// No need of the workaround for Docker
return;
}

const adminPort = config[emulatorType]?.ports?.admin ?? EMULATOR_SKYLAB.ports.admin;

try {
const response = await fetch(
`http://localhost:${adminPort}/admin/touch?file=${encodeURIComponent(filename)}`,
{signal: AbortSignal.timeout(5000)}
);

if (!response.ok) {
console.log(
red(`Invalid response from the emulator. Touching '${filename}' did not succeed.`)
);
}
} catch (_error: unknown) {
// We silence the error. Maybe the emulator is not running on purpose.
}
};