github.com/prysmaticlabs/prysm@v1.4.4/tools/cross-toolchain/cc_toolchain_config_osx.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 = "osxcross"
    23      compiler = "clang"
    24      abi_version = "darwin_x86_64"
    25      abi_libc_version = "darwin_x86_64"
    26      install = "/usr/x86_64-apple-darwin/"
    27      clang_version = "10.0.0"
    28      target_libc = "macosx"
    29      target_cpu = "x86_64"
    30      osxcross = install + "osxcross/"
    31      osxcross_binprefix = osxcross + "bin/x86_64-apple-darwin19-"
    32      sdkroot = osxcross + "SDK/MacOSX10.15.sdk/"
    33      cross_system_include_dirs = [
    34          "/usr/lib/clang/10.0.0/include",
    35          osxcross + "include",
    36          sdkroot + "usr/include",
    37      ]
    38  
    39      opt_feature = feature(name = "opt")
    40      dbg_feature = feature(name = "dbg")
    41      fastbuild_feature = feature(name = "fastbuild")
    42      random_seed_feature = feature(name = "random_seed", enabled = True)
    43      supports_pic_feature = feature(name = "supports_pic", enabled = True)
    44      supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
    45  
    46      unfiltered_compile_flags_feature = feature(
    47          name = "unfiltered_compile_flags",
    48          enabled = True,
    49          flag_sets = [
    50              flag_set(
    51                  actions = ALL_COMPILE_ACTIONS,
    52                  flag_groups = [
    53                      flag_group(
    54                          flags = [
    55                              "-stdlib=libc++",
    56                              "-no-canonical-prefixes",
    57                              "-Wno-builtin-macro-redefined",
    58                              "-D__DATE__=\"redacted\"",
    59                              "-D__TIMESTAMP__=\"redacted\"",
    60                              "-D__TIME__=\"redacted\"",
    61                          ],
    62                      ),
    63                  ],
    64              ),
    65          ],
    66      )
    67  
    68      # explicit arch specific system includes
    69      system_include_flags = []
    70      for d in cross_system_include_dirs:
    71          system_include_flags += ["-idirafter", d]
    72  
    73      default_compile_flags_feature = feature(
    74          name = "default_compile_flags",
    75          enabled = True,
    76          flag_sets = [
    77              flag_set(
    78                  actions = ALL_COMPILE_ACTIONS,
    79                  flag_groups = [
    80                      flag_group(
    81                          flags = [
    82                              "-mlinker-version=400",
    83                              "-B " + osxcross + "bin",
    84                              "-nostdinc",
    85                              "-U_FORTIFY_SOURCE",
    86                              "-fstack-protector",
    87                              "-fno-omit-frame-pointer",
    88                              "-fcolor-diagnostics",
    89                              "-Wall",
    90                              "-Wthread-safety",
    91                              "-Wself-assign",
    92                          ] + system_include_flags,
    93                      ),
    94                  ],
    95              ),
    96              flag_set(
    97                  actions = ALL_COMPILE_ACTIONS,
    98                  flag_groups = [flag_group(flags = ["-g", "-fstandalone-debug"])],
    99                  with_features = [with_feature_set(features = ["dbg"])],
   100              ),
   101              flag_set(
   102                  actions = ALL_COMPILE_ACTIONS,
   103                  flag_groups = [
   104                      flag_group(
   105                          flags = [
   106                              "-g0",
   107                              "-O2",
   108                              "-D_FORTIFY_SOURCE=1",
   109                              "-DNDEBUG",
   110                              "-ffunction-sections",
   111                              "-fdata-sections",
   112                          ],
   113                      ),
   114                  ],
   115                  with_features = [with_feature_set(features = ["opt"])],
   116              ),
   117              flag_set(
   118                  actions = ALL_CPP_COMPILE_ACTIONS,
   119                  flag_groups = [flag_group(flags = ["-std=c++17", "-nostdinc++"])],
   120              ),
   121          ],
   122      )
   123  
   124      default_link_flags_feature = feature(
   125          name = "default_link_flags",
   126          enabled = True,
   127          flag_sets = [
   128              flag_set(
   129                  actions = ALL_LINK_ACTIONS,
   130                  flag_groups = [
   131                      flag_group(
   132                          flags = [
   133                              "-v",
   134                              "-lm",
   135                              "-no-canonical-prefixes",
   136                              "-lc++",
   137                              "-lc++abi",
   138                              "-F" + sdkroot + "System/Library/Frameworks/",
   139                              "-L"+ sdkroot + "usr/lib",
   140                              "-undefined",
   141                              "dynamic_lookup",
   142                              ],
   143                      ),
   144                  ],
   145              ),
   146          ],
   147      )
   148  
   149      objcopy_embed_flags_feature = feature(
   150          name = "objcopy_embed_flags",
   151          enabled = True,
   152          flag_sets = [
   153              flag_set(
   154                  actions = ["objcopy_embed_data"],
   155                  flag_groups = [flag_group(flags = ["-I", "binary"])],
   156              ),
   157          ],
   158      )
   159  
   160      user_compile_flags_feature = feature(
   161          name = "user_compile_flags",
   162          enabled = True,
   163          flag_sets = [
   164              flag_set(
   165                  actions = ALL_COMPILE_ACTIONS,
   166                  flag_groups = [
   167                      flag_group(
   168                          expand_if_available = "user_compile_flags",
   169                          flags = ["%{user_compile_flags}"],
   170                          iterate_over = "user_compile_flags",
   171                      ),
   172                  ],
   173              ),
   174          ],
   175      )
   176  
   177      coverage_feature = feature(
   178          name = "coverage",
   179          flag_sets = [
   180              flag_set(
   181                  actions = ALL_COMPILE_ACTIONS,
   182                  flag_groups = [
   183                      flag_group(
   184                          flags = ["-fprofile-instr-generate", "-fcoverage-mapping"],
   185                      ),
   186                  ],
   187              ),
   188              flag_set(
   189                  actions = ALL_LINK_ACTIONS,
   190                  flag_groups = [flag_group(flags = ["-fprofile-instr-generate"])],
   191              ),
   192          ],
   193          provides = ["profile"],
   194      )
   195  
   196      features = [
   197          opt_feature,
   198          fastbuild_feature,
   199          dbg_feature,
   200          random_seed_feature,
   201          supports_pic_feature,
   202          supports_dynamic_linker_feature,
   203          unfiltered_compile_flags_feature,
   204          default_link_flags_feature,
   205          default_compile_flags_feature,
   206          objcopy_embed_flags_feature,
   207          user_compile_flags_feature,
   208          coverage_feature,
   209      ]
   210  
   211      tool_paths = [
   212          tool_path(name = "ld", path = osxcross_binprefix + "ld"),
   213          tool_path(name = "cpp", path = osxcross + "bin/o64-clang++"),
   214          tool_path(name = "dwp", path = "/usr/bin/dwp"),
   215          tool_path(name = "gcov", path = "/usr/bin/gcov"),
   216          tool_path(name = "nm", path = osxcross_binprefix + "nm"),
   217          tool_path(name = "objdump", path = osxcross_binprefix + "ObjectDump"),
   218          tool_path(name = "strip", path = osxcross_binprefix + "strip"),
   219          tool_path(name = "gcc", path = osxcross + "bin/o64-clang"),
   220          tool_path(name = "ar", path = osxcross_binprefix + "libtool"),
   221      ]
   222  
   223      return cc_common.create_cc_toolchain_config_info(
   224          ctx = ctx,
   225          features = features,
   226          abi_version = abi_version,
   227          abi_libc_version = abi_libc_version,
   228          compiler = compiler,
   229          cxx_builtin_include_directories = cross_system_include_dirs,
   230          host_system_name = "x86_64-unknown-linux-gnu",
   231          target_cpu = target_cpu,
   232          target_libc = target_libc,
   233          target_system_name = ctx.attr.target,
   234          tool_paths = tool_paths,
   235          toolchain_identifier = toolchain_identifier,
   236      )
   237  
   238  osx_cc_toolchain_config = rule(
   239      implementation = _impl,
   240      attrs = {
   241          "target": attr.string(mandatory = True),
   242          "stdlib": attr.string(),
   243      },
   244      provides = [CcToolchainConfigInfo],
   245  )