• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS.  PLEASE
16//     CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE
17//     DEPENDING ON IT IN YOUR PROJECT. ***
18package {
19    default_applicable_licenses: ["external_python_cpython3_license"],
20}
21
22// Added automatically by a large-scale-change that took the approach of
23// 'apply every license found to every target'. While this makes sure we respect
24// every license restriction, it may not be entirely correct.
25//
26// e.g. GPL in an MIT project might only apply to the contrib/ directory.
27//
28// Please consider splitting the single license below into multiple licenses,
29// taking care not to lose any license_kind information, and overriding the
30// default license using the 'licenses: [...]' property on targets as needed.
31//
32// For unused files, consider creating a 'fileGroup' with "//visibility:private"
33// to attach the license to, and including a comment whether the files may be
34// used in the current project.
35// See: http://go/android-license-faq
36license {
37    name: "external_python_cpython3_license",
38    visibility: [":__subpackages__"],
39    license_kinds: [
40        "SPDX-license-identifier-0BSD",
41        "SPDX-license-identifier-Apache-2.0",
42        "SPDX-license-identifier-BSD",
43        "SPDX-license-identifier-CC0-1.0",
44        "SPDX-license-identifier-GPL",
45        "SPDX-license-identifier-MIT",
46        "SPDX-license-identifier-MS-RL", // by exception only
47        "SPDX-license-identifier-PSF-2.0",
48        "SPDX-license-identifier-Unicode-DFS",
49        "SPDX-license-identifier-W3C",
50        "SPDX-license-identifier-Zlib",
51        "legacy_by_exception_only", // by exception only
52        "legacy_notice",
53        "legacy_unencumbered",
54    ],
55    license_text: [
56        "LICENSE",
57    ],
58}
59
60build = [
61    "Android-bionic.bp",
62    "Android-linux_x86_64.bp",
63    "Android-darwin_x86_64.bp",
64]
65
66soong_config_module_type {
67    name: "cpython3_cc_defaults",
68    module_type: "cc_defaults",
69    config_namespace: "cpython3",
70    bool_variables: ["force_build_host"],
71    properties: ["defaults"],
72}
73
74// By default, disable the source and use the prebuilts for host linux
75// and darwin. Overridden by cpython3-interp-force_build_host when
76// force_build_host is true (set on aosp-build-tools).
77cc_defaults {
78    name: "cpython3-interp-host-prebuilts",
79    defaults_visibility: ["//visibility:private"],
80    target: {
81        linux_glibc: {
82            enabled: false,
83        },
84        linux_musl: {
85            enabled: false,
86        },
87        darwin: {
88            enabled: false,
89        },
90    },
91}
92
93cc_defaults {
94    name: "cpython3-interp-force_build_host",
95    defaults_visibility: ["//visibility:private"],
96    target: {
97        linux_glibc: {
98            enabled: true,
99        },
100        linux_musl: {
101            enabled: true,
102        },
103        darwin: {
104            enabled: true,
105        },
106    },
107}
108
109cpython3_cc_defaults {
110    name: "py3-interp-defaults",
111    defaults_visibility: ["//visibility:private"],
112    cflags: [
113        "-fwrapv",
114        "-O3",
115        "-Wall",
116        "-Wstrict-prototypes",
117        "-DPy_BUILD_CORE",
118        "-Werror",
119        "-Wno-invalid-source-encoding",
120        "-Wno-int-conversion",
121        "-Wno-missing-field-initializers",
122        "-Wno-null-pointer-arithmetic",
123        "-Wno-register",
124        "-Wno-shift-count-overflow",
125        "-Wno-sign-compare",
126        "-Wno-tautological-compare",
127        "-Wno-tautological-constant-out-of-range-compare",
128        "-Wno-unused-function",
129        "-Wno-unused-parameter",
130        "-Wno-unused-result",
131    ],
132    local_include_dirs: [
133        "Include",
134        "Include/internal",
135    ],
136    static_libs: ["libffi"],
137    target: {
138        android: {
139            local_include_dirs: ["android/bionic/pyconfig"],
140        },
141        android_arm: {
142            cflags: ["-DSOABI=\"cpython-310android-arm-android-bionic\""],
143        },
144        android_arm64: {
145            cflags: ["-DSOABI=\"cpython-310android-arm64-android-bionic\""],
146        },
147        android_x86: {
148            cflags: ["-DSOABI=\"cpython-310android-x86-android-bionic\""],
149        },
150        android_x86_64: {
151            cflags: ["-DSOABI=\"cpython-310android-x86_64-android-bionic\""],
152        },
153        host: {
154            // Host builds are moving to prebuilts, which has a higher risk of
155            // having an incompatible libc++.so when installed.
156            stl: "libc++_static",
157        },
158        // Regenerate include dirs with android_regen.sh
159        darwin_x86_64: {
160            local_include_dirs: ["android/darwin_x86_64/pyconfig"],
161            cflags: [
162                "-Wno-deprecated-declarations",
163                "-Wno-pointer-arith",
164                "-DSOABI=\"cpython-310android-x86_64-darwin\"",
165            ],
166        },
167        linux_bionic: {
168            // NB linux_bionic is a 'host' architecture but it uses the bionic libc like 'android'
169            // targets so use the android pyconfig.
170            local_include_dirs: ["android/bionic/pyconfig"],
171            cflags: ["-DSOABI=\"cpython-310android-x86_64-linux-bionic\""],
172        },
173        linux_glibc_x86: {
174            enabled: false,
175        },
176        linux_musl_x86: {
177            enabled: false,
178        },
179        linux_glibc_x86_64: {
180            local_include_dirs: ["android/linux_x86_64/pyconfig"],
181            cflags: ["-DSOABI=\"cpython-310android-x86_64-linux-gnu\""],
182        },
183        linux_musl_x86_64: {
184            local_include_dirs: ["android/linux_x86_64/pyconfig"],
185            cflags: ["-DSOABI=\"cpython-310android-x86_64-linux-gnu\""],
186        },
187        windows: {
188            enabled: false,
189        },
190    },
191    host_supported: true,
192    compile_multilib: "both",
193    multilib: {
194        lib32: {
195            suffix: "32",
196        },
197        lib64: {
198            suffix: "64",
199        },
200    },
201    soong_config_variables: {
202        force_build_host: {
203            defaults: ["cpython3-interp-force_build_host"],
204        },
205    },
206}
207
208cc_library_static {
209    name: "py3-interp",
210    defaults: ["py3-interp-defaults", "cpython3-interp-host-prebuilts"],
211    cflags: ["-DPy_BUILD_CORE", "-DPLATLIBDIR=\"lib\""],
212    srcs: [
213        // Makefile.pre.in PEGEN_OBJS
214        "Parser/pegen.c",
215        "Parser/parser.c",
216        "Parser/string_parser.c",
217        "Parser/peg_api.c",
218
219        // Makefile.pre.in PARSER_OBJS
220        "Parser/myreadline.c",
221        "Parser/token.c",
222        "Parser/tokenizer.c",
223
224        // Makefile.pre.in OBJECT_OBJS
225        "Objects/abstract.c",
226        "Objects/accu.c",
227        "Objects/boolobject.c",
228        "Objects/bytes_methods.c",
229        "Objects/bytearrayobject.c",
230        "Objects/bytesobject.c",
231        "Objects/call.c",
232        "Objects/capsule.c",
233        "Objects/cellobject.c",
234        "Objects/classobject.c",
235        "Objects/codeobject.c",
236        "Objects/complexobject.c",
237        "Objects/descrobject.c",
238        "Objects/enumobject.c",
239        "Objects/exceptions.c",
240        "Objects/genericaliasobject.c",
241        "Objects/genobject.c",
242        "Objects/fileobject.c",
243        "Objects/floatobject.c",
244        "Objects/frameobject.c",
245        "Objects/funcobject.c",
246        "Objects/interpreteridobject.c",
247        "Objects/iterobject.c",
248        "Objects/listobject.c",
249        "Objects/longobject.c",
250        "Objects/dictobject.c",
251        "Objects/odictobject.c",
252        "Objects/memoryobject.c",
253        "Objects/methodobject.c",
254        "Objects/moduleobject.c",
255        "Objects/namespaceobject.c",
256        "Objects/object.c",
257        "Objects/obmalloc.c",
258        "Objects/picklebufobject.c",
259        "Objects/rangeobject.c",
260        "Objects/setobject.c",
261        "Objects/sliceobject.c",
262        "Objects/structseq.c",
263        "Objects/tupleobject.c",
264        "Objects/typeobject.c",
265        "Objects/unicodeobject.c",
266        "Objects/unicodectype.c",
267        "Objects/unionobject.c",
268        "Objects/weakrefobject.c",
269
270        // Makefile.pre.in PYTHON_OBJS
271        "Python/_warnings.c",
272        "Python/Python-ast.c",
273        "Python/asdl.c",
274        "Python/ast.c",
275        "Python/ast_opt.c",
276        "Python/ast_unparse.c",
277        "Python/bltinmodule.c",
278        "Python/ceval.c",
279        "Python/codecs.c",
280        "Python/compile.c",
281        "Python/context.c",
282        "Python/dynamic_annotations.c",
283        "Python/errors.c",
284        "Python/frozen.c",
285        "Python/frozenmain.c",
286        "Python/future.c",
287        "Python/getargs.c",
288        "Python/getcompiler.c",
289        "Python/getcopyright.c",
290        "Python/getplatform.c",
291        "Python/getversion.c",
292        "Python/hamt.c",
293        "Python/hashtable.c",
294        "Python/import.c",
295        "Python/importdl.c",
296        "Python/initconfig.c",
297        "Python/marshal.c",
298        "Python/modsupport.c",
299        "Python/mysnprintf.c",
300        "Python/mystrtoul.c",
301        "Python/pathconfig.c",
302        "Python/preconfig.c",
303        "Python/pyarena.c",
304        "Python/pyctype.c",
305        "Python/pyfpe.c",
306        "Python/pyhash.c",
307        "Python/pylifecycle.c",
308        "Python/pymath.c",
309        "Python/pystate.c",
310        "Python/pythonrun.c",
311        "Python/pytime.c",
312        "Python/bootstrap_hash.c",
313        "Python/structmember.c",
314        "Python/symtable.c",
315        "Python/sysmodule.c",
316        "Python/thread.c",
317        "Python/traceback.c",
318        "Python/getopt.c",
319        "Python/pystrcmp.c",
320        "Python/pystrtod.c",
321        "Python/pystrhex.c",
322        "Python/dtoa.c",
323        "Python/formatter_unicode.c",
324        "Python/fileutils.c",
325        "Python/suggestions.c",
326        "Python/dynload_shlib.c",
327    ],
328
329    target: {
330        linux: {
331            cflags: [
332                "-DPLATFORM=\"linux\"",
333                "-DABIFLAGS=\"\"",
334            ],
335        },
336        darwin_x86_64: {
337            cflags: [
338                "-DPLATFORM=\"darwin\"",
339                "-DABIFLAGS=\"\"",
340            ],
341        },
342    },
343}
344
345cc_defaults {
346    name: "py3-launcher-defaults",
347    defaults: ["py3-interp-defaults", "cpython3-interp-host-prebuilts"],
348    cflags: [
349        "-DVERSION=\"3.10\"",
350        "-DVPATH=\"\"",
351        "-DPREFIX=\"\"",
352        "-DEXEC_PREFIX=\"\"",
353        "-DPYTHONPATH=\"..:\"",
354        "-DANDROID_SKIP_ZIP_PATH",
355        "-DANDROID_SKIP_EXEC_PREFIX_PATH",
356        "-DANDROID_LIB_PYTHON_PATH=\"internal/stdlib\"",
357        "-DDATE=\"Dec 31 1969\"",
358        "-DTIME=\"23:59:59\"",
359    ],
360    static_libs: [
361        "libbase",
362        "libexpat",
363        "libz",
364    ],
365    target: {
366        linux_glibc_x86_64: {
367            host_ldlibs: ["-lutil"],
368        },
369        linux: {
370            // Due to test infra limitations, Python native symbols are linked
371            // statically to py3-launcher(s). Hence, need this flag to export
372            // these symbols so that runtime imported native extensions can use
373            // them (e.g. PyBaseObject_Type)
374            ldflags: ["-Wl,--export-dynamic"],
375        },
376        darwin: {
377            host_ldlibs: [
378                "-framework SystemConfiguration",
379                "-framework CoreFoundation",
380            ],
381        },
382        host: {
383            static_libs: [
384                "libsqlite",
385                "liblog",
386                "libopenssl_ssl",
387                "libopenssl_crypto",
388            ],
389        },
390        linux_bionic: {
391            // Linux Bionic doesn't have openssl prebuilts
392            exclude_static_libs: [
393                "libopenssl_ssl",
394                "libopenssl_crypto",
395            ],
396        },
397        android: {
398            shared_libs: [
399                // Use shared libsqlite for device side, otherwise
400                // the executable size will be really huge.
401                "libsqlite",
402                // Dependency from libbase
403                "liblog",
404            ],
405        },
406    },
407}
408
409cc_library_static {
410    name: "py3-launcher-lib",
411    defaults: ["py3-launcher-defaults"],
412    cflags: ["-DPy_BUILD_CORE"],
413    srcs: [
414        // Makefile.pre.in MODULE_OBJS
415        "Modules/getpath.c",
416        "Modules/main.c",
417        "Modules/gcmodule.c",
418
419        // Makefile.pre.in LIBRARY_OBJS_OMIT_FROZEN
420        "Modules/getbuildinfo.c",
421    ],
422    whole_static_libs: [
423        "py3-interp",
424        "py3-c-modules",
425    ],
426    target: {
427        android: {
428            srcs: ["android/bionic/config.c"],
429        },
430        linux_bionic: {
431            srcs: ["android/bionic/config.c"],
432        },
433        glibc_x86_64: {
434            srcs: ["android/linux_x86_64/config.c"],
435        },
436        musl_x86_64: {
437            srcs: ["android/linux_x86_64/config.c"],
438        },
439        darwin: {
440            srcs: ["android/darwin_x86_64/config.c"],
441        },
442    },
443}
444
445cc_binary {
446    name: "py3-launcher",
447    defaults: ["py3-launcher-defaults"],
448    srcs: ["android/launcher_main.cpp"],
449    static_libs: ["py3-launcher-lib"],
450}
451
452cc_binary {
453    name: "py3-launcher-autorun",
454    defaults: ["py3-launcher-defaults"],
455    srcs: ["android/launcher_main.cpp"],
456    static_libs: ["py3-launcher-lib"],
457    cflags: ["-DANDROID_AUTORUN"],
458}
459
460cc_binary_host {
461    name: "py3-launcher-static",
462    defaults: ["py3-launcher-defaults"],
463    srcs: ["android/launcher_main.cpp"],
464    static_libs: ["py3-launcher-lib"],
465    static_executable: true,
466    target: {
467        glibc: {
468            enabled: false,
469        },
470    },
471}
472
473cc_binary_host {
474    name: "py3-launcher-autorun-static",
475    defaults: ["py3-launcher-defaults"],
476    srcs: ["android/launcher_main.cpp"],
477    static_libs: ["py3-launcher-lib"],
478    static_executable: true,
479    cflags: ["-DANDROID_AUTORUN"],
480    target: {
481        glibc: {
482            enabled: false,
483        },
484    },
485}
486
487python_binary_host {
488    name: "py3-cmd",
489    autorun: false,
490    version: {
491        py3: {
492            embedded_launcher: true,
493        },
494    },
495}
496
497// Enabled extension py3-c-modules.
498
499cc_library_static {
500    name: "py3-c-modules",
501    defaults: ["py3-interp-defaults", "cpython3-interp-host-prebuilts"],
502    cflags: [
503        "-DPy_BUILD_CORE_BUILTIN",
504        "-DUSE_PYEXPAT_CAPI",
505    ],
506    static_libs: [
507        "libexpat",
508        "libz",
509    ],
510    target: {
511        android: {
512            srcs: [":py3-c-modules-bionic"],
513        },
514        linux_bionic: {
515            srcs: [":py3-c-modules-bionic"],
516        },
517        glibc_x86_64: {
518            srcs: [":py3-c-modules-linux_x86_64"],
519            static_libs: [
520                "libopenssl_ssl",
521                "libopenssl_crypto",
522            ],
523        },
524        musl_x86_64: {
525            srcs: [":py3-c-modules-linux_x86_64"],
526            static_libs: [
527                "libopenssl_ssl",
528                "libopenssl_crypto",
529            ],
530        },
531        darwin: {
532            cflags: ["-D__APPLE_USE_RFC_3542"],
533            srcs: [":py3-c-modules-darwin_x86_64"],
534            static_libs: [
535                "libopenssl_ssl",
536                "libopenssl_crypto",
537            ],
538        },
539    },
540}
541