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// See: http://go/android-license-faq 23license { 24 name: "external_python_cpython3_license", 25 visibility: [":__subpackages__"], 26 license_kinds: [ 27 "SPDX-license-identifier-0BSD", 28 "SPDX-license-identifier-Apache-2.0", 29 "SPDX-license-identifier-BSD", 30 "SPDX-license-identifier-CC0-1.0", 31 "SPDX-license-identifier-MIT", 32 "SPDX-license-identifier-MS-RL", // by exception only 33 "SPDX-license-identifier-PSF-2.0", 34 "SPDX-license-identifier-Unicode-DFS", 35 "SPDX-license-identifier-W3C", 36 "SPDX-license-identifier-Zlib", 37 "legacy_by_exception_only", // by exception only 38 "legacy_notice", 39 "legacy_unencumbered", 40 // GPL removed. All GPL code either Autoconf exception or dual-licensed PSF 41 ], 42 license_text: [ 43 "LICENSE", 44 ], 45} 46 47build = [ 48 "Android-bionic.bp", 49 "Android-linux_arm64.bp", 50 "Android-linux_x86_64.bp", 51 "Android-darwin.bp", 52] 53 54soong_config_module_type { 55 name: "cpython3_cc_defaults", 56 module_type: "cc_defaults", 57 config_namespace: "cpython3", 58 bool_variables: ["force_build_host"], 59 properties: ["defaults"], 60} 61 62// By default, disable the source and use the prebuilts for host linux 63// and darwin. Overridden by cpython3-interp-force_build_host when 64// force_build_host is true (set on aosp-build-tools). 65cc_defaults { 66 name: "cpython3-interp-host-prebuilts", 67 defaults_visibility: ["//visibility:private"], 68 target: { 69 linux_glibc: { 70 enabled: false, 71 }, 72 linux_musl: { 73 enabled: false, 74 }, 75 darwin: { 76 enabled: false, 77 }, 78 }, 79} 80 81cc_defaults { 82 name: "cpython3-interp-force_build_host", 83 defaults_visibility: ["//visibility:private"], 84 target: { 85 linux_glibc: { 86 enabled: true, 87 }, 88 linux_musl: { 89 enabled: true, 90 }, 91 darwin: { 92 enabled: true, 93 }, 94 }, 95} 96 97cpython3_cc_defaults { 98 name: "py3-interp-defaults", 99 defaults_visibility: ["//visibility:private"], 100 cflags: [ 101 "-fwrapv", 102 "-O3", 103 "-Wall", 104 "-DPy_BUILD_CORE", 105 "-Werror", 106 "-Wno-atomic-alignment", 107 "-Wno-gnu-pointer-arith", 108 "-Wno-invalid-source-encoding", 109 "-Wno-int-conversion", 110 "-Wno-missing-field-initializers", 111 "-Wno-null-pointer-arithmetic", 112 "-Wno-register", 113 "-Wno-shift-count-overflow", 114 "-Wno-sign-compare", 115 "-Wno-tautological-compare", 116 "-Wno-tautological-constant-out-of-range-compare", 117 "-Wno-unused-function", 118 "-Wno-unused-parameter", 119 "-Wno-unused-result", 120 ], 121 local_include_dirs: [ 122 "Include", 123 "Include/internal", 124 "Include/internal/mimalloc", 125 ], 126 static_libs: ["libffi"], 127 target: { 128 android: { 129 local_include_dirs: ["android/bionic/pyconfig"], 130 }, 131 android_arm: { 132 cflags: ["-DSOABI=\"cpython-311android-arm-android-bionic\""], 133 }, 134 android_arm64: { 135 cflags: ["-DSOABI=\"cpython-311android-arm64-android-bionic\""], 136 }, 137 android_riscv64: { 138 cflags: ["-DSOABI=\"cpython-311android-riscv64-android-bionic\""], 139 }, 140 android_x86: { 141 cflags: ["-DSOABI=\"cpython-311android-x86-android-bionic\""], 142 }, 143 android_x86_64: { 144 cflags: ["-DSOABI=\"cpython-311android-x86_64-android-bionic\""], 145 }, 146 host: { 147 // Host builds are moving to prebuilts, which has a higher risk of 148 // having an incompatible libc++.so when installed. 149 stl: "libc++_static", 150 }, 151 // Regenerate include dirs with android_regen.sh 152 darwin: { 153 local_include_dirs: ["android/darwin/pyconfig"], 154 cflags: [ 155 "-Wno-deprecated-declarations", 156 "-Wno-pointer-arith", 157 "-DSOABI=\"cpython-311android-x86_64-darwin\"", 158 ], 159 }, 160 linux_bionic: { 161 // NB linux_bionic is a 'host' architecture but it uses the bionic libc like 'android' 162 // targets so use the android pyconfig. 163 local_include_dirs: ["android/bionic/pyconfig"], 164 cflags: ["-DSOABI=\"cpython-311android-x86_64-linux-bionic\""], 165 }, 166 linux_glibc_x86: { 167 enabled: false, 168 }, 169 linux_musl_x86: { 170 enabled: false, 171 }, 172 linux_musl_arm: { 173 enabled: false, 174 }, 175 linux_glibc_x86_64: { 176 local_include_dirs: ["android/linux_x86_64/pyconfig"], 177 cflags: ["-DSOABI=\"cpython-311android-x86_64-linux-gnu\""], 178 }, 179 linux_musl_x86_64: { 180 local_include_dirs: ["android/linux_x86_64/pyconfig"], 181 cflags: ["-DSOABI=\"cpython-311android-x86_64-linux-gnu\""], 182 }, 183 linux_musl_arm64: { 184 local_include_dirs: ["android/linux_arm64/pyconfig"], 185 cflags: ["-DSOABI=\"cpython-311android-arm64-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: [ 211 "py3-interp-defaults", 212 "cpython3-interp-host-prebuilts", 213 ], 214 cflags: [ 215 "-DPy_BUILD_CORE", 216 "-DPLATLIBDIR=\"lib\"", 217 ], 218 srcs: [ 219 // Corresponds to PARSER_OBJS, OBJECT_OBJS, and PYTHON_OBJS in Makefile.pre.in 220 221 // Makefile.pre.in POBJS 222 "Parser/token.c", 223 224 // Makefile.pre.in PEGEN_OBJS 225 "Parser/pegen.c", 226 "Parser/pegen_errors.c", 227 "Parser/action_helpers.c", 228 "Parser/parser.c", 229 "Parser/string_parser.c", 230 "Parser/peg_api.c", 231 232 // Makefile.pre.in TOKENIZER_OBJS 233 "Parser/lexer/buffer.c", 234 "Parser/lexer/lexer.c", 235 "Parser/lexer/state.c", 236 "Parser/tokenizer/file_tokenizer.c", 237 "Parser/tokenizer/readline_tokenizer.c", 238 "Parser/tokenizer/string_tokenizer.c", 239 "Parser/tokenizer/utf8_tokenizer.c", 240 "Parser/tokenizer/helpers.c", 241 242 // Makefile.pre.in PARSER_OBJS 243 "Parser/myreadline.c", 244 245 // Makefile.pre.in OBJECT_OBJS 246 "Objects/abstract.c", 247 "Objects/boolobject.c", 248 "Objects/bytes_methods.c", 249 "Objects/bytearrayobject.c", 250 "Objects/bytesobject.c", 251 "Objects/call.c", 252 "Objects/capsule.c", 253 "Objects/cellobject.c", 254 "Objects/classobject.c", 255 "Objects/codeobject.c", 256 "Objects/complexobject.c", 257 "Objects/descrobject.c", 258 "Objects/enumobject.c", 259 "Objects/exceptions.c", 260 "Objects/genericaliasobject.c", 261 "Objects/genobject.c", 262 "Objects/fileobject.c", 263 "Objects/floatobject.c", 264 "Objects/frameobject.c", 265 "Objects/funcobject.c", 266 "Objects/iterobject.c", 267 "Objects/listobject.c", 268 "Objects/longobject.c", 269 "Objects/dictobject.c", 270 "Objects/odictobject.c", 271 "Objects/memoryobject.c", 272 "Objects/methodobject.c", 273 "Objects/moduleobject.c", 274 "Objects/namespaceobject.c", 275 "Objects/object.c", 276 "Objects/obmalloc.c", 277 "Objects/picklebufobject.c", 278 "Objects/rangeobject.c", 279 "Objects/setobject.c", 280 "Objects/sliceobject.c", 281 "Objects/structseq.c", 282 "Objects/tupleobject.c", 283 "Objects/typeobject.c", 284 "Objects/typevarobject.c", 285 "Objects/unicodeobject.c", 286 "Objects/unicodectype.c", 287 "Objects/unionobject.c", 288 "Objects/weakrefobject.c", 289 290 // Makefile.pre.in PYTHON_OBJS 291 "Python/_warnings.c", 292 "Python/Python-ast.c", 293 "Python/Python-tokenize.c", 294 "Python/asdl.c", 295 "Python/assemble.c", 296 "Python/ast.c", 297 "Python/ast_opt.c", 298 "Python/ast_unparse.c", 299 "Python/bltinmodule.c", 300 "Python/brc.c", 301 "Python/ceval.c", 302 "Python/codecs.c", 303 "Python/compile.c", 304 "Python/context.c", 305 "Python/critical_section.c", 306 "Python/crossinterp.c", 307 "Python/dynamic_annotations.c", 308 "Python/errors.c", 309 "Python/flowgraph.c", 310 "Python/frame.c", 311 "Python/frozenmain.c", 312 "Python/future.c", 313 "Python/gc.c", 314 "Python/gc_free_threading.c", 315 "Python/gc_gil.c", 316 "Python/getargs.c", 317 "Python/getcompiler.c", 318 "Python/getcopyright.c", 319 "Python/getplatform.c", 320 "Python/getversion.c", 321 "Python/ceval_gil.c", 322 "Python/hamt.c", 323 "Python/hashtable.c", 324 "Python/import.c", 325 "Python/importdl.c", 326 "Python/initconfig.c", 327 "Python/interpconfig.c", 328 "Python/instrumentation.c", 329 "Python/instruction_sequence.c", 330 "Python/intrinsics.c", 331 "Python/jit.c", 332 "Python/legacy_tracing.c", 333 "Python/lock.c", 334 "Python/marshal.c", 335 "Python/modsupport.c", 336 "Python/mysnprintf.c", 337 "Python/mystrtoul.c", 338 "Python/object_stack.c", 339 "Python/optimizer.c", 340 "Python/optimizer_analysis.c", 341 "Python/optimizer_symbols.c", 342 "Python/parking_lot.c", 343 "Python/pathconfig.c", 344 "Python/preconfig.c", 345 "Python/pyarena.c", 346 "Python/pyctype.c", 347 "Python/pyfpe.c", 348 "Python/pyhash.c", 349 "Python/pylifecycle.c", 350 "Python/pymath.c", 351 "Python/pystate.c", 352 "Python/pythonrun.c", 353 "Python/pytime.c", 354 "Python/qsbr.c", 355 "Python/bootstrap_hash.c", 356 "Python/specialize.c", 357 "Python/structmember.c", 358 "Python/symtable.c", 359 "Python/sysmodule.c", 360 "Python/thread.c", 361 "Python/traceback.c", 362 "Python/tracemalloc.c", 363 "Python/getopt.c", 364 "Python/pystrcmp.c", 365 "Python/pystrtod.c", 366 "Python/pystrhex.c", 367 "Python/dtoa.c", 368 "Python/formatter_unicode.c", 369 "Python/fileutils.c", 370 "Python/suggestions.c", 371 "Python/perf_trampoline.c", 372 "Python/perf_jit_trampoline.c", 373 "Python/dynload_shlib.c", 374 ], 375 376 target: { 377 linux: { 378 cflags: [ 379 "-DPLATFORM=\"linux\"", 380 "-DABIFLAGS=\"\"", 381 ], 382 }, 383 linux_arm64: { 384 srcs: [ 385 // PERF_TRAMPOLINE_OBJ 386 "Python/asm_trampoline.S", 387 ], 388 }, 389 linux_x86_64: { 390 srcs: [ 391 // PERF_TRAMPOLINE_OBJ 392 "Python/asm_trampoline.S", 393 ], 394 }, 395 darwin: { 396 cflags: [ 397 "-DPLATFORM=\"darwin\"", 398 "-DABIFLAGS=\"\"", 399 ], 400 }, 401 }, 402} 403 404cc_defaults { 405 name: "py3-launcher-defaults", 406 defaults: [ 407 "py3-interp-defaults", 408 "cpython3-interp-host-prebuilts", 409 ], 410 cflags: [ 411 "-DVERSION=\"3.13\"", 412 "-DVPATH=\"\"", 413 "-DPREFIX=\"\"", 414 "-DEXEC_PREFIX=\"\"", 415 "-DPLATLIBDIR=\"lib\"", 416 "-DPYTHONPATH=\"\"", 417 "-DDATE=\"Dec 31 1969\"", 418 "-DTIME=\"23:59:59\"", 419 ], 420 static_libs: [ 421 "libbase", 422 "libexpat", 423 "libz", 424 "libbz", 425 ], 426 target: { 427 linux_glibc_x86_64: { 428 host_ldlibs: ["-lutil"], 429 }, 430 linux: { 431 // Due to test infra limitations, Python native symbols are linked 432 // statically to py3-launcher(s). Hence, need this flag to export 433 // these symbols so that runtime imported native extensions can use 434 // them (e.g. PyBaseObject_Type) 435 ldflags: ["-Wl,--export-dynamic"], 436 }, 437 darwin: { 438 host_ldlibs: [ 439 "-framework SystemConfiguration", 440 "-framework CoreFoundation", 441 ], 442 }, 443 host: { 444 static_libs: [ 445 "libsqlite_static_noicu", 446 "liblog", 447 "libopenssl_ssl", 448 "libopenssl_crypto", 449 ], 450 }, 451 linux_bionic: { 452 // Linux Bionic doesn't have openssl prebuilts 453 exclude_static_libs: [ 454 "libopenssl_ssl", 455 "libopenssl_crypto", 456 ], 457 }, 458 android: { 459 shared_libs: [ 460 // Use shared libsqlite for device side, otherwise 461 // the executable size will be really huge. 462 "libsqlite", 463 // Dependency from libbase 464 "liblog", 465 ], 466 }, 467 }, 468} 469 470cc_library_static { 471 name: "py3-launcher-lib-omit-frozen", 472 defaults: ["py3-launcher-defaults"], 473 cflags: ["-DPy_BUILD_CORE"], 474 srcs: [ 475 // Makefile.pre.in MODULE_OBJS 476 "Modules/main.c", 477 "Modules/gcmodule.c", 478 479 // Makefile.pre.in LIBRARY_OBJS_OMIT_FROZEN 480 "Modules/getbuildinfo.c", 481 ], 482 whole_static_libs: [ 483 "py3-interp", 484 "py3-c-modules", 485 ], 486 target: { 487 android: { 488 srcs: ["android/bionic/config.c"], 489 }, 490 linux_bionic: { 491 srcs: ["android/bionic/config.c"], 492 }, 493 glibc_x86_64: { 494 srcs: ["android/linux_x86_64/config.c"], 495 }, 496 musl_x86_64: { 497 srcs: ["android/linux_x86_64/config.c"], 498 }, 499 musl_arm64: { 500 srcs: ["android/linux_arm64/config.c"], 501 }, 502 darwin: { 503 srcs: ["android/darwin/config.c"], 504 }, 505 }, 506} 507 508cc_library_static { 509 name: "py3-launcher-lib", 510 defaults: ["py3-launcher-defaults"], 511 cflags: ["-DPy_BUILD_CORE"], 512 srcs: [ 513 // Makefile.pre.in LIBRARY_OBJS 514 "Modules/getpath.c", 515 "Python/frozen.c", 516 ], 517 local_include_dirs: [ 518 "android", 519 "android/Python", 520 ], 521 whole_static_libs: [ 522 "py3-launcher-lib-omit-frozen", 523 ], 524} 525 526cc_library_headers { 527 name: "py3-headers", 528 defaults: [ 529 "py3-interp-defaults", 530 "cpython3-interp-host-prebuilts", 531 ], 532 host_supported: true, 533 device_supported: false, 534 export_include_dirs: ["Include"], 535 target: { 536 darwin: { 537 export_include_dirs: ["android/darwin/pyconfig"], 538 }, 539 linux_bionic: { 540 export_include_dirs: ["android/bionic/pyconfig"], 541 }, 542 linux_glibc_x86_64: { 543 export_include_dirs: ["android/linux_x86_64/pyconfig"], 544 }, 545 linux_musl_x86_64: { 546 export_include_dirs: ["android/linux_x86_64/pyconfig"], 547 }, 548 linux_musl_arm64: { 549 export_include_dirs: ["android/linux_arm64/pyconfig"], 550 }, 551 }, 552 visibility: ["//visibility:public"], 553} 554 555cc_binary { 556 name: "py3-launcher", 557 defaults: ["py3-launcher-defaults"], 558 srcs: ["android/launcher_main.cpp"], 559 static_libs: ["py3-launcher-lib"], 560} 561 562cc_binary { 563 name: "py3-launcher-autorun", 564 defaults: ["py3-launcher-defaults"], 565 srcs: ["android/launcher_main.cpp"], 566 static_libs: ["py3-launcher-lib"], 567 cflags: ["-DANDROID_AUTORUN"], 568} 569 570cc_binary_host { 571 name: "py3-launcher-static", 572 defaults: ["py3-launcher-defaults"], 573 srcs: ["android/launcher_main.cpp"], 574 static_libs: ["py3-launcher-lib"], 575 static_executable: true, 576 target: { 577 glibc: { 578 enabled: false, 579 }, 580 }, 581} 582 583cc_binary_host { 584 name: "py3-launcher-autorun-static", 585 defaults: ["py3-launcher-defaults"], 586 srcs: ["android/launcher_main.cpp"], 587 static_libs: ["py3-launcher-lib"], 588 static_executable: true, 589 cflags: ["-DANDROID_AUTORUN"], 590 target: { 591 glibc: { 592 enabled: false, 593 }, 594 }, 595} 596 597python_binary_host { 598 name: "py3-cmd", 599 autorun: false, 600 version: { 601 py3: { 602 embedded_launcher: true, 603 }, 604 }, 605} 606 607// Enabled extension py3-c-modules. 608 609cc_library_static { 610 name: "py3-c-modules", 611 defaults: [ 612 "py3-interp-defaults", 613 "cpython3-interp-host-prebuilts", 614 ], 615 cflags: [ 616 "-DPy_BUILD_CORE_BUILTIN", 617 "-DSQLITE_OMIT_LOAD_EXTENSION", 618 ], 619 local_include_dirs: [ 620 "Modules/_hacl/include", 621 ], 622 shared_libs: ["libsqlite"], 623 static_libs: [ 624 "libexpat", 625 "libz", 626 "libbz", 627 ], 628 whole_static_libs: ["libmpdec"], 629 srcs: [ 630 "Modules/_hacl/Hacl_Hash_SHA2.c", 631 ], 632 target: { 633 android: { 634 srcs: [":py3-c-modules-bionic"], 635 }, 636 linux_bionic: { 637 srcs: [":py3-c-modules-bionic"], 638 }, 639 glibc_x86_64: { 640 srcs: [":py3-c-modules-linux_x86_64"], 641 static_libs: [ 642 "libopenssl_ssl", 643 "libopenssl_crypto", 644 ], 645 }, 646 musl_x86_64: { 647 srcs: [":py3-c-modules-linux_x86_64"], 648 static_libs: [ 649 "libopenssl_ssl", 650 "libopenssl_crypto", 651 ], 652 }, 653 musl_arm64: { 654 srcs: [":py3-c-modules-linux_arm64"], 655 static_libs: [ 656 "libopenssl_ssl", 657 "libopenssl_crypto", 658 ], 659 }, 660 darwin: { 661 cflags: [ 662 "-D__APPLE_USE_RFC_3542", 663 "-DUSING_MALLOC_CLOSURE_DOT_C=1", 664 ], 665 srcs: [":py3-c-modules-darwin"], 666 static_libs: [ 667 "libopenssl_ssl", 668 "libopenssl_crypto", 669 ], 670 }, 671 }, 672} 673