rust-lang/rust · error · Error

Multiple compilation artifacts are not supported.

Error message

Multiple compilation artifacts are not supported.

What it means

Thrown by Cargo.executableFromArgs() at toolchain.ts:117-118 when getArtifacts() returns more than one CompilationArtifact. executableFromArgs() expects exactly one executable to run/debug; when multiple match (e.g. both a binary and a test binary, or multiple binaries from the same build), it cannot decide which to launch and aborts.

Source

Thrown at src/tools/rust-analyzer/editors/code/src/toolchain.ts:118

            );
        } catch (err) {
            log.error(`Cargo invocation has failed: ${err}`);
            throw new Error(`Cargo invocation has failed: ${err}`, { cause: err });
        }

        return spec.filter?.(artifacts) ?? artifacts;
    }

    async executableFromArgs(runnableArgs: CargoRunnableArgs): Promise<string> {
        const artifacts = await this.getArtifacts(
            Cargo.artifactSpec(runnableArgs.cargoArgs, runnableArgs.executableArgs),
            runnableArgs.environment,
        );

        if (artifacts.length === 0) {
            throw new Error("No compilation artifacts");
        } else if (artifacts.length > 1) {
            throw new Error("Multiple compilation artifacts are not supported.");
        }

        const artifact = unwrapUndefinable(artifacts[0]);
        return artifact.fileName;
    }

    private async runCargo(
        cargoArgs: string[],
        onStdoutJson: (obj: CompilerMessage) => void,
        onStderrString: (data: string) => void,
        env?: Record<string, string>,
    ): Promise<number> {
        const path = await cargoPath(env);
        return await new Promise((resolve, reject) => {
            const cargo = cp.spawn(path, cargoArgs, {
                stdio: ["ignore", "pipe", "pipe"],
                cwd: this.rootFolder,
                env: this.env,

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Specify the exact binary or test target in the cargoArgs (e.g. add '--bin <name>' or '--test <name>') so cargo produces a single artifact.
  2. Check the generated cargo command in the error context and narrow its scope.
  3. If this is a rust-analyzer bug (filter not narrowing correctly), report it with the cargo command and the artifact list from 'cargo build --message-format=json'.

Example fix

// before: ambiguous, produces multiple artifacts
args.cargoArgs = ['run']
// after: specify the binary explicitly
args.cargoArgs = ['run', '--bin', 'my-binary']
Defensive patterns

Strategy: validation

Validate before calling

// Before calling executableFromArgs, narrow the cargo args to a single target.
function ensureSingleArtifact(cargoArgs: string[]): string[] {
  // If no explicit --bin/--test/--example is given and the workspace has multiple bins,
  // require the caller to specify one.
  if (cargoArgs[0] === 'run' && !cargoArgs.some(a => a.startsWith('--bin') || a.startsWith('--example'))) {
    throw new Error('Multiple binaries possible. Specify --bin <name>.');
  }
  return cargoArgs;
}

Try / catch

try {
  const exe = await cargo.executableFromArgs(args);
} catch (e) {
  if (e.message === 'Multiple compilation artifacts are not supported.') {
    // Prompt user to pick which binary
    const choice = await vscode.window.showQuickPick(binNames, {
      placeHolder: 'Select which binary to run'
    });
    if (choice) {
      args.cargoArgs.push('--bin', choice);
      // retry
    }
  }
  throw e;
}

Prevention

When it happens

Trigger: getArtifacts() returns an array with length > 1 at toolchain.ts:117. This happens when: a 'run'/'build' spec is used on a crate with multiple [[bin]] targets that all match, the filter (line 64) doesn't narrow sufficiently (e.g. a non-test/non-bench build produces both a bin and a custom-build artifact that slips through), or cargo emits multiple compiler-artifact messages with executables for the same invocation.

Common situations: A workspace with multiple binary targets where the code lens resolves to an ambiguous cargo invocation; running a crate that produces both a dylib and a bin; or the artifact filter logic at lines 84-92 lets through more than expected (e.g. a profile.test flag is set on a non-test artifact).

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/8b19fb6cd26ed05b. Report an issue: GitHub.