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