### Quick Start Example Source: https://github.com/maaxyz/maa-framework-rs/blob/main/README.md A basic example demonstrating how to initialize MaaFramework, connect to an ADB device, and start a task. ```rust use maa_framework::toolkit::Toolkit; use maa_framework::controller::Controller; use maa_framework::resource::Resource; use maa_framework::tasker::Tasker; fn main() -> Result<(), Box> { // [Dynamic only] Load MaaFramework library #[cfg(feature = "dynamic")] maa_framework::load_library(std::path::Path::new("MaaFramework.dll"))?; Toolkit::init_option("./", "{{}}")?; let devices = Toolkit::find_adb_devices()?; if devices.is_empty() { eprintln!("No ADB device found"); return Ok(()) } let device = &devices[0]; let controller = Controller::new_adb( device.adb_path.to_str().unwrap(), &device.address, &device.config.to_string(), None, )?; controller.post_connection()?; let resource = Resource::new()?; resource.post_bundle("./resource")?; let tasker = Tasker::new()?; tasker.bind_controller(&controller)?; tasker.bind_resource(&resource)?; if !tasker.inited() { eprintln!("Failed to initialize MAA"); return Ok(()) } tasker.post_task("Startup", "{{}}")?; println!("Task started!"); Ok(()) } ``` -------------------------------- ### Compile and Install MaaFramework Core (with Debug Controller) Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Compiles and installs the MaaFramework core library, ensuring the Debug Controller is enabled. This example shows configuration for Linux/macOS. ```bash # Example (Linux/macOS): cmake -B build -DWITH_DBG_CONTROLLER=ON -DCMAKE_INSTALL_PREFIX=../maa-install cmake --build build -j cmake --install build ``` -------------------------------- ### Unsafe Code Safety Comment Example Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md An example demonstrating how to add a comment explaining the safety of an unsafe block, particularly when dealing with pointers and lifetimes. ```rust // SAFETY: ptr 来源于 CString,保证非空且以 null 结尾 unsafe { sys::SomeCApi(ptr) }; ``` -------------------------------- ### Set Environment Variable for SDK Path Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Sets the MAA_SDK_PATH environment variable to the installation directory of the compiled MaaFramework, allowing Rust to find the compiled libraries. ```bash export MAA_SDK_PATH=/path/to/your/maa-install ``` -------------------------------- ### Build & Run Source: https://github.com/maaxyz/maa-framework-rs/blob/main/README.md Build and run your Rust project. ```bash cargo build cargo run ``` -------------------------------- ### Download Third-Party Dependencies Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Downloads necessary third-party dependencies for MaaFramework using a Python script. ```bash python tools/maadeps-download.py ``` -------------------------------- ### Main CMakeLists.txt Source: https://github.com/maaxyz/maa-framework-rs/blob/main/maa-framework-sys/cmake/CMakeLists.txt This is the main CMakeLists.txt file for the MAA_FW_PROBE project. It sets the minimum required CMake version, defines the project, finds the MaaFramework package, determines library paths based on the operating system, and adds the executable target. ```cmake cmake_minimum_required(VERSION 3.12) project(MAA_FW_PROBE) find_package(MaaFramework REQUIRED CONFIGS MaaFramework.cmake) if(WIN32) get_target_property(MaaFramework_LIBRARIES MaaFramework::MaaFramework IMPORTED_IMPLIB_RELEASE) get_target_property(MaaToolkit_LIBRARIES MaaFramework::MaaToolkit IMPORTED_IMPLIB_RELEASE) endif(WIN32) if(UNIX) get_target_property(MaaFramework_LIBRARIES MaaFramework::MaaFramework IMPORTED_LOCATION_RELEASE) get_target_property(MaaToolkit_LIBRARIES MaaFramework::MaaToolkit IMPORTED_LOCATION_RELEASE) endif(UNIX) get_target_property(MaaFramework_INCLUDE_DIRS MaaFramework::MaaFramework INTERFACE_INCLUDE_DIRECTORIES) add_executable(MAA_FW_PROBE maa_framework_probe.cpp) target_link_libraries(MAA_FW_PROBE MaaFramework) message("IncludeDir=${MaaFramework_INCLUDE_DIRS}") message("MaaFrameworkLibraries=${MaaFramework_LIBRARIES}") message("MaaToolkitLibraries=${MaaToolkit_LIBRARIES}") ``` -------------------------------- ### Clone MaaFramework Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Clones the MaaFramework repository and navigates into it. ```bash git clone --recursive https://github.com/MaaXYZ/MaaFramework.git cd MaaFramework ``` -------------------------------- ### Run Tests (Dynamic Linking) Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Command to run tests in dynamic linking mode, which requires configuring the dynamic library path and also forces single-threaded execution. ```bash # 动态链接模式(需要配置动态库路径) cargo test --features dynamic -- --test-threads=1 ``` -------------------------------- ### Extract SDK Source: https://github.com/maaxyz/maa-framework-rs/blob/main/README.md Extract the downloaded MaaFramework SDK to your project directory. ```treeview my-project/ ├── Cargo.toml ├── src/ │ └── main.rs └── MAA-win-x86_64-v5.4.1/ # Extracted SDK ├── bin/ ├── lib/ └── include/ ``` -------------------------------- ### Run Tests (Static Linking) Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Command to run tests in static linking mode, ensuring to force single-threaded execution to avoid resource contention. ```bash # 静态链接模式(默认) cargo test -- --test-threads=1 ``` -------------------------------- ### Load Library (Dynamic Linking) Source: https://github.com/maaxyz/maa-framework-rs/blob/main/README.md Manually load the MaaFramework library at runtime when using dynamic linking. This must be called before any other API. ```rust // Must be called before any other API maa_framework::load_library(std::path::Path::new("path/to/MaaFramework.dll"))?; ``` -------------------------------- ### Add Dependency Source: https://github.com/maaxyz/maa-framework-rs/blob/main/README.md Add the maa-framework crate to your project's dependencies. ```toml [dependencies] maa-framework = "1" ``` -------------------------------- ### Dynamic Linking Feature Source: https://github.com/maaxyz/maa-framework-rs/blob/main/README.md Enable the 'dynamic' feature for dynamic linking. ```toml [dependencies] maa-framework = { version = "1", features = ["dynamic"] } ``` -------------------------------- ### Format Code Source: https://github.com/maaxyz/maa-framework-rs/blob/main/CONTRIBUTING.md Command to format the code according to standard Rust style guidelines. ```bash # 格式化代码 cargo fmt ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.