已合并
[CP] 3.7 Embed ICU data inside libflutter.so on ohos #1001
[CP] 3.7 Embed ICU data inside libflutter.so on ohos #1001
已合并
KeminLuo创建于 2025年9月1日
共 4 个文件变更+126-17
@@ -0,0 +1,105 @@
1+# Copyright 2013 The Flutter Authors. All rights reserved.
2+# Use of this source code is governed by a BSD-style license that can be
3+# found in the LICENSE file.
4+ 
5+import("//flutter/build/dart/dart.gni")
6+ 
7+# Generates an assembly file defining a given symbol with the bytes from a
8+# binary file. Places the symbol in a text section if 'executable' is true,
9+# otherwise places the symbol in a read-only data section.
10+template("bin_to_assembly") {
11+ assert(defined(invoker.deps), "Must define deps")
12+ assert(defined(invoker.input), "Must define input binary file")
13+ assert(defined(invoker.symbol), "Must define symbol name")
14+ assert(defined(invoker.executable), "Must define boolean executable")
15+ 
16+ action(target_name) {
17+ deps = invoker.deps
18+ script = "$dart_src/runtime/tools/bin_to_assembly.py"
19+ output = "$target_gen_dir/${invoker.input}.S"
20+ args = [
21+ "--input",
22+ rebase_path(invoker.input),
23+ "--output",
24+ rebase_path(output),
25+ "--symbol_name",
26+ invoker.symbol,
27+ "--target_os",
28+ current_os,
29+ ]
30+ if (defined(invoker.size_symbol)) {
31+ args += [
32+ "--size_symbol_name",
33+ invoker.size_symbol,
34+ "--target_arch",
35+ current_cpu,
36+ ]
37+ }
38+ if (invoker.executable) {
39+ args += [ "--executable" ]
40+ }
41+ if (current_os != "win") {
42+ args += [ "--incbin" ]
43+ }
44+ inputs = [
45+ script,
46+ invoker.input,
47+ ]
48+ outputs = [ output ]
49+ }
50+}
51+ 
52+# Generates an object file defining a given symbol with the bytes from a
53+# binary file. Places the symbol in the read-only data section.
54+template("bin_to_coff") {
55+ assert(defined(invoker.deps), "Must define deps")
56+ assert(defined(invoker.input), "Must define input binary file")
57+ assert(defined(invoker.symbol), "Must define symbol name")
58+ assert(defined(invoker.executable), "Must define executable")
59+ 
60+ action(target_name) {
61+ deps = invoker.deps
62+ script = "$dart_src/runtime/tools/bin_to_coff.py"
63+ output = "$target_gen_dir/${invoker.input}.o"
64+ args = [
65+ "--input",
66+ rebase_path(invoker.input),
67+ "--output",
68+ rebase_path(output),
69+ "--symbol_name",
70+ invoker.symbol,
71+ ]
72+ 
73+ if (defined(invoker.size_symbol)) {
74+ args += [
75+ "--size_symbol_name",
76+ invoker.size_symbol,
77+ ]
78+ }
79+ 
80+ if (invoker.executable) {
81+ args += [ "--executable" ]
82+ }
83+ 
84+ args += [ "--arch=$current_cpu" ]
85+ inputs = [ invoker.input ]
86+ outputs = [ output ]
87+ }
88+}
89+ 
90+# Generates a linkable output file defining the specified symbol with the bytes
91+# from the binary file. Emits a COFF object file when targeting Windows,
92+# otherwise assembly.
93+template("bin_to_linkable") {
94+ assert(defined(invoker.deps), "Must define deps")
95+ assert(defined(invoker.input), "Must define input binary file")
96+ assert(defined(invoker.symbol), "Must define symbol name")
97+ target_type = "bin_to_assembly"
98+ if (is_win) {
99+ target_type = "bin_to_coff"
100+ }
101+ 
102+ target(target_type, target_name) {
103+ forward_variables_from(invoker, "*")
104+ }
105+}
@@ -0,0 +1,7 @@
1+# Copyright 2013 The Flutter Authors. All rights reserved.
2+# Use of this source code is governed by a BSD-style license that can be
3+# found in the LICENSE file.
4+ 
5+declare_args() {
6+ dart_src = "//third_party/dart"
7+}
@@ -7,6 +7,7 @@ assert(is_ohos)
7import("//build/config/ohos/config.gni")7import("//build/config/ohos/config.gni")
8import("//build/toolchain/clang.gni")8import("//build/toolchain/clang.gni")
9import("//flutter/build/zip_bundle.gni")9import("//flutter/build/zip_bundle.gni")
10+import("//flutter/build/bin_to_obj.gni")
10import("//flutter/common/config.gni")11import("//flutter/common/config.gni")
11import("//flutter/shell/gpu/gpu.gni")12import("//flutter/shell/gpu/gpu.gni")
12import("//flutter/shell/version/version.gni")13import("//flutter/shell/version/version.gni")
@@ -45,9 +46,15 @@ _public_headers = [
45]46]
46 47 
47config("relative_flutter_ohos_headers") {48config("relative_flutter_ohos_headers") {
48- include_dirs = [ "public",49+ include_dirs = [ "public" ]
49- 50+}
50- ]51+ 
52+bin_to_assembly("icudtl_asm") {
53+ deps = []
54+ input = "//third_party/icu/flutter/icudtl.dat"
55+ symbol = "_binary_icudtl_dat_start"
56+ size_symbol = "_binary_icudtl_dat_size"
57+ executable = false
51}58}
52 59 
53source_set("flutter_ohos_sources") {60source_set("flutter_ohos_sources") {
@@ -120,6 +127,8 @@ source_set("flutter_ohos_sources") {
120 "image_lru.cpp"127 "image_lru.cpp"
121 ]128 ]
122 129 
130+ sources += get_target_outputs(":icudtl_asm")
131+ 
123 # Set flag to stop headers being directly included (library users should not do this)132 # Set flag to stop headers being directly included (library users should not do this)
124 defines = [133 defines = [
125 "FLUTTER_LINUX_COMPILATION",134 "FLUTTER_LINUX_COMPILATION",
@@ -136,6 +145,7 @@ source_set("flutter_ohos_sources") {
136 ]145 ]
137 146 
138 public_deps = [147 public_deps = [
148+ ":icudtl_asm",
139 ":ohos_gpu_configuration",149 ":ohos_gpu_configuration",
140 "//flutter/assets",150 "//flutter/assets",
141 "//flutter/common",151 "//flutter/common",
@@ -48,8 +48,6 @@ const FILE_SEPARATOR = "/";
48 48 
49const TIMESTAMP_PREFIX = "res_timestamp-";49const TIMESTAMP_PREFIX = "res_timestamp-";
50 50 
51-const OH_ICU_DATA_FILE_PATH = "/system/usr/ohos_icu/"
52- 
53async function prefetchDefaultFontManager(): Promise<void> {51async function prefetchDefaultFontManager(): Promise<void> {
54 await new Promise<void>((resolve: Function) => {52 await new Promise<void>((resolve: Function) => {
55 FlutterNapi.prefetchDefaultFontManager()53 FlutterNapi.prefetchDefaultFontManager()
@@ -187,18 +185,7 @@ export default class FlutterLoader {
187 + FILE_SEPARATOR185 + FILE_SEPARATOR
188 + this.flutterApplicationInfo!.aotSharedLibraryName);186 + this.flutterApplicationInfo!.aotSharedLibraryName);
189 187
190- const fileIsAccess = fs.accessSync(OH_ICU_DATA_FILE_PATH)188+ shellArgs.push("--icu-symbol-prefix=_binary_icudtl_dat")
191- 
192- if (fileIsAccess) {
193- const ICUPath = fs.listFileSync(OH_ICU_DATA_FILE_PATH);
194- if (ICUPath.length == 1) {
195- shellArgs.push("--icu-data-file-path=" + OH_ICU_DATA_FILE_PATH + ICUPath[0]);
196- } else {
197- Log.e(TAG, "The file in the " + OH_ICU_DATA_FILE_PATH + " directory is not unique")
198- }
199- } else {
200- Log.e(TAG, "The file " + OH_ICU_DATA_FILE_PATH + " does not exist")
201- }
202 189 
203 if (this.flutterApplicationInfo!.isProfile) {190 if (this.flutterApplicationInfo!.isProfile) {
204 shellArgs.push("--" + AOT_VMSERVICE_SHARED_LIBRARY_NAME + "=" + VMSERVICE_SNAPSHOT_LIBRARY);191 shellArgs.push("--" + AOT_VMSERVICE_SHARED_LIBRARY_NAME + "=" + VMSERVICE_SNAPSHOT_LIBRARY);