Skip to content

Commit bcad439

Browse files
committed
ci(rust-core): 用 rust-toolchain.toml 固定 Rust 1.100.0
- 仓库根目录新增 rust-toolchain.toml,本地和 CI 都使用 1.100.0。 - rust-core.yml、plugins-verify.yml 的 dtolnay/rust-toolchain 从 @stable 改为 @1.100.0,与固定文件写同一个版本字符串;SDK 的 @1.87 和 cargo +1.87 保持不变。 - rust-toolchain.toml 加入 affected-crates.mjs 的 EVERY_CRATE,改动它会 选中全部 crate。 - CONTRIBUTING.md 新增“工具链 / Toolchain”一节,说明安装方式、额外目标 和升级步骤;shared/plugins/README.md 的 SDK 检查说明不再写 stable。
1 parent e01c2aa commit bcad439

7 files changed

Lines changed: 44 additions & 13 deletions

File tree

‎.github/workflows/plugins-verify.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ jobs:
9292
steps:
9393
- uses: actions/checkout@v7
9494
# The SDK supports Rust 1.87 and newer: the tests run on that release,
95-
# and formatting and lints on the current stable toolchain.
95+
# and formatting and lints on the toolchain rust-toolchain.toml pins.
9696
- uses: dtolnay/rust-toolchain@1.87
9797
- name: Test on the oldest supported Rust
9898
run: cargo +1.87 test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml
99-
- uses: dtolnay/rust-toolchain@stable
99+
- uses: dtolnay/rust-toolchain@1.100.0
100100
with:
101101
components: clippy, rustfmt
102102
- name: Check formatting and lints
@@ -124,7 +124,7 @@ jobs:
124124
with:
125125
distribution: temurin
126126
java-version: '21'
127-
- uses: dtolnay/rust-toolchain@stable
127+
- uses: dtolnay/rust-toolchain@1.100.0
128128

129129
- uses: actions/cache@v6
130130
with:

‎.github/workflows/rust-core.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- uses: actions/setup-node@v6
4848
with:
4949
node-version: 22
50-
- uses: dtolnay/rust-toolchain@stable
50+
- uses: dtolnay/rust-toolchain@1.100.0
5151

5252
- name: Test the CI scripts
5353
run: node --test scripts/rust-core/*.test.mjs
@@ -82,7 +82,7 @@ jobs:
8282
- uses: actions/setup-node@v6
8383
with:
8484
node-version: 22
85-
- uses: dtolnay/rust-toolchain@stable
85+
- uses: dtolnay/rust-toolchain@1.100.0
8686
with:
8787
components: clippy, rustfmt
8888
targets: x86_64-pc-windows-msvc
@@ -139,7 +139,7 @@ jobs:
139139
TEST_ARGS: ${{ matrix.test-args }}
140140
steps:
141141
- uses: actions/checkout@v7
142-
- uses: dtolnay/rust-toolchain@stable
142+
- uses: dtolnay/rust-toolchain@1.100.0
143143

144144
- name: Test
145145
run: |

‎CONTRIBUTING.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 参与 Rust Core 开发
22

3-
本页规定平台相关代码怎么写、平台测试放在哪里,以及 CI 怎样只运行受影响的 crate。插件契约和 SDK 的规则见 [`shared/plugins/README.md`](shared/plugins/README.md)。
3+
本页规定平台相关代码怎么写、平台测试放在哪里、CI 怎样只运行受影响的 crate,以及固定的 Rust 版本怎么升级。插件契约和 SDK 的规则见 [`shared/plugins/README.md`](shared/plugins/README.md)。
44

55
## 平台差异写成数据
66

@@ -35,7 +35,7 @@ test-features = ["server"] # 测试需要的 feature,在每台主机上都
3535
[`.github/workflows/rust-core.yml`](.github/workflows/rust-core.yml) 由四个作业组成:
3636

3737
- **Select crates**:先运行 CI 脚本的测试和上面的放置检查,再由 [`affected-crates.mjs`](scripts/rust-core/affected-crates.mjs) 根据 PR 改动的文件选出 crate。选中的是文件所在的 crate,加上所有直接或间接依赖它的 crate(各种依赖都算,包括 dev-dependency)。另外几类文件的处理是:
38-
- 会选中全部 crate:`rust/` 下不属于某个 crate 的文件(workspace 清单、`Cargo.lock`、`fixtures/`、`contracts/`、`logging/`)、`shared/plugins/contract/`、`scripts/rust-core/`、`scripts/logging/`,以及工作流文件本身。
38+
- 会选中全部 crate:`rust/` 下不属于某个 crate 的文件(workspace 清单、`Cargo.lock`、`fixtures/`、`contracts/`、`logging/`)、`shared/plugins/contract/`、`scripts/rust-core/`、`scripts/logging/`、`rust-toolchain.toml`,以及工作流文件本身。
3939
- `shared/plugins/sdk/e2e/` 只选中 `lithe-core`。
4040
- 文档、SDK 等其他文件不选中任何 crate。
4141
- **Linux**:对选中的 crate 依次运行格式检查(全部 crate,耗时很短)、日志事件目录检查、注释规范(文本检查覆盖全部 crate,Rustdoc 只构建选中的 crate)、启用全部 feature 的 clippy、针对 `x86_64-pc-windows-msvc` 的 clippy(只用默认 feature),最后是启用 `test-features` 的测试。
@@ -44,6 +44,16 @@ test-features = ["server"] # 测试需要的 feature,在每台主机上都
4444

4545
手动运行工作流(workflow_dispatch)会检查全部 crate。CI 只缓存下载的依赖,不缓存构建产物。
4646

47+
## 工具链
48+
49+
仓库根目录的 [`rust-toolchain.toml`](rust-toolchain.toml) 固定 Rust 版本,本地和 CI 用同一个版本,新版本 clippy 新增的 lint 只会在主动升级时出现,不会让无关的 PR 失败。
50+
51+
- 在仓库里运行 `cargo` 时,rustup 自动安装并使用这个版本,不需要切换默认工具链。Homebrew 等不经过 rustup 安装的 Rust 不读这个文件,请改用 rustup。
52+
- 额外的编译目标装在固定版本上:在仓库目录里运行 `rustup target add x86_64-pc-windows-msvc`,再运行下面的 Windows clippy。
53+
- 升级时在同一个 PR 里修改 `rust-toolchain.toml` 的 `channel` 和 `.github/workflows` 里所有 `dtolnay/rust-toolchain@<版本>`(`@1.87` 除外),并修复新版本报出的问题。两处必须写同一个版本字符串,例如都写 `1.100.0`:rustup 把 `1.100` 和 `1.100.0` 当成两个工具链,写得不一致时 CI 会另装一份没有 clippy、rustfmt 和 Windows 目标的工具链。
54+
- Lithe-IDEA 构建 Core 时使用 Lithe-IDEA 仓库根目录自己的 `rust-toolchain.toml`,Core 升级合入后,Lithe-IDEA 要同步升级到同一版本。
55+
- Rust 插件 SDK(`shared/plugins/sdk/rust`)的最低版本 `rust-version = "1.87"` 不随固定版本变化,CI 用 `cargo +1.87` 测试它。
56+
4757
## 本地命令
4858

4959
```sh
@@ -59,7 +69,7 @@ cargo test --manifest-path rust/Cargo.toml -p lithe-platform -p lithe-platform-t
5969

6070
# Contributing to Rust Core (English)
6171

62-
This page sets how platform code is written, where platform tests go, and how CI runs only the crates a change affects. The plugin contract and SDK rules live in [`shared/plugins/README.md`](shared/plugins/README.md).
72+
This page sets how platform code is written, where platform tests go, how CI runs only the crates a change affects, and how the pinned Rust release is upgraded. The plugin contract and SDK rules live in [`shared/plugins/README.md`](shared/plugins/README.md).
6373

6474
## Platform differences are data
6575

@@ -94,7 +104,7 @@ test-features = ["server"] # features the tests need, enabled on every host
94104
[`.github/workflows/rust-core.yml`](.github/workflows/rust-core.yml) has four jobs:
95105

96106
- **Select crates** tests the CI scripts, runs the placement check above, and lets [`affected-crates.mjs`](scripts/rust-core/affected-crates.mjs) choose crates from the files the pull request changes: the crate each file belongs to, plus every crate that depends on it directly or indirectly, through any kind of dependency, dev-dependencies included. Other files are handled as follows:
97-
- These select every crate: files under `rust/` outside any crate (the workspace manifest, `Cargo.lock`, `fixtures/`, `contracts/`, `logging/`), `shared/plugins/contract/`, `scripts/rust-core/`, `scripts/logging/` and the workflow itself.
107+
- These select every crate: files under `rust/` outside any crate (the workspace manifest, `Cargo.lock`, `fixtures/`, `contracts/`, `logging/`), `shared/plugins/contract/`, `scripts/rust-core/`, `scripts/logging/`, `rust-toolchain.toml` and the workflow itself.
98108
- `shared/plugins/sdk/e2e/` selects `lithe-core` only.
99109
- Documentation, the SDKs and other files select no crate.
100110
- **Linux** runs, for the selected crates: the formatting check (every crate; it is quick), the log event catalog check, the comment rules (the textual checks cover every crate, Rustdoc builds the selected ones), clippy with every feature, clippy for `x86_64-pc-windows-msvc` with default features, and the tests with their `test-features`.
@@ -103,6 +113,16 @@ test-features = ["server"] # features the tests need, enabled on every host
103113

104114
A manual run (workflow_dispatch) checks every crate. CI caches downloaded dependencies only, not build output.
105115

116+
## Toolchain
117+
118+
[`rust-toolchain.toml`](rust-toolchain.toml) at the repository root pins the Rust release. Local builds and CI use the same release, so lints added by a new clippy show up only when the pin is upgraded, never in an unrelated pull request.
119+
120+
- When `cargo` runs in this repository, rustup installs and uses that release; there is no need to change the default toolchain. Rust installed without rustup, for example by Homebrew, ignores the file; use rustup instead.
121+
- Extra targets are added to the pinned release: run `rustup target add x86_64-pc-windows-msvc` in the repository before the Windows clippy below.
122+
- An upgrade changes, in one pull request, the `channel` in `rust-toolchain.toml` and every `dtolnay/rust-toolchain@<version>` in `.github/workflows` except `@1.87`, and fixes what the new release reports. Both places must spell the version the same way, for example `1.100.0` in each: rustup treats `1.100` and `1.100.0` as two toolchains, and a mismatch makes CI install a second one without clippy, rustfmt or the Windows target.
123+
- Lithe-IDEA builds Core with the `rust-toolchain.toml` at its own repository root. Once a Core upgrade is merged, Lithe-IDEA moves to the same release.
124+
- The Rust plugin SDK (`shared/plugins/sdk/rust`) keeps its minimum `rust-version = "1.87"` whatever the pin is; CI tests it with `cargo +1.87`.
125+
106126
## Local commands
107127

108128
```sh

‎rust-toolchain.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The Rust release Rust Core is built, linted and tested with, locally and in CI.
2+
# rustup reads this file when cargo runs in this repository and installs the
3+
# release on first use. Upgrade it as described in CONTRIBUTING.md ("工具链" /
4+
# "Toolchain"): every `dtolnay/rust-toolchain@<version>` in .github/workflows
5+
# must name the same version. The Rust plugin SDK keeps its own minimum
6+
# (`rust-version = "1.87"`), which CI tests with `cargo +1.87`.
7+
[toolchain]
8+
channel = "1.100.0"

‎scripts/rust-core/affected-crates.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ export const HOSTS = {
3333
/**
3434
* Paths outside crate directories that can change the build or tests of any
3535
* crate. `rust/` holds the workspace manifest, the lock file, and the
36-
* fixtures, contracts and log catalog that several crates read.
36+
* fixtures, contracts and log catalog that several crates read;
37+
* `rust-toolchain.toml` pins the compiler every crate is built with.
3738
*/
3839
export const EVERY_CRATE = [
3940
'rust/',
4041
'shared/plugins/contract/',
4142
'scripts/rust-core/',
4243
'scripts/logging/',
4344
'.github/workflows/rust-core.yml',
45+
'rust-toolchain.toml',
4446
];
4547

4648
/** Paths outside crate directories that only one crate builds. */

‎scripts/rust-core/affected-crates.test.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ test('workspace files, contract fixtures and the checks select every crate', ()
7777
'shared/plugins/contract/v1/README.md',
7878
'scripts/rust-core/verify-rust-core-comments.sh',
7979
'.github/workflows/rust-core.yml',
80+
'rust-toolchain.toml',
8081
]) {
8182
assert.equal(selectCrates(crates, [file]).size, crates.length, file);
8283
}

‎shared/plugins/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fixture 放在 `fixtures/<功能>/` 下,文件按演示的能力命名,例
199199
| `node --test shared/plugins/sdk/node/test/*.test.mjs` | Node.js SDK 的单元测试 |
200200
| `npm run --prefix shared/plugins/sdk/node test:types` | Node.js SDK 的 TypeScript 使用方检查;先运行 `npm ci --prefix shared/plugins/sdk/node --ignore-scripts` 安装开发依赖 |
201201
| `mvn -B -ntp -f shared/plugins/sdk/java/pom.xml verify` | Java SDK 的单元测试;加 `-Djvm=<java>` 可指定运行测试的 Java(CI 用 Java 8) |
202-
| `cargo test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml` | Rust SDK 的单元测试(CI 用 Rust 1.87,另用 stable 跑 `cargo fmt` 和 `cargo clippy`) |
202+
| `cargo test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml` | Rust SDK 的单元测试(CI 用 Rust 1.87,另用仓库 `rust-toolchain.toml` 固定的版本跑 `cargo fmt` 和 `cargo clippy`) |
203203
| `node shared/plugins/scripts/sdk-e2e.mjs` | 端到端测试:先构建三个 SDK 的示例后端,再运行 `cargo test -p lithe-core --features plugin-sdk-e2e` 的 `plugin_sdk_node`、`plugin_sdk_java`、`plugin_sdk_rust` 和 `plugin_sdk_build` 四个测试,对象是**当前工作树的 Core**;总是包含原生构建工作流和快捷键导入场景 |
204204

205205
端到端测试需要 Rust、Node.js 20.3+、Java(`LITHE_PLUGIN_SDK_JAVA_RUNTIME` 指定,或 `PATH` 上的 `java`)和 Maven。场景文件在 [`sdk/e2e/`](sdk/e2e):Node.js 和 Java 跑同一套构建后端场景,Rust 跑插件后端场景(`plugin_sdk/backend.rs`),测试代替宿主应答凭据请求。`LITHE_PLUGIN_SDK_JAVA_SAMPLE`、`LITHE_PLUGIN_SDK_JAVA_NATIVE_SAMPLE` 和 `LITHE_PLUGIN_SDK_RUST_SAMPLE` 可以指定已构建好的示例,跳过构建。
@@ -409,7 +409,7 @@ When a change touches the contract, a capability version, or the plugin function
409409
| `node --test shared/plugins/sdk/node/test/*.test.mjs` | Node.js SDK unit tests |
410410
| `npm run --prefix shared/plugins/sdk/node test:types` | Node.js SDK TypeScript consumer check; first run `npm ci --prefix shared/plugins/sdk/node --ignore-scripts` to install the development dependencies |
411411
| `mvn -B -ntp -f shared/plugins/sdk/java/pom.xml verify` | Java SDK unit tests; add `-Djvm=<java>` to choose the Java that runs them (CI uses Java 8) |
412-
| `cargo test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml` | Rust SDK unit tests (CI uses Rust 1.87, plus stable for `cargo fmt` and `cargo clippy`) |
412+
| `cargo test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml` | Rust SDK unit tests (CI uses Rust 1.87, plus the release `rust-toolchain.toml` pins for `cargo fmt` and `cargo clippy`) |
413413
| `node shared/plugins/scripts/sdk-e2e.mjs` | End-to-end tests: builds the sample backends of the three SDKs, then runs the four tests `plugin_sdk_node`, `plugin_sdk_java`, `plugin_sdk_rust`, and `plugin_sdk_build` of `cargo test -p lithe-core --features plugin-sdk-e2e` against the **Core in the current working tree**; it always includes the native build workflow and shortcut import scenarios |
414414

415415
The end-to-end tests need Rust, Node.js 20.3+, Java (set `LITHE_PLUGIN_SDK_JAVA_RUNTIME`, or have `java` on `PATH`), and Maven. The scenario files are in [`sdk/e2e/`](sdk/e2e): Node.js and Java run the same build backend scenarios, Rust runs the plugin backend scenario (`plugin_sdk/backend.rs`), and the test answers credential requests in place of the host. `LITHE_PLUGIN_SDK_JAVA_SAMPLE`, `LITHE_PLUGIN_SDK_JAVA_NATIVE_SAMPLE`, and `LITHE_PLUGIN_SDK_RUST_SAMPLE` can point at already built samples to skip building them.

0 commit comments

Comments
 (0)