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
This commit is contained in:
Jon C 2024-03-20 13:21:00 +01:00 committed by GitHub
parent 184ba6cb84
commit 261b3e9ee7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 26 deletions

View File

@ -6,6 +6,10 @@ os_name="$1"
case "$os_name" in case "$os_name" in
"Windows") "Windows")
vcpkg install openssl:x64-windows-static-md
vcpkg integrate install
choco install protoc
export PROTOC='C:\ProgramData\chocolatey\lib\protoc\tools\bin\protoc.exe'
;; ;;
"macOS") "macOS")
brew install protobuf brew install protobuf

View File

@ -31,6 +31,7 @@ jobs:
matrix: matrix:
os: os:
- macos-latest-large - macos-latest-large
- windows-latest
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -53,6 +54,7 @@ jobs:
matrix: matrix:
os: os:
- macos-latest-large - macos-latest-large
- windows-latest
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View File

@ -205,6 +205,9 @@ where
#[cfg(windows)] #[cfg(windows)]
fn set_perms(dst: &Path, _mode: u32) -> std::io::Result<()> { fn set_perms(dst: &Path, _mode: u32) -> std::io::Result<()> {
let mut perm = fs::metadata(dst)?.permissions(); let mut perm = fs::metadata(dst)?.permissions();
// This is OK for Windows, but clippy doesn't realize we're doing this
// only on Windows.
#[allow(clippy::permissions_set_readonly_false)]
perm.set_readonly(false); perm.set_readonly(false);
fs::set_permissions(dst, perm) fs::set_permissions(dst, perm)
} }

View File

@ -451,9 +451,13 @@ mod tests {
plugin: P, plugin: P,
config_path: &'static str, config_path: &'static str,
) -> (LoadedGeyserPlugin, Library, &'static str) { ) -> (LoadedGeyserPlugin, Library, &'static str) {
#[cfg(unix)]
let library = libloading::os::unix::Library::this();
#[cfg(windows)]
let library = libloading::os::windows::Library::this().unwrap();
( (
LoadedGeyserPlugin::new(Box::new(plugin), None), LoadedGeyserPlugin::new(Box::new(plugin), None),
Library::from(libloading::os::unix::Library::this()), Library::from(library),
config_path, config_path,
) )
} }

View File

@ -333,9 +333,7 @@ pub fn string_from_winreg_value(val: &winreg::RegValue) -> Option<String> {
let words = unsafe { let words = unsafe {
slice::from_raw_parts(val.bytes.as_ptr() as *const u16, val.bytes.len() / 2) slice::from_raw_parts(val.bytes.as_ptr() as *const u16, val.bytes.len() / 2)
}; };
let mut s = if let Ok(s) = String::from_utf16(words) { let Ok(mut s) = String::from_utf16(words) else {
s
} else {
return None; return None;
}; };
while s.ends_with('\u{0}') { while s.ends_with('\u{0}') {
@ -392,11 +390,9 @@ fn add_to_path(new_path: &str) -> bool {
}, },
}; };
let old_path = if let Some(s) = let Some(old_path) =
get_windows_path_var().unwrap_or_else(|err| panic!("Unable to get PATH: {}", err)) get_windows_path_var().unwrap_or_else(|err| panic!("Unable to get PATH: {}", err))
{ else {
s
} else {
return false; return false;
}; };

View File

@ -2,7 +2,10 @@
#![cfg(feature = "sbf_c")] #![cfg(feature = "sbf_c")]
#![allow(clippy::uninlined_format_args)] #![allow(clippy::uninlined_format_args)]
#![allow(clippy::arithmetic_side_effects)] #![allow(clippy::arithmetic_side_effects)]
#![cfg_attr(not(target_arch = "x86_64"), allow(dead_code, unused_imports))] #![cfg_attr(
any(target_os = "windows", not(target_arch = "x86_64")),
allow(dead_code, unused_imports)
)]
use { use {
solana_rbpf::memory_region::MemoryState, solana_rbpf::memory_region::MemoryState,
@ -103,7 +106,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) {
} }
#[bench] #[bench]
#[cfg(target_arch = "x86_64")] #[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))]
fn bench_program_alu(bencher: &mut Bencher) { fn bench_program_alu(bencher: &mut Bencher) {
let ns_per_s = 1000000000; let ns_per_s = 1000000000;
let one_million = 1000000; let one_million = 1000000;

View File

@ -878,24 +878,21 @@ mod tests {
panic!("Unexpected RequestMiddlewareAction variant"); panic!("Unexpected RequestMiddlewareAction variant");
} }
#[cfg(unix)] std::fs::remove_file(&genesis_path).unwrap();
{ {
std::fs::remove_file(&genesis_path).unwrap(); let mut file = std::fs::File::create(ledger_path.path().join("wrong")).unwrap();
{ file.write_all(b"wrong file").unwrap();
let mut file = std::fs::File::create(ledger_path.path().join("wrong")).unwrap(); }
file.write_all(b"wrong file").unwrap(); symlink::symlink_file("wrong", &genesis_path).unwrap();
}
symlink::symlink_file("wrong", &genesis_path).unwrap();
// File is a symbolic link => request should fail. // File is a symbolic link => request should fail.
let action = rrm.process_file_get(DEFAULT_GENESIS_DOWNLOAD_PATH); let action = rrm.process_file_get(DEFAULT_GENESIS_DOWNLOAD_PATH);
if let RequestMiddlewareAction::Respond { response, .. } = action { if let RequestMiddlewareAction::Respond { response, .. } = action {
let response = runtime.block_on(response); let response = runtime.block_on(response);
let response = response.unwrap(); let response = response.unwrap();
assert_ne!(response.status(), 200); assert_ne!(response.status(), 200);
} else { } else {
panic!("Unexpected RequestMiddlewareAction variant"); panic!("Unexpected RequestMiddlewareAction variant");
}
} }
} }
} }