ohos_rust_binding
This is a Rust language binding library for the OpenHarmony operating system, allowing developers to interact with OpenHarmony native APIs using Rust.
Features
- Provides Rust language bindings for OpenHarmony native APIs
- Supports various OpenHarmony feature modules, including:
- Logging system (log)
- ArkTS callback handling (arkts_cb)
- XComponent access (xcomponent)
- Account management (account)
- Resource management (asset)
- Bundle management (bundle)
- Drawing functionality (drawing)
- EGL graphics interface (egl)
- HiAppEvent events (hiappevent)
- HiDebug debugging tools (hidebug)
- HiTrace tracing (hitrace)
- Input event handling (input)
- Relational database (rdb)
- Task scheduler (scheduler)
- Web functionality access (web)
- Window management (window)
- Cross-platform development support
- Type-safe API calls
Environment Requirements
- Rust 1.60+ (latest stable version recommended)
- Cargo package manager
- OpenHarmony Native SDK
Installation and Configuration
1. Set Environment Variables
Before using this library, you need to set the following environment variables:
# Set OpenHarmony Native SDK path
2. Add Dependency
Add the ohos_rust_binding dependency to your Cargo.toml file:
[]
= {
path = "../ohos_rust_binding",
= ["log", "arkts_cb", "xcomponent"] # Select modules as needed
}
Build Instructions
Supported Target Platforms
The library currently supports the following target platform:
- aarch64-unknown-linux-ohos
Build Commands
# Execute in the ohos_rust_binding directory
# Build for a specific target platform
Usage Examples
Log Module Example
use *;
XComponent Example
use *;
use ;
ArkTS Callback Example
use *;
use ;
Development Notes
-
Platform Compatibility:
- On unsupported target platforms, the build process will automatically skip bindgen code generation but still allows development work in the development environment.
- When running on unsupported platforms, relevant API calls may return errors or perform no operations.
-
Memory Management:
- Pay attention to memory management differences between Rust and C when using this library
- Avoid creating memory leaks, especially when handling C strings and pointers
-
Asynchronous Operations:
- For asynchronous operations, it is recommended to use Rust's Future and async/await syntax
- Communicate across threads through napi's thread-safe functions
Contribution Guidelines
Contributions to this project are welcome! If you want to participate in development, please follow these steps:
- Fork this repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
If you have any questions or suggestions, please raise them on the project's Issue page.