mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
add OpenHarmony (OHOS) target support
On OpenHarmony the user/process model is sandbox-based. libgit2's owner validation (GIT_OPT_SET_OWNER_VALIDATION) compares file UID with process EUID, which is not applicable and causes spurious "not owned by current user" errors (code=Owner -36). This disables owner validation on all OHOS targets (cfg(target_env = "ohos"): aarch64/armv7/x86_64) via a std::sync::Once in the repository opening entry points. Also adds cross-compilation instructions to CONTRIBUTING.md.
This commit is contained in:
parent
8619c07f3f
commit
1bc06a2b94
3 changed files with 51 additions and 0 deletions
|
|
@ -22,5 +22,34 @@ good first issue, you can take a look at [issues labelled with
|
|||
too much context so that people not familiar with the codebase yet can still
|
||||
make a contribution.
|
||||
|
||||
## Cross-compiling for OpenHarmony
|
||||
|
||||
GitUI can be built for OpenHarmony (target `aarch64-unknown-linux-ohos`). This requires the [OpenHarmony SDK](https://www.openharmony.cn/) native toolchain.
|
||||
|
||||
First, install the `aarch64-unknown-linux-ohos` Rust target:
|
||||
|
||||
```sh
|
||||
rustup target add aarch64-unknown-linux-ohos
|
||||
```
|
||||
|
||||
Set the following environment variables (adjust paths to your OHOS SDK location):
|
||||
|
||||
```sh
|
||||
export OHOS_SDK=/path/to/ohos-sdk
|
||||
export CC_aarch64_unknown_linux_ohos="$OHOS_SDK/native/llvm/bin/clang"
|
||||
export CXX_aarch64_unknown_linux_ohos="$OHOS_SDK/native/llvm/bin/clang++"
|
||||
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_OHOS_LINKER="$OHOS_SDK/native/llvm/bin/clang"
|
||||
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_OHOS_AR="$OHOS_SDK/native/llvm/bin/llvm-ar"
|
||||
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_OHOS_RUSTFLAGS="-C link-arg=--sysroot=$OHOS_SDK/native/sysroot -C link-arg=-L$OHOS_SDK/native/sysroot/usr/lib/aarch64-linux-ohos -C link-arg=-Wl,--allow-multiple-definition -C link-arg=-Wl,--undefined-version -C link-arg=-Wl,--defsym=__xpg_strerror_r=0"
|
||||
```
|
||||
|
||||
Then build:
|
||||
|
||||
```sh
|
||||
cargo build --target aarch64-unknown-linux-ohos --release
|
||||
```
|
||||
|
||||
> **Note:** On OpenHarmony the user/process model is sandbox-based. GitUI automatically disables libgit2's owner validation on OHOS targets to avoid spurious "not owned by current user" errors.
|
||||
|
||||
[discord-server]: https://discord.gg/rZv4uxSQx3
|
||||
[good-first-issues]: https://github.com/gitui-org/gitui/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22
|
||||
|
|
|
|||
|
|
@ -7,6 +7,22 @@ use git2::{Repository, RepositoryOpenFlags};
|
|||
|
||||
use crate::error::Result;
|
||||
|
||||
#[cfg(target_env = "ohos")]
|
||||
use std::sync::Once;
|
||||
|
||||
#[cfg(target_env = "ohos")]
|
||||
static INIT_OHOS: Once = Once::new();
|
||||
|
||||
#[cfg(target_env = "ohos")]
|
||||
pub(crate) fn init_ohos_owner_validation() {
|
||||
INIT_OHOS.call_once(|| {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe {
|
||||
git2::opts::set_verify_owner_validation(false).ok();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
pub type RepoPathRef = RefCell<RepoPath>;
|
||||
|
||||
|
|
@ -55,6 +71,9 @@ impl From<&str> for RepoPath {
|
|||
}
|
||||
|
||||
pub fn repo(repo_path: &RepoPath) -> Result<Repository> {
|
||||
#[cfg(target_env = "ohos")]
|
||||
init_ohos_owner_validation();
|
||||
|
||||
let repo = Repository::open_ext(
|
||||
repo_path.gitpath(),
|
||||
RepositoryOpenFlags::FROM_ENV,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ pub struct Head {
|
|||
|
||||
///
|
||||
pub fn repo_open_error(repo_path: &RepoPath) -> Option<String> {
|
||||
#[cfg(target_env = "ohos")]
|
||||
super::repository::init_ohos_owner_validation();
|
||||
|
||||
if let Err(e) = Repository::open_ext(
|
||||
repo_path.gitpath(),
|
||||
RepositoryOpenFlags::FROM_ENV,
|
||||
|
|
|
|||
Loading…
Reference in a new issue