Skip to content

Commit

Permalink
Fix compilation error with target_env=ohos
Browse files Browse the repository at this point in the history
OpenHarmony(alias ohos) is tie 3 supported target for rust.
see rust-lang/compiler-team#568.

In implementation it sits close to musl instead of bionic
and napi instead jni when comparing with android.

Tested with:
- cargo build --target x86_64-unknown-linux-ohos --features acct,dir,env,fs
- cargo build --target aarch64-unknown-linux-ohos --features acct,dir,env,fs
  • Loading branch information
Chilledheart committed Jan 29, 2024
1 parent d9e1146 commit 916ed62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ libc_bitflags!(
O_EXLOCK;
/// Same as `O_SYNC`.
#[cfg(any(bsd,
all(target_os = "linux", not(target_env = "musl")),
all(target_os = "linux", not(target_env = "musl"), not(target_env = "ohos")),
target_os = "redox"))]
O_FSYNC;
/// Allow files whose sizes can't be represented in an `off_t` to be opened.
Expand Down
19 changes: 17 additions & 2 deletions src/sys/statfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ type fs_type_t = libc::c_ulong;
type fs_type_t = libc::c_uint;
#[cfg(all(target_os = "linux", target_env = "musl"))]
type fs_type_t = libc::c_ulong;
#[cfg(all(target_os = "linux", target_env = "ohos"))]
type fs_type_t = libc::c_ulong;
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
type fs_type_t = libc::c_int;
#[cfg(all(
target_os = "linux",
not(any(
target_arch = "s390x",
target_env = "musl",
target_env = "ohos",
target_env = "uclibc"
))
))]
Expand All @@ -73,6 +76,7 @@ type fs_type_t = libc::__fsword_t;
target_os = "android",
all(target_os = "linux", target_arch = "s390x"),
all(target_os = "linux", target_env = "musl"),
all(target_os = "linux", target_env = "ohos"),
all(
target_os = "linux",
not(any(target_arch = "s390x", target_env = "musl"))
Expand Down Expand Up @@ -279,7 +283,7 @@ pub const XENFS_SUPER_MAGIC: FsType =
#[cfg(linux_android)]
#[allow(missing_docs)]
pub const NSFS_MAGIC: FsType = FsType(libc::NSFS_MAGIC as fs_type_t);
#[cfg(all(linux_android, not(target_env = "musl")))]
#[cfg(all(linux_android, not(target_env = "musl"), not(target_env = "ohos")))]
#[allow(missing_docs)]
pub const XFS_SUPER_MAGIC: FsType = FsType(libc::XFS_SUPER_MAGIC as fs_type_t);

Expand Down Expand Up @@ -322,7 +326,8 @@ impl Statfs {
/// Optimal transfer block size
#[cfg(any(
target_os = "android",
all(target_os = "linux", target_env = "musl")
all(target_os = "linux", target_env = "musl"),
all(target_os = "linux", target_env = "ohos")
))]
pub fn optimal_transfer_size(&self) -> libc::c_ulong {
self.0.f_bsize
Expand All @@ -334,6 +339,7 @@ impl Statfs {
not(any(
target_arch = "s390x",
target_env = "musl",
target_env = "ohos",
target_env = "uclibc"
))
))]
Expand Down Expand Up @@ -379,6 +385,13 @@ impl Statfs {
self.0.f_bsize
}

/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
#[cfg(all(target_os = "linux", target_env = "ohos"))]
pub fn block_size(&self) -> libc::c_ulong {
self.0.f_bsize
}

/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
Expand All @@ -393,6 +406,7 @@ impl Statfs {
not(any(
target_arch = "s390x",
target_env = "musl",
target_env = "ohos",
target_env = "uclibc"
))
))]
Expand Down Expand Up @@ -463,6 +477,7 @@ impl Statfs {
not(any(
target_arch = "s390x",
target_env = "musl",
target_env = "ohos",
target_env = "uclibc"
))
))]
Expand Down
2 changes: 1 addition & 1 deletion src/sys/statvfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ libc_bitflags!(
#[cfg(linux_android)]
ST_NODIRATIME;
/// Update access time relative to modify/change time
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_env = "musl"))))]
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_env = "musl"), not(target_env = "ohos"))))]
ST_RELATIME;
}
);
Expand Down

0 comments on commit 916ed62

Please sign in to comment.