diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-08 22:43:34 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-08 22:43:34 +0800 |
| commit | 90ed18a41fef137ed0637cf9fc6aa667de2c905f (patch) | |
| tree | d0e472f860ce0c771f4ae47ed35be36aa2df76b7 | |
| parent | 62fd90b639a0e24570c558738205d752d2d957bb (diff) | |
Update dependencies and add C bindings generation
| -rw-r--r-- | Cargo.lock | 6 | ||||
| -rw-r--r-- | build.rs | 41 | ||||
| -rw-r--r-- | cbindgen.toml | 45 | ||||
| -rw-r--r-- | scripts/deploy/cbindgen.ps1 | 18 | ||||
| -rwxr-xr-x | scripts/deploy/cbindgen.sh | 16 | ||||
| -rw-r--r-- | systems/_constants/macros/src/lib.rs | 6 | ||||
| -rw-r--r-- | systems/_constants/src/lib.rs | 2 | ||||
| -rw-r--r-- | systems/sheet/Cargo.toml | 6 | ||||
| -rw-r--r-- | systems/sheet/src/sheet/reader.rs | 6 |
9 files changed, 130 insertions, 16 deletions
@@ -1727,7 +1727,7 @@ dependencies = [ "serde", "sha2 0.10.9", "sheet_system_macros", - "thiserror 1.0.69", + "thiserror 2.0.17", "tokio", ] @@ -1919,9 +1919,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.48.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" dependencies = [ "bytes", "libc", @@ -10,12 +10,53 @@ fn main() { let repo_root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); + // Only run on nightly, + // because cbindgen requires nightly features + // + // For stable toolchain, you can use ./scripts/deploy/cbindgen.* to build + if env::var("RUSTUP_TOOLCHAIN") + .map(|s| s.contains("nightly")) + .unwrap_or(false) + { + generate_c_binding(); + } + if let Err(e) = generate_compile_info(&repo_root) { eprintln!("Failed to generate compile info: {}", e); std::process::exit(1); } } +fn generate_c_binding() { + // Try to run cbindgen to generate C bindings + // > cbindgen --config cbindgen.toml ffi --output ffi/.temp/jvlib.h --quiet + let output = std::process::Command::new("cbindgen") + .args([ + "--config", + "cbindgen.toml", + "ffi", + "--output", + "ffi/.temp/jvlib.h", + "--quiet", + ]) + .output(); + + match output { + Ok(output) if output.status.success() => { + // Successfully generated bindings + } + Ok(_) => { + eprintln!("cbindgen failed to generate bindings"); + } + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + eprintln!("cbindgen not found, skipping C binding generation"); + } + Err(e) => { + eprintln!("Failed to run cbindgen: {}", e); + } + } +} + /// Generate compile info fn generate_compile_info(repo_root: &PathBuf) -> Result<(), Box<dyn std::error::Error>> { // Read the template code diff --git a/cbindgen.toml b/cbindgen.toml new file mode 100644 index 0000000..d333dda --- /dev/null +++ b/cbindgen.toml @@ -0,0 +1,45 @@ +language = "C" + +documentation = true +documentation_style = "doxy" + +line_length = 75 +tab_width = 2 +braces = "SameLine" + +header = """ +/*! + * This file is automatically generated by cbindgen. + * DO NOT EDIT THIS FILE MANUALLY. + * + * All string-returning functions allocate memory that must be freed using JV_FreeString(). + */ +""" + +include_guard = "JVLIB_H" + +include_version = true + +[parse] +parse_deps = true +include = ["constants"] +extra_bindings = ["constants"] +expand = { crates = ["constants"] } + +[export] +include = ["JV_.*"] +exclude = [] + +[fn] +sort_by = "Name" +rename_args = "None" + +[const] +sort_by = "Name" + +[struct] +rename_fields = "None" + +[enum] +rename_variants = "None" +enum_class = false diff --git a/scripts/deploy/cbindgen.ps1 b/scripts/deploy/cbindgen.ps1 new file mode 100644 index 0000000..4dd9eb9 --- /dev/null +++ b/scripts/deploy/cbindgen.ps1 @@ -0,0 +1,18 @@ +$originalLocation = Get-Location +Set-Location (Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)) + +if (-not (Get-Command cbindgen -ErrorAction SilentlyContinue)) { + cargo install cbindgen +} + +if (Test-Path ffi/.temp/jvlib.h) { + Remove-Item ffi/.temp/jvlib.h +} +$env:RUSTUP_TOOLCHAIN = "nightly" +cbindgen ` + --config cbindgen.toml ` + ffi ` + --output ffi/.temp/jvlib.h ` + --quiet + +Set-Location $originalLocation diff --git a/scripts/deploy/cbindgen.sh b/scripts/deploy/cbindgen.sh new file mode 100755 index 0000000..2be2328 --- /dev/null +++ b/scripts/deploy/cbindgen.sh @@ -0,0 +1,16 @@ +#!/bin/bash +cd "$(dirname "$(readlink -f "$0")")/../.." + +if ! command -v cbindgen &> /dev/null; then + cargo install cbindgen +fi + +rm ffi/.temp/jvlib.h +RUSTUP_TOOLCHAIN=nightly \ +cbindgen \ + --config cbindgen.toml \ + ffi \ + --output ffi/.temp/jvlib.h \ + --quiet + +cd - diff --git a/systems/_constants/macros/src/lib.rs b/systems/_constants/macros/src/lib.rs index d7b7059..7384182 100644 --- a/systems/_constants/macros/src/lib.rs +++ b/systems/_constants/macros/src/lib.rs @@ -184,10 +184,8 @@ fn generate_functions_with_params( let ffi_fn_name = format!("JV_Const_{}{}", pascal_prefix, pascal_name); let ffi_fn_ident = Ident::new(&ffi_fn_name, const_name.span()); - // Generate parameter list for FFI - let ffi_param_idents: Vec<Ident> = (0..params.len()) - .map(|i| Ident::new(&format!("p{}", i), value_span)) - .collect(); + // Generate parameter list for FFI using original parameter names + let ffi_param_idents: Vec<Ident> = params.iter().map(|p| Ident::new(p, value_span)).collect(); let ffi_param_decls = ffi_param_idents.iter().map(|ident| { quote! { #ident: *const libc::c_char } diff --git a/systems/_constants/src/lib.rs b/systems/_constants/src/lib.rs index 30ea89b..c9dee11 100644 --- a/systems/_constants/src/lib.rs +++ b/systems/_constants/src/lib.rs @@ -8,8 +8,6 @@ macro_rules! c { pub const TEMP_FILE_PREFIX: &str = ".tmp_"; pub const LOCK_FILE_PREFIX: &str = "~"; -pub const CURRENT_SHEET_VERSION: u8 = 0; - /// File and directory path constants for the server root #[allow(unused)] pub mod server { diff --git a/systems/sheet/Cargo.toml b/systems/sheet/Cargo.toml index 1151c8d..33d17dc 100644 --- a/systems/sheet/Cargo.toml +++ b/systems/sheet/Cargo.toml @@ -12,10 +12,10 @@ asset_system = { path = "../_asset" } serde = { version = "1", features = ["derive"] } -tokio = { version = "1.48", features = ["full"] } +tokio = { version = "1.50", features = ["full"] } -thiserror = "1.0.69" +thiserror = "2" just_fmt = "0.1.2" memmap2 = "0.9" -sha2 = "0.10.8" +sha2 = "0.10" diff --git a/systems/sheet/src/sheet/reader.rs b/systems/sheet/src/sheet/reader.rs index 583e3b7..7a41bc1 100644 --- a/systems/sheet/src/sheet/reader.rs +++ b/systems/sheet/src/sheet/reader.rs @@ -1,5 +1,3 @@ -use constants::CURRENT_SHEET_VERSION; - use crate::{ mapping::{LocalMappingForward, Mapping}, sheet::{SheetData, error::ReadSheetDataError}, @@ -12,9 +10,9 @@ macro_rules! reader_do { let sheet_version = $full_sheet_data .first() .copied() - .unwrap_or(CURRENT_SHEET_VERSION); + .unwrap_or(crate::sheet::v1::constants::CURRENT_SHEET_VERSION); // CURRENT match sheet_version { - 1 => crate::sheet::v1::reader::$func($($arg),*), + 1 => crate::sheet::v1::reader::$func($($arg),*), // CURRENT _ => reader::$func($($arg),*), } }}; |
