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
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,39 @@ 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 native toolchain.

Download the SDK command-line tools from [HarmonyOS Developer](https://developer.huawei.com/consumer/cn/download/command-line-tools-for-hmos). After installation, the default SDK path is typically:

- Linux: `~/command-line-tools/sdk/default/openharmony`
- macOS: `~/Library/command-line-tools/sdk/default/openharmony`

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
19 changes: 19 additions & 0 deletions asyncgit/src/sync/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions asyncgit/src/sync/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down