From f93b65656436781817c312ecc4bc3d2bf31e43a7 Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Wed, 23 Jul 2025 09:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E5=BA=93=E9=93=BE=E6=8E=A5c?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue:https://gitee.com/openharmony/interface_sdk_c/issues/ICO5PF?from=project-issue Signed-off-by: xwx1135370 --- ndk_targets.gni | 4 +-- third_party/musl/ndk_script/BUILD.gn | 32 ++++++++++++++++++ third_party/musl/ndk_script/link_libc.sh | 41 ++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100755 third_party/musl/ndk_script/link_libc.sh diff --git a/ndk_targets.gni b/ndk_targets.gni index 18b88960d..5e88961ea 100644 --- a/ndk_targets.gni +++ b/ndk_targets.gni @@ -270,9 +270,7 @@ _ndk_library_targets = [ _ndk_base_libs = [ "//interface/sdk_c/third_party/musl/ndk_script/adapter:libc_ndk", - "//interface/sdk_c/third_party/musl/ndk_script:musl_ndk_libs_arm32", - "//interface/sdk_c/third_party/musl/ndk_script:musl_ndk_libs_aarch64", - "//interface/sdk_c/third_party/musl/ndk_script:musl_ndk_libs_x86_64", + "//interface/sdk_c/third_party/musl/ndk_script:musl_ndk_libs", "//interface/sdk_c/third_party/musl/ndk_script:ndk_toolchain", ] _ndk_sysroot_uapi = diff --git a/third_party/musl/ndk_script/BUILD.gn b/third_party/musl/ndk_script/BUILD.gn index a6e1f689b..4dd078e49 100644 --- a/third_party/musl/ndk_script/BUILD.gn +++ b/third_party/musl/ndk_script/BUILD.gn @@ -404,6 +404,14 @@ ohos_copy("musl_ndk_libs_arm32") { outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/arm-linux-ohos/{{source_file_part}}" ] } +action("libs_link_libc_arm32") { + script = "link_libc.sh" + outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/arm-linux-ohos" ] + args = [ rebase_path("$ndk_os_irrelevant_out_dir/sysroot/usr/lib/arm-linux-ohos") ] + + deps = [ ":musl_ndk_libs_arm32" ] +} + ohos_copy("musl_ndk_libs_aarch64") { deps = musl_lib_arm64 sources = [ get_label_info(deps[0], "target_out_dir") + @@ -438,6 +446,14 @@ ohos_copy("musl_ndk_libs_aarch64") { outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/aarch64-linux-ohos/{{source_file_part}}" ] } +action("libs_link_libc_aarch64") { + script = "link_libc.sh" + outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/aarch64-linux-ohos" ] + args = [ rebase_path("$ndk_os_irrelevant_out_dir/sysroot/usr/lib/aarch64-linux-ohos") ] + + deps = [ ":musl_ndk_libs_aarch64" ] +} + ohos_copy("musl_ndk_libs_x86_64") { deps = musl_lib_x86_64 crt_dir = "${root_build_dir}/obj/third_party/musl/usr/lib/x86_64-linux-ohos" @@ -470,9 +486,25 @@ ohos_copy("musl_ndk_libs_x86_64") { outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/x86_64-linux-ohos/{{source_file_part}}" ] } +action("libs_link_libc_x86_64") { + script = "link_libc.sh" + outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/x86_64-linux-ohos" ] + args = [ rebase_path("$ndk_os_irrelevant_out_dir/sysroot/usr/lib/x86_64-linux-ohos") ] + + deps = [ ":musl_ndk_libs_x86_64" ] +} + ohos_ndk_copy("copy_compatible_config") { dest_dir = "$ndk_os_irrelevant_out_dir" sources = [ "//interface/sdk_c/third_party/musl/ndk_script/compatible_config.json" ] args = [ "--ignore-stale" ] } + +group("musl_ndk_libs") { + deps = [ + ":libs_link_libc_arm32", + ":libs_link_libc_aarch64", + ":libs_link_libc_x86_64", + ] +} diff --git a/third_party/musl/ndk_script/link_libc.sh b/third_party/musl/ndk_script/link_libc.sh new file mode 100755 index 000000000..2bc01333c --- /dev/null +++ b/third_party/musl/ndk_script/link_libc.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +SOURCE_DIR=$1 + +# 检查必需参数 +if [ -z "$SOURCE_DIR" ]; then + echo "Error: Source directory is required" + exit 1 +fi + +if [ ! -d "$SOURCE_DIR" ]; then + echo "Error: $SOURCE_DIR is not a valid directory" + exit 1 +fi + +if [ ! -w "$SOURCE_DIR" ]; then + echo "Error: No write permission for directory $SOURCE_DIR" + exit 1 +fi + +# 定义要处理的库文件映射 +declare -A lib_map=( + ["libcrypt.a"]="INPUT(-lc)" + ["libm.a"]="INPUT(-lc)" + ["libdl.a"]="INPUT(-lc)" + ["libpthread.a"]="INPUT(-lc)" + ["libresolv.a"]="INPUT(-lc)" + ["librt.a"]="INPUT(-lc)" + ["libutil.a"]="INPUT(-lc)" + ["libxnet.a"]="INPUT(-lc)" +) + +# 处理每个库文件 +for lib in "${!lib_map[@]}"; do + find "$SOURCE_DIR" -type f -name "$lib" -print0 | while IFS= read -r -d '' file; do + echo "${lib_map[$lib]}" > "$file" + echo "Modified: $file" + done +done + +echo "Processing complete. Modified files are in $SOURCE_DIR" \ No newline at end of file -- Gitee