summaryrefslogtreecommitdiff
path: root/chromium/build/toolchain/mac/BUILD.gn
blob: ffd039a4f18a5cfc2fba955379a8cb3f11746afe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires
# some enhancements since the commands on Mac are slightly different than on
# Linux.

import("//build/config/clang/clang.gni")
import("//build/config/coverage/coverage.gni")
import("../goma.gni")
if (is_ios) {
  import("//build/config/ios/ios_sdk.gni")
}
import("//build/config/mac/mac_sdk.gni")
import("//build/config/mac/symbols.gni")

assert((is_ios && host_os == "mac") || host_os != "win")

import("//build/toolchain/cc_wrapper.gni")
import("//build/toolchain/concurrent_links.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/toolchain.gni")

declare_args() {
  # Reduce the number of tasks using the copy_bundle_data and compile_xcassets
  # tools as they can cause lots of I/O contention when invoking ninja with a
  # large number of parallel jobs (e.g. when using distributed build like goma).
  bundle_pool_depth = -1

  # This makes the linker set timestamps in Mach-O files to 0. This isn't
  # enabled by default because this breaks Xcode's lldb. This has been fixed in
  # https://reviews.llvm.org/rL368199 but that has not yet made it into a public
  # lldb release.
  mac_deterministic_build = false

  # This controls whether whole module optimization is enabled when building
  # Swift modules. If enabled, the compiler will compile the module as one
  # unit, generating just one single object file. Otherwise, it will generate
  # one object file per .swift file. If unspecified, will default to "true"
  # for official builds, and "false" for all other builds.
  swift_whole_module_optimization = -1
}

if (swift_whole_module_optimization == -1) {
  swift_whole_module_optimization = is_official_build
}

if (current_toolchain == default_toolchain) {
  pool("bundle_pool") {
    if (bundle_pool_depth == -1) {
      depth = concurrent_links
    } else {
      depth = bundle_pool_depth
    }
  }
}

# When implementing tools using Python scripts, a TOOL_VERSION=N env
# variable is placed in front of the command. The N should be incremented
# whenever the script is changed, so that the build system rebuilds all
# edges that utilize the script. Ideally this should be changed to use
# proper input-dirty checking, but that could be expensive. Instead, use a
# script to get the tool scripts' modification time to use as the version.
# This won't cause a re-generation of GN files when the tool script changes
# but it will cause edges to be marked as dirty if the ninja files are
# regenerated. See https://crbug.com/619083 for details. A proper fix
# would be to have inputs to tools (https://crbug.com/621119).
tool_versions =
    exec_script("get_tool_mtime.py",
                rebase_path([
                              "//build/apple/swiftc.py",
                              "//build/config/ios/compile_xcassets.py",
                              "//build/toolchain/mac/filter_libtool.py",
                              "//build/toolchain/mac/linker_driver.py",
                            ],
                            root_build_dir),
                "trim scope")

# Shared toolchain definition. Invocations should set current_os to set the
# build args in this definition.
template("mac_toolchain") {
  toolchain(target_name) {
    # When invoking this toolchain not as the default one, these args will be
    # passed to the build. They are ignored when this is the default toolchain.
    assert(defined(invoker.toolchain_args),
           "Toolchains must declare toolchain_args")
    toolchain_args = {
      # Populate toolchain args from the invoker.
      forward_variables_from(invoker.toolchain_args, "*")

      # The host toolchain value computed by the default toolchain's setup
      # needs to be passed through unchanged to all secondary toolchains to
      # ensure that it's always the same, regardless of the values that may be
      # set on those toolchains.
      host_toolchain = host_toolchain
    }

    # Supports building with the version of clang shipped with Xcode when
    # targeting iOS by not respecting clang_base_path.
    if (toolchain_args.current_os == "ios" && use_xcode_clang) {
      prefix = ""
    } else {
      prefix = rebase_path("$clang_base_path/bin/", root_build_dir)
    }

    _cc = "${prefix}clang"
    _cxx = "${prefix}clang++"

    swiftmodule_switch = "-Wl,-add_ast_path,"

    # When the invoker has explicitly overridden use_goma or cc_wrapper in the
    # toolchain args, use those values, otherwise default to the global one.
    # This works because the only reasonable override that toolchains might
    # supply for these values are to force-disable them.
    if (defined(toolchain_args.use_goma)) {
      toolchain_uses_goma = toolchain_args.use_goma
    } else {
      toolchain_uses_goma = use_goma
    }
    if (defined(toolchain_args.cc_wrapper)) {
      toolchain_cc_wrapper = toolchain_args.cc_wrapper
    } else {
      toolchain_cc_wrapper = cc_wrapper
    }

    # Compute the compiler prefix.
    if (toolchain_uses_goma) {
      assert(toolchain_cc_wrapper == "",
             "Goma and cc_wrapper can't be used together.")
      compiler_prefix = "$goma_dir/gomacc "
    } else if (toolchain_cc_wrapper != "") {
      compiler_prefix = toolchain_cc_wrapper + " "
    } else {
      compiler_prefix = ""
    }

    cc = compiler_prefix + _cc
    cxx = compiler_prefix + _cxx
    ld = _cxx

    # Set the explicit search path for clang++ so it uses the right linker
    # binary.
    ld += " -B " + mac_bin_path

    if (defined(toolchain_args.coverage_instrumentation_input_file)) {
      toolchain_coverage_instrumentation_input_file =
          toolchain_args.coverage_instrumentation_input_file
    } else {
      toolchain_coverage_instrumentation_input_file =
          coverage_instrumentation_input_file
    }
    _use_clang_coverage_wrapper =
        toolchain_coverage_instrumentation_input_file != ""
    if (_use_clang_coverage_wrapper) {
      _coverage_wrapper =
          rebase_path("//build/toolchain/clang_code_coverage_wrapper.py",
                      root_build_dir) + " --files-to-instrument=" +
          rebase_path(toolchain_coverage_instrumentation_input_file,
                      root_build_dir) + " --target-os=" + target_os
      cc = _coverage_wrapper + " ${cc}"
      cxx = _coverage_wrapper + " ${cxx}"
    }

    linker_driver =
        "TOOL_VERSION=${tool_versions.linker_driver} " + python_path + " " +
        rebase_path("//build/toolchain/mac/linker_driver.py", root_build_dir)

    # Specify an explicit path for the strip binary.
    _strippath = mac_bin_path + "strip"
    linker_driver += " -Wcrl,strippath," + _strippath

    if (mac_deterministic_build) {
      linker_driver += " --deterministic"
    }

    # On iOS, the final applications are assembled using lipo (to support fat
    # builds). The correct flags are passed to the linker_driver.py script
    # directly during the lipo call. The test is against the target_os because
    # there is no need to create .dSYMs for targets compiled for the host.
    if (target_os != "ios") {
      _enable_dsyms = enable_dsyms
      _save_unstripped_output = save_unstripped_output
    } else {
      _enable_dsyms = false
      _save_unstripped_output = false
    }

    # Make these apply to all tools below.
    lib_switch = "-l"
    lib_dir_switch = "-L"

    # Object files go in this directory. Use label_name instead of
    # target_output_name since labels will generally have no spaces and will be
    # unique in the directory.
    object_subdir = "{{target_out_dir}}/{{label_name}}"

    # If dSYMs are enabled, this flag will be added to the link tools.
    if (_enable_dsyms) {
      dsym_switch = " -Wcrl,dsym,{{root_out_dir}} "
      dsym_switch += "-Wcrl,dsymutilpath," +
                     "${prefix}dsymutil" + " "

      dsym_output_dir =
          "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.dSYM"
      dsym_output = [
        "$dsym_output_dir/Contents/Info.plist",
        "$dsym_output_dir/Contents/Resources/DWARF/" +
            "{{target_output_name}}{{output_extension}}",
      ]
    } else {
      dsym_switch = ""
    }

    if (_save_unstripped_output) {
      _unstripped_output = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.unstripped"
    }

    tool("cc") {
      depfile = "{{output}}.d"
      precompiled_header_type = "gcc"
      command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
      depsformat = "gcc"
      description = "CC {{output}}"
      outputs = [ "$object_subdir/{{source_name_part}}.o" ]
    }

    tool("cxx") {
      depfile = "{{output}}.d"
      precompiled_header_type = "gcc"
      command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
      depsformat = "gcc"
      description = "CXX {{output}}"
      outputs = [ "$object_subdir/{{source_name_part}}.o" ]
    }

    tool("asm") {
      # For GCC we can just use the C compiler to compile assembly.
      depfile = "{{output}}.d"
      command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}"
      depsformat = "gcc"
      description = "ASM {{output}}"
      outputs = [ "$object_subdir/{{source_name_part}}.o" ]
    }

    tool("objc") {
      depfile = "{{output}}.d"
      precompiled_header_type = "gcc"
      command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{framework_dirs}} {{cflags}} {{cflags_objc}} -c {{source}} -o {{output}}"
      depsformat = "gcc"
      description = "OBJC {{output}}"
      outputs = [ "$object_subdir/{{source_name_part}}.o" ]
    }

    tool("objcxx") {
      depfile = "{{output}}.d"
      precompiled_header_type = "gcc"
      command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{framework_dirs}} {{cflags}} {{cflags_objcc}} -c {{source}} -o {{output}}"
      depsformat = "gcc"
      description = "OBJCXX {{output}}"
      outputs = [ "$object_subdir/{{source_name_part}}.o" ]
    }

    tool("alink") {
      rspfile = "{{output}}.rsp"

      if (!use_lld) {
        # Note about -filelist: Apple's linker reads the file list file and
        # interprets each newline-separated chunk of text as a file name. It
        # doesn't do the things one would expect from the shell like unescaping
        # or handling quotes. In contrast, when Ninja finds a file name with
        # spaces, it single-quotes them in $inputs_newline as it would normally
        # do for command-line arguments. Thus any source names with spaces, or
        # label names with spaces (which GN bases the output paths on) will be
        # corrupted by this process. Don't use spaces for source files or
        # labels.
        rspfile_content = "{{inputs_newline}}"

        script = rebase_path("//build/toolchain/mac/filter_libtool.py",
                             root_build_dir)

        # Specify explicit path for libtool.
        libtool = mac_bin_path + "libtool"
        command = "rm -f {{output}} && TOOL_VERSION=${tool_versions.filter_libtool} " + python_path + " $script $libtool -static {{arflags}} -o {{output}} -filelist $rspfile"
        description = "LIBTOOL-STATIC {{output}}"
      } else {
        rspfile_content = "{{inputs}}"
        ar = "${prefix}llvm-ar"
        command = "\"$ar\" {{arflags}} -r -c -s -D {{output}} \"@$rspfile\""

        # Remove the output file first so that ar doesn't try to modify the
        # existing file.
        command = "rm -f {{output}} && $command"
        description = "AR {{output}}"
      }
      outputs = [ "{{output_dir}}/{{target_output_name}}{{output_extension}}" ]
      default_output_dir = "{{target_out_dir}}"
      default_output_extension = ".a"
      output_prefix = "lib"
    }

    tool("solink") {
      # E.g. "./libfoo.dylib":
      dylib = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      rspfile = dylib + ".rsp"
      pool = "//build/toolchain:link_pool($default_toolchain)"

      # These variables are not built into GN but are helpers that implement
      # (1) linking to produce a .dylib, (2) extracting the symbols from that
      # file to a temporary file, (3) if the temporary file has differences from
      # the existing .TOC file, overwrite it, otherwise, don't change it.
      #
      # As a special case, if the library reexports symbols from other dynamic
      # libraries, we always update the .TOC and skip the temporary file and
      # diffing steps, since that library always needs to be re-linked.
      tocname = dylib + ".TOC"
      temporary_tocname = dylib + ".tmp"

      # Use explicit paths to binaries. The binaries present on the default
      # search path in /usr/bin are thin wrappers around xcrun, which requires a
      # full CommandLineTools or Xcode install, and still may not choose the
      # appropriate binary if there are multiple installs.
      otool = mac_bin_path + "otool"
      nm = mac_bin_path + "nm"

      does_reexport_command = "[ ! -e \"$dylib\" -o ! -e \"$tocname\" ] || $otool -l \"$dylib\" | grep -q LC_REEXPORT_DYLIB"

      link_command = "$linker_driver $ld -shared "
      if (is_component_build) {
        link_command += " -Wl,-install_name,@rpath/\"{{target_output_name}}{{output_extension}}\" "
      }
      link_command += dsym_switch
      link_command += "{{ldflags}} -o \"$dylib\" -Wl,-filelist,\"$rspfile\" {{frameworks}} {{swiftmodules}} {{solibs}} {{libs}}"

      replace_command = "if ! cmp -s \"$temporary_tocname\" \"$tocname\"; then mv \"$temporary_tocname\" \"$tocname\""
      extract_toc_command = "{ $otool -l \"$dylib\" | grep LC_ID_DYLIB -A 5; $nm -gPp \"$dylib\" | cut -f1-2 -d' ' | grep -v U\$\$; true; }"

      command = "if $does_reexport_command ; then $link_command && $extract_toc_command > \"$tocname\"; else $link_command && $extract_toc_command > \"$temporary_tocname\" && $replace_command ; fi; fi"

      rspfile_content = "{{inputs_newline}}"

      description = "SOLINK {{output}}"

      # Use this for {{output_extension}} expansions unless a target manually
      # overrides it (in which case {{output_extension}} will be what the target
      # specifies).
      default_output_dir = "{{root_out_dir}}"
      default_output_extension = ".dylib"

      output_prefix = "lib"

      # Since the above commands only updates the .TOC file when it changes, ask
      # Ninja to check if the timestamp actually changed to know if downstream
      # dependencies should be recompiled.
      restat = true

      # Tell GN about the output files. It will link to the dylib but use the
      # tocname for dependency management.
      outputs = [
        dylib,
        tocname,
      ]
      link_output = dylib
      depend_output = tocname

      if (_enable_dsyms) {
        outputs += dsym_output
      }
      if (_save_unstripped_output) {
        outputs += [ _unstripped_output ]
      }
    }

    tool("solink_module") {
      # E.g. "./libfoo.so":
      sofile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      rspfile = sofile + ".rsp"
      pool = "//build/toolchain:link_pool($default_toolchain)"

      link_command = "$linker_driver $ld -bundle {{ldflags}} -o \"$sofile\" -Wl,-filelist,\"$rspfile\""
      if (is_component_build) {
        link_command += " -Wl,-install_name,@rpath/{{target_output_name}}{{output_extension}}"
      }
      link_command += dsym_switch
      link_command += " {{frameworks}} {{swiftmodules}} {{solibs}} {{libs}}"
      command = link_command

      rspfile_content = "{{inputs_newline}}"

      description = "SOLINK_MODULE {{output}}"

      # Use this for {{output_extension}} expansions unless a target manually
      # overrides it (in which case {{output_extension}} will be what the target
      # specifies).
      default_output_dir = "{{root_out_dir}}"
      default_output_extension = ".so"

      outputs = [ sofile ]

      if (_enable_dsyms) {
        outputs += dsym_output
      }
      if (_save_unstripped_output) {
        outputs += [ _unstripped_output ]
      }
    }

    tool("link") {
      outfile = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
      rspfile = "$outfile.rsp"
      pool = "//build/toolchain:link_pool($default_toolchain)"

      # Note about -filelist: Apple's linker reads the file list file and
      # interprets each newline-separated chunk of text as a file name. It
      # doesn't do the things one would expect from the shell like unescaping
      # or handling quotes. In contrast, when Ninja finds a file name with
      # spaces, it single-quotes them in $inputs_newline as it would normally
      # do for command-line arguments. Thus any source names with spaces, or
      # label names with spaces (which GN bases the output paths on) will be
      # corrupted by this process. Don't use spaces for source files or labels.
      command = "$linker_driver $ld $dsym_switch {{ldflags}} -o \"$outfile\" -Wl,-filelist,\"$rspfile\" {{frameworks}} {{swiftmodules}} {{solibs}} {{libs}}"
      description = "LINK $outfile"
      rspfile_content = "{{inputs_newline}}"
      outputs = [ outfile ]

      if (_enable_dsyms) {
        outputs += dsym_output
      }
      if (_save_unstripped_output) {
        outputs += [ _unstripped_output ]
      }

      default_output_dir = "{{root_out_dir}}"
    }

    # These two are really entirely generic, but have to be repeated in
    # each toolchain because GN doesn't allow a template to be used here.
    # See //build/toolchain/toolchain.gni for details.
    tool("stamp") {
      command = stamp_command
      description = stamp_description
    }
    tool("copy") {
      command = copy_command
      description = copy_description
    }

    tool("copy_bundle_data") {
      # copy_command use hardlink if possible but this does not work with
      # directories. Also when running EG2 tests from Xcode, Xcode tries to
      # copy some files into the application bundle which fails if source
      # and destination are hardlinked together.
      #
      # Instead use clonefile to copy the files which is as efficient as
      # hardlink but ensure the file have distinct metadata (thus avoid the
      # error with ditto, see https://crbug.com/1042182).
      if (host_os == "mac") {
        command = "rm -rf {{output}} && cp -Rc {{source}} {{output}}"
      } else {
        command = "rm -rf {{output}} && cp -Rl {{source}} {{output}}"
      }
      description = "COPY_BUNDLE_DATA {{source}} {{output}}"
      pool = ":bundle_pool($default_toolchain)"
    }

    tool("swift") {
      _tool = rebase_path("//build/apple/swiftc.py", root_build_dir)

      depfile = "{{target_out_dir}}/{{module_name}}.d"
      depsformat = "gcc"

      outputs = [
        # The module needs to be the first output listed. The blank line after
        # the module is required to prevent `gn format` from changing the file
        # order.
        "{{target_gen_dir}}/{{module_name}}.swiftmodule",

        "{{target_gen_dir}}/{{module_name}}.h",
        "{{target_gen_dir}}/{{module_name}}.swiftdoc",
        "{{target_gen_dir}}/{{module_name}}.swiftsourceinfo",
      ]

      if (swift_whole_module_optimization) {
        _extra_flags = "-whole-module-optimization"
        _objects_dir = "{{target_out_dir}}"

        outputs += [ "$_objects_dir/{{module_name}}.o" ]
      } else {
        _extra_flags = ""
        _objects_dir = "{{target_out_dir}}/{{label_name}}"

        partial_outputs = [ "$_objects_dir/{{source_name_part}}.o" ]
      }

      _env_vars = "TOOL_VERSION=${tool_versions.swiftc}"
      if (is_ios && ios_sdk_developer_dir != "") {
        _env_vars += " DEVELOPER_DIR=$ios_sdk_developer_dir"
      }

      command =
          "$_env_vars $_tool -module-name {{module_name}} " +
          "-object-dir $_objects_dir " +
          "-module-path {{target_gen_dir}}/{{module_name}}.swiftmodule " +
          "-header-path {{target_gen_dir}}/{{module_name}}.h " +
          "-depfile {{target_out_dir}}/{{module_name}}.d " +
          "-depfile-filter {{target_gen_dir}}/{{module_name}}.swiftmodule " +
          "-bridge-header {{bridge_header}} $_extra_flags " +
          "{{swiftflags}} {{include_dirs}} {{module_dirs}} {{inputs}}"
    }

    # xcassets are only used on iOS, not macOS. We want to minimize the number
    # of Xcode-based tools used by the macOS toolchain, so we intentionally
    # disallow future uses of xcassets on macOS. https://crbug.com/965663.
    if (toolchain_args.current_os == "ios") {
      tool("compile_xcassets") {
        _tool = rebase_path("//build/config/ios/compile_xcassets.py",
                            root_build_dir)
        if (is_ios) {
          _sdk_name = ios_sdk_name
          _min_deployment_target = ios_deployment_target
          _compress_pngs = ""
        } else {
          _sdk_name = mac_sdk_name
          _min_deployment_target = mac_deployment_target
          _compress_pngs = " -c "
        }
        command =
            "rm -f \"{{output}}\" && " +
            "TOOL_VERSION=${tool_versions.compile_xcassets} " +
            python_path + " $_tool$_compress_pngs -p \"$_sdk_name\" " +
            "-t \"$_min_deployment_target\" -T \"{{bundle_product_type}}\" " +
            "-P \"{{bundle_partial_info_plist}}\" -o {{output}} {{inputs}}"

        description = "COMPILE_XCASSETS {{output}}"
        pool = ":bundle_pool($default_toolchain)"
      }
    }

    tool("action") {
      pool = "//build/toolchain:action_pool($default_toolchain)"
    }
  }
}

mac_toolchain("clang_arm") {
  toolchain_args = {
    current_cpu = "arm"
    current_os = "mac"
  }
}

mac_toolchain("clang_arm64") {
  toolchain_args = {
    current_cpu = "arm64"
    current_os = "mac"
  }
}

mac_toolchain("clang_x64") {
  toolchain_args = {
    current_cpu = "x64"
    current_os = "mac"

    if (target_os == "ios") {
      # TODO(crbug.com/753445): the use_sanitizer_coverage arg is currently
      # not supported by the Chromium mac_clang_x64 toolchain on iOS
      # distribution.
      use_sanitizer_coverage = false
    }
  }
}

mac_toolchain("clang_x86") {
  toolchain_args = {
    current_cpu = "x86"
    current_os = "mac"
  }
}

mac_toolchain("clang_x86_v8_arm") {
  toolchain_args = {
    current_cpu = "x86"
    current_os = "mac"

    if (defined(v8_current_cpu)) {
      v8_current_cpu = "arm"
    }
  }
}

mac_toolchain("clang_x86_v8_mipsel") {
  toolchain_args = {
    current_cpu = "x86"
    current_os = "mac"

    if (defined(v8_current_cpu)) {
      v8_current_cpu = "mipsel"
    }
  }
}

mac_toolchain("clang_x64_v8_arm64") {
  toolchain_args = {
    current_cpu = "x64"
    current_os = "mac"

    if (defined(v8_current_cpu)) {
      v8_current_cpu = "arm64"
    }
  }
}

mac_toolchain("clang_x64_v8_mips64el") {
  toolchain_args = {
    current_cpu = "x64"
    current_os = "mac"

    if (defined(v8_current_cpu)) {
      v8_current_cpu = "mips64el"
    }
  }
}

mac_toolchain("clang_arm_v8_x86") {
  toolchain_args = {
    current_cpu = "arm"
    current_os = "mac"

    if (defined(v8_current_cpu)) {
      v8_current_cpu = "x86"
    }
  }
}

mac_toolchain("clang_arm64_v8_x64") {
  toolchain_args = {
    current_cpu = "arm64"
    current_os = "mac"

    if (defined(v8_current_cpu)) {
      v8_current_cpu = "x64"
    }
  }
}

if (is_ios) {
  mac_toolchain("ios_clang_arm64") {
    toolchain_args = {
      current_cpu = "arm64"
      current_os = "ios"
    }
  }

  mac_toolchain("ios_clang_arm64_14_0") {
    toolchain_args = {
      current_cpu = "arm64"
      current_os = "ios"
      ios_deployment_target = "14.0"
    }
  }

  mac_toolchain("ios_clang_arm") {
    toolchain_args = {
      current_cpu = "arm"
      current_os = "ios"
    }
  }

  mac_toolchain("ios_clang_arm_fat") {
    toolchain_args = {
      current_cpu = "arm"
      current_os = "ios"
      is_fat_secondary_toolchain = true
      primary_fat_toolchain_name = "//build/toolchain/mac:ios_clang_arm64"
    }
  }

  mac_toolchain("ios_clang_x64") {
    toolchain_args = {
      current_cpu = "x64"
      current_os = "ios"
    }
  }

  mac_toolchain("ios_clang_x64_14_0") {
    toolchain_args = {
      current_cpu = "x64"
      current_os = "ios"
      ios_deployment_target = "14.0"
    }
  }

  mac_toolchain("ios_clang_x86") {
    toolchain_args = {
      current_cpu = "x86"
      current_os = "ios"
    }
  }

  mac_toolchain("ios_clang_x86_fat") {
    toolchain_args = {
      current_cpu = "x86"
      current_os = "ios"
      is_fat_secondary_toolchain = true
      primary_fat_toolchain_name = "//build/toolchain/mac:ios_clang_x64"
    }
  }
}