Skip to content

Commit 992afc3

Browse files
committed
Add restriction and cargo
1 parent 8f31db6 commit 992afc3

35 files changed

+458
-258
lines changed

Cargo.toml

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,52 @@ description = "A Rust framework for developing WSL plugins using safe and idioma
2222
[patch.crates-io]
2323
wslpluginapi-sys = { version = "0.1.0-rc.1", git = "https://github.com/mveril/wslpluginapi-sys.git", branch = "develop" }
2424

25+
2526
[workspace.lints.rust]
26-
missing_docs = "warn"
27-
missing_errors_doc = "warn"
28-
missing_panics_doc = "warn"
29-
pub_use_of_private_imports = "allow"
27+
unused = "warn"
28+
future_incompatible = "deny"
3029

3130
[workspace.lints.clippy]
32-
all = "warn"
31+
all = { level = "warn", priority = -1 }
3332
pedantic = { level = "warn", priority = -1 }
3433
nursery = { level = "warn", priority = -1 }
35-
# useful lib lints
34+
cargo = {level = "warn", priority = -1}
35+
# Enable some restriction
3636
needless_pass_by_value = "warn"
3737
implicit_clone = "warn"
3838
unnecessary_wraps = "warn"
39-
unwrap_used = "warn"
40-
expect_used = "warn"
39+
missing_const_for_fn = "warn"
40+
missing_inline_in_public_items = "warn"
41+
unnecessary_safety_doc = "deny"
42+
43+
# ---- Strong DENY (CI-breaking, catch critical bugs) ----
44+
unwrap_used = "deny" # Avoid panics in production.
45+
expect_used = "deny" # Same as unwrap, no `.expect`.
46+
panic = "deny" # No panic! in library code.
47+
todo = "deny" # No todo! in shipped code.
48+
print_stdout = "deny" # Use logging, not println.
49+
print_stderr = "deny" # Use logging, not eprintln.
50+
dbg_macro = "deny" # No dbg! in release builds.
51+
mem_forget = "deny" # Prevent memory leaks.
52+
await_holding_lock = "deny" # Prevent async deadlocks with held locks.
53+
exit = "deny" # Libraries must not kill the process.
54+
55+
# ---- Useful WARN (signal, but not blocking) ----
56+
undocumented_unsafe_blocks = "warn" # Every unsafe block must be justified with SAFETY.
57+
missing_assert_message = "warn" # Clear messages for all asserts.
58+
integer_division = "warn" # Be explicit about truncating integer division.
59+
indexing_slicing = "warn" # Can panic if index is wrong.
60+
float_arithmetic = "warn" # Flag nondeterministic floating arithmetic.
61+
mutable_key_type = "warn" # Prevent mutable keys in maps (subtle bugs).
62+
manual_non_exhaustive = "warn" # Use #[non_exhaustive] instead of manual tricks.
63+
wrong_self_convention = "warn" # Enforce idiomatic naming for as_/to_/into_ methods.
64+
rc_mutex = "warn"
65+
use_debug = "warn"
66+
67+
[workspace.lints.rustdoc]
68+
all = "warn"
69+
broken_intra_doc_links = "forbid"
70+
private_intra_doc_links = "deny"
71+
invalid_rust_codeblocks = "deny"
72+
bare_urls = "warn"
73+
missing_crate_level_docs = "warn"

wslplugins-macro-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ version.workspace = true
55
license.workspace = true
66
repository.workspace = true
77
edition = "2021"
8+
description = "internal core implementation of for wslplugins-macro"
9+
keywords = ["wsl", "plugin", "windows", "linux", "internal"]
10+
categories = ["os::windows-apis", "api-bindings", "virtualization"]
811

912
[dependencies]
1013
syn = { version = "*", features = ["full", "extra-traits"] }

wslplugins-macro-core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# wslplugins-macro-core
2+
This package is a dependency of `wslplugins-macro` and provide the core of the macro logic it not intended to be installed manually

wslplugins-macro-core/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(missing_docs)]
2-
use std::{env, fs::File, io::Write, path::PathBuf};
3-
use struct_field_names_as_array::FieldNamesAsSlice;
2+
use std::{env, fs::File, io::Write as _, path::PathBuf};
3+
use struct_field_names_as_array::FieldNamesAsSlice as _;
44
use wslpluginapi_sys::WSLPluginHooksV1;
55

66
fn main() -> Result<(), Box<dyn std::error::Error>> {

wslplugins-macro-core/src/generator/c_funcs_tokens.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,7 @@ pub(super) fn get_c_func_tokens(hook: Hooks) -> Result<Option<TokenStream>> {
6969
}).unwrap_or(::wslplugins_rs::sys::windows_sys::Win32::Foundation::E_FAIL)
7070
}
7171
}),
72-
Hooks::OnDistributionRegistered => Some(quote! {
73-
extern "C" fn #c_method_ident(
74-
session: *const ::wslplugins_rs::sys::WSLSessionInformation,
75-
distribution: *const ::wslplugins_rs::sys::WSLOfflineDistributionInformation,
76-
) -> ::wslplugins_rs::sys::windows_sys::core::HRESULT {
77-
let session_ptr = unsafe { &*session };
78-
let distribution_ptr = unsafe { &*distribution };
79-
PLUGIN.get().map(|plugin|{
80-
::wslplugins_rs::windows_core::HRESULT::from(plugin.#trait_method_ident(
81-
session_ptr.as_ref(),
82-
distribution_ptr.as_ref(),
83-
)).0
84-
}).unwrap_or(::wslplugins_rs::sys::windows_sys::Win32::Foundation)
85-
}
86-
}),
87-
Hooks::OnDistributionUnregistered => Some(quote! {
72+
Hooks::OnDistributionRegistered | Hooks::OnDistributionUnregistered => Some(quote! {
8873
extern "C" fn #c_method_ident(
8974
session: *const ::wslplugins_rs::sys::WSLSessionInformation,
9075
distribution: *const ::wslplugins_rs::sys::WSLOfflineDistributionInformation,

wslplugins-macro-core/src/generator/hook_field_mapping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn generate_hook_fns(hooks: &[Hooks]) -> Result<Vec<TokenStream>> {
3232
}
3333

3434
// Create a static version of the type for plugin management
35-
fn create_static_type(imp: &ParsedImpl) -> Result<Type> {
35+
fn create_static_type(imp: &ParsedImpl) -> Type {
3636
let mut static_type = imp.target_type.as_ref().clone();
3737
if let Some(lifetime) = utils::get_path_lifetime(&imp.trait_) {
3838
utils::replace_lifetime_in_type(
@@ -41,7 +41,7 @@ fn create_static_type(imp: &ParsedImpl) -> Result<Type> {
4141
&Lifetime::new("'static", Span::call_site()),
4242
);
4343
}
44-
Ok(static_type)
44+
static_type
4545
}
4646

4747
// Prepare hooks by mapping them to their respective fields in the hook structure
@@ -83,7 +83,7 @@ fn hook_field_mapping(hooks_struct_name: &Ident, hook: Hooks) -> Result<TokenStr
8383

8484
// Generate the plugin entry function with hook management and initialization
8585
fn generate_entry_point(imp: &ParsedImpl, version: &RequiredVersion) -> Result<TokenStream> {
86-
let static_plugin_type = create_static_type(imp)?;
86+
let static_plugin_type = create_static_type(imp);
8787
let hooks_ref_name = format_ident!("hooks_ref");
8888
let hook_set = prepare_hooks(&hooks_ref_name, &imp.hooks)?;
8989
let RequiredVersion {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mod c_funcs_tokens;
22
mod hook_field_mapping;
33
mod utils;
4-
pub(crate) use hook_field_mapping::generate;
4+
pub use hook_field_mapping::generate;

wslplugins-macro-core/src/generator/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use syn::*;
1+
use syn::{
2+
GenericArgument, Lifetime, Path, PathArguments, Type, TypeBareFn, TypePath, TypeReference,
3+
TypeTuple,
4+
};
25

36
pub(super) fn replace_lifetime_in_type(
47
ty: &mut Type,

wslplugins-macro-core/src/hooks.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
use heck::ToSnakeCase;
2-
use strum::IntoEnumIterator;
1+
use heck::ToSnakeCase as _;
2+
use strum::IntoEnumIterator as _;
33
include!(concat!(env!("OUT_DIR"), "/hooks.rs"));
44

55
impl Hooks {
6-
pub fn get_c_method_name(&self) -> String {
6+
pub(crate) fn get_c_method_name(self) -> String {
77
self.to_string().to_snake_case()
88
}
99

10-
pub fn get_hook_field_name(&self) -> String {
10+
pub(crate) fn get_hook_field_name(self) -> String {
1111
self.to_string()
1212
}
1313

14-
pub fn get_trait_method_name(&self) -> String {
14+
pub(crate) fn get_trait_method_name(self) -> String {
1515
self.to_string().to_snake_case()
1616
}
1717

18-
pub fn from_trait_method_name(trait_method_name: impl AsRef<str>) -> Option<Hooks> {
19-
Hooks::iter().find(|hook| hook.get_trait_method_name() == trait_method_name.as_ref())
18+
pub(crate) fn from_trait_method_name(trait_method_name: impl AsRef<str>) -> Option<Self> {
19+
Self::iter().find(|hook| hook.get_trait_method_name() == trait_method_name.as_ref())
2020
}
2121
}
2222

wslplugins-macro-core/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#![allow(missing_docs)]
2-
#![allow(rustdoc::missing_errors_doc)]
3-
#![allow(rustdoc::missing_panics_doc)]
1+
#![allow(rustdoc::missing_doc)]
2+
#![allow(clippy::missing_errors_doc)]
3+
#![allow(clippy::missing_panics_doc)]
4+
#![allow(clippy::panic)]
5+
#![allow(clippy::panic_in_result_fn)]
46
mod generator;
57
mod hooks;
68
mod parser;
@@ -12,8 +14,8 @@ use quote::quote;
1214
use syn::{parse2, Result};
1315

1416
use crate::parser::{ParsedImpl, RequiredVersion};
15-
16-
pub fn wsl_plugin_v1(attr: TokenStream, item: TokenStream) -> Result<TokenStream> {
17+
#[inline]
18+
pub fn wsl_plugin_v1(attr: TokenStream, item: &TokenStream) -> Result<TokenStream> {
1719
let parsed_impl_result = parse2::<ParsedImpl>(item.clone());
1820
let required_version_result = parse2::<RequiredVersion>(attr);
1921
let (parsed_impl, required_version) =

0 commit comments

Comments
 (0)