1# Copyright (C) 2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("//foundation/filemanagement/file_api/file_api.gni")
16
17ohos_shared_library("cj_file_fs_ffi") {
18  sanitize = {
19    integer_overflow = true
20    ubsan = true
21    boundary_sanitize = true
22    cfi = true
23    cfi_cross_dso = true
24    debug = false
25  }
26
27  defines = []
28  cflags = [
29    "-fvisibility=hidden",
30    "-fdata-sections",
31    "-ffunction-sections",
32    "-Oz",
33  ]
34  cflags_cc = [
35    "-fvisibility-inlines-hidden",
36    "-Oz",
37  ]
38  if (is_mingw || is_mac || is_linux) {
39    defines += [ "PREVIEW" ]
40  }
41
42  if (current_os == "ohos" && current_cpu == "x86_64") {
43    defines += [ "SIMULATOR" ]
44  }
45  if (is_ohos) {
46    defines += [ "OHOS_PLATFORM" ]
47    if (use_musl && !is_asan) {
48      defines += [ "HOOK_ENABLE" ]
49    }
50  } else if (is_mingw) {
51    defines += [ "WINDOWS_PLATFORM" ]
52    cflags_cc += [ "-std=c++17" ]
53  } else if (is_mac) {
54    defines += [ "MAC_PLATFORM" ]
55  } else if (is_linux) {
56    defines += [ "LINUX_PLATFORM" ]
57    cflags_cc += [ "-std=c++17" ]
58  } else if (is_arkui_x && target_os == "ios") {
59    defines += [ "IOS_PLATFORM" ]
60  }
61
62  include_dirs = [
63    "${src_path}/common",
64    "${src_path}/common/napi",
65    "${src_path}/common/napi/n_async",
66    "${src_path}/common/file_helper",
67    "${src_path}/mod_fs",
68    "${src_path}/mod_fs/class_randomaccessfile",
69    "${src_path}/mod_fs/class_readeriterator",
70    "${src_path}/mod_fs/properties",
71    "${utils_path}/common/include",
72    "${utils_path}/filemgmt_libhilog",
73    "${utils_path}/filemgmt_libh",
74    "${utils_path}/filemgmt_libn/include",
75    "${file_api_path}/interfaces/kits/cj/src",
76    "${file_api_path}/interfaces/kits/native/remote_uri",
77    "${file_api_path}/interfaces/kits/rust/include",
78  ]
79
80  if (!defined(defines)) {
81    defines = []
82  }
83
84  use_exceptions = true
85
86  if (product_name != "ohos-sdk") {
87    deps = [
88      "${file_api_path}/interfaces/kits/js:build_kits_js",
89      "${file_api_path}/interfaces/kits/js:fs",
90      "${file_api_path}/interfaces/kits/native:remote_uri_native",
91      "${file_api_path}/interfaces/kits/rust:rust_file",
92      "${utils_path}/filemgmt_libhilog:filemgmt_libhilog",
93      "${utils_path}/filemgmt_libn:filemgmt_libn",
94    ]
95    external_deps = [
96      "ability_base:zuri",
97      "ability_runtime:ability_manager",
98      "ability_runtime:abilitykit_native",
99      "access_token:libtokenid_sdk",
100      "app_file_service:fileuri_native",
101      "bounds_checking_function:libsec_shared",
102      "bundle_framework:appexecfwk_base",
103      "bundle_framework:appexecfwk_core",
104      "c_utils:utils",
105      "data_share:datashare_common",
106      "data_share:datashare_consumer",
107      "hilog:libhilog",
108      "ipc:ipc_core",
109      "napi:ace_napi",
110      "napi:cj_bind_ffi",
111      "napi:cj_bind_native",
112      "samgr:samgr_proxy",
113    ]
114    sources = [
115      "../js/src/common/file_helper/fd_guard.cpp",
116      "src/copy_dir.cpp",
117      "src/copy_file.cpp",
118      "src/fdatasync.cpp",
119      "src/file_ffi.cpp",
120      "src/file_fs_ffi.cpp",
121      "src/file_fs_impl.cpp",
122      "src/file_impl.cpp",
123      "src/fsync.cpp",
124      "src/list_file.cpp",
125      "src/lseek.cpp",
126      "src/mkdtemp.cpp",
127      "src/move_file.cpp",
128      "src/randomAccessFile_impl.cpp",
129      "src/readerIterator_impl.cpp",
130      "src/stat_ffi.cpp",
131      "src/stream_ffi.cpp",
132      "src/stream_impl.cpp",
133      "src/symlink.cpp",
134      "src/uni_error.cpp",
135      "src/utils.cpp",
136      "src/watcher_impl.cpp",
137    ]
138  } else {
139    defines += [ "PREVIEWER" ]
140    sources = [ "src/file_fs_mock.cpp" ]
141    external_deps = [ "napi:cj_bind_ffi" ]
142  }
143
144  if (current_os == "ohos") {
145    defines += [ "OHOS_PLATFORM" ]
146  }
147
148  if (current_os == "mingw") {
149    defines += [ "WINDOWS_PLATFORM" ]
150  }
151
152  innerapi_tags = [ "platformsdk" ]
153  part_name = "file_api"
154  subsystem_name = "filemanagement"
155}
156