Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overrideCargo to CargoConfig #600

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ to use this feature, replace `program` property in your launch configuration wit
"type": "lldb",
"request": "launch",
"cargo": {
// "overrideCargo": "mold -run cargo", Command to be executed instead of 'cargo'.
"args": ["test", "--no-run", "--lib"], // Cargo command line to build the debug target
// "args": ["build", "--bin=foo"] is another possibility
"filter": { // Filter applied to compilation artifacts (optional)
Expand Down
21 changes: 20 additions & 1 deletion debuggee/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@
"sourceLanguages": [
"rust"
]
}
},
{
"name": "cargo override",
"type": "lldb",
"request": "launch",
"cargo": {
"args": [
"build",
"--bin=rust-debuggee",
"--package=rust-debuggee"
],
"filter": {
"name": "rust-debuggee",
"kind": "bin"
},
"overrideCargo": "./wrapper.sh cargo"
},
"args": [],
"cwd": "${workspaceFolder}"
},
]
}
5 changes: 5 additions & 0 deletions debuggee/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

echo "Hello, this is a wrapper!" 1>&2
echo "I will run the following commands: $@" 1>&2
exec $@
18 changes: 11 additions & 7 deletions extension/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export interface CargoConfig {
filter?: {
name?: string;
kind?: string;
}
},
overrideCargo?: string
}

interface CompilationArtifact {
Expand All @@ -33,12 +34,13 @@ export class Cargo {

public async getProgramFromCargoConfig(cargoConfig: CargoConfig): Promise<string> {
let cargoArgs = cargoConfig.args;
let cargoProg = cargoConfig.overrideCargo || "cargo";
let pos = cargoArgs.indexOf('--');
// Insert either before `--` or at the end.
cargoArgs.splice(pos >= 0 ? pos : cargoArgs.length, 0, '--message-format=json');

output.appendLine('Running `cargo ' + cargoArgs.join(' ') + '`...');
let artifacts = await this.getCargoArtifacts(cargoArgs);
output.appendLine(`Running \`${cargoProg} ${cargoArgs.join(' ')}\`...`);
let artifacts = await this.getCargoArtifacts(cargoProg, cargoArgs);

output.appendLine('Raw artifacts:');
for (let artifact of artifacts) {
Expand Down Expand Up @@ -75,10 +77,10 @@ export class Cargo {
}

// Runs cargo, returns a list of compilation artifacts.
async getCargoArtifacts(cargoArgs: string[]): Promise<CompilationArtifact[]> {
async getCargoArtifacts(cargoProg: string, cargoArgs: string[]): Promise<CompilationArtifact[]> {
let artifacts: CompilationArtifact[] = [];
try {
await this.runCargo(cargoArgs,
await this.runCargo(cargoProg, cargoArgs,
message => {
if (message.reason == 'compiler-artifact') {
let isBinary = message.target.crate_types.includes('bin');
Expand Down Expand Up @@ -123,7 +125,7 @@ export class Cargo {

let metadata: any = null;

await this.runCargo(['metadata', '--no-deps', '--format-version=1'],
await this.runCargo('cargo', ['metadata', '--no-deps', '--format-version=1'],
m => { metadata = m },
stderr => { output.append(stderr); }
);
Expand Down Expand Up @@ -194,12 +196,14 @@ export class Cargo {

// Runs cargo, invokes stdout/stderr callbacks as data comes in, returns the exit code.
runCargo(
cargoProg: string,
cargoArgs: string[],
onStdoutJson: (obj: any) => void,
onStderrString: (data: string) => void
): Promise<number> {
return new Promise<number>((resolve, reject) => {
let cargo = cp.spawn('cargo', cargoArgs, {
const fullCommand = [...cargoProg.split(" "), ...cargoArgs];
let cargo = cp.spawn(fullCommand[0], fullCommand.slice(1), {
stdio: ['ignore', 'pipe', 'pipe'],
cwd: this.cargoTomlFolder,
env: mergedEnvironment(this.extraEnv),
Expand Down