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 [email protected] 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-invalid-source-encoding", 107 "-Wno-int-conversion", 108 "-Wno-missing-field-initializers", 109 "-Wno-null-pointer-arithmetic", 110 "-Wno-register", 111 "-Wno-shift-count-overflow", 112 "-Wno-sign-compare", 113 "-Wno-tautological-compare", 114 "-Wno-tautological-constant-out-of-range-compare", 115 "-Wno-unused-function", 116 "-Wno-unused-parameter", 117 "-Wno-unused-result", 118 ], 119 local_include_dirs: [ 120 "Include", 121 "Include/internal", 122 ], 123 static_libs: ["libffi"], 124 target: { 125 android: { 126 local_include_dirs: ["android/bionic/pyconfig"], 127 }, 128 android_arm: { 129 cflags: ["-DSOABI=\"cpython-311android-arm-android-bionic\""], 130 }, 131 android_arm64: { 132 cflags: ["-DSOABI=\"cpython-311android-arm64-android-bionic\""], 133 }, 134 android_riscv64: { 135 cflags: ["-DSOABI=\"cpython-311android-riscv64-android-bionic\""], 136 }, 137 android_x86: { 138 cflags: ["-DSOABI=\"cpython-311android-x86-android-bionic\""], 139 }, 140 android_x86_64: { 141 cflags: ["-DSOABI=\"cpython-311android-x86_64-android-bionic\""], 142 }, 143 host: { 144 // Host builds are moving to prebuilts, which has a higher risk of 145 // having an incompatible libc++.so when installed. 146 stl: "libc++_static", 147 }, 148 // Regenerate include dirs with android_regen.sh 149 darwin: { 150 local_include_dirs: ["android/darwin/pyconfig"], 151 cflags: [ 152 "-Wno-deprecated-declarations", 153 "-Wno-pointer-arith", 154 "-DSOABI=\"cpython-311android-x86_64-darwin\"", 155 ], 156 }, 157 linux_bionic: { 158 // NB linux_bionic is a 'host' architecture but it uses the bionic libc like 'android' 159 // targets so use the android pyconfig. 160 local_include_dirs: ["android/bionic/pyconfig"], 161 cflags: ["-DSOABI=\"cpython-311android-x86_64-linux-bionic\""], 162 }, 163 linux_glibc_x86: { 164 enabled: false, 165 }, 166 linux_musl_x86: { 167 enabled: false, 168 }, 169 linux_musl_arm: { 170 enabled: false, 171 }, 172 linux_glibc_x86_64: { 173 local_include_dirs: ["android/linux_x86_64/pyconfig"], 174 cflags: ["-DSOABI=\"cpython-311android-x86_64-linux-gnu\""], 175 }, 176 linux_musl_x86_64: { 177 local_include_dirs: ["android/linux_x86_64/pyconfig"], 178 cflags: ["-DSOABI=\"cpython-311android-x86_64-linux-gnu\""], 179 }, 180 linux_musl_arm64: { 181 local_include_dirs: ["android/linux_arm64/pyconfig"], 182 cflags: ["-DSOABI=\"cpython-311android-arm64-linux-gnu\""], 183 }, 184 windows: { 185 enabled: false, 186 }, 187 }, 188 host_supported: true, 189 compile_multilib: "both", 190 multilib: { 191 lib32: { 192 suffix: "32", 193 }, 194 lib64: { 195 suffix: "64", 196 }, 197 }, 198 soong_config_variables: { 199 force_build_host: { 200 defaults: ["cpython3-interp-force_build_host"], 201 }, 202 }, 203} 204 205cc_library_static { 206 name: "py3-interp", 207 defaults: ["py3-interp-defaults", "cpython3-interp-host-prebuilts"], 208 cflags: ["-DPy_BUILD_CORE", "-DPLATLIBDIR=\"lib\""], 209 srcs: [ 210 // Corresponds to PARSER_OBJS, OBJECT_OBJS, and PYTHON_OBJS in Makefile.pre.in 211 212 // Makefile.pre.in POBJS 213 "Parser/token.c", 214 215 // Makefile.pre.in PEGEN_OBJS 216 "Parser/pegen.c", 217 "Parser/pegen_errors.c", 218 "Parser/action_helpers.c", 219 "Parser/parser.c", 220 "Parser/string_parser.c", 221 "Parser/peg_api.c", 222 223 // Makefile.pre.in PARSER_OBJS 224 "Parser/myreadline.c", 225 "Parser/tokenizer.c", 226 227 // Makefile.pre.in OBJECT_OBJS 228 "Objects/abstract.c", 229 "Objects/accu.c", 230 "Objects/boolobject.c", 231 "Objects/bytes_methods.c", 232 "Objects/bytearrayobject.c", 233 "Objects/bytesobject.c", 234 "Objects/call.c", 235 "Objects/capsule.c", 236 "Objects/cellobject.c", 237 "Objects/classobject.c", 238 "Objects/codeobject.c", 239 "Objects/complexobject.c", 240 "Objects/descrobject.c", 241 "Objects/enumobject.c", 242 "Objects/exceptions.c", 243 "Objects/genericaliasobject.c", 244 "Objects/genobject.c", 245 "Objects/fileobject.c", 246 "Objects/floatobject.c", 247 "Objects/frameobject.c", 248 "Objects/funcobject.c", 249 "Objects/interpreteridobject.c", 250 "Objects/iterobject.c", 251 "Objects/listobject.c", 252 "Objects/longobject.c", 253 "Objects/dictobject.c", 254 "Objects/odictobject.c", 255 "Objects/memoryobject.c", 256 "Objects/methodobject.c", 257 "Objects/moduleobject.c", 258 "Objects/namespaceobject.c", 259 "Objects/object.c", 260 "Objects/obmalloc.c", 261 "Objects/picklebufobject.c", 262 "Objects/rangeobject.c", 263 "Objects/setobject.c", 264 "Objects/sliceobject.c", 265 "Objects/structseq.c", 266 "Objects/tupleobject.c", 267 "Objects/typeobject.c", 268 "Objects/unicodeobject.c", 269 "Objects/unicodectype.c", 270 "Objects/unionobject.c", 271 "Objects/weakrefobject.c", 272 273 // Makefile.pre.in PYTHON_OBJS 274 "Python/_warnings.c", 275 "Python/Python-ast.c", 276 "Python/Python-tokenize.c", 277 "Python/asdl.c", 278 "Python/ast.c", 279 "Python/ast_opt.c", 280 "Python/ast_unparse.c", 281 "Python/bltinmodule.c", 282 "Python/ceval.c", 283 "Python/codecs.c", 284 "Python/compile.c", 285 "Python/context.c", 286 "Python/dynamic_annotations.c", 287 "Python/errors.c", 288 "Python/frame.c", 289 "Python/frozenmain.c", 290 "Python/future.c", 291 "Python/getargs.c", 292 "Python/getcompiler.c", 293 "Python/getcopyright.c", 294 "Python/getplatform.c", 295 "Python/getversion.c", 296 "Python/hamt.c", 297 "Python/hashtable.c", 298 "Python/import.c", 299 "Python/importdl.c", 300 "Python/initconfig.c", 301 "Python/marshal.c", 302 "Python/modsupport.c", 303 "Python/mysnprintf.c", 304 "Python/mystrtoul.c", 305 "Python/pathconfig.c", 306 "Python/preconfig.c", 307 "Python/pyarena.c", 308 "Python/pyctype.c", 309 "Python/pyfpe.c", 310 "Python/pyhash.c", 311 "Python/pylifecycle.c", 312 "Python/pymath.c", 313 "Python/pystate.c", 314 "Python/pythonrun.c", 315 "Python/pytime.c", 316 "Python/bootstrap_hash.c", 317 "Python/specialize.c", 318 "Python/structmember.c", 319 "Python/symtable.c", 320 "Python/sysmodule.c", 321 "Python/thread.c", 322 "Python/traceback.c", 323 "Python/getopt.c", 324 "Python/pystrcmp.c", 325 "Python/pystrtod.c", 326 "Python/pystrhex.c", 327 "Python/dtoa.c", 328 "Python/formatter_unicode.c", 329 "Python/fileutils.c", 330 "Python/suggestions.c", 331 "Python/dynload_shlib.c", 332 ], 333 334 target: { 335 linux: { 336 cflags: [ 337 "-DPLATFORM=\"linux\"", 338 "-DABIFLAGS=\"\"", 339 ], 340 }, 341 darwin: { 342 cflags: [ 343 "-DPLATFORM=\"darwin\"", 344 "-DABIFLAGS=\"\"", 345 ], 346 }, 347 }, 348} 349 350cc_defaults { 351 name: "py3-launcher-defaults", 352 defaults: ["py3-interp-defaults", "cpython3-interp-host-prebuilts"], 353 cflags: [ 354 "-DVERSION=\"3.11\"", 355 "-DVPATH=\"\"", 356 "-DPREFIX=\"\"", 357 "-DEXEC_PREFIX=\"\"", 358 "-DPLATLIBDIR=\"lib\"", 359 "-DPYTHONPATH=\"\"", 360 "-DDATE=\"Dec 31 1969\"", 361 "-DTIME=\"23:59:59\"", 362 ], 363 static_libs: [ 364 "libbase", 365 "libexpat", 366 "libz", 367 "libbz", 368 ], 369 target: { 370 linux_glibc_x86_64: { 371 host_ldlibs: ["-lutil"], 372 }, 373 linux: { 374 // Due to test infra limitations, Python native symbols are linked 375 // statically to py3-launcher(s). Hence, need this flag to export 376 // these symbols so that runtime imported native extensions can use 377 // them (e.g. PyBaseObject_Type) 378 ldflags: ["-Wl,--export-dynamic"], 379 }, 380 darwin: { 381 host_ldlibs: [ 382 "-framework SystemConfiguration", 383 "-framework CoreFoundation", 384 ], 385 }, 386 host: { 387 static_libs: [ 388 "libsqlite_static_noicu", 389 "liblog", 390 "libopenssl_ssl", 391 "libopenssl_crypto", 392 ], 393 }, 394 linux_bionic: { 395 // Linux Bionic doesn't have openssl prebuilts 396 exclude_static_libs: [ 397 "libopenssl_ssl", 398 "libopenssl_crypto", 399 ], 400 }, 401 android: { 402 shared_libs: [ 403 // Use shared libsqlite for device side, otherwise 404 // the executable size will be really huge. 405 "libsqlite", 406 // Dependency from libbase 407 "liblog", 408 ], 409 }, 410 }, 411} 412 413cc_library_static { 414 name: "py3-launcher-lib-omit-frozen", 415 defaults: ["py3-launcher-defaults"], 416 cflags: ["-DPy_BUILD_CORE"], 417 srcs: [ 418 // Makefile.pre.in MODULE_OBJS 419 "Modules/main.c", 420 "Modules/gcmodule.c", 421 422 // Makefile.pre.in LIBRARY_OBJS_OMIT_FROZEN 423 "Modules/getbuildinfo.c", 424 ], 425 whole_static_libs: [ 426 "py3-interp", 427 "py3-c-modules", 428 ], 429 target: { 430 android: { 431 srcs: ["android/bionic/config.c"], 432 }, 433 linux_bionic: { 434 srcs: ["android/bionic/config.c"], 435 }, 436 glibc_x86_64: { 437 srcs: ["android/linux_x86_64/config.c"], 438 }, 439 musl_x86_64: { 440 srcs: ["android/linux_x86_64/config.c"], 441 }, 442 musl_arm64: { 443 srcs: ["android/linux_arm64/config.c"], 444 }, 445 darwin: { 446 srcs: ["android/darwin/config.c"], 447 }, 448 }, 449} 450 451cc_library_static { 452 name: "py3-launcher-lib", 453 defaults: ["py3-launcher-defaults"], 454 cflags: ["-DPy_BUILD_CORE"], 455 srcs: [ 456 // Makefile.pre.in DEEPFREEZE_OBJS 457 "android/Python/deepfreeze/deepfreeze.c", 458 459 // Makefile.pre.in LIBRARY_OBJS 460 "Modules/getpath.c", 461 "Python/frozen.c", 462 ], 463 local_include_dirs: [ 464 "android/Python", 465 ], 466 whole_static_libs: [ 467 "py3-launcher-lib-omit-frozen", 468 ], 469} 470 471cc_binary { 472 name: "py3-launcher", 473 defaults: ["py3-launcher-defaults"], 474 srcs: ["android/launcher_main.cpp"], 475 static_libs: ["py3-launcher-lib"], 476} 477 478cc_binary { 479 name: "py3-launcher-autorun", 480 defaults: ["py3-launcher-defaults"], 481 srcs: ["android/launcher_main.cpp"], 482 static_libs: ["py3-launcher-lib"], 483 cflags: ["-DANDROID_AUTORUN"], 484} 485 486cc_binary_host { 487 name: "py3-launcher-static", 488 defaults: ["py3-launcher-defaults"], 489 srcs: ["android/launcher_main.cpp"], 490 static_libs: ["py3-launcher-lib"], 491 static_executable: true, 492 target: { 493 glibc: { 494 enabled: false, 495 }, 496 }, 497} 498 499cc_binary_host { 500 name: "py3-launcher-autorun-static", 501 defaults: ["py3-launcher-defaults"], 502 srcs: ["android/launcher_main.cpp"], 503 static_libs: ["py3-launcher-lib"], 504 static_executable: true, 505 cflags: ["-DANDROID_AUTORUN"], 506 target: { 507 glibc: { 508 enabled: false, 509 }, 510 }, 511} 512 513python_binary_host { 514 name: "py3-cmd", 515 autorun: false, 516 version: { 517 py3: { 518 embedded_launcher: true, 519 }, 520 }, 521} 522 523// Enabled extension py3-c-modules. 524 525cc_library_static { 526 name: "py3-c-modules", 527 defaults: ["py3-interp-defaults", "cpython3-interp-host-prebuilts"], 528 cflags: [ 529 "-DPy_BUILD_CORE_BUILTIN", 530 "-DSQLITE_OMIT_LOAD_EXTENSION", 531 ], 532 shared_libs: ["libsqlite"], 533 static_libs: [ 534 "libexpat", 535 "libz", 536 "libbz", 537 ], 538 target: { 539 android: { 540 srcs: [":py3-c-modules-bionic"], 541 }, 542 linux_bionic: { 543 srcs: [":py3-c-modules-bionic"], 544 }, 545 glibc_x86_64: { 546 srcs: [":py3-c-modules-linux_x86_64"], 547 static_libs: [ 548 "libopenssl_ssl", 549 "libopenssl_crypto", 550 ], 551 }, 552 musl_x86_64: { 553 srcs: [":py3-c-modules-linux_x86_64"], 554 static_libs: [ 555 "libopenssl_ssl", 556 "libopenssl_crypto", 557 ], 558 }, 559 musl_arm64: { 560 srcs: [":py3-c-modules-linux_arm64"], 561 static_libs: [ 562 "libopenssl_ssl", 563 "libopenssl_crypto", 564 ], 565 }, 566 darwin: { 567 cflags: ["-D__APPLE_USE_RFC_3542"], 568 srcs: [":py3-c-modules-darwin"], 569 static_libs: [ 570 "libopenssl_ssl", 571 "libopenssl_crypto", 572 ], 573 }, 574 }, 575} 576