/**
* Rust Adapter Factory
*
* Factory for creating Rust debug adapter instances.
* Implements the adapter factory interface for dependency injection.
*/
import { IDebugAdapter } from '@debugmcp/shared';
import { IAdapterFactory, AdapterDependencies, AdapterMetadata, FactoryValidationResult } from '@debugmcp/shared';
import { RustDebugAdapter } from './rust-debug-adapter.js';
import { DebugLanguage } from '@debugmcp/shared';
import { checkCargoInstallation, getCargoVersion, getRustHostTriple } from './utils/rust-utils.js';
import { resolveCodeLLDBExecutable, getCodeLLDBVersion } from './utils/codelldb-resolver.js';
/**
* Factory for creating Rust debug adapters
*/
export class RustAdapterFactory implements IAdapterFactory {
/**
* Create a new Rust debug adapter instance
*/
createAdapter(dependencies: AdapterDependencies): IDebugAdapter {
return new RustDebugAdapter(dependencies);
}
/**
* Get metadata about the Rust adapter
*/
getMetadata(): AdapterMetadata {
return {
language: DebugLanguage.RUST,
displayName: 'Rust',
version: '0.1.0',
author: 'mcp-debugger team',
description: 'Debug Rust applications using CodeLLDB',
documentationUrl: 'https://github.com/debugmcp/mcp-debugger/docs/rust',
minimumDebuggerVersion: '1.0.0',
fileExtensions: ['.rs'],
icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48cGF0aCBkPSJNMCA1MTJWMGg1MTJWNTI2LCJmaWxsPSIjMDAwIi8+PHBhdGggZD0iTTM5My4yIDIzNi42bC0zMC40LTMxLjRjLS43LS43LTEuOS0uNy0yLjYgMGwtMzAgMzFjLS43LjctLjcgMS45IDAgMi42bDMwIDMxLjRjLjcuNyAxLjkuNyAyLjYgMGwzMC40LTMxLjRjLjctLjcuNy0xLjkgMC0yLjZ6IiBmaWxsPSIjZmU3ZjJkIi8+PHBhdGggZD0iTTEyOC40IDI1NC41YzAtNy44LTYuMy0xNC4xLTE0LjEtMTQuMXMtMTQuMSA2LjMtMTQuMSAxNC4xIDYuMyAxNC4xIDE0LjEgMTQuMS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uNSAwIDIwLjktOS40IDIwLjktMjAuOXoiIGZpbGw9IiNmZTdmMmQiLz48L3N2Zz4='
};
}
/**
* Validate that the factory can create adapters in current environment
*/
async validate(): Promise<FactoryValidationResult> {
const errors: string[] = [];
const warnings: string[] = [];
let codelldbPath: string | undefined;
let codelldbVersion: string | undefined;
let cargoVersion: string | undefined;
let hostTriple: string | undefined;
// Check CodeLLDB
const resolvedCodelldb = await resolveCodeLLDBExecutable();
if (!resolvedCodelldb) {
errors.push('CodeLLDB not found. Run: npm run build:adapter');
} else {
codelldbPath = resolvedCodelldb;
codelldbVersion = await getCodeLLDBVersion() || undefined;
}
// Check Cargo
const cargoInstalled = await checkCargoInstallation();
if (!cargoInstalled) {
warnings.push('Cargo not found. Install Rust from https://rustup.rs/');
} else {
cargoVersion = await getCargoVersion() || undefined;
}
const rustHost = await getRustHostTriple();
if (rustHost) {
hostTriple = rustHost;
if (/-pc-windows-msvc/i.test(rustHost)) {
warnings.push('Rust MSVC toolchain detected. CodeLLDB works best with the GNU toolchain (x86_64-pc-windows-gnu) or DWARF debug info.');
}
}
return {
valid: errors.length === 0,
errors,
warnings,
details: {
codelldbPath,
codelldbVersion,
cargoVersion,
hostTriple,
platform: process.platform,
arch: process.arch,
timestamp: new Date().toISOString()
}
};
}
}