diff --git a/.github/workflows/rust-core.yml b/.github/workflows/rust-core.yml index 3d7786ed..335d9717 100644 --- a/.github/workflows/rust-core.yml +++ b/.github/workflows/rust-core.yml @@ -111,8 +111,13 @@ jobs: cargo clippy --locked --manifest-path rust/Cargo.toml "${packages[@]}" --all-targets --all-features -- -D warnings # Code behind cfg(windows) compiles only for Windows. Checking it here # finds its errors without a Windows runner; default features only, - # because the remote server feature targets Unix hosts. + # because the remote server feature targets Unix hosts. Clippy only + # checks and never links, so SQLite (bundled for the Motty import) is + # told to link a system library instead of compiling its C source, + # which needs the MSVC tools that a Linux runner does not have. - name: Lint for Windows + env: + LIBSQLITE3_SYS_USE_PKG_CONFIG: "1" run: | read -ra packages <<< "$PACKAGES" cargo clippy --locked --manifest-path rust/Cargo.toml "${packages[@]}" --all-targets --target x86_64-pc-windows-msvc -- -D warnings diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0216cb78..1760c4f2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,7 +63,7 @@ node --test scripts/rust-core/*.test.mjs # CI 脚本自己的 cargo test --manifest-path rust/Cargo.toml -p lithe-platform -p lithe-platform-tests # 在 macOS 或 Windows 上运行平台测试 ``` -手边没有 Windows 时,至少运行一次 `cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings`,确认 Windows 代码能编译。 +手边没有 Windows 时,至少运行一次 `LIBSQLITE3_SYS_USE_PKG_CONFIG=1 cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings`,确认 Windows 代码能编译。环境变量让 SQLite 改为链接系统库、不编译自带的 C 源码:编译它需要 MSVC 工具,macOS 和 Linux 上没有;clippy 只检查不链接,不受影响。 --- @@ -132,4 +132,4 @@ node --test scripts/rust-core/*.test.mjs # the CI scripts' own cargo test --manifest-path rust/Cargo.toml -p lithe-platform -p lithe-platform-tests # platform tests on macOS or Windows ``` -Without a Windows host, at least run `cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings` to confirm the Windows code compiles. +Without a Windows host, at least run `LIBSQLITE3_SYS_USE_PKG_CONFIG=1 cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings` to confirm the Windows code compiles. The variable makes SQLite link a system library instead of compiling its bundled C source, which needs the MSVC tools that macOS and Linux do not have; clippy only checks and never links, so this does not matter. diff --git a/rust/crates/workspace/src/ssh_configuration/tests.rs b/rust/crates/workspace/src/ssh_configuration/tests.rs index f1931f04..bfb0f3be 100644 --- a/rust/crates/workspace/src/ssh_configuration/tests.rs +++ b/rust/crates/workspace/src/ssh_configuration/tests.rs @@ -18,6 +18,9 @@ impl Directory { Self(path) } + // Writing files, `lines` and `DEFAULTS` serve only the tests that run + // `fake_ssh`, a shell script, so they are Unix only like those tests. + #[cfg(unix)] fn write(&self, relative: &str, text: &str) { let path = self.0.join(relative); std::fs::create_dir_all(path.parent().unwrap()).unwrap(); @@ -53,10 +56,12 @@ fn fake_ssh(directory: &Directory, configured: &str, baseline: &str) -> String { program.display().to_string() } +#[cfg(unix)] fn lines(values: &[&str]) -> String { values.join("\n") } +#[cfg(unix)] const DEFAULTS: &[&str] = &[ "user localdev", "port 22",