Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/plugins-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ jobs:
steps:
- uses: actions/checkout@v7
# The SDK supports Rust 1.87 and newer: the tests run on that release,
# and formatting and lints on the current stable toolchain.
# and formatting and lints on the toolchain rust-toolchain.toml pins.
- uses: dtolnay/rust-toolchain@1.87
- name: Test on the oldest supported Rust
run: cargo +1.87 test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@1.100.0
with:
components: clippy, rustfmt
- name: Check formatting and lints
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
with:
distribution: temurin
java-version: '21'
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@1.100.0

- uses: actions/cache@v6
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- uses: actions/setup-node@v6
with:
node-version: 22
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@1.100.0

- name: Test the CI scripts
run: node --test scripts/rust-core/*.test.mjs
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
- uses: actions/setup-node@v6
with:
node-version: 22
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@1.100.0
with:
components: clippy, rustfmt
targets: x86_64-pc-windows-msvc
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
TEST_ARGS: ${{ matrix.test-args }}
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@1.100.0

- name: Test
run: |
Expand Down
28 changes: 24 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 参与 Rust Core 开发

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

## 平台差异写成数据

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

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

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

## 工具链

仓库根目录的 [`rust-toolchain.toml`](rust-toolchain.toml) 固定 Rust 版本,本地和 CI 用同一个版本,新版本 clippy 新增的 lint 只会在主动升级时出现,不会让无关的 PR 失败。

- 在仓库里运行 `cargo` 时,rustup 自动安装并使用这个版本,不需要切换默认工具链。Homebrew 等不经过 rustup 安装的 Rust 不读这个文件,请改用 rustup。
- 额外的编译目标装在固定版本上:在仓库目录里运行 `rustup target add x86_64-pc-windows-msvc`,再运行下面的 Windows clippy。
- 升级时在同一个 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 目标的工具链。
- Lithe-IDEA 构建 Core 时使用 Lithe-IDEA 仓库根目录自己的 `rust-toolchain.toml`,Core 升级合入后,Lithe-IDEA 要同步升级到同一版本。
- Rust 插件 SDK(`shared/plugins/sdk/rust`)的最低版本 `rust-version = "1.87"` 不随固定版本变化,CI 用 `cargo +1.87` 测试它。

## 本地命令

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

# Contributing to Rust Core (English)

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).
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).

## Platform differences are data

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

- **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:
- 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.
- 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.
- `shared/plugins/sdk/e2e/` selects `lithe-core` only.
- Documentation, the SDKs and other files select no crate.
- **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`.
Expand All @@ -103,6 +113,16 @@ test-features = ["server"] # features the tests need, enabled on every host

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

## Toolchain

[`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.

- 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.
- 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.
- 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.
- 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.
- 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`.

## Local commands

```sh
Expand Down
8 changes: 8 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The Rust release Rust Core is built, linted and tested with, locally and in CI.
# rustup reads this file when cargo runs in this repository and installs the
# release on first use. Upgrade it as described in CONTRIBUTING.md ("工具链" /
# "Toolchain"): every `dtolnay/rust-toolchain@<version>` in .github/workflows
# must name the same version. The Rust plugin SDK keeps its own minimum
# (`rust-version = "1.87"`), which CI tests with `cargo +1.87`.
[toolchain]
channel = "1.100.0"
2 changes: 1 addition & 1 deletion rust/crates/build/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn resolve(
model_values: Option<&BTreeMap<String, Vec<String>>>,
) -> ResolvedOptions {
let mut resolved = ResolvedOptions::default();
for (id, _) in stored.iter() {
for id in stored.keys() {
if build_system.option(id).is_none() {
resolved.dropped.push(id.clone());
}
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/core/src/tests/build_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ fn gradle_canonical_outputs_are_read_from_the_output_file() {
"format": "litheBuildModel",
"version": 0,
"projects": [
{ "path": format!("{root}"), "name": "shop", "properties": { "taskPrefix": ":" } },
{ "path": root.to_string(), "name": "shop", "properties": { "taskPrefix": ":" } },
{ "path": "app", "name": "app", "properties": { "taskPrefix": ":app:" } }
],
"tasks": [
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/git/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn entries(bytes: &[u8]) -> Result<Vec<Entry>, CoreError> {
));
}
let mut result: Vec<Entry> = Vec::new();
for part in parts.chunks_exact(3) {
for part in parts.as_chunks::<3>().0 {
let (key, value) = part[2].split_once('\n').unwrap_or((part[2], "true"));
let key = key.to_string();
if !readable(&key) {
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/git/src/diff_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ pub(super) fn worktree_attributes_safe(root: &str, paths: &[String]) -> Result<b
}
let fields = output.stdout.split('\0').collect::<Vec<_>>();
let mut reported = 0;
for record in fields.chunks_exact(3) {
for record in fields.as_chunks::<3>().0 {
if record[1] == "filter" || record[1] == "working-tree-encoding" {
reported += 1;
if record[2] != "unspecified" && record[2] != "unset" {
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/lsp-client/src/client/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ pub(crate) fn semantic_token_result(
}
let mut tokens = Vec::with_capacity(data.len() / 5);
let (mut line, mut column) = (0_u64, 0_u64);
for chunk in data.chunks_exact(5) {
for chunk in data.as_chunks::<5>().0 {
let numbers: Vec<u64> = chunk.iter().map(Value::as_u64).collect::<Option<_>>()?;
if numbers.iter().any(|value| *value > u32::MAX as u64) {
return None;
Expand Down
26 changes: 15 additions & 11 deletions rust/crates/project-generators/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,22 @@ fn is_plain_relative(path: &Path, platform: Platform) -> bool {
})
}

/// A directory that is neither a symbolic link nor, on Windows, another
/// reparse point such as a junction.
fn real_directory(metadata: &fs::Metadata) -> bool {
if !metadata.is_dir() || metadata.file_type().is_symlink() {
return false;
}
#[cfg(windows)]
{
use std::os::windows::fs::MetadataExt;
if metadata.file_attributes() & 0x400 != 0 {
return false;
}
}
true
metadata.is_dir() && !metadata.file_type().is_symlink() && !reparse_point(metadata)
}

#[cfg(windows)]
fn reparse_point(metadata: &fs::Metadata) -> bool {
use std::os::windows::fs::MetadataExt;
// FILE_ATTRIBUTE_REPARSE_POINT
metadata.file_attributes() & 0x400 != 0
}

#[cfg(not(windows))]
fn reparse_point(_metadata: &fs::Metadata) -> bool {
false
}

/// Unix stores any name the earlier checks let through. Windows needs valid
Expand Down
6 changes: 3 additions & 3 deletions rust/crates/toolchain/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub fn normalize(path: &str, platform: &str, case_sensitive: bool) -> Option<Str
&& bytes[2] == b'/'
{
(text[..3].to_owned(), &text[3..])
} else if let Some(unc) = text.strip_prefix("//") {
} else {
// Anything else must be a UNC path: `//server/share/...`.
let unc = text.strip_prefix("//")?;
let mut components = unc.splitn(3, '/');
let server = components.next()?;
let share = components.next()?;
Expand All @@ -40,8 +42,6 @@ pub fn normalize(path: &str, platform: &str, case_sensitive: bool) -> Option<Str
format!("//{server}/{share}/"),
components.next().unwrap_or(""),
)
} else {
return None;
}
} else {
("/".to_owned(), text.strip_prefix('/')?)
Expand Down
4 changes: 3 additions & 1 deletion scripts/rust-core/affected-crates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ export const HOSTS = {
/**
* Paths outside crate directories that can change the build or tests of any
* crate. `rust/` holds the workspace manifest, the lock file, and the
* fixtures, contracts and log catalog that several crates read.
* fixtures, contracts and log catalog that several crates read;
* `rust-toolchain.toml` pins the compiler every crate is built with.
*/
export const EVERY_CRATE = [
'rust/',
'shared/plugins/contract/',
'scripts/rust-core/',
'scripts/logging/',
'.github/workflows/rust-core.yml',
'rust-toolchain.toml',
];

/** Paths outside crate directories that only one crate builds. */
Expand Down
1 change: 1 addition & 0 deletions scripts/rust-core/affected-crates.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test('workspace files, contract fixtures and the checks select every crate', ()
'shared/plugins/contract/v1/README.md',
'scripts/rust-core/verify-rust-core-comments.sh',
'.github/workflows/rust-core.yml',
'rust-toolchain.toml',
]) {
assert.equal(selectCrates(crates, [file]).size, crates.length, file);
}
Expand Down
4 changes: 2 additions & 2 deletions shared/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fixture 放在 `fixtures/<功能>/` 下,文件按演示的能力命名,例
| `node --test shared/plugins/sdk/node/test/*.test.mjs` | Node.js SDK 的单元测试 |
| `npm run --prefix shared/plugins/sdk/node test:types` | Node.js SDK 的 TypeScript 使用方检查;先运行 `npm ci --prefix shared/plugins/sdk/node --ignore-scripts` 安装开发依赖 |
| `mvn -B -ntp -f shared/plugins/sdk/java/pom.xml verify` | Java SDK 的单元测试;加 `-Djvm=<java>` 可指定运行测试的 Java(CI 用 Java 8) |
| `cargo test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml` | Rust SDK 的单元测试(CI 用 Rust 1.87,另用 stable 跑 `cargo fmt` 和 `cargo clippy`) |
| `cargo test --locked --manifest-path shared/plugins/sdk/rust/Cargo.toml` | Rust SDK 的单元测试(CI 用 Rust 1.87,另用仓库 `rust-toolchain.toml` 固定的版本跑 `cargo fmt` 和 `cargo clippy`) |
| `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**;总是包含原生构建工作流和快捷键导入场景 |

端到端测试需要 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` 可以指定已构建好的示例,跳过构建。
Expand Down Expand Up @@ -409,7 +409,7 @@ When a change touches the contract, a capability version, or the plugin function
| `node --test shared/plugins/sdk/node/test/*.test.mjs` | Node.js SDK unit tests |
| `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 |
| `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) |
| `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`) |
| `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`) |
| `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 |

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.
Expand Down
Loading