Installing Rust toolchain during pages build

Hi I am using a Rust module compiled to WASM in my Pages project. Since Rust isn't supported natively I have the following script to install it duringpostinstall While it works most of the time, invoking the cargo-component build step gives me an error sh: 1: cargo: not found. I guess this is because the current shell session is not configured correctly. I tried doing it manually with by invoking source $HOME/.cargo/env but the build environment does not seem to have access to the source command... /bin/sh: 1: source: not found. Now I'm looking for a way to configure the current shell to have access to the rust toolchain commands. Rust install script:
import { execSync } from 'node:child_process';

if (process.env.CF_PAGES !== '1') {
console.log('Skipping Rust setup: Not on Cloudflare Pages CI.');
process.exit(0);
}

console.log('Setting up Rust toolchain...');
execSync('curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none', {
stdio: 'inherit',
});
process.env.PATH = `${process.env.PATH}:${process.env.HOME}/.cargo/bin`;

// TODO: https://github.com/rust-lang/rustup/issues/2686 use rustup ensure to sync with rust-toolchain.toml
execSync('rustup install nightly', { stdio: 'inherit' });
console.log('Rust toolchain setup successfully!');

execSync('cargo install cargo-component', { stdio: 'inherit' });
console.log('cargo-component installed successfully!');
import { execSync } from 'node:child_process';

if (process.env.CF_PAGES !== '1') {
console.log('Skipping Rust setup: Not on Cloudflare Pages CI.');
process.exit(0);
}

console.log('Setting up Rust toolchain...');
execSync('curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none', {
stdio: 'inherit',
});
process.env.PATH = `${process.env.PATH}:${process.env.HOME}/.cargo/bin`;

// TODO: https://github.com/rust-lang/rustup/issues/2686 use rustup ensure to sync with rust-toolchain.toml
execSync('rustup install nightly', { stdio: 'inherit' });
console.log('Rust toolchain setup successfully!');

execSync('cargo install cargo-component', { stdio: 'inherit' });
console.log('cargo-component installed successfully!');
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server