Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: resolve all new nightly clippy failures #32

Merged
merged 6 commits into from
Nov 9, 2024
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
27 changes: 16 additions & 11 deletions .github/actions/winget-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@ inputs:
runs:
using: "composite"
steps:
- name: Get URIs for Latest Winget assets
- name: Get URIs for Winget v1.8.1911 assets
shell: pwsh
run: |
$AuthenticatedHeaders = @{ "Authorization" = "Bearer ${{ inputs.GITHUB_TOKEN }}" }

$LatestReleaseInfo = Invoke-RestMethod -Headers $AuthenticatedHeaders 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
$LatestWingetDownloadUri = $LatestReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('.msixbundle') }
$LatestWingetLicenseDownloadUri = $LatestReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('License1.xml') }
$ReleaseInfo = Invoke-RestMethod -Headers $AuthenticatedHeaders 'https://api.github.com/repos/microsoft/winget-cli/releases/164835566'
$WingetDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('.msixbundle') }
$WingetLicenseDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('License1.xml') }

# Print to logs
Write-Host "LatestWingetDownloadUri=$LatestWingetDownloadUri"
Write-Host "LatestWingetLicenseDownloadUri=$LatestWingetLicenseDownloadUri"
Write-Host "WingetDownloadUri=$WingetDownloadUri"
Write-Host "WingetLicenseDownloadUri=$WingetLicenseDownloadUri"

# Save output for next step
Write-Output "LatestWingetDownloadUri=$LatestWingetDownloadUri" >> $env:GITHUB_ENV
Write-Output "LatestWingetLicenseDownloadUri=$LatestWingetLicenseDownloadUri" >> $env:GITHUB_ENV
Write-Output "WingetDownloadUri=$WingetDownloadUri" >> $env:GITHUB_ENV
Write-Output "WingetLicenseDownloadUri=$WingetLicenseDownloadUri" >> $env:GITHUB_ENV

- name: Download Winget Assets and Dependencies
shell: pwsh
run: |
New-Item -Type Directory $env:RUNNER_TEMP/winget-install
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.8.x64.appx
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx # Needed per https://github.com/microsoft/winget-cli/blob/21de1607ed5c90174e6bb931406975c18681a5dd/README.md?plain=1#L35C19-L35C19
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:LatestWingetDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/winget.msixbundle
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:LatestWingetLicenseDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/license.xml
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/winget.msixbundle
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetLicenseDownloadUri -OutFile $env:RUNNER_TEMP/winget-install/license.xml

- name: Start Winget Installation
- name: Start Winget Installation for all Users
shell: pwsh
run: |
Add-AppxProvisionedPackage -Online -PackagePath $env:RUNNER_TEMP/winget-install/winget.msixbundle -LicensePath $env:RUNNER_TEMP/winget-install/license.xml -DependencyPackagePath $env:RUNNER_TEMP/winget-install/Microsoft.UI.Xaml.2.8.x64.appx, $env:RUNNER_TEMP/winget-install/Microsoft.VCLibs.x64.14.00.Desktop.appx

- name: Install Winget for Current User (for better install diagnostics)
shell: powershell
run: |
Add-AppxPackage $env:RUNNER_TEMP/winget-install/winget.msixbundle

- name: Wait for Completion of Winget Installation
shell: pwsh
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ jobs:
targets: ${{ matrix.target_triple }}

- name: Run Cargo Clippy
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets -- -D warnings

- name: Run Cargo Clippy (--features nightly)
if: matrix.rust_toolchain == 'nightly'
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets --features nightly
run: cargo +${{ matrix.rust_toolchain }} clippy --locked --profile ${{ matrix.cargo_profile }} --target ${{ matrix.target_triple }} --all-targets --features nightly -- -D warnings

udeps:
name: Detect Unused Cargo Dependencies
Expand Down
11 changes: 6 additions & 5 deletions general/echo/kmdf/driver/DriverSync/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use wdk_sys::{
APC_LEVEL,
NTSTATUS,
STATUS_SUCCESS,
ULONG,
WDFDEVICE,
WDFDEVICE_INIT,
WDFOBJECT,
Expand All @@ -28,6 +27,8 @@ use crate::{
KeGetCurrentIrql,
GUID_DEVINTERFACE_ECHO,
WDF_DEVICE_CONTEXT_TYPE_INFO,
WDF_OBJECT_ATTRIBUTES_SIZE,
WDF_PNPPOWER_EVENT_CALLBACKS_SIZE,
WDF_REQUEST_CONTEXT_TYPE_INFO,
};

Expand All @@ -49,7 +50,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
// Register pnp/power callbacks so that we can start and stop the timer as the
// device gets started and stopped.
let mut pnp_power_callbacks = WDF_PNPPOWER_EVENT_CALLBACKS {
Size: core::mem::size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>() as ULONG,
Size: WDF_PNPPOWER_EVENT_CALLBACKS_SIZE,
EvtDeviceSelfManagedIoInit: Some(echo_evt_device_self_managed_io_start),
EvtDeviceSelfManagedIoSuspend: Some(echo_evt_device_self_managed_io_suspend),
// Function used for both Init and Restart Callbacks
Expand All @@ -68,7 +69,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
};

let mut attributes = WDF_OBJECT_ATTRIBUTES {
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
Size: WDF_OBJECT_ATTRIBUTES_SIZE,
ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent,
SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent,
ContextTypeInfo: wdf_get_context_type_info!(RequestContext),
Expand All @@ -84,7 +85,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
};

let mut attributes = WDF_OBJECT_ATTRIBUTES {
Size: core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>() as ULONG,
Size: WDF_OBJECT_ATTRIBUTES_SIZE,
ExecutionLevel: _WDF_EXECUTION_LEVEL::WdfExecutionLevelInheritFromParent,
SynchronizationScope: _WDF_SYNCHRONIZATION_SCOPE::WdfSynchronizationScopeInheritFromParent,
ContextTypeInfo: wdf_get_context_type_info!(DeviceContext),
Expand All @@ -95,7 +96,7 @@ pub fn echo_device_create(mut device_init: &mut WDFDEVICE_INIT) -> NTSTATUS {
let mut nt_status = unsafe {
call_unsafe_wdf_function_binding!(
WdfDeviceCreate,
(core::ptr::addr_of_mut!(device_init)) as *mut *mut WDFDEVICE_INIT,
(core::ptr::addr_of_mut!(device_init)).cast(),
&mut attributes,
&mut device,
)
Expand Down
8 changes: 3 additions & 5 deletions general/echo/kmdf/driver/DriverSync/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use wdk_sys::{
PDRIVER_OBJECT,
PWDFDEVICE_INIT,
STATUS_SUCCESS,
ULONG,
UNICODE_STRING,
WDFDRIVER,
WDFOBJECT,
Expand All @@ -23,7 +22,7 @@ use wdk_sys::{
WDF_NO_OBJECT_ATTRIBUTES,
};

use crate::device;
use crate::{device, WDF_DRIVER_CONFIG_SIZE, WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE};

extern crate alloc;

Expand Down Expand Up @@ -55,7 +54,7 @@ extern "system" fn driver_entry(
registry_path: PCUNICODE_STRING,
) -> NTSTATUS {
let mut driver_config = WDF_DRIVER_CONFIG {
Size: core::mem::size_of::<WDF_DRIVER_CONFIG>() as ULONG,
Size: WDF_DRIVER_CONFIG_SIZE,
EvtDriverDeviceAdd: Some(echo_evt_device_add),
..WDF_DRIVER_CONFIG::default()
};
Expand Down Expand Up @@ -167,12 +166,11 @@ fn echo_print_driver_version() -> NTSTATUS {
unsafe {
call_unsafe_wdf_function_binding!(WdfObjectDelete, string as WDFOBJECT);
};
// string = core::ptr::null_mut();

// 2) Find out to which version of framework this driver is bound to.
//
let mut ver = WDF_DRIVER_VERSION_AVAILABLE_PARAMS {
Size: core::mem::size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>() as ULONG,
Size: WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE,
MajorVersion: 1,
MinorVersion: 0,
};
Expand Down
117 changes: 117 additions & 0 deletions general/echo/kmdf/driver/DriverSync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ use wdk_sys::{
ULONG,
WDFOBJECT,
WDFREQUEST,
WDF_DRIVER_CONFIG,
WDF_DRIVER_VERSION_AVAILABLE_PARAMS,
WDF_IO_QUEUE_CONFIG,
WDF_OBJECT_ATTRIBUTES,
WDF_OBJECT_CONTEXT_TYPE_INFO,
WDF_PNPPOWER_EVENT_CALLBACKS,
WDF_TIMER_CONFIG,
};
mod wdf_object_context;
use core::sync::atomic::AtomicI32;
Expand Down Expand Up @@ -100,3 +106,114 @@ pub struct RequestContext {
cancel_completion_ownership_count: AtomicI32,
}
wdf_declare_context_type_with_name!(RequestContext, request_get_context);

// None of the below SIZE constants should be needed after an equivalent `WDF_STRUCTURE_SIZE` macro is added to `wdk-sys`: https://github.com/microsoft/windows-drivers-rs/issues/242

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_DRIVER_CONFIG>() is known to fit in ULONG due to below const assert"
)]
const WDF_DRIVER_CONFIG_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_DRIVER_CONFIG>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_DRIVER_CONFIG>() should fit in ULONG"
);
};
S as ULONG
};

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>() is known to fit in ULONG due to \
below const assert"
)]
const WDF_DRIVER_VERSION_AVAILABLE_PARAMS_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_DRIVER_VERSION_AVAILABLE_PARAMS>() should fit in ULONG"
);
};
S as ULONG
};

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_IO_QUEUE_CONFIG>() is known to fit in ULONG due to below const assert"
)]
const WDF_IO_QUEUE_CONFIG_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_IO_QUEUE_CONFIG>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_IO_QUEUE_CONFIG>() should fit in ULONG"
);
};
S as ULONG
};

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_OBJECT_ATTRIBUTES>() is known to fit in ULONG due to below const \
assert"
)]
const WDF_OBJECT_ATTRIBUTES_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_OBJECT_ATTRIBUTES>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_OBJECT_ATTRIBUTES>() should fit in ULONG"
);
};
S as ULONG
};

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>() is known to fit in ULONG due to below \
const assert"
)]
const WDF_OBJECT_CONTEXT_TYPE_INFO_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_OBJECT_CONTEXT_TYPE_INFO>() should fit in ULONG"
);
};
S as ULONG
};

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>() is known to fit in ULONG due to below \
const assert"
)]
const WDF_PNPPOWER_EVENT_CALLBACKS_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_PNPPOWER_EVENT_CALLBACKS>() should fit in ULONG"
);
};
S as ULONG
};

#[allow(
clippy::cast_possible_truncation,
reason = "size_of::<WDF_TIMER_CONFIG>() is known to fit in ULONG due to below const assert"
)]
const WDF_TIMER_CONFIG_SIZE: ULONG = {
const S: usize = core::mem::size_of::<WDF_TIMER_CONFIG>();
const {
assert!(
S <= ULONG::MAX as usize,
"size_of::<WDF_TIMER_CONFIG>() should fit in ULONG"
);
};
S as ULONG
};
wmmc88 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading