import { init_esm_shims, __name } from './PHXMTVK6.js';
import fs from 'fs';
import path from 'path';
import { parse } from 'toml';
import { executeToolCommand } from '@layerzerolabs/vm-tooling';

// src/commands/sync-toolchain.ts
init_esm_shims();
async function syncToolchain(context, options) {
  const filePath = path.join(options.cwd, "rust-toolchain.toml");
  if (!fs.existsSync(filePath)) {
    console.info("No rust-toolchain.toml found, skipping toolchain sync");
    return;
  }
  const parsed = parse(fs.readFileSync(filePath, "utf-8"));
  const channel = parsed.toolchain?.channel;
  if (typeof channel !== "string") {
    throw new Error(`Missing 'toolchain.channel' in ${filePath}`);
  }
  const targets = parsed.toolchain?.targets ?? [];
  const components = parsed.toolchain?.components ?? [];
  const installArgs = [
    `rustup toolchain install ${channel}`
  ];
  for (const target of targets) {
    installArgs.push(`--target ${target}`);
  }
  for (const component of components) {
    installArgs.push(`--component ${component}`);
  }
  const installCmd = installArgs.join(" ");
  const script = [
    "mkdir -p $CARGO_HOME/bin",
    "ln -sf /usr/local/cargo/bin/rustup $CARGO_HOME/bin/rustup",
    installCmd
  ].join(" && ");
  console.info(`\u{1F527} Syncing Rust toolchain: ${installCmd}`);
  await executeToolCommand(context, "stellar", [], {
    ...options,
    script,
    volumes: [
      ...options.volumes,
      {
        type: "isolate",
        containerPath: "/cache/rustup",
        name: "stellar-rustup",
        shared: true,
        locked: true
      }
    ]
  });
}
__name(syncToolchain, "syncToolchain");

export { syncToolchain };
//# sourceMappingURL=PIFLCQLQ.js.map
//# sourceMappingURL=PIFLCQLQ.js.map