Skip to content

Commit 0846a0a

Browse files
committed
heft-cargo-test-plugin
1 parent 3e35f5a commit 0846a0a

17 files changed

+1528
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# @rushstack/heft-cargo-plugin
2+
3+
This is a Heft plugin for integrating Cargo (Rust's package manager and build tool) with Heft.
4+
5+
## Available Plugins
6+
7+
### cargo-test-plugin
8+
9+
Runs `cargo test` to execute Rust tests.
10+
11+
**Configuration file:** `config/cargo-test.json`
12+
13+
**Options:**
14+
- `release` - Run in release mode
15+
- `workspace` - Run tests for all packages in the workspace
16+
17+
**CLI Parameters:**
18+
- `--release` - Run cargo test in release mode
19+
- `--workspace` - Run tests for all packages in the workspace
20+
21+
### cargo-build-plugin
22+
23+
Runs `cargo build` to compile Rust code.
24+
25+
**Configuration file:** `config/cargo-build.json`
26+
27+
**Options:**
28+
- `release` - Build in release mode
29+
- `workspace` - Build all packages in the workspace
30+
31+
**CLI Parameters:**
32+
- `--release` - Run cargo build in release mode
33+
- `--workspace` - Build all packages in the workspace
34+
35+
### cargo-clippy-plugin
36+
37+
Runs `cargo clippy` for Rust linting.
38+
39+
**Configuration file:** `config/cargo-clippy.json`
40+
41+
**Options:**
42+
- `release` - Run in release mode
43+
- `workspace` - Run clippy for all packages in the workspace
44+
- `fix` - Automatically apply suggested fixes
45+
- `warningsAsErrors` - Treat warnings as errors
46+
47+
**CLI Parameters:**
48+
- `--release` - Run cargo clippy in release mode
49+
- `--workspace` - Run clippy for all packages in the workspace
50+
- `--fix` - Automatically apply suggested fixes
51+
- `--warnings-as-errors` - Treat warnings as errors
52+
53+
### cargo-fmt-plugin
54+
55+
Runs `cargo fmt` for Rust code formatting.
56+
57+
**Configuration file:** `config/cargo-fmt.json`
58+
59+
**Options:**
60+
- `workspace` - Format all packages in the workspace
61+
- `check` - Run in check mode (no files will be modified)
62+
63+
**CLI Parameters:**
64+
- `--workspace` - Format all packages in the workspace
65+
- `--check` - Run in check mode (no files will be modified)
66+
67+
### cargo-lint-plugin
68+
69+
A combined linting plugin that runs both `cargo fmt --check` and `cargo clippy`.
70+
71+
**Configuration file:** `config/cargo-lint.json`
72+
73+
**Options:**
74+
- `release` - Run cargo clippy in release mode
75+
- `workspace` - Lint all packages in the workspace
76+
- `warningsAsErrors` - Treat clippy warnings as errors
77+
- `skipFmt` - Skip the cargo fmt check step
78+
- `skipClippy` - Skip the cargo clippy step
79+
80+
**CLI Parameters:**
81+
- `--release` - Run cargo clippy in release mode
82+
- `--workspace` - Lint all packages in the workspace
83+
- `--warnings-as-errors` - Treat clippy warnings as errors
84+
- `--skip-fmt` - Skip the cargo fmt check step
85+
- `--skip-clippy` - Skip the cargo clippy step
86+
87+
## Usage Example
88+
89+
In your `config/heft.json`:
90+
91+
```json
92+
{
93+
"phasesByName": {
94+
"build": {
95+
"tasksByName": {
96+
"cargo-build": {
97+
"taskPlugin": {
98+
"pluginPackage": "@rushstack/heft-cargo-plugin",
99+
"pluginName": "cargo-build-plugin"
100+
}
101+
}
102+
}
103+
},
104+
"test": {
105+
"tasksByName": {
106+
"cargo-test": {
107+
"taskPlugin": {
108+
"pluginPackage": "@rushstack/heft-cargo-plugin",
109+
"pluginName": "cargo-test-plugin"
110+
}
111+
}
112+
}
113+
},
114+
"lint": {
115+
"tasksByName": {
116+
"cargo-lint": {
117+
"taskPlugin": {
118+
"pluginPackage": "@rushstack/heft-cargo-plugin",
119+
"pluginName": "cargo-lint-plugin"
120+
}
121+
}
122+
}
123+
}
124+
}
125+
}
126+
```
127+
128+
## Links
129+
130+
- [CHANGELOG.md](
131+
https://github.com/microsoft/rushstack/blob/main/heft-plugins/heft-cargo-plugin/CHANGELOG.md) - Find
132+
out what's new in the latest version
133+
- [@rushstack/heft](https://www.npmjs.com/package/@rushstack/heft) - Heft is a config-driven toolchain that invokes popular tools such as TypeScript, ESLint, Jest, Webpack, and API Extractor.
134+
135+
Heft is part of the [Rush Stack](https://rushstack.io/) family of projects.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
4+
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
5+
"apiReport": {
6+
"enabled": true,
7+
"reportFolder": "../../../common/reviews/api"
8+
},
9+
"docModel": {
10+
"enabled": false
11+
},
12+
"dtsRollup": {
13+
"enabled": true,
14+
"betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts"
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// The "rig.json" file directs tools to look for their config files in an external package.
3+
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
4+
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
5+
6+
"rigPackageName": "@rushstack/heft-node-rig"
7+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft-plugin.schema.json",
3+
4+
"taskPlugins": [
5+
{
6+
"pluginName": "cargo-test-plugin",
7+
"entryPoint": "./lib/CargoTestPlugin",
8+
"optionsSchema": "./lib/schemas/cargo-test.schema.json",
9+
10+
"parameterScope": "cargo-test",
11+
"parameters": [
12+
{
13+
"longName": "--release",
14+
"parameterKind": "flag",
15+
"description": "Run cargo test in release mode."
16+
},
17+
{
18+
"longName": "--workspace",
19+
"parameterKind": "flag",
20+
"description": "Run tests for all packages in the workspace."
21+
}
22+
]
23+
},
24+
{
25+
"pluginName": "cargo-build-plugin",
26+
"entryPoint": "./lib/CargoBuildPlugin",
27+
"optionsSchema": "./lib/schemas/cargo-build.schema.json",
28+
29+
"parameterScope": "cargo-build",
30+
"parameters": [
31+
{
32+
"longName": "--release",
33+
"parameterKind": "flag",
34+
"description": "Run cargo build in release mode."
35+
},
36+
{
37+
"longName": "--workspace",
38+
"parameterKind": "flag",
39+
"description": "Build all packages in the workspace."
40+
}
41+
]
42+
},
43+
{
44+
"pluginName": "cargo-clippy-plugin",
45+
"entryPoint": "./lib/CargoClippyPlugin",
46+
"optionsSchema": "./lib/schemas/cargo-clippy.schema.json",
47+
48+
"parameterScope": "cargo-clippy",
49+
"parameters": [
50+
{
51+
"longName": "--release",
52+
"parameterKind": "flag",
53+
"description": "Run cargo clippy in release mode."
54+
},
55+
{
56+
"longName": "--workspace",
57+
"parameterKind": "flag",
58+
"description": "Run clippy for all packages in the workspace."
59+
},
60+
{
61+
"longName": "--fix",
62+
"parameterKind": "flag",
63+
"description": "Automatically apply suggested fixes."
64+
},
65+
{
66+
"longName": "--warnings-as-errors",
67+
"parameterKind": "flag",
68+
"description": "Treat warnings as errors."
69+
}
70+
]
71+
},
72+
{
73+
"pluginName": "cargo-fmt-plugin",
74+
"entryPoint": "./lib/CargoFmtPlugin",
75+
"optionsSchema": "./lib/schemas/cargo-fmt.schema.json",
76+
77+
"parameterScope": "cargo-fmt",
78+
"parameters": [
79+
{
80+
"longName": "--workspace",
81+
"parameterKind": "flag",
82+
"description": "Format all packages in the workspace."
83+
},
84+
{
85+
"longName": "--check",
86+
"parameterKind": "flag",
87+
"description": "Run in check mode (no files will be modified)."
88+
}
89+
]
90+
},
91+
{
92+
"pluginName": "cargo-lint-plugin",
93+
"entryPoint": "./lib/CargoLintPlugin",
94+
"optionsSchema": "./lib/schemas/cargo-lint.schema.json",
95+
96+
"parameterScope": "cargo-lint",
97+
"parameters": [
98+
{
99+
"longName": "--release",
100+
"parameterKind": "flag",
101+
"description": "Run cargo clippy in release mode."
102+
},
103+
{
104+
"longName": "--workspace",
105+
"parameterKind": "flag",
106+
"description": "Lint all packages in the workspace."
107+
},
108+
{
109+
"longName": "--warnings-as-errors",
110+
"parameterKind": "flag",
111+
"description": "Treat clippy warnings as errors."
112+
},
113+
{
114+
"longName": "--skip-fmt",
115+
"parameterKind": "flag",
116+
"description": "Skip the cargo fmt check step."
117+
},
118+
{
119+
"longName": "--skip-clippy",
120+
"parameterKind": "flag",
121+
"description": "Skip the cargo clippy step."
122+
}
123+
]
124+
}
125+
]
126+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@rushstack/heft-cargo-plugin",
3+
"version": "0.0.0",
4+
"description": "Heft plugin for running Cargo commands",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/microsoft/rushstack.git",
8+
"directory": "heft-plugins/heft-cargo-plugin"
9+
},
10+
"homepage": "https://rushstack.io/pages/heft/overview/",
11+
"main": "lib/index.js",
12+
"types": "dist/heft-cargo-plugin.d.ts",
13+
"license": "MIT",
14+
"scripts": {
15+
"build": "heft build --clean",
16+
"_phase:build": "heft run --only build -- --clean",
17+
"_phase:test": "heft run --only test -- --clean"
18+
},
19+
"peerDependencies": {
20+
"@rushstack/heft": "^0.75.0"
21+
},
22+
"dependencies": {
23+
"@rushstack/node-core-library": "5.17.0"
24+
},
25+
"devDependencies": {
26+
"@rushstack/heft": "1.1.1",
27+
"@rushstack/heft-node-rig": "2.10.2",
28+
"@types/node": "24.0.12"
29+
}
30+
}

0 commit comments

Comments
 (0)