github.com/prysmaticlabs/prysm@v1.4.4/tools/cross-toolchain/cc_toolchain_config_linux_arm64.bzl.tpl (about)

     1  load(
     2      "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
     3      "action_config",
     4      "feature",
     5      "feature_set",
     6      "flag_group",
     7      "flag_set",
     8      "make_variable",
     9      "tool",
    10      "tool_path",
    11      "with_feature_set",
    12  )
    13  
    14  load(
    15      "@bazel_tools//tools/cpp:cc_toolchain_config.bzl",
    16      ALL_COMPILE_ACTIONS = "all_compile_actions",
    17      ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions",
    18      ALL_LINK_ACTIONS = "all_link_actions",
    19  )
    20  
    21  def _impl(ctx):
    22      toolchain_identifier = "clang-linux-cross"
    23      compiler = "clang"
    24      abi_version = "clang"
    25      abi_libc_version = "glibc_unknown"
    26      target_libc = "glibc_unknown"
    27      target_cpu = ctx.attr.target.split("-")[0]
    28  
    29      if (target_cpu == "aarch64"):
    30          sysroot = "/usr/aarch64-linux-gnu"
    31          include_path_prefix = sysroot
    32      elif (target_cpu == "x86_64"):
    33          sysroot = "/"
    34          include_path_prefix = "/usr"
    35      else:
    36          fail("Unreachable")
    37  
    38      if (target_cpu == "aarch64"):
    39          cross_system_include_dirs = [
    40              include_path_prefix + "/include/c++/v1",
    41              include_path_prefix + "/lib/clang/10.0.0/include",
    42          ]
    43      else:
    44          cross_system_include_dirs = [
    45              include_path_prefix + "/include/c++/v1",
    46              include_path_prefix + "/lib/clang/10.0.0/include",
    47              include_path_prefix + "/include/x86_64-linux-gnu",
    48          ]
    49  
    50      cross_system_include_dirs += [
    51          include_path_prefix + "/include/",
    52          include_path_prefix + "/include/linux",
    53          include_path_prefix + "/include/asm",
    54          include_path_prefix + "/include/asm-generic",
    55      ]
    56  
    57      if (target_cpu == "aarch64"):
    58          cross_system_lib_dirs = [
    59              "/usr/" + ctx.attr.target + "/lib",
    60          ]
    61      else:
    62          cross_system_lib_dirs = [
    63              "/usr/lib/x86_64-linux-gnu/",
    64          ]
    65  
    66      cross_system_lib_dirs += [
    67          "/usr/lib/gcc/x86_64-linux-gnu/8",
    68      ]
    69  
    70      opt_feature = feature(name = "opt")
    71      dbg_feature = feature(name = "dbg")
    72      fastbuild_feature = feature(name = "fastbuild")
    73      random_seed_feature = feature(name = "random_seed", enabled = True)
    74      supports_pic_feature = feature(name = "supports_pic", enabled = True)
    75      supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
    76  
    77      unfiltered_compile_flags_feature = feature(
    78          name = "unfiltered_compile_flags",
    79          enabled = True,
    80          flag_sets = [
    81              flag_set(
    82                  actions = ALL_COMPILE_ACTIONS,
    83                  flag_groups = [
    84                      flag_group(
    85                          flags = [
    86                              "-no-canonical-prefixes",
    87                              "-Wno-builtin-macro-redefined",
    88                              "-D__DATE__=\"redacted\"",
    89                              "-D__TIMESTAMP__=\"redacted\"",
    90                              "-D__TIME__=\"redacted\"",
    91                          ],
    92                      ),
    93                  ],
    94              ),
    95          ],
    96      )
    97  
    98      # explicit arch specific system includes
    99      system_include_flags = []
   100      for d in cross_system_include_dirs:
   101          system_include_flags += ["-idirafter", d]
   102  
   103      default_compile_flags_feature = feature(
   104          name = "default_compile_flags",
   105          enabled = True,
   106          flag_sets = [
   107              flag_set(
   108                  actions = ALL_COMPILE_ACTIONS,
   109                  flag_groups = [
   110                      flag_group(
   111                          flags = [
   112                              "--target=" + ctx.attr.target,
   113                              "-nostdinc",
   114                              "-U_FORTIFY_SOURCE",
   115                              "-fstack-protector",
   116                              "-fno-omit-frame-pointer",
   117                              "-fcolor-diagnostics",
   118                              "-Wall",
   119                              "-Wthread-safety",
   120                              "-Wself-assign",
   121                          ] + system_include_flags,
   122                      ),
   123                  ],
   124              ),
   125              flag_set(
   126                  actions = ALL_COMPILE_ACTIONS,
   127                  flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])],
   128                  with_features = [with_feature_set(features = ["dbg"])],
   129              ),
   130              flag_set(
   131                  actions = ALL_COMPILE_ACTIONS,
   132                  flag_groups = [
   133                      flag_group(
   134                          flags = [
   135                              "-g0",
   136                              "-O2",
   137                              "-D_FORTIFY_SOURCE=1",
   138                              "-DNDEBUG",
   139                              "-ffunction-sections",
   140                              "-fdata-sections",
   141                          ],
   142                      ),
   143                  ],
   144                  with_features = [with_feature_set(features = ["opt"])],
   145              ),
   146              flag_set(
   147                  actions = ALL_CPP_COMPILE_ACTIONS,
   148                  flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])],
   149              ),
   150          ],
   151      )
   152  
   153      additional_link_flags = [
   154          "-l:libc++.a",
   155          "-l:libc++abi.a",
   156          "-l:libunwind.a",
   157          "-lpthread",
   158          "-ldl",
   159          "-rtlib=compiler-rt",
   160      ]
   161  
   162      default_link_flags_feature = feature(
   163          name = "default_link_flags",
   164          enabled = True,
   165          flag_sets = [
   166              flag_set(
   167                  actions = ALL_LINK_ACTIONS,
   168                  flag_groups = [
   169                      flag_group(
   170                          flags = additional_link_flags + [
   171                              "--target=" + ctx.attr.target,
   172                              "-lm",
   173                              "-no-canonical-prefixes",
   174                              "-fuse-ld=lld",
   175                              "-Wl,--build-id=md5",
   176                              "-Wl,--hash-style=gnu",
   177                              "-Wl,-z,relro,-z,now",
   178                          ] + ["-L" + d for d in cross_system_lib_dirs],
   179                      ),
   180                  ],
   181              ),
   182              flag_set(
   183                  actions = ALL_LINK_ACTIONS,
   184                  flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])],
   185                  with_features = [with_feature_set(features = ["opt"])],
   186              ),
   187          ],
   188      )
   189  
   190      objcopy_embed_flags_feature = feature(
   191          name = "objcopy_embed_flags",
   192          enabled = True,
   193          flag_sets = [
   194              flag_set(
   195                  actions = ["objcopy_embed_data"],
   196                  flag_groups = [flag_group(flags = ["-I", "binary"])],
   197              ),
   198          ],
   199      )
   200  
   201      user_compile_flags_feature = feature(
   202          name = "user_compile_flags",
   203          enabled = True,
   204          flag_sets = [
   205              flag_set(
   206                  actions = ALL_COMPILE_ACTIONS,
   207                  flag_groups = [
   208                      flag_group(
   209                          expand_if_available = "user_compile_flags",
   210                          flags = ["%{user_compile_flags}"],
   211                          iterate_over = "user_compile_flags",
   212                      ),
   213                  ],
   214              ),
   215          ],
   216      )
   217  
   218      sysroot_feature = feature(
   219          name = "sysroot",
   220          enabled = True,
   221          flag_sets = [
   222              flag_set(
   223                  actions = ALL_COMPILE_ACTIONS + ALL_LINK_ACTIONS,
   224                  flag_groups = [
   225                      flag_group(
   226                          expand_if_available = "sysroot",
   227                          flags = ["--sysroot=%{sysroot}"],
   228                      ),
   229                  ],
   230              ),
   231          ],
   232      )
   233  
   234      coverage_feature = feature(
   235          name = "coverage",
   236          flag_sets = [
   237              flag_set(
   238                  actions = ALL_COMPILE_ACTIONS,
   239                  flag_groups = [
   240                      flag_group(
   241                          flags = ["-fprofile-instr-generate", "-fcoverage-mapping"],
   242                      ),
   243                  ],
   244              ),
   245              flag_set(
   246                  actions = ALL_LINK_ACTIONS,
   247                  flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])],
   248              ),
   249          ],
   250          provides = ["profile"],
   251      )
   252  
   253      features = [
   254          opt_feature,
   255          fastbuild_feature,
   256          dbg_feature,
   257          random_seed_feature,
   258          supports_pic_feature,
   259          supports_dynamic_linker_feature,
   260          unfiltered_compile_flags_feature,
   261          default_link_flags_feature,
   262          default_compile_flags_feature,
   263          objcopy_embed_flags_feature,
   264          user_compile_flags_feature,
   265          sysroot_feature,
   266          coverage_feature,
   267      ]
   268  
   269      tool_paths = [
   270          tool_path(name = "ld", path = "/usr/bin/ld.lld"),
   271          tool_path(name = "cpp", path = "/usr/bin/clang-cpp"),
   272          tool_path(name = "dwp", path = "/usr/bin/llvm-dwp"),
   273          tool_path(name = "gcov", path = "/usr/bin/llvm-profdata"),
   274          tool_path(name = "nm", path = "/usr/bin/llvm-nm"),
   275          tool_path(name = "objcopy", path = "/usr/bin/llvm-objcopy"),
   276          tool_path(name = "objdump", path = "/usr/bin/llvm-objdump"),
   277          tool_path(name = "strip", path = "/usr/bin/strip"),
   278          tool_path(name = "gcc", path = "/usr/bin/clang"),
   279          tool_path(name = "ar", path = "/usr/bin/llvm-ar"),
   280      ]
   281  
   282      return cc_common.create_cc_toolchain_config_info(
   283          ctx = ctx,
   284          features = features,
   285          abi_version = abi_version,
   286          abi_libc_version = abi_libc_version,
   287          builtin_sysroot = sysroot,
   288          compiler = compiler,
   289          cxx_builtin_include_directories = cross_system_include_dirs,
   290          host_system_name = "x86_64-unknown-linux-gnu",
   291          target_cpu = target_cpu,
   292          target_libc = target_libc,
   293          target_system_name = ctx.attr.target,
   294          tool_paths = tool_paths,
   295          toolchain_identifier = toolchain_identifier,
   296      )
   297  
   298  arm64_cc_toolchain_config = rule(
   299      implementation = _impl,
   300      attrs = {
   301          "target": attr.string(mandatory = True),
   302          "stdlib": attr.string(),
   303      },
   304      provides = [CcToolchainConfigInfo],
   305  )