Skip to content

Commit 6d30883

Browse files
author
Keeyou
authored
Fix compilation error with target_env=ohos (#2301)
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
1 parent d9e1146 commit 6d30883

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/fcntl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ libc_bitflags!(
126126
O_EXLOCK;
127127
/// Same as `O_SYNC`.
128128
#[cfg(any(bsd,
129-
all(target_os = "linux", not(target_env = "musl")),
129+
all(target_os = "linux", not(target_env = "musl"), not(target_env = "ohos")),
130130
target_os = "redox"))]
131131
O_FSYNC;
132132
/// Allow files whose sizes can't be represented in an `off_t` to be opened.

src/sys/statfs.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ type fs_type_t = libc::c_ulong;
5555
type fs_type_t = libc::c_uint;
5656
#[cfg(all(target_os = "linux", target_env = "musl"))]
5757
type fs_type_t = libc::c_ulong;
58+
#[cfg(all(target_os = "linux", target_env = "ohos"))]
59+
type fs_type_t = libc::c_ulong;
5860
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
5961
type fs_type_t = libc::c_int;
6062
#[cfg(all(
6163
target_os = "linux",
6264
not(any(
6365
target_arch = "s390x",
6466
target_env = "musl",
67+
target_env = "ohos",
6568
target_env = "uclibc"
6669
))
6770
))]
@@ -73,6 +76,7 @@ type fs_type_t = libc::__fsword_t;
7376
target_os = "android",
7477
all(target_os = "linux", target_arch = "s390x"),
7578
all(target_os = "linux", target_env = "musl"),
79+
all(target_os = "linux", target_env = "ohos"),
7680
all(
7781
target_os = "linux",
7882
not(any(target_arch = "s390x", target_env = "musl"))
@@ -279,7 +283,7 @@ pub const XENFS_SUPER_MAGIC: FsType =
279283
#[cfg(linux_android)]
280284
#[allow(missing_docs)]
281285
pub const NSFS_MAGIC: FsType = FsType(libc::NSFS_MAGIC as fs_type_t);
282-
#[cfg(all(linux_android, not(target_env = "musl")))]
286+
#[cfg(all(linux_android, not(target_env = "musl"), not(target_env = "ohos")))]
283287
#[allow(missing_docs)]
284288
pub const XFS_SUPER_MAGIC: FsType = FsType(libc::XFS_SUPER_MAGIC as fs_type_t);
285289

@@ -322,7 +326,8 @@ impl Statfs {
322326
/// Optimal transfer block size
323327
#[cfg(any(
324328
target_os = "android",
325-
all(target_os = "linux", target_env = "musl")
329+
all(target_os = "linux", target_env = "musl"),
330+
all(target_os = "linux", target_env = "ohos")
326331
))]
327332
pub fn optimal_transfer_size(&self) -> libc::c_ulong {
328333
self.0.f_bsize
@@ -334,6 +339,7 @@ impl Statfs {
334339
not(any(
335340
target_arch = "s390x",
336341
target_env = "musl",
342+
target_env = "ohos",
337343
target_env = "uclibc"
338344
))
339345
))]
@@ -379,6 +385,13 @@ impl Statfs {
379385
self.0.f_bsize
380386
}
381387

388+
/// Size of a block
389+
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
390+
#[cfg(all(target_os = "linux", target_env = "ohos"))]
391+
pub fn block_size(&self) -> libc::c_ulong {
392+
self.0.f_bsize
393+
}
394+
382395
/// Size of a block
383396
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
384397
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
@@ -393,6 +406,7 @@ impl Statfs {
393406
not(any(
394407
target_arch = "s390x",
395408
target_env = "musl",
409+
target_env = "ohos",
396410
target_env = "uclibc"
397411
))
398412
))]
@@ -463,6 +477,7 @@ impl Statfs {
463477
not(any(
464478
target_arch = "s390x",
465479
target_env = "musl",
480+
target_env = "ohos",
466481
target_env = "uclibc"
467482
))
468483
))]

src/sys/statvfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ libc_bitflags!(
4848
#[cfg(linux_android)]
4949
ST_NODIRATIME;
5050
/// Update access time relative to modify/change time
51-
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_env = "musl"))))]
51+
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_env = "musl"), not(target_env = "ohos"))))]
5252
ST_RELATIME;
5353
}
5454
);

0 commit comments

Comments
 (0)