适配ohos#61
Open
imndx wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds OpenHarmony (OHOS) support for the native node-screenshots binding, primarily by adjusting how N-API symbols are resolved under OHOS’s linker namespace isolation and by adding OHOS cross-compilation configuration.
Changes:
- Adds an OHOS-specific
.init_arrayinitializer plus a localdlopenoverride to ensure Electron’slibelectron.so(V8 N-API) is used instead of the system ArkTS N-API. - Adds OHOS cross-compile linker wrappers and Cargo target configuration for
*-unknown-linux-ohos. - Updates build/link settings and target lists to include OHOS, and switches
xcapto a local path dependency.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/ohos_init.rs |
Adds OHOS runtime initialization to preload libelectron.so and intercept dlopen("libelectron.so"). |
src/lib.rs |
Conditionally includes the OHOS init module for target_env = "ohos". |
build.rs |
Adds OHOS-only linker args (whole-archive shim, version script, symbolic binding behavior). |
scripts/ohos_napi.map |
Version script to localize napi_*/uv_*/node_* and keep only napi_register_module_v1 global. |
scripts/ohos-clang-aarch64.sh |
Cargo linker wrapper for OHOS aarch64. |
scripts/ohos-clang-arm.sh |
Cargo linker wrapper for OHOS armv7. |
scripts/ohos-clang-x86_64.sh |
Cargo linker wrapper for OHOS x86_64. |
.cargo/config.toml |
Adds OHOS target linker configuration pointing to wrapper scripts. |
Cargo.toml |
Disables default napi features, enables napi4, and changes xcap to a path dependency. |
package.json |
Adds OHOS triples to napi.targets. |
lib.rs |
Adds a new top-level lib.rs file (appears unrelated to this crate’s actual source layout). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| napi = { version = "3.0.0", default-features = false, features = ["napi4"] } | ||
| napi-derive = "3.0.0" | ||
| xcap = { version = "0.4.1", features = ["image"] } | ||
| xcap = { path = "../xcap", features = ["image"] } |
Comment on lines
+3
to
+16
| let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
| let manifest_path = std::path::Path::new(&manifest_dir); | ||
|
|
||
| let shim_a = manifest_path | ||
| .parent() | ||
| .expect("workspace parent dir") | ||
| .join("electron-napi-library/lib/libshim.a"); | ||
|
|
||
| println!("cargo:warning=libshim.a path: {}", shim_a.display()); | ||
| assert!( | ||
| shim_a.exists(), | ||
| "libshim.a not found at {}", | ||
| shim_a.display() | ||
| ); |
Author
There was a problem hiding this comment.
这儿编译时,依赖了 electron-napi-library,是从ohos_electron 的适配示例里面拿到的。
可能和electron版本有关系,目前 ohos electron主要适配了v34
electron-v34 electron-napi-library.zip
Comment on lines
+46
to
+52
| let ver_script = manifest_path.join("scripts/ohos_napi.map"); | ||
| println!("cargo:warning=version script: {}", ver_script.display()); | ||
| println!( | ||
| "cargo:rustc-link-arg=-Wl,--version-script={}", | ||
| ver_script.display() | ||
| ); | ||
| println!("cargo:rustc-link-arg=-Wl,-Bsymbolic-functions"); |
Comment on lines
+41
to
+46
| // Write diagnostics to a file — eprintln! does not reach hilog on OHOS. | ||
| let mut log = std::fs::OpenOptions::new() | ||
| .create(true) | ||
| .append(true) | ||
| .open("/data/storage/el1/base/nscr.log") | ||
| .ok(); |
Comment on lines
+1
to
+6
| use std::env; | ||
|
|
||
| mod android; | ||
| mod wasi; | ||
| mod windows; | ||
|
|
Comment on lines
+36
to
+39
| "aarch64-pc-windows-msvc", | ||
| "aarch64-unknown-linux-ohos", | ||
| "armv7-unknown-linux-ohos", | ||
| "x86_64-unknown-linux-ohos" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
你好
这些代码是在 AI 协助下实现的,测试可以工作
另外:
../xcapohos上,截图之前,需要先申请ohos.permission.CUSTOM_SCREEN_CAPTURE权限