Add features for each script type

This commit is contained in:
2025-06-02 22:31:46 +08:00
parent abf30c8a55
commit 52811fe2eb
6 changed files with 107 additions and 0 deletions

21
.github/workflows/CI.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
CARGO_TERM_COLOR: always
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install toml
run: pip3 install toml
- name: Check
run: python check_features.py

View File

@@ -13,5 +13,11 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
unicode-segmentation = "1.12"
[features]
default = ["bgi", "circus", "escude"]
bgi = []
circus = []
escude = []
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0", features = ["Win32_Globalization", "Win32_System_Diagnostics_Debug"] }

63
check_features.py Normal file
View File

@@ -0,0 +1,63 @@
import toml
import subprocess
import sys
def main():
# 检查cargo是否可用
try:
subprocess.run(
["cargo", "--version"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True
)
except FileNotFoundError:
print("Error: 'cargo' not found. Install Rust and ensure it's in PATH.")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"Error checking cargo: {e}")
sys.exit(1)
# 读取Cargo.toml
try:
with open("Cargo.toml", "r") as f:
cargo_toml = toml.load(f)
except FileNotFoundError:
print("Error: Cargo.toml not found in current directory.")
sys.exit(1)
except Exception as e:
print(f"Error parsing Cargo.toml: {e}")
sys.exit(1)
features = cargo_toml.get("features", {})
feature_names = list(features.keys())
if not feature_names:
print("No features defined in Cargo.toml.")
sys.exit(0)
failed_features = []
print(f"Testing {len(feature_names)} features...")
for idx, feature in enumerate(feature_names, 1):
print(f"\nTesting feature {idx}/{len(feature_names)}: {feature}")
cmd = ["cargo", "check", "--no-default-features", "--features", feature, '--target-dir', 'target/features_check']
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError:
failed_features.append(feature)
print(f"❌ Feature '{feature}' failed to compile")
else:
print(f"✅ Feature '{feature}' compiled successfully")
if failed_features:
print("\nFailed features:")
for f in failed_features:
print(f" - {f}")
sys.exit(1)
else:
print("\nAll features compiled successfully!")
sys.exit(0)
if __name__ == "__main__":
main()

View File

@@ -18,10 +18,16 @@ impl FixedFormatter {
}
}
#[cfg(feature = "circus")]
fn is_circus(&self) -> bool {
matches!(self.typ, Some(ScriptType::Circus))
}
#[cfg(not(feature = "circus"))]
fn is_circus(&self) -> bool {
false
}
pub fn format(&self, message: &str) -> String {
let mut result = String::new();
let vec: Vec<_> = UnicodeSegmentation::graphemes(message, true).collect();

View File

@@ -1,15 +1,22 @@
pub mod base;
#[cfg(feature = "bgi")]
pub mod bgi;
#[cfg(feature = "circus")]
pub mod circus;
#[cfg(feature = "escude")]
pub mod escude;
pub use base::{Script, ScriptBuilder};
lazy_static::lazy_static! {
pub static ref BUILDER: Vec<Box<dyn ScriptBuilder + Sync + Send>> = vec![
#[cfg(feature = "circus")]
Box::new(circus::script::CircusMesScriptBuilder::new()),
#[cfg(feature = "bgi")]
Box::new(bgi::script::BGIScriptBuilder::new()),
#[cfg(feature = "escude")]
Box::new(escude::archive::EscudeBinArchiveBuilder::new()),
#[cfg(feature = "escude")]
Box::new(escude::script::EscudeBinScriptBuilder::new()),
];
pub static ref ALL_EXTS: Vec<String> =

View File

@@ -182,13 +182,17 @@ pub struct ExtraConfig {
#[derive(Clone, Copy, Debug, ValueEnum, PartialEq, Eq, PartialOrd, Ord)]
/// Script type
pub enum ScriptType {
#[cfg(feature = "circus")]
/// Circus MES script
Circus,
#[cfg(feature = "bgi")]
#[value(alias("ethornell"))]
/// Buriko General Interpreter/Ethornell Script
BGI,
#[cfg(feature = "escude")]
/// Escude bin archive
EscudeArc,
#[cfg(feature = "escude")]
/// Escude bin script
Escude,
}