From ae6b814e50dc83dd0a380c6076f73012041570b8 Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Tue, 6 May 2025 11:40:22 +0800 Subject: [PATCH] add compile support for win and mac platform Issue: https://gitee.com/openharmony/commonlibrary_c_utils/issues/IC5MJ3?from=project-issue Signed-off-by: chenkeyu --- base/BUILD.gn | 36 +++++++++++++++++++++++++++++++++--- base/include/flat_obj.h | 6 +++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/base/BUILD.gn b/base/BUILD.gn index fd26200..67dcaf3 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -29,6 +29,9 @@ config("utils_config") { if (current_os == "ios") { defines += [ "IOS_PLATFORM" ] } + if (current_os == "win" || current_os == "mingw") { + defines += [ "WINDOWS_PLATFORM" ] + } if (is_emulator == true) { defines += [ "EMULATOR_PLATFORM" ] } @@ -95,6 +98,26 @@ sources_utils = [ "src/rwlock.cpp", ] +if (current_os == "ios") { + sources_utils_ios = [ + "src/directory_ex.cpp", + "src/parcel.cpp", + "src/refbase.cpp", + "src/rwlock.cpp", + "src/string_ex.cpp", + "src/unicode_ex.cpp", + ] +} + +if (current_os == "win" || current_os == "mingw") { + sources_utils_win = [ + "src/parcel.cpp", + "src/refbase.cpp", + "src/string_ex.cpp", + "src/unicode_ex.cpp", + ] +} + if (current_os == "ios") { sources_utils_ios = [ "src/directory_ex.cpp", @@ -155,7 +178,14 @@ ohos_shared_library("utils") { "platformsdk", "sasdk", ] - if (current_os == "ios") { + if (current_os == "win" || current_os == "mingw") { + sources = sources_utils_win + public_configs = [ ":utils_config" ] + public_external_deps = [ "bounds_checking_function:libsec_shared" ] + + subsystem_name = "commonlibrary" + part_name = "c_utils" + } else if (current_os == "ios") { sources = sources_utils_ios configs = [ ":utils_coverage_config" ] all_dependent_configs = [ ":utils_config" ] @@ -210,7 +240,7 @@ ohos_shared_library("utils") { ########## modules for `c_utils` in rust ########## # rust compiler is not supportted on mac -if (host_os == "linux" && host_cpu != "arm64" && !is_arkui_x) { +if (host_os == "linux" && host_cpu != "arm64" && !is_arkui_x && current_os != "mac") { import("//build/templates/rust/rust_cxx.gni") # used for templates rust_cxx() rust_cxx("cxx_rust_gen") { sources = [ @@ -243,7 +273,7 @@ if (host_os == "linux" && host_cpu != "arm64" && !is_arkui_x) { } } -if (!is_arkui_x && !(host_os == "linux" && host_cpu == "arm64")) { +if (!is_arkui_x && !(host_os == "linux" && host_cpu == "arm64") && current_os != "mac") { ohos_rust_shared_library("utils_rust") { if (host_os == "linux") { sources = [ diff --git a/base/include/flat_obj.h b/base/include/flat_obj.h index 1691998..94bc1a9 100644 --- a/base/include/flat_obj.h +++ b/base/include/flat_obj.h @@ -26,11 +26,11 @@ #include -#ifndef IOS_PLATFORM +#if !defined(IOS_PLATFORM) && !defined(WINDOWS_PLATFORM) #include #else - typedef u_int32_t __u32; - typedef u_int64_t __u64; + typedef uint32_t __u32; + typedef uint64_t __u64; #endif #ifdef BINDER_IPC_32BIT -- Gitee