# Rust and Cargo

Run Rust workspace tasks through Nx without replacing Cargo.


Use Cargo for Rust builds and dependencies, with Nx coordinating those tasks alongside your JavaScript and other projects. Megamono discovers Cargo workspace members and connects local path dependencies.

## Add to your workspace

Check the [Node.js and Nx requirements](/docs/workflows/requirements#platform-plugins) for this plugin before installing.

Install `@megamono/nx-cargo` as a development dependency using your workspace's package manager. Merge this entry into the existing `plugins` list in `nx.json`:

```json
{
  "plugins": [
    "@megamono/nx-cargo"
  ]
}
```

Run `npm exec -- nx show projects` to find your project, then `npm exec -- nx show project <project>` to see its tasks. Replace `<project>` with the name from the list.

## Work with Rust projects

Install Cargo before inspecting the graph. Each Cargo workspace member becomes an Nx project; the virtual workspace root does not become a separate package. Build and test commands select the appropriate Cargo package.

Plugin options such as `features`, `allFeatures`, `noDefaultFeatures`, `profile`, and `target` customize the inferred commands.

## Execution and release checks

The Cargo plugin uses `@megamono/nx-cargo:run` with a tool and argument array rather than a shell command. It preserves paths containing spaces on Windows, Linux, and macOS.

Plugin options `locked: true` and `allTargets: true` add `--locked` and `--all-targets` to Cargo build, test, and Clippy. `denyWarnings: true` adds `-- -D warnings` to Clippy. Default lint does not imply those stricter release settings. Merge the options into your existing plugin registration; do not replace unrelated options.

Inspect the resulting targets with `npm exec -- nx show project <project>`. Existing explicit tasks remain repository-owned. Test actual native execution on each operating system you support; graph discovery is not Windows or release qualification.

## Cache deliberately

New inferred native targets default to `cache: false`. Older targets and explicit cache overrides need review. Before opting in, account for compiler and Cargo versions, lockfiles, features, target/profile, SDKs, linkers, environment, build scripts and external inputs, and exact output paths. Generic Nx source inputs do not capture all of these.

Do not restore signed or notarized artifacts from an unqualified cache. Signing, notarization, credentials, and release approval remain separate repository-owned work.

## Tauri applications

Tauri projects are grouped with their frontend rather than treating `src-tauri` as an unrelated app. If you already have an npm script named `tauri`, set `tauriTargetName` to a different name, such as `tauri-build`, to avoid a target-name conflict.

The development runner resolves an app-owned `@tauri-apps/cli` locally rather than downloading one or using a global npm shim. Cargo-only projects use the `cargo tauri` subcommand. Keep Tauri packaging, platform SDKs, and signing qualification in your own release workflow.
