From 92ec83b8d72b0bcd4c3f96ea878e20c695083e37 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 16 May 2026 13:58:12 +0800 Subject: [PATCH] feat: remove cbindgen. use manual writing instead (actually AI writing) --- Cargo.lock | 124 +----------------- wfassoc-cdylib/Cargo.toml | 3 - wfassoc-cdylib/build.rs | 23 ---- wfassoc-cdylib/cbindgen.toml | 160 ----------------------- wfassoc-cdylib/codegen/Findwfassoc.cmake | 101 ++++++++++++++ wfassoc-cdylib/codegen/wfassoc.h | 84 ++++++++++++ wfassoc-cdylib/codegen/wfassoc.hpp | 74 +++++++++++ wfassoc-cdylib/src/object_pool.rs | 2 +- 8 files changed, 265 insertions(+), 306 deletions(-) delete mode 100644 wfassoc-cdylib/build.rs delete mode 100644 wfassoc-cdylib/cbindgen.toml create mode 100644 wfassoc-cdylib/codegen/Findwfassoc.cmake create mode 100644 wfassoc-cdylib/codegen/wfassoc.h create mode 100644 wfassoc-cdylib/codegen/wfassoc.hpp diff --git a/Cargo.lock b/Cargo.lock index c33d988..65d8d7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,25 +73,6 @@ version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" -[[package]] -name = "cbindgen" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684" -dependencies = [ - "clap", - "heck", - "indexmap", - "log", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn", - "tempfile", - "toml 0.8.23", -] - [[package]] name = "cfg-if" version = "1.0.3" @@ -203,12 +184,6 @@ dependencies = [ "windows-sys 0.60.2", ] -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - [[package]] name = "getrandom" version = "0.3.4" @@ -249,12 +224,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - [[package]] name = "js-sys" version = "0.3.81" @@ -367,7 +336,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" dependencies = [ - "toml_edit 0.23.9", + "toml_edit", ] [[package]] @@ -451,12 +420,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "scopeguard" version = "1.2.0" @@ -493,28 +456,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_json" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", - "serde_core", -] - -[[package]] -name = "serde_spanned" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" -dependencies = [ - "serde", -] - [[package]] name = "serde_spanned" version = "1.0.3" @@ -556,19 +497,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" -dependencies = [ - "fastrand", - "getrandom", - "once_cell", - "rustix", - "windows-sys 0.60.2", -] - [[package]] name = "thiserror" version = "2.0.17" @@ -589,18 +517,6 @@ dependencies = [ "syn", ] -[[package]] -name = "toml" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" -dependencies = [ - "serde", - "serde_spanned 0.6.9", - "toml_datetime 0.6.11", - "toml_edit 0.22.27", -] - [[package]] name = "toml" version = "0.9.8" @@ -609,22 +525,13 @@ checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" dependencies = [ "indexmap", "serde_core", - "serde_spanned 1.0.3", - "toml_datetime 0.7.3", + "serde_spanned", + "toml_datetime", "toml_parser", "toml_writer", "winnow", ] -[[package]] -name = "toml_datetime" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" -dependencies = [ - "serde", -] - [[package]] name = "toml_datetime" version = "0.7.3" @@ -634,20 +541,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "toml_edit" -version = "0.22.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" -dependencies = [ - "indexmap", - "serde", - "serde_spanned 0.6.9", - "toml_datetime 0.6.11", - "toml_write", - "winnow", -] - [[package]] name = "toml_edit" version = "0.23.9" @@ -655,7 +548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d7cbc3b4b49633d57a0509303158ca50de80ae32c265093b24c414705807832" dependencies = [ "indexmap", - "toml_datetime 0.7.3", + "toml_datetime", "toml_parser", "winnow", ] @@ -669,12 +562,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - [[package]] name = "toml_writer" version = "1.0.4" @@ -807,7 +694,6 @@ dependencies = [ name = "wfassoc-cdylib" version = "0.1.0" dependencies = [ - "cbindgen", "num_enum", "slotmap", "thiserror", @@ -822,7 +708,7 @@ dependencies = [ "comfy-table", "serde", "thiserror", - "toml 0.9.8", + "toml", "wfassoc", ] diff --git a/wfassoc-cdylib/Cargo.toml b/wfassoc-cdylib/Cargo.toml index 02171e1..6b161cf 100644 --- a/wfassoc-cdylib/Cargo.toml +++ b/wfassoc-cdylib/Cargo.toml @@ -14,6 +14,3 @@ thiserror = { workspace = true } wfassoc = { path="../wfassoc" } slotmap = "1.1.1" num_enum = "0.7.6" - -[build-dependencies] -cbindgen = "0.29.0" diff --git a/wfassoc-cdylib/build.rs b/wfassoc-cdylib/build.rs deleted file mode 100644 index ac1ad36..0000000 --- a/wfassoc-cdylib/build.rs +++ /dev/null @@ -1,23 +0,0 @@ -extern crate cbindgen; - -use std::{env, path::Path}; - -fn main() { - let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - - let crate_dir_path = Path::new(&crate_dir); - let cbindgen_toml_path = crate_dir_path.join("cbindgen.toml"); - let cbindgen_config = cbindgen::Config::from_file(cbindgen_toml_path) - .expect("Unable to load cbindgen configuration file."); - - let out_dir = env::var("OUT_DIR").unwrap(); - let out_dir_path = Path::new(&out_dir); - let wfassoc_h_path = out_dir_path.join("wfassoc.h"); - - cbindgen::Builder::new() - .with_crate(crate_dir) - .with_config(cbindgen_config) - .generate() - .expect("Unable to generate bindings") - .write_to_file(wfassoc_h_path); -} diff --git a/wfassoc-cdylib/cbindgen.toml b/wfassoc-cdylib/cbindgen.toml deleted file mode 100644 index d817f59..0000000 --- a/wfassoc-cdylib/cbindgen.toml +++ /dev/null @@ -1,160 +0,0 @@ -# This is a template cbindgen.toml file with all of the default values. -# Some values are commented out because their absence is the real default. -# -# See https://github.com/mozilla/cbindgen/blob/main/docs.md#cbindgentoml -# for detailed documentation of every option here. - - - -language = "C" - - - -############## Options for Wrapping the Contents of the Header ################# - -# header = "/* Text to put at the beginning of the generated file. Probably a license. */" -# trailer = "/* Text to put at the end of the generated file */" -# include_guard = "my_bindings_h" -pragma_once = true -# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" -include_version = false -# namespace = "my_namespace" -namespaces = [] -using_namespaces = [] -sys_includes = [] -includes = [] -no_includes = false -cpp_compat = true -after_includes = "" - - - - -############################ Code Style Options ################################ - -braces = "SameLine" -line_length = 100 -tab_width = 4 -documentation = true -documentation_style = "auto" -documentation_length = "full" -line_endings = "Native" # also "LF", "CR", "CRLF", "Native" - - - - -############################# Codegen Options ################################## - -style = "both" -sort_by = "Name" # default for `fn.sort_by` and `const.sort_by` -usize_is_size_t = true - - - -[defines] -# "target_os = freebsd" = "DEFINE_FREEBSD" -# "feature = serde" = "DEFINE_SERDE" - - - -[export] -include = [] -exclude = [] -# prefix = "CAPI_" -item_types = [] -renaming_overrides_prefixing = false - - - -[export.rename] - - - -[export.body] - - -[export.mangle] - - -[fn] -rename_args = "None" -# must_use = "MUST_USE_FUNC" -# deprecated = "DEPRECATED_FUNC" -# deprecated_with_note = "DEPRECATED_FUNC_WITH_NOTE" -# no_return = "NO_RETURN" -# prefix = "START_FUNC" -# postfix = "END_FUNC" -args = "auto" -sort_by = "None" - - - - -[struct] -rename_fields = "None" -# must_use = "MUST_USE_STRUCT" -# deprecated = "DEPRECATED_STRUCT" -# deprecated_with_note = "DEPRECATED_STRUCT_WITH_NOTE" -rename_associated_constant = "None" -derive_constructor = false -derive_eq = false -derive_neq = false -derive_lt = false -derive_lte = false -derive_gt = false -derive_gte = false - - - - -[enum] -rename_variants = "UpperCase" -# must_use = "MUST_USE_ENUM" -# deprecated = "DEPRECATED_ENUM" -# deprecated_with_note = "DEPRECATED_ENUM_WITH_NOTE" -add_sentinel = false -prefix_with_name = true -derive_helper_methods = false -derive_const_casts = false -derive_mut_casts = false -# cast_assert_name = "ASSERT" -derive_tagged_enum_destructor = false -derive_tagged_enum_copy_constructor = false -enum_class = true -private_default_tagged_enum_constructor = false - - - - -[const] -allow_static_const = true -allow_constexpr = false -sort_by = "Name" - - - - -[macro_expansion] -bitflags = false - - - - - - -############## Options for How Your Rust library Should Be Parsed ############## - -[parse] -parse_deps = false -# include = [] -exclude = [] -clean = false -extra_bindings = [] - - - -[parse.expand] -crates = ["wfassoc-cdylib"] -all_features = false -default_features = true -features = [] diff --git a/wfassoc-cdylib/codegen/Findwfassoc.cmake b/wfassoc-cdylib/codegen/Findwfassoc.cmake new file mode 100644 index 0000000..e0744c2 --- /dev/null +++ b/wfassoc-cdylib/codegen/Findwfassoc.cmake @@ -0,0 +1,101 @@ +# Findwfassoc.cmake +# ---------------- +# Find wfassoc library and headers. +# +# This module requires the user to set wfassoc_ROOT to the installation +# directory of wfassoc. The directory structure under wfassoc_ROOT must be: +# bin/ - contains wfassoc_cdylib.dll +# include/ - contains wfassoc.h and wfassoc.hpp +# lib/ - contains wfassoc_cdylib.dll.lib (import library) +# +# This module defines the following variables: +# wfassoc_FOUND - True if wfassoc was found +# wfassoc_INCLUDE_DIRS - Path to wfassoc include directory +# wfassoc_LIBRARIES - Path to wfassoc import library +# wfassoc_DLL - Path to wfassoc DLL +# wfassoc_ROOT - The root directory (user-provided) +# +# This module also creates the following imported targets: +# wfassoc::wfassoc - Main wfassoc library (includes both include and link) +# + +set(wfassoc_FOUND FALSE) + +# Require user to set wfassoc_ROOT +if(NOT wfassoc_ROOT) + message(FATAL_ERROR "wfassoc_ROOT must be set to the installation directory of wfassoc") +endif() + +# Check existence of required subdirectories +if(NOT EXISTS ${wfassoc_ROOT}) + message(FATAL_ERROR "wfassoc_ROOT directory does not exist: ${wfassoc_ROOT}") +endif() + +set(wfassoc_INCLUDE_DIR ${wfassoc_ROOT}/include) +set(wfassoc_LIB_DIR ${wfassoc_ROOT}/lib) +set(wfassoc_BIN_DIR ${wfassoc_ROOT}/bin) + +# Find header files +if(EXISTS ${wfassoc_INCLUDE_DIR}/wfassoc.h AND EXISTS ${wfassoc_INCLUDE_DIR}/wfassoc.hpp) + set(wfassoc_INCLUDE_DIRS ${wfassoc_INCLUDE_DIR}) +else() + message(SEND_ERROR "Missing wfassoc header files in ${wfassoc_INCLUDE_DIR}") + return() +endif() + +# Find import library (.lib) +find_file(wfassoc_LIBRARIES + NAMES wfassoc_cdylib.dll.lib + PATHS ${wfassoc_LIB_DIR} + NO_DEFAULT_PATH + DOC "wfassoc import library" +) + +if(NOT wfassoc_LIBRARIES) + message(SEND_ERROR "Missing wfassoc import library (wfassoc_cdylib.dll.lib) in ${wfassoc_LIB_DIR}") + return() +endif() + +# Find DLL file +find_file(wfassoc_DLL + NAMES wfassoc_cdylib.dll + PATHS ${wfassoc_BIN_DIR} + NO_DEFAULT_PATH + DOC "wfassoc dynamic library" +) + +if(NOT wfassoc_DLL) + message(SEND_ERROR "Missing wfassoc DLL (wfassoc_cdylib.dll) in ${wfassoc_BIN_DIR}") + return() +endif() + +# Everything found +set(wfassoc_FOUND TRUE) + +# Mark variables as advanced for ccmake/cmake-gui +mark_as_advanced(wfassoc_INCLUDE_DIRS wfassoc_LIBRARIES wfassoc_DLL) + +# Create imported target for wfassoc +if(wfassoc_FOUND AND NOT TARGET wfassoc::wfassoc) + add_library(wfassoc::wfassoc SHARED IMPORTED) + + # Set include directories + set_target_properties(wfassoc::wfassoc PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${wfassoc_INCLUDE_DIRS} + ) + + # Set import library location + set_target_properties(wfassoc::wfassoc PROPERTIES + IMPORTED_IMPLIB "${wfassoc_LIBRARIES}" + IMPORTED_LOCATION "${wfassoc_DLL}" + ) +endif() + +# Optional: Print status message +if(wfassoc_FOUND) + message(STATUS "Found wfassoc:") + message(STATUS " Root : ${wfassoc_ROOT}") + message(STATUS " Include : ${wfassoc_INCLUDE_DIRS}") + message(STATUS " Library : ${wfassoc_LIBRARIES}") + message(STATUS " DLL : ${wfassoc_DLL}") +endif() diff --git a/wfassoc-cdylib/codegen/wfassoc.h b/wfassoc-cdylib/codegen/wfassoc.h new file mode 100644 index 0000000..0fc1dc8 --- /dev/null +++ b/wfassoc-cdylib/codegen/wfassoc.h @@ -0,0 +1,84 @@ +#pragma once +#ifndef __WFASSOC_H__ +#define __WFASSOC_H__ + +#include +#include +#include +#include +#include + + +typedef const char *CStyleString; + +typedef uint64_t Token; + +typedef uint32_t Scope; +#define SCOPE_USER 0u +#define SCOPE_SYSTEM 1u + +typedef uint32_t View; +#define VIEW_USER 0u +#define VIEW_SYSTEM 1u +#define VIEW_HYBRID 2u + + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +bool WFStartup(void); + +bool WFShutdown(void); + +CStyleString WFGetLastError(void); + +bool WFHasPrivilege(void); + +bool WFSchemaCreate(Token *out_schema); + +bool WFSchemaDestroy(Token in_schema); + +bool WFSchemaSetIdentifier(Token in_schema, CStyleString in_value); + +bool WFSchemaSetPath(Token in_schema, CStyleString in_value); + +bool WFSchemaSetClsid(Token in_schema, CStyleString in_value); + +bool WFSchemaSetName(Token in_schema, CStyleString in_value); + +bool WFSchemaSetIcon(Token in_schema, CStyleString in_value); + +bool WFSchemaSetBehavior(Token in_schema, CStyleString in_value); + +bool WFSchemaAddStr(Token in_schema, CStyleString in_name, CStyleString in_value); + +bool WFSchemaAddIcon(Token in_schema, CStyleString in_name, CStyleString in_value); + +bool WFSchemaAddBehavior(Token in_schema, CStyleString in_name, CStyleString in_value); + +bool WFSchemaAddExt(Token in_schema, + CStyleString in_ext, + CStyleString in_ext_name, + CStyleString in_ext_icon, + CStyleString in_ext_behavior); + +bool WFProgramCreate(Token in_schema, Token *out_program); + +bool WFProgramDestroy(Token in_program); + +bool WFProgramRegister(Token in_program, uint32_t in_scope); + +bool WFProgramUnregister(Token in_program, uint32_t in_scope); + +bool WFProgramIsRegistered(Token in_program, uint32_t in_scope, bool *out_is_registered); + +bool WFProgramLinkExt(Token in_program, uint32_t in_scope, size_t in_index); + +bool WFProgramUnlinkExt(Token in_program, uint32_t in_scope, size_t in_index); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // __WFASSOC_H__ diff --git a/wfassoc-cdylib/codegen/wfassoc.hpp b/wfassoc-cdylib/codegen/wfassoc.hpp new file mode 100644 index 0000000..c2480d6 --- /dev/null +++ b/wfassoc-cdylib/codegen/wfassoc.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include +#include + +enum class Scope : uint32_t { + User = 0u, + System = 1u +}; + +enum class View : uint32_t { + User = 0u, + System = 1u, + Hybrid = 2u +}; + +using Token = uint64_t; + +using CStyleString = const char*; + +extern "C" { + +bool WFStartup(void); + +bool WFShutdown(void); + +CStyleString WFGetLastError(void); + +bool WFHasPrivilege(void); + +bool WFSchemaCreate(Token *out_schema); + +bool WFSchemaDestroy(Token in_schema); + +bool WFSchemaSetIdentifier(Token in_schema, CStyleString in_value); + +bool WFSchemaSetPath(Token in_schema, CStyleString in_value); + +bool WFSchemaSetClsid(Token in_schema, CStyleString in_value); + +bool WFSchemaSetName(Token in_schema, CStyleString in_value); + +bool WFSchemaSetIcon(Token in_schema, CStyleString in_value); + +bool WFSchemaSetBehavior(Token in_schema, CStyleString in_value); + +bool WFSchemaAddStr(Token in_schema, CStyleString in_name, CStyleString in_value); + +bool WFSchemaAddIcon(Token in_schema, CStyleString in_name, CStyleString in_value); + +bool WFSchemaAddBehavior(Token in_schema, CStyleString in_name, CStyleString in_value); + +bool WFSchemaAddExt(Token in_schema, + CStyleString in_ext, + CStyleString in_ext_name, + CStyleString in_ext_icon, + CStyleString in_ext_behavior); + +bool WFProgramCreate(Token in_schema, Token *out_program); + +bool WFProgramDestroy(Token in_program); + +bool WFProgramRegister(Token in_program, uint32_t in_scope); + +bool WFProgramUnregister(Token in_program, uint32_t in_scope); + +bool WFProgramIsRegistered(Token in_program, uint32_t in_scope, bool *out_is_registered); + +bool WFProgramLinkExt(Token in_program, uint32_t in_scope, size_t in_index); + +bool WFProgramUnlinkExt(Token in_program, uint32_t in_scope, size_t in_index); + +} \ No newline at end of file diff --git a/wfassoc-cdylib/src/object_pool.rs b/wfassoc-cdylib/src/object_pool.rs index 029eb97..5f5374b 100644 --- a/wfassoc-cdylib/src/object_pool.rs +++ b/wfassoc-cdylib/src/object_pool.rs @@ -14,7 +14,7 @@ pub enum Error { NoSuchToken, } -/// The token for fetching obejct in [ObjectPool]. +/// The token for fetching object in [ObjectPool]. pub type Token = u64; /// A pool for managing objects with unique tokens.