feat(toolchain): add automatic bundled Rust toolchain fallback and integrate with CLI/CargoRunner

This commit is contained in:
2026-02-09 20:57:52 +00:00
parent 18dc4c3a79
commit 85273e2933
10 changed files with 218 additions and 43 deletions

View File

@@ -9,21 +9,23 @@ export interface ICargoRunResult {
export class CargoRunner {
private shell: plugins.smartshell.Smartshell;
private rustDir: string;
private envPrefix: string;
constructor(rustDir: string) {
constructor(rustDir: string, envPrefix: string = '') {
this.rustDir = rustDir;
this.envPrefix = envPrefix;
this.shell = new plugins.smartshell.Smartshell({
executor: 'bash',
});
}
public async checkCargoInstalled(): Promise<boolean> {
const result = await this.shell.execSilent('cargo --version');
const result = await this.shell.execSilent(`${this.envPrefix}cargo --version`);
return result.exitCode === 0;
}
public async getCargoVersion(): Promise<string> {
const result = await this.shell.execSilent('cargo --version');
const result = await this.shell.execSilent(`${this.envPrefix}cargo --version`);
return result.stdout.trim();
}
@@ -39,7 +41,7 @@ export class CargoRunner {
const profile = options.debug ? '' : ' --release';
const targetFlag = options.target ? ` --target ${options.target}` : '';
const command = `cd ${this.rustDir} && cargo build${profile}${targetFlag}`;
const command = `${this.envPrefix}cd ${this.rustDir} && cargo build${profile}${targetFlag}`;
console.log(`Running: cargo build${profile}${targetFlag}`);
const result = await this.shell.exec(command);
@@ -55,20 +57,20 @@ export class CargoRunner {
* Ensures a rustup target is installed. If not present, installs it via `rustup target add`.
*/
public async ensureTarget(triple: string): Promise<void> {
const listResult = await this.shell.execSilent('rustup target list --installed');
const listResult = await this.shell.execSilent(`${this.envPrefix}rustup target list --installed`);
const installedTargets = listResult.stdout.split('\n').map((l) => l.trim());
if (installedTargets.includes(triple)) {
return;
}
console.log(`Installing rustup target: ${triple}`);
const addResult = await this.shell.exec(`rustup target add ${triple}`);
const addResult = await this.shell.exec(`${this.envPrefix}rustup target add ${triple}`);
if (addResult.exitCode !== 0) {
throw new Error(`Failed to install rustup target ${triple}`);
}
}
public async clean(): Promise<ICargoRunResult> {
const command = `cd ${this.rustDir} && cargo clean`;
const command = `${this.envPrefix}cd ${this.rustDir} && cargo clean`;
const result = await this.shell.exec(command);
return {