Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ log-impl = []
[target.'cfg(target_os = "linux")'.dependencies]
libc = "0.2"

[target.'cfg(target_env = "ohos")'.dependencies]
ohos-xcomponent-binding = "0.1"
raw-window-handle = "0.6"
napi-ohos = { version = "1.1.3", default-features = false, features = [
"napi8",
"async",
] }
napi-derive-ohos = { version = "1.1.3" }
ohos-hilog-binding = { version = "0.1.2", features = [
"redirect"
] }
xcomponent-sys = { version = "0.3.4", features = ["api-14", "keyboard-types"] }
keyboard-types = "0.8.3"
ohos-xcomponent-sys = { version = "0.0.2" }
ohos_enum_macro = { version = "0.0.2" }
ohos-input-sys = { version = "0.3.2", features = ["api-17"] }
ohos-qos-sys = { version = "0.0.1", features = ["api-20"] }
ohos-native-window-sys = { version = "0.0.1" }

[target.'cfg(target_env = "ohos")'.build-dependencies]
napi-build-ohos = { version = "1.1.3" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [
"wingdi",
Expand Down
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Miniquad aims to provide a graphics abstraction that works the same way on any p
* macOS, OpenGL 3, Metal;
* iOS, GLES 2, GLES 3, Metal;
* WASM, WebGL 1 - tested on iOS Safari, Firefox, Chrome;
* Android, GLES 2, GLES 3.
* Android, GLES 2, GLES 3;
* OpenHarmony, GLES 2, GLES 3.

## Examples

Expand Down Expand Up @@ -150,6 +151,79 @@ xcrun simctl launch booted com.mygame

For details and instructions on provisioning for real iphone, check [https://macroquad.rs/articles/ios/](https://macroquad.rs/articles/ios/)

## OpenHarmony (OHOS)

Due to limitations in ohrs, running examples requires extracting the example project separately and marking the C entry point:

Ensure your example crate type is set to `cdylib`

```rust
#[no_mangle]
pub extern "C" fn quad_main()
```

Assume your project is named `nativerender`.

### Prerequisites

```bash
rustup target add aarch64-unknown-linux-ohos
rustup target add armv7-unknown-linux-ohos
rustup target add x86_64-unknown-linux-ohos
cargo install ohrs
```

### 1. Create an XComponent in Your App using DevEco Studio

```typescript
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
xComponentContext: ESObject | undefined = undefined;
xComponentAttrs: XComponentAttrs = {
id: 'xcomponentId',
type: XComponentType.SURFACE,
libraryname: 'nativerender'
}

build() {
Row() {
Button("draw").onClick(() => {
this.xComponentContext!.drawXcomponent();
})
// ...
// Define XComponent
XComponent(this.xComponentAttrs)
.focusable(true) // Enable keyboard events
.onLoad((xComponentContext) => {
this.xComponentContext = xComponentContext;
})
.onDestroy(() => {
console.log("onDestroy");
})
// ...
}
.height('100%')
}
}

interface XComponentAttrs {
id: string;
type: number;
libraryname: string;
}
```

### 2. Build with ohrs

```bash
ohrs build --arch aarch
```

Copy the `libnativerender.so` file from `dist/arm64-v8a` or `dist/x86_64` to your Harmony project.


## Cross Compilation

```bash
Expand Down
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ fn main() {
if target.contains("darwin") || target.contains("ios") {
println!("cargo:rustc-link-lib=framework=MetalKit");
}
#[cfg(target_env = "ohos")]
napi_build_ohos::setup();
}
Loading
Loading