projects/aports·blob master · refs

329 lines · 9.8 KiB

1From 903ae13d643c305c48c4271ed4a05939656ed041 Mon Sep 17 00:00:00 2001
2From: "Lauren N. Liberda" <[email protected]>
3Date: Sat, 8 Apr 2023 02:56:35 +0200
4Subject: [PATCH 1/2] add gn args specifying libc for linux
5
6---
7 build/config/compiler/BUILD.gn | 8 ++-
8 build/config/linux/detect_host_libc.py | 42 ++++++++++++
9 build/config/linux/libc.gni | 51 +++++++++++++++
10 build/toolchain/linux/BUILD.gn | 89 ++++++++++++++------------
11 4 files changed, 147 insertions(+), 43 deletions(-)
12 create mode 100755 build/config/linux/detect_host_libc.py
13 create mode 100644 build/config/linux/libc.gni
14
15diff --git a/engine/src/build/config/compiler/BUILD.gn b/engine/src/build/config/compiler/BUILD.gn
16index 4c9a1ee..155d433 100644
17--- ./engine/src/build/config/compiler/BUILD.gn.orig
18+++ ./engine/src/build/config/compiler/BUILD.gn
19@@ -13,6 +13,9 @@
20 if (is_win) {
21 import("//build/config/win/visual_studio_version.gni")
22 }
23+if (is_linux) {
24+ import("//build/config/linux/libc.gni")
25+}
26
27 import("//build/config/c++/c++.gni")
28 import("//build/config/profiler.gni")
29@@ -397,8 +400,8 @@
30 ldflags += [ "-pthread" ]
31
32 if (current_cpu == "arm64") {
33- cflags += [ "--target=aarch64-linux-gnu" ]
34- ldflags += [ "--target=aarch64-linux-gnu" ]
35+ cflags += [ "--target=aarch64-alpine-linux-musl" ]
36+ ldflags += [ "--target=aarch64-alpine-linux-musl" ]
37 cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ]
38 }
39 }
40@@ -695,7 +698,7 @@
41 "-Wno-unused-parameter", # Unused function parameters.
42 ]
43
44- if (!is_qnx) {
45+ if (!is_qnx && (!is_linux || is_glibc)) {
46 default_warning_flags += [
47 "-Werror", # Warnings as errors.
48 ]
49diff --git a/engine/src/build/config/linux/detect_host_libc.py b/engine/src/build/config/linux/detect_host_libc.py
50new file mode 100755
51index 0000000..1ebb498
52--- /dev/null
53+++ b/engine/src/build/config/linux/detect_host_libc.py
54@@ -0,0 +1,42 @@
55+#!/usr/bin/env python3
56+#
57+# Copyright (c) 2013 The Flutter Authors. All rights reserved.
58+# Use of this source code is governed by a BSD-style license that can be
59+# found in the LICENSE file.
60+
61+from optparse import OptionParser
62+import re
63+import subprocess
64+import sys
65+
66+
67+def main():
68+ if 'linux' not in sys.platform:
69+ return 1
70+
71+ parser = OptionParser()
72+ parser.add_option('--compiler-path', action='store',
73+ type='string', default='gcc')
74+ (options, args) = parser.parse_args()
75+
76+ # should work with both gcc and clang
77+ #
78+ # example outputs: "aarch64-unknown-linux-gnu", "x86_64-alpine-linux-musl",
79+ # "armv7-unknown-linux-musleabihf", "mipsel-linux-muslhf"
80+ default_target = subprocess.check_output([
81+ options.compiler_path, '-dumpmachine']).decode('utf-8').strip()
82+
83+ host_libc_re = re.match(
84+ r'^(?:[^-]+-){1,2}linux-(?P<libc>gnu|musl|uclibc)(?:eabi)?(?:hf)?$',
85+ default_target)
86+ if host_libc_re is None:
87+ print(f'Target not understood: {default_target}')
88+
89+ host_libc = host_libc_re.group('libc')
90+ # print would add a newline
91+ sys.stdout.write(host_libc)
92+ return 0
93+
94+
95+if __name__ == '__main__':
96+ sys.exit(main())
97diff --git a/engine/src/build/config/linux/libc.gni b/engine/src/build/config/linux/libc.gni
98new file mode 100644
99index 0000000..653f312
100--- /dev/null
101+++ b/engine/src/build/config/linux/libc.gni
102@@ -0,0 +1,51 @@
103+# Copyright (c) 2013 The Flutter Authors. All rights reserved.
104+# Use of this source code is governed by a BSD-style license that can be
105+# found in the LICENSE file.
106+
107+import("//build/config/sysroot.gni")
108+
109+declare_args() {
110+ # The C library used by the compilation host.
111+ # Expecting one of: "gnu" (glibc), "uclibc", "musl"
112+ host_libc = ""
113+
114+ # The C library of the compilation target.
115+ # Expecting one of: "gnu" (glibc), "uclibc", "musl"
116+ target_libc = ""
117+}
118+
119+# try to detect host's libc if not explicitly provided
120+if (host_libc == "" && is_linux) {
121+ if (sysroot == "") {
122+ host_compiler = "gcc"
123+ if (is_clang) {
124+ host_compiler = "clang"
125+ }
126+
127+ # tries to determine libc from "gcc/clang -printmachine"
128+ host_libc = exec_script("//build/config/linux/detect_host_libc.py",
129+ [
130+ "--compiler-path",
131+ host_compiler,
132+ ],
133+ "string")
134+ } else {
135+ # currently there is only debian sysroot
136+ host_libc = "gnu"
137+ }
138+}
139+
140+assert(!is_linux || host_libc != "", "Host libc not specified and not detected")
141+
142+# assume compiling for host if not explicitly specified
143+if (target_libc == "") {
144+ target_libc = host_libc
145+}
146+
147+is_cross_libc = host_libc != target_libc
148+
149+is_glibc = target_libc == "gnu"
150+is_musl = target_libc == "musl"
151+
152+is_host_glibc = host_libc == "gnu"
153+is_host_musl = host_libc == "musl"
154diff --git a/engine/src/build/toolchain/linux/BUILD.gn b/engine/src/build/toolchain/linux/BUILD.gn
155index 05630d0..b1288ce 100644
156--- a/engine/src/build/toolchain/linux/BUILD.gn
157+++ b/engine/src/build/toolchain/linux/BUILD.gn
158@@ -2,6 +2,7 @@
159 # Use of this source code is governed by a BSD-style license that can be
160 # found in the LICENSE file.
161
162+import("//build/config/linux/libc.gni")
163 import("//build/config/sysroot.gni")
164 import("//build/toolchain/ccache.gni")
165 import("//build/toolchain/gcc_toolchain.gni")
166@@ -33,16 +34,10 @@
167 link_prefix = ""
168 }
169
170-if (host_cpu == "arm64") {
171- rebased_clang_dir =
172- rebase_path("$buildtools_path/linux-arm64/clang/bin", root_build_dir)
173-} else {
174- rebased_clang_dir =
175- rebase_path("$buildtools_path/linux-x64/clang/bin", root_build_dir)
176-}
177+rebased_clang_dir = ""
178
179 gcc_toolchain("arm") {
180- prefix = "arm-linux-gnueabihf-"
181+ prefix = "arm-linux-${target_libc}eabihf-"
182 if (toolchain_prefix != "") {
183 prefix = toolchain_prefix
184 }
185@@ -64,15 +59,15 @@
186
187 gcc_toolchain("clang_arm") {
188 prefix = rebased_clang_dir
189- asm = "${prefix}/clang"
190- cc = "${compiler_prefix}${prefix}/clang"
191- cxx = "${compiler_prefix}${prefix}/clang++"
192+ asm = "${prefix}clang"
193+ cc = "${compiler_prefix}${prefix}clang"
194+ cxx = "${compiler_prefix}${prefix}clang++"
195
196- readelf = "${prefix}/llvm-readelf"
197- nm = "${prefix}/llvm-nm"
198- ar = "${prefix}/llvm-ar"
199- ld = "${link_prefix}${prefix}/clang++"
200- llvm_objcopy = "${prefix}/llvm-objcopy"
201+ readelf = "${prefix}llvm-readelf"
202+ nm = "${prefix}llvm-nm"
203+ ar = "${prefix}llvm-ar"
204+ ld = "${link_prefix}${prefix}clang++"
205+ llvm_objcopy = "${prefix}llvm-objcopy"
206
207 toolchain_cpu = "arm"
208 toolchain_os = "linux"
209@@ -80,7 +75,7 @@
210 }
211
212 gcc_toolchain("arm64") {
213- prefix = "aarch64-linux-gnu-"
214+ prefix = "aarch64-linux-${target_libc}-"
215 if (toolchain_prefix != "") {
216 prefix = toolchain_prefix
217 }
218@@ -102,15 +97,15 @@
219
220 gcc_toolchain("clang_arm64") {
221 prefix = rebased_clang_dir
222- asm = "${prefix}/clang"
223- cc = "${compiler_prefix}${prefix}/clang"
224- cxx = "${compiler_prefix}${prefix}/clang++"
225+ asm = "${prefix}clang"
226+ cc = "${compiler_prefix}${prefix}clang"
227+ cxx = "${compiler_prefix}${prefix}clang++"
228
229 readelf = "readelf"
230- nm = "${prefix}/llvm-nm"
231- ar = "${prefix}/llvm-ar"
232- ld = "${link_prefix}${prefix}/clang++"
233- llvm_objcopy = "${prefix}/llvm-objcopy"
234+ nm = "${prefix}llvm-nm"
235+ ar = "${prefix}llvm-ar"
236+ ld = "${link_prefix}${prefix}clang++"
237+ llvm_objcopy = "${prefix}llvm-objcopy"
238
239 toolchain_cpu = "arm64"
240 toolchain_os = "linux"
241@@ -119,15 +114,15 @@
242
243 gcc_toolchain("clang_x86") {
244 prefix = rebased_clang_dir
245- asm = "${prefix}/clang"
246- cc = "${compiler_prefix}${prefix}/clang"
247- cxx = "${compiler_prefix}${prefix}/clang++"
248+ asm = "${prefix}clang"
249+ cc = "${compiler_prefix}${prefix}clang"
250+ cxx = "${compiler_prefix}${prefix}clang++"
251
252- readelf = "${prefix}/llvm-readelf"
253- nm = "${prefix}/llvm-nm"
254- ar = "${prefix}/llvm-ar"
255- ld = "${link_prefix}${prefix}/clang++"
256- llvm_objcopy = "${prefix}/llvm-objcopy"
257+ readelf = "${prefix}llvm-readelf"
258+ nm = "${prefix}llvm-nm"
259+ ar = "${prefix}llvm-ar"
260+ ld = "${link_prefix}${prefix}clang++"
261+ llvm_objcopy = "${prefix}llvm-objcopy"
262
263 toolchain_cpu = "x86"
264 toolchain_os = "linux"
265@@ -153,15 +148,15 @@
266
267 gcc_toolchain("clang_x64") {
268 prefix = rebased_clang_dir
269- asm = "${prefix}/clang"
270- cc = "${compiler_prefix}${prefix}/clang"
271- cxx = "${compiler_prefix}${prefix}/clang++"
272+ asm = "${prefix}clang"
273+ cc = "${compiler_prefix}${prefix}clang"
274+ cxx = "${compiler_prefix}${prefix}clang++"
275
276- readelf = "${prefix}/llvm-readelf"
277- nm = "${prefix}/llvm-nm"
278- ar = "${prefix}/llvm-ar"
279- ld = "${link_prefix}${prefix}/clang++"
280- llvm_objcopy = "${prefix}/llvm-objcopy"
281+ readelf = "${prefix}llvm-readelf"
282+ nm = "${prefix}llvm-nm"
283+ ar = "${prefix}llvm-ar"
284+ ld = "${link_prefix}${prefix}clang++"
285+ llvm_objcopy = "${prefix}llvm-objcopy"
286
287 toolchain_cpu = "x64"
288 toolchain_os = "linux"
289@@ -186,7 +181,7 @@
290 }
291
292 gcc_toolchain("riscv32") {
293- prefix = "riscv32-linux-gnu-"
294+ prefix = "riscv32-linux-${target_libc}-"
295 if (toolchain_prefix != "") {
296 prefix = toolchain_prefix
297 }
298@@ -224,7 +219,7 @@
299 }
300
301 gcc_toolchain("riscv64") {
302- prefix = "riscv64-linux-gnu-"
303+ prefix = "riscv64-linux-${target_libc}-"
304 if (toolchain_prefix != "") {
305 prefix = toolchain_prefix
306 }
307@@ -246,15 +241,15 @@
308
309 gcc_toolchain("clang_riscv64") {
310 prefix = rebased_clang_dir
311- asm = "${prefix}/clang"
312- cc = "${compiler_prefix}${prefix}/clang"
313- cxx = "${compiler_prefix}${prefix}/clang++"
314+ asm = "${prefix}clang"
315+ cc = "${compiler_prefix}${prefix}clang"
316+ cxx = "${compiler_prefix}${prefix}clang++"
317
318 readelf = "readelf"
319- nm = "${prefix}/llvm-nm"
320- ar = "${prefix}/llvm-ar"
321- ld = "${link_prefix}${prefix}/clang++"
322- llvm_objcopy = "${prefix}/llvm-objcopy"
323+ nm = "${prefix}llvm-nm"
324+ ar = "${prefix}llvm-ar"
325+ ld = "${link_prefix}${prefix}clang++"
326+ llvm_objcopy = "${prefix}llvm-objcopy"
327
328 toolchain_cpu = "riscv64"
329 toolchain_os = "linux"