github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/toolchains/cpus/arm/cc_config.bzl.tpl (about) 1 load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", 2 "action_config", 3 "artifact_name_pattern", 4 "env_entry", 5 "env_set", 6 "feature", 7 "feature_set", 8 "flag_group", 9 "flag_set", 10 "make_variable", 11 "tool", 12 "tool_path", 13 "variable_with_value", 14 "with_feature_set", 15 ) 16 load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") 17 18 def _impl(ctx): 19 if (ctx.attr.cpu == "armeabi"): 20 toolchain_identifier = "arm-linux-gnueabihf" 21 elif (ctx.attr.cpu == "local"): 22 toolchain_identifier = "local_linux" 23 else: 24 fail("Unreachable") 25 26 if (ctx.attr.cpu == "armeabi"): 27 host_system_name = "armeabi" 28 elif (ctx.attr.cpu == "local"): 29 host_system_name = "local" 30 else: 31 fail("Unreachable") 32 33 if (ctx.attr.cpu == "armeabi"): 34 target_system_name = "armeabi" 35 elif (ctx.attr.cpu == "local"): 36 target_system_name = "local" 37 else: 38 fail("Unreachable") 39 40 if (ctx.attr.cpu == "armeabi"): 41 target_cpu = "armeabi" 42 elif (ctx.attr.cpu == "local"): 43 target_cpu = "local" 44 else: 45 fail("Unreachable") 46 47 if (ctx.attr.cpu == "armeabi"): 48 target_libc = "armeabi" 49 elif (ctx.attr.cpu == "local"): 50 target_libc = "local" 51 else: 52 fail("Unreachable") 53 54 compiler = "compiler" 55 56 if (ctx.attr.cpu == "armeabi"): 57 abi_version = "armeabi" 58 elif (ctx.attr.cpu == "local"): 59 abi_version = "local" 60 else: 61 fail("Unreachable") 62 63 if (ctx.attr.cpu == "armeabi"): 64 abi_libc_version = "armeabi" 65 elif (ctx.attr.cpu == "local"): 66 abi_libc_version = "local" 67 else: 68 fail("Unreachable") 69 70 cc_target_os = None 71 72 builtin_sysroot = None 73 74 all_compile_actions = [ 75 ACTION_NAMES.c_compile, 76 ACTION_NAMES.cpp_compile, 77 ACTION_NAMES.linkstamp_compile, 78 ACTION_NAMES.assemble, 79 ACTION_NAMES.preprocess_assemble, 80 ACTION_NAMES.cpp_header_parsing, 81 ACTION_NAMES.cpp_module_compile, 82 ACTION_NAMES.cpp_module_codegen, 83 ACTION_NAMES.clif_match, 84 ACTION_NAMES.lto_backend, 85 ] 86 87 all_cpp_compile_actions = [ 88 ACTION_NAMES.cpp_compile, 89 ACTION_NAMES.linkstamp_compile, 90 ACTION_NAMES.cpp_header_parsing, 91 ACTION_NAMES.cpp_module_compile, 92 ACTION_NAMES.cpp_module_codegen, 93 ACTION_NAMES.clif_match, 94 ] 95 96 preprocessor_compile_actions = [ 97 ACTION_NAMES.c_compile, 98 ACTION_NAMES.cpp_compile, 99 ACTION_NAMES.linkstamp_compile, 100 ACTION_NAMES.preprocess_assemble, 101 ACTION_NAMES.cpp_header_parsing, 102 ACTION_NAMES.cpp_module_compile, 103 ACTION_NAMES.clif_match, 104 ] 105 106 codegen_compile_actions = [ 107 ACTION_NAMES.c_compile, 108 ACTION_NAMES.cpp_compile, 109 ACTION_NAMES.linkstamp_compile, 110 ACTION_NAMES.assemble, 111 ACTION_NAMES.preprocess_assemble, 112 ACTION_NAMES.cpp_module_codegen, 113 ACTION_NAMES.lto_backend, 114 ] 115 116 all_link_actions = [ 117 ACTION_NAMES.cpp_link_executable, 118 ACTION_NAMES.cpp_link_dynamic_library, 119 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 120 ] 121 122 objcopy_embed_data_action = action_config( 123 action_name = "objcopy_embed_data", 124 enabled = True, 125 tools = [tool(path = "/usr/bin/objcopy")], 126 ) 127 128 if (ctx.attr.cpu == "armeabi"): 129 action_configs = [] 130 elif (ctx.attr.cpu == "local"): 131 action_configs = [objcopy_embed_data_action] 132 else: 133 fail("Unreachable") 134 135 opt_feature = feature(name = "opt") 136 137 dbg_feature = feature(name = "dbg") 138 139 sysroot_feature = feature( 140 name = "sysroot", 141 enabled = True, 142 flag_sets = [ 143 flag_set( 144 actions = [ 145 ACTION_NAMES.preprocess_assemble, 146 ACTION_NAMES.linkstamp_compile, 147 ACTION_NAMES.c_compile, 148 ACTION_NAMES.cpp_compile, 149 ACTION_NAMES.cpp_header_parsing, 150 ACTION_NAMES.cpp_module_compile, 151 ACTION_NAMES.cpp_module_codegen, 152 ACTION_NAMES.lto_backend, 153 ACTION_NAMES.clif_match, 154 ACTION_NAMES.cpp_link_executable, 155 ACTION_NAMES.cpp_link_dynamic_library, 156 ACTION_NAMES.cpp_link_nodeps_dynamic_library, 157 ], 158 flag_groups = [ 159 flag_group( 160 flags = ["--sysroot=%{sysroot}"], 161 expand_if_available = "sysroot", 162 ), 163 ], 164 ), 165 ], 166 ) 167 168 if (ctx.attr.cpu == "armeabi"): 169 unfiltered_compile_flags_feature = feature( 170 name = "unfiltered_compile_flags", 171 enabled = True, 172 flag_sets = [ 173 flag_set( 174 actions = [ 175 ACTION_NAMES.assemble, 176 ACTION_NAMES.preprocess_assemble, 177 ACTION_NAMES.linkstamp_compile, 178 ACTION_NAMES.c_compile, 179 ACTION_NAMES.cpp_compile, 180 ACTION_NAMES.cpp_header_parsing, 181 ACTION_NAMES.cpp_module_compile, 182 ACTION_NAMES.cpp_module_codegen, 183 ACTION_NAMES.lto_backend, 184 ACTION_NAMES.clif_match, 185 ], 186 flag_groups = [ 187 flag_group( 188 flags = [ 189 "-Wno-builtin-macro-redefined", 190 "-D__DATE__=\"redacted\"", 191 "-D__TIMESTAMP__=\"redacted\"", 192 "-D__TIME__=\"redacted\"", 193 "-no-canonical-prefixes", 194 "-fno-canonical-system-headers", 195 ], 196 ), 197 ], 198 ), 199 ], 200 ) 201 elif (ctx.attr.cpu == "local"): 202 unfiltered_compile_flags_feature = feature( 203 name = "unfiltered_compile_flags", 204 enabled = True, 205 flag_sets = [ 206 flag_set( 207 actions = [ 208 ACTION_NAMES.assemble, 209 ACTION_NAMES.preprocess_assemble, 210 ACTION_NAMES.linkstamp_compile, 211 ACTION_NAMES.c_compile, 212 ACTION_NAMES.cpp_compile, 213 ACTION_NAMES.cpp_header_parsing, 214 ACTION_NAMES.cpp_module_compile, 215 ACTION_NAMES.cpp_module_codegen, 216 ACTION_NAMES.lto_backend, 217 ACTION_NAMES.clif_match, 218 ], 219 flag_groups = [ 220 flag_group( 221 flags = [ 222 "-no-canonical-prefixes", 223 "-fno-canonical-system-headers", 224 "-Wno-builtin-macro-redefined", 225 "-D__DATE__=\"redacted\"", 226 "-D__TIMESTAMP__=\"redacted\"", 227 "-D__TIME__=\"redacted\"", 228 ], 229 ), 230 ], 231 ), 232 ], 233 ) 234 else: 235 unfiltered_compile_flags_feature = None 236 237 objcopy_embed_flags_feature = feature( 238 name = "objcopy_embed_flags", 239 enabled = True, 240 flag_sets = [ 241 flag_set( 242 actions = ["objcopy_embed_data"], 243 flag_groups = [flag_group(flags = ["-I", "binary"])], 244 ), 245 ], 246 ) 247 248 if (ctx.attr.cpu == "armeabi"): 249 default_compile_flags_feature = feature( 250 name = "default_compile_flags", 251 enabled = True, 252 flag_sets = [ 253 flag_set( 254 actions = [ 255 ACTION_NAMES.assemble, 256 ACTION_NAMES.preprocess_assemble, 257 ACTION_NAMES.linkstamp_compile, 258 ACTION_NAMES.c_compile, 259 ACTION_NAMES.cpp_compile, 260 ACTION_NAMES.cpp_header_parsing, 261 ACTION_NAMES.cpp_module_compile, 262 ACTION_NAMES.cpp_module_codegen, 263 ACTION_NAMES.lto_backend, 264 ACTION_NAMES.clif_match, 265 ], 266 flag_groups = [ 267 flag_group( 268 flags = [ 269 "-U_FORTIFY_SOURCE", 270 "-D_FORTIFY_SOURCE=1", 271 "-fstack-protector", 272 "-DRASPBERRY_PI", 273 ], 274 ), 275 ], 276 ), 277 flag_set( 278 actions = [ 279 ACTION_NAMES.assemble, 280 ACTION_NAMES.preprocess_assemble, 281 ACTION_NAMES.linkstamp_compile, 282 ACTION_NAMES.c_compile, 283 ACTION_NAMES.cpp_compile, 284 ACTION_NAMES.cpp_header_parsing, 285 ACTION_NAMES.cpp_module_compile, 286 ACTION_NAMES.cpp_module_codegen, 287 ACTION_NAMES.lto_backend, 288 ACTION_NAMES.clif_match, 289 ], 290 flag_groups = [flag_group(flags = ["-g"])], 291 with_features = [with_feature_set(features = ["dbg"])], 292 ), 293 flag_set( 294 actions = [ 295 ACTION_NAMES.assemble, 296 ACTION_NAMES.preprocess_assemble, 297 ACTION_NAMES.linkstamp_compile, 298 ACTION_NAMES.c_compile, 299 ACTION_NAMES.cpp_compile, 300 ACTION_NAMES.cpp_header_parsing, 301 ACTION_NAMES.cpp_module_compile, 302 ACTION_NAMES.cpp_module_codegen, 303 ACTION_NAMES.lto_backend, 304 ACTION_NAMES.clif_match, 305 ], 306 flag_groups = [ 307 flag_group( 308 flags = [ 309 "-g0", 310 "-O2", 311 "-DNDEBUG", 312 "-ffunction-sections", 313 "-fdata-sections", 314 ], 315 ), 316 ], 317 with_features = [with_feature_set(features = ["opt"])], 318 ), 319 flag_set( 320 actions = [ 321 ACTION_NAMES.linkstamp_compile, 322 ACTION_NAMES.cpp_compile, 323 ACTION_NAMES.cpp_header_parsing, 324 ACTION_NAMES.cpp_module_compile, 325 ACTION_NAMES.cpp_module_codegen, 326 ACTION_NAMES.lto_backend, 327 ACTION_NAMES.clif_match, 328 ], 329 flag_groups = [ 330 flag_group( 331 flags = [ 332 "-std=c++11", 333 "-isystem", 334 "%{ARM_COMPILER_PATH}%/arm-linux-gnueabihf/include/c++/4.9.3/", 335 "-isystem", 336 "%{ARM_COMPILER_PATH}%/arm-linux-gnueabihf/sysroot/usr/include/", 337 "-isystem", 338 "%{ARM_COMPILER_PATH}%/arm-linux-gnueabihf/libc/usr/include/", 339 "-isystem", 340 "%{ARM_COMPILER_PATH}%/lib/gcc/arm-linux-gnueabihf/4.9.3/include", 341 "-isystem", 342 "%{ARM_COMPILER_PATH}%/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed", 343 "-isystem", 344 "%{ARM_COMPILER_PATH}%/local_include", 345 "-isystem", 346 "%{PYTHON_INCLUDE_PATH}%", 347 "-isystem", 348 "/usr/include/", 349 ], 350 ), 351 ], 352 ), 353 ], 354 ) 355 elif (ctx.attr.cpu == "local"): 356 default_compile_flags_feature = feature( 357 name = "default_compile_flags", 358 enabled = True, 359 flag_sets = [ 360 flag_set( 361 actions = [ 362 ACTION_NAMES.assemble, 363 ACTION_NAMES.preprocess_assemble, 364 ACTION_NAMES.linkstamp_compile, 365 ACTION_NAMES.c_compile, 366 ACTION_NAMES.cpp_compile, 367 ACTION_NAMES.cpp_header_parsing, 368 ACTION_NAMES.cpp_module_compile, 369 ACTION_NAMES.cpp_module_codegen, 370 ACTION_NAMES.lto_backend, 371 ACTION_NAMES.clif_match, 372 ], 373 flag_groups = [ 374 flag_group( 375 flags = [ 376 "-U_FORTIFY_SOURCE", 377 "-D_FORTIFY_SOURCE=1", 378 "-fstack-protector", 379 "-Wall", 380 "-Wunused-but-set-parameter", 381 "-Wno-free-nonheap-object", 382 "-fno-omit-frame-pointer", 383 ], 384 ), 385 ], 386 ), 387 flag_set( 388 actions = [ 389 ACTION_NAMES.assemble, 390 ACTION_NAMES.preprocess_assemble, 391 ACTION_NAMES.linkstamp_compile, 392 ACTION_NAMES.c_compile, 393 ACTION_NAMES.cpp_compile, 394 ACTION_NAMES.cpp_header_parsing, 395 ACTION_NAMES.cpp_module_compile, 396 ACTION_NAMES.cpp_module_codegen, 397 ACTION_NAMES.lto_backend, 398 ACTION_NAMES.clif_match, 399 ], 400 flag_groups = [flag_group(flags = ["-g"])], 401 with_features = [with_feature_set(features = ["dbg"])], 402 ), 403 flag_set( 404 actions = [ 405 ACTION_NAMES.assemble, 406 ACTION_NAMES.preprocess_assemble, 407 ACTION_NAMES.linkstamp_compile, 408 ACTION_NAMES.c_compile, 409 ACTION_NAMES.cpp_compile, 410 ACTION_NAMES.cpp_header_parsing, 411 ACTION_NAMES.cpp_module_compile, 412 ACTION_NAMES.cpp_module_codegen, 413 ACTION_NAMES.lto_backend, 414 ACTION_NAMES.clif_match, 415 ], 416 flag_groups = [ 417 flag_group( 418 flags = [ 419 "-g0", 420 "-O2", 421 "-DNDEBUG", 422 "-ffunction-sections", 423 "-fdata-sections", 424 ], 425 ), 426 ], 427 with_features = [with_feature_set(features = ["opt"])], 428 ), 429 flag_set( 430 actions = [ 431 ACTION_NAMES.linkstamp_compile, 432 ACTION_NAMES.cpp_compile, 433 ACTION_NAMES.cpp_header_parsing, 434 ACTION_NAMES.cpp_module_compile, 435 ACTION_NAMES.cpp_module_codegen, 436 ACTION_NAMES.lto_backend, 437 ACTION_NAMES.clif_match, 438 ], 439 flag_groups = [flag_group(flags = ["-std=c++0x"])], 440 ), 441 ], 442 ) 443 else: 444 default_compile_flags_feature = None 445 446 if (ctx.attr.cpu == "local"): 447 default_link_flags_feature = feature( 448 name = "default_link_flags", 449 enabled = True, 450 flag_sets = [ 451 flag_set( 452 actions = all_link_actions, 453 flag_groups = [ 454 flag_group( 455 flags = [ 456 "-lstdc++", 457 "-B/usr/bin/", 458 "-Wl,-z,relro,-z,now", 459 "-no-canonical-prefixes", 460 "-pass-exit-codes", 461 "-Wl,--build-id=md5", 462 "-Wl,--hash-style=gnu", 463 ], 464 ), 465 ], 466 ), 467 flag_set( 468 actions = all_link_actions, 469 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], 470 with_features = [with_feature_set(features = ["opt"])], 471 ), 472 ], 473 ) 474 elif (ctx.attr.cpu == "armeabi"): 475 default_link_flags_feature = feature( 476 name = "default_link_flags", 477 enabled = True, 478 flag_sets = [ 479 flag_set( 480 actions = all_link_actions, 481 flag_groups = [ 482 flag_group( 483 flags = [ 484 "-lstdc++", 485 "-Wl,-z,relro,-z,now", 486 "-no-canonical-prefixes", 487 "-pass-exit-codes", 488 "-Wl,--build-id=md5", 489 "-Wl,--hash-style=gnu", 490 ], 491 ), 492 ], 493 ), 494 flag_set( 495 actions = all_link_actions, 496 flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], 497 with_features = [with_feature_set(features = ["opt"])], 498 ), 499 ], 500 ) 501 else: 502 default_link_flags_feature = None 503 504 supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) 505 506 supports_pic_feature = feature(name = "supports_pic", enabled = True) 507 508 user_compile_flags_feature = feature( 509 name = "user_compile_flags", 510 enabled = True, 511 flag_sets = [ 512 flag_set( 513 actions = [ 514 ACTION_NAMES.assemble, 515 ACTION_NAMES.preprocess_assemble, 516 ACTION_NAMES.linkstamp_compile, 517 ACTION_NAMES.c_compile, 518 ACTION_NAMES.cpp_compile, 519 ACTION_NAMES.cpp_header_parsing, 520 ACTION_NAMES.cpp_module_compile, 521 ACTION_NAMES.cpp_module_codegen, 522 ACTION_NAMES.lto_backend, 523 ACTION_NAMES.clif_match, 524 ], 525 flag_groups = [ 526 flag_group( 527 flags = ["%{user_compile_flags}"], 528 iterate_over = "user_compile_flags", 529 expand_if_available = "user_compile_flags", 530 ), 531 ], 532 ), 533 ], 534 ) 535 536 if (ctx.attr.cpu == "local"): 537 features = [ 538 default_compile_flags_feature, 539 default_link_flags_feature, 540 supports_dynamic_linker_feature, 541 supports_pic_feature, 542 objcopy_embed_flags_feature, 543 opt_feature, 544 dbg_feature, 545 user_compile_flags_feature, 546 sysroot_feature, 547 unfiltered_compile_flags_feature, 548 ] 549 elif (ctx.attr.cpu == "armeabi"): 550 features = [ 551 default_compile_flags_feature, 552 default_link_flags_feature, 553 supports_dynamic_linker_feature, 554 supports_pic_feature, 555 opt_feature, 556 dbg_feature, 557 user_compile_flags_feature, 558 sysroot_feature, 559 unfiltered_compile_flags_feature, 560 ] 561 else: 562 fail("Unreachable") 563 564 if (ctx.attr.cpu == "armeabi"): 565 cxx_builtin_include_directories = [ 566 "%{ARM_COMPILER_PATH}%/arm-linux-gnueabihf/include/c++/4.9.3/", 567 "%{ARM_COMPILER_PATH}%/arm-linux-gnueabihf/sysroot/usr/include/", 568 "%{ARM_COMPILER_PATH}%/arm-linux-gnueabihf/libc/usr/include/", 569 "%{ARM_COMPILER_PATH}%/lib/gcc/arm-linux-gnueabihf/4.9.3/include", 570 "%{ARM_COMPILER_PATH}%/lib/gcc/arm-linux-gnueabihf/4.9.3/include-fixed", 571 "%{ARM_COMPILER_PATH}%/local_include", 572 "/usr/include", 573 "/tmp/openblas_install/include/", 574 ] 575 elif (ctx.attr.cpu == "local"): 576 cxx_builtin_include_directories = ["/usr/lib/gcc/", "/usr/local/include", "/usr/include"] 577 else: 578 fail("Unreachable") 579 580 artifact_name_patterns = [] 581 582 make_variables = [] 583 584 if (ctx.attr.cpu == "armeabi"): 585 tool_paths = [ 586 tool_path( 587 name = "ar", 588 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-ar", 589 ), 590 tool_path(name = "compat-ld", path = "/bin/false"), 591 tool_path( 592 name = "cpp", 593 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-cpp", 594 ), 595 tool_path( 596 name = "dwp", 597 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-dwp", 598 ), 599 tool_path( 600 name = "gcc", 601 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-gcc", 602 ), 603 tool_path( 604 name = "gcov", 605 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-gcov", 606 ), 607 tool_path( 608 name = "ld", 609 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-ld", 610 ), 611 tool_path( 612 name = "nm", 613 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-nm", 614 ), 615 tool_path( 616 name = "objcopy", 617 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-objcopy", 618 ), 619 tool_path( 620 name = "objdump", 621 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-objdump", 622 ), 623 tool_path( 624 name = "strip", 625 path = "%{ARM_COMPILER_PATH}%/bin/arm-linux-gnueabihf-strip", 626 ), 627 ] 628 elif (ctx.attr.cpu == "local"): 629 tool_paths = [ 630 tool_path(name = "ar", path = "/usr/bin/ar"), 631 tool_path(name = "compat-ld", path = "/usr/bin/ld"), 632 tool_path(name = "cpp", path = "/usr/bin/cpp"), 633 tool_path(name = "dwp", path = "/usr/bin/dwp"), 634 tool_path(name = "gcc", path = "/usr/bin/gcc"), 635 tool_path(name = "gcov", path = "/usr/bin/gcov"), 636 tool_path(name = "ld", path = "/usr/bin/ld"), 637 tool_path(name = "nm", path = "/usr/bin/nm"), 638 tool_path(name = "objcopy", path = "/usr/bin/objcopy"), 639 tool_path(name = "objdump", path = "/usr/bin/objdump"), 640 tool_path(name = "strip", path = "/usr/bin/strip"), 641 ] 642 else: 643 fail("Unreachable") 644 645 646 out = ctx.actions.declare_file(ctx.label.name) 647 ctx.actions.write(out, "Fake executable") 648 return [ 649 cc_common.create_cc_toolchain_config_info( 650 ctx = ctx, 651 features = features, 652 action_configs = action_configs, 653 artifact_name_patterns = artifact_name_patterns, 654 cxx_builtin_include_directories = cxx_builtin_include_directories, 655 toolchain_identifier = toolchain_identifier, 656 host_system_name = host_system_name, 657 target_system_name = target_system_name, 658 target_cpu = target_cpu, 659 target_libc = target_libc, 660 compiler = compiler, 661 abi_version = abi_version, 662 abi_libc_version = abi_libc_version, 663 tool_paths = tool_paths, 664 make_variables = make_variables, 665 builtin_sysroot = builtin_sysroot, 666 cc_target_os = cc_target_os 667 ), 668 DefaultInfo( 669 executable = out, 670 ), 671 ] 672 cc_toolchain_config = rule( 673 implementation = _impl, 674 attrs = { 675 "cpu": attr.string(mandatory=True, values=["armeabi", "local"]), 676 }, 677 provides = [CcToolchainConfigInfo], 678 executable = True, 679 )