Skip to content

Commit 261b3e9

Browse files
authored
CI: Add windows clippy job and fix clippy errors (#330)
* CI: Run clippy on windows * Update cargo-clippy-before-script.sh for Windows * Pacify clippy
1 parent 184ba6c commit 261b3e9

File tree

7 files changed

+36
-27
lines changed

7 files changed

+36
-27
lines changed

.github/scripts/cargo-clippy-before-script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ os_name="$1"
66

77
case "$os_name" in
88
"Windows")
9+
vcpkg install openssl:x64-windows-static-md
10+
vcpkg integrate install
11+
choco install protoc
12+
export PROTOC='C:\ProgramData\chocolatey\lib\protoc\tools\bin\protoc.exe'
913
;;
1014
"macOS")
1115
brew install protobuf

.github/workflows/cargo.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
matrix:
3232
os:
3333
- macos-latest-large
34+
- windows-latest
3435
runs-on: ${{ matrix.os }}
3536
steps:
3637
- uses: actions/checkout@v4
@@ -53,6 +54,7 @@ jobs:
5354
matrix:
5455
os:
5556
- macos-latest-large
57+
- windows-latest
5658
runs-on: ${{ matrix.os }}
5759
steps:
5860
- uses: actions/checkout@v4

accounts-db/src/hardened_unpack.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ where
205205
#[cfg(windows)]
206206
fn set_perms(dst: &Path, _mode: u32) -> std::io::Result<()> {
207207
let mut perm = fs::metadata(dst)?.permissions();
208+
// This is OK for Windows, but clippy doesn't realize we're doing this
209+
// only on Windows.
210+
#[allow(clippy::permissions_set_readonly_false)]
208211
perm.set_readonly(false);
209212
fs::set_permissions(dst, perm)
210213
}

geyser-plugin-manager/src/geyser_plugin_manager.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,13 @@ mod tests {
451451
plugin: P,
452452
config_path: &'static str,
453453
) -> (LoadedGeyserPlugin, Library, &'static str) {
454+
#[cfg(unix)]
455+
let library = libloading::os::unix::Library::this();
456+
#[cfg(windows)]
457+
let library = libloading::os::windows::Library::this().unwrap();
454458
(
455459
LoadedGeyserPlugin::new(Box::new(plugin), None),
456-
Library::from(libloading::os::unix::Library::this()),
460+
Library::from(library),
457461
config_path,
458462
)
459463
}

install/src/command.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ pub fn string_from_winreg_value(val: &winreg::RegValue) -> Option<String> {
333333
let words = unsafe {
334334
slice::from_raw_parts(val.bytes.as_ptr() as *const u16, val.bytes.len() / 2)
335335
};
336-
let mut s = if let Ok(s) = String::from_utf16(words) {
337-
s
338-
} else {
336+
let Ok(mut s) = String::from_utf16(words) else {
339337
return None;
340338
};
341339
while s.ends_with('\u{0}') {
@@ -392,11 +390,9 @@ fn add_to_path(new_path: &str) -> bool {
392390
},
393391
};
394392

395-
let old_path = if let Some(s) =
393+
let Some(old_path) =
396394
get_windows_path_var().unwrap_or_else(|err| panic!("Unable to get PATH: {}", err))
397-
{
398-
s
399-
} else {
395+
else {
400396
return false;
401397
};
402398

programs/sbf/benches/bpf_loader.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#![cfg(feature = "sbf_c")]
33
#![allow(clippy::uninlined_format_args)]
44
#![allow(clippy::arithmetic_side_effects)]
5-
#![cfg_attr(not(target_arch = "x86_64"), allow(dead_code, unused_imports))]
5+
#![cfg_attr(
6+
any(target_os = "windows", not(target_arch = "x86_64")),
7+
allow(dead_code, unused_imports)
8+
)]
69

710
use {
811
solana_rbpf::memory_region::MemoryState,
@@ -103,7 +106,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) {
103106
}
104107

105108
#[bench]
106-
#[cfg(target_arch = "x86_64")]
109+
#[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))]
107110
fn bench_program_alu(bencher: &mut Bencher) {
108111
let ns_per_s = 1000000000;
109112
let one_million = 1000000;

rpc/src/rpc_service.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -878,24 +878,21 @@ mod tests {
878878
panic!("Unexpected RequestMiddlewareAction variant");
879879
}
880880

881-
#[cfg(unix)]
881+
std::fs::remove_file(&genesis_path).unwrap();
882882
{
883-
std::fs::remove_file(&genesis_path).unwrap();
884-
{
885-
let mut file = std::fs::File::create(ledger_path.path().join("wrong")).unwrap();
886-
file.write_all(b"wrong file").unwrap();
887-
}
888-
symlink::symlink_file("wrong", &genesis_path).unwrap();
889-
890-
// File is a symbolic link => request should fail.
891-
let action = rrm.process_file_get(DEFAULT_GENESIS_DOWNLOAD_PATH);
892-
if let RequestMiddlewareAction::Respond { response, .. } = action {
893-
let response = runtime.block_on(response);
894-
let response = response.unwrap();
895-
assert_ne!(response.status(), 200);
896-
} else {
897-
panic!("Unexpected RequestMiddlewareAction variant");
898-
}
883+
let mut file = std::fs::File::create(ledger_path.path().join("wrong")).unwrap();
884+
file.write_all(b"wrong file").unwrap();
885+
}
886+
symlink::symlink_file("wrong", &genesis_path).unwrap();
887+
888+
// File is a symbolic link => request should fail.
889+
let action = rrm.process_file_get(DEFAULT_GENESIS_DOWNLOAD_PATH);
890+
if let RequestMiddlewareAction::Respond { response, .. } = action {
891+
let response = runtime.block_on(response);
892+
let response = response.unwrap();
893+
assert_ne!(response.status(), 200);
894+
} else {
895+
panic!("Unexpected RequestMiddlewareAction variant");
899896
}
900897
}
901898
}

0 commit comments

Comments
 (0)