Re-enable blink_perf.canvas on Windows
[chromium-blink-merge.git] / build / toolchain / mac / BUILD.gn
blobda4ca0532e5282974bfbfdf75282e903e545ced2
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires
6 # some enhancements since the commands on Mac are slightly different than on
7 # Linux.
9 import("../goma.gni")
11 assert(host_os == "mac")
13 import("//build/toolchain/clang.gni")
14 import("//build/toolchain/goma.gni")
16 if (use_goma) {
17   goma_prefix = "$goma_dir/gomacc "
18 } else {
19   goma_prefix = ""
22 # This will copy the gyp-mac-tool to the build directory. We pass in the source
23 # file of the win tool.
24 gyp_mac_tool_source =
25     rebase_path("//tools/gyp/pylib/gyp/mac_tool.py", root_build_dir)
26 exec_script("setup_toolchain.py", [ gyp_mac_tool_source ])
28 # Shared toolchain definition. Invocations should set toolchain_os to set the
29 # build args in this definition.
30 template("mac_toolchain") {
31   toolchain(target_name) {
32     assert(defined(invoker.cc), "mac_toolchain() must specify a \"cc\" value")
33     assert(defined(invoker.cxx), "mac_toolchain() must specify a \"cxx\" value")
34     assert(defined(invoker.ld), "mac_toolchain() must specify a \"ld\" value")
35     assert(defined(invoker.toolchain_cpu),
36            "mac_toolchain() must specify a \"toolchain_cpu\"")
37     assert(defined(invoker.toolchain_os),
38            "mac_toolchain() must specify a \"toolchain_os\"")
40     # We can't do string interpolation ($ in strings) on things with dots in
41     # them. To allow us to use $cc below, for example, we create copies of
42     # these values in our scope.
43     cc = invoker.cc
44     cxx = invoker.cxx
45     ld = invoker.ld
47     # Make these apply to all tools below.
48     lib_switch = "-l"
49     lib_dir_switch = "-L"
51     tool("cc") {
52       depfile = "{{output}}.d"
53       command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
54       depsformat = "gcc"
55       description = "CC {{output}}"
56       outputs = [
57         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
58       ]
59     }
61     tool("cxx") {
62       depfile = "{{output}}.d"
63       command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
64       depsformat = "gcc"
65       description = "CXX {{output}}"
66       outputs = [
67         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
68       ]
69     }
71     tool("asm") {
72       # For GCC we can just use the C compiler to compile assembly.
73       depfile = "{{output}}.d"
74       command = "$cc -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
75       depsformat = "gcc"
76       description = "ASM {{output}}"
77       outputs = [
78         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
79       ]
80     }
82     tool("objc") {
83       depfile = "{{output}}.d"
84       command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} {{cflags_objc}} -c {{source}} -o {{output}}"
85       depsformat = "gcc"
86       description = "OBJC {{output}}"
87       outputs = [
88         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
89       ]
90     }
92     tool("objcxx") {
93       depfile = "{{output}}.d"
94       command = "$cxx -MMD -MF $depfile {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} {{cflags_objcc}} -c {{source}} -o {{output}}"
95       depsformat = "gcc"
96       description = "OBJCXX {{output}}"
97       outputs = [
98         "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o",
99       ]
100     }
102     tool("alink") {
103       command = "rm -f {{output}} && ./gyp-mac-tool filter-libtool libtool -static -o {{output}} {{inputs}}"
104       description = "LIBTOOL-STATIC {{output}}"
105       outputs = [
106         "{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
107       ]
108       default_output_extension = ".a"
109       output_prefix = "lib"
110     }
112     tool("solink") {
113       dylib = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"  # eg "./libfoo.dylib"
114       rspfile = dylib + ".rsp"
116       # These variables are not build into GN but are helpers that implement
117       # (1) linking to produce a .so, (2) extracting the symbols from that file
118       # to a temporary file, (3) if the temporary file has differences from the
119       # existing .TOC file, overwrite it, oterwise, don't change it.
120       #
121       # As a special case, if the library reexports symbols from other dynamic
122       # libraries, we always update the .TOC and skip the temporary file and
123       # diffing steps, since that library always needs to be re-linked.
124       tocname = dylib + ".TOC"
125       temporary_tocname = dylib + ".tmp"
127       does_reexport_command = "[ ! -e $dylib -o ! -e $tocname ] || otool -l $dylib | grep -q LC_REEXPORT_DYLIB"
128       link_command = "$ld -shared {{ldflags}} -o $dylib -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
129       replace_command = "if ! cmp -s $temporary_tocname $tocname; then mv $temporary_tocname $tocname"
130       extract_toc_command = "{ otool -l $dylib | grep LC_ID_DYLIB -A 5; nm -gP $dylib | cut -f1-2 -d' ' | grep -v U\$\$; true; }"
132       command = "if $does_reexport_command ; then $link_command && $extract_toc_command > $tocname; else $link_command && $extract_toc_command > $temporary_tocname && $replace_command ; fi; fi"
134       rspfile_content = "{{inputs_newline}}"
136       description = "SOLINK {{output}}"
138       # Use this for {{output_extension}} expansions unless a target manually
139       # overrides it (in which case {{output_extension}} will be what the target
140       # specifies).
141       default_output_extension = ".dylib"
143       output_prefix = "lib"
145       # Since the above commands only updates the .TOC file when it changes, ask
146       # Ninja to check if the timestamp actually changed to know if downstream
147       # dependencies should be recompiled.
148       restat = true
150       # Tell GN about the output files. It will link to the dylib but use the
151       # tocname for dependency management.
152       outputs = [
153         dylib,
154         tocname,
155       ]
156       link_output = dylib
157       depend_output = tocname
158     }
160     tool("link") {
161       outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
162       rspfile = "$outfile.rsp"
163       command = "$ld {{ldflags}} -o $outfile -Wl,-filelist,$rspfile {{solibs}} {{libs}}"
164       description = "LINK $outfile"
165       rspfile_content = "{{inputs_newline}}"
166       outputs = [
167         outfile,
168       ]
169     }
171     tool("stamp") {
172       command = "touch {{output}}"
173       description = "STAMP {{output}}"
174     }
176     tool("copy") {
177       command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
178       description = "COPY {{source}} {{output}}"
179     }
181     toolchain_args() {
182       current_cpu = invoker.toolchain_cpu
183       current_os = invoker.toolchain_os
185       # These values need to be passed through unchanged.
186       target_os = target_os
187       target_cpu = target_cpu
189       if (defined(invoker.is_clang)) {
190         is_clang = invoker.is_clang
191       }
192     }
193   }
196 mac_toolchain("clang_arm") {
197   toolchain_cpu = "arm"
198   toolchain_os = "mac"
199   prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
200                        root_build_dir)
201   cc = "${goma_prefix}$prefix/clang"
202   cxx = "${goma_prefix}$prefix/clang++"
203   ld = cxx
204   is_clang = true
207 mac_toolchain("arm") {
208   toolchain_cpu = "arm"
209   toolchain_os = "mac"
210   cc = "${goma_prefix}/gcc"
211   cxx = "${goma_prefix}/g++"
212   ld = cxx
213   is_clang = false
216 mac_toolchain("clang_x64") {
217   toolchain_cpu = "x64"
218   toolchain_os = "mac"
219   prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
220                        root_build_dir)
221   cc = "${goma_prefix}$prefix/clang"
222   cxx = "${goma_prefix}$prefix/clang++"
223   ld = cxx
224   is_clang = true
227 mac_toolchain("x64") {
228   toolchain_cpu = "x64"
229   toolchain_os = "mac"
230   cc = "${goma_prefix}/gcc"
231   cxx = "${goma_prefix}/g++"
232   ld = cxx
233   is_clang = false