• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5import("//build/config/win/visual_studio_version.gni")
6import("//build/toolchain/goma.gni")
7
8# Should only be running on Windows.
9assert(is_win)
10
11# Setup the Visual Studio state.
12#
13# Its arguments are the VS path and the compiler wrapper tool. It will write
14# "environment.x86" and "environment.x64" to the build directory and return a
15# list to us.
16gyp_win_tool_path = rebase_path("//tools/gyp/pylib/gyp/win_tool.py",
17                                root_build_dir)
18exec_script("setup_toolchain.py",
19            [ visual_studio_path, gyp_win_tool_path, windows_sdk_path ])
20
21# This value will be inherited in the toolchain below.
22concurrent_links = exec_script("../get_concurrent_links.py", [], "value")
23
24# Parameters:
25#  cpu_arch: cpu_arch to pass as a build arg
26#  environment: File name of environment file.
27#  force_win64 (optional): value for this build arg.
28template("msvc_toolchain") {
29  if (defined(invoker.concurrent_links)) {
30    concurrent_links = invoker.concurrent_links
31  }
32
33  env = invoker.environment
34
35  toolchain(target_name) {
36    # Make these apply to all tools below.
37    lib_switch = ""
38    lib_dir_switch="/LIBPATH:"
39
40    tool("cc") {
41      rspfile = "{{output}}.rsp"
42      pdbname = "{{target_out_dir}}/{{target_output_name}}_c.pdb"
43      command = "ninja -t msvc -e $env -- cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
44      depsformat = "msvc"
45      description = "CC {{output}}"
46      outputs = [
47        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
48      ]
49      rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
50    }
51
52    tool("cxx") {
53      rspfile = "{{output}}.rsp"
54      # The PDB name needs to be different between C and C++ compiled files.
55      pdbname = "{{target_out_dir}}/{{target_output_name}}_cc.pdb"
56      command = "ninja -t msvc -e $env -- cl.exe /nologo /showIncludes /FC @$rspfile /c {{source}} /Fo{{output}} /Fd$pdbname"
57      depsformat = "msvc"
58      description = "CXX {{output}}"
59      outputs = [
60        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
61      ]
62      rspfile_content = "{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
63    }
64
65    tool("rc") {
66      command = "$python_path gyp-win-tool rc-wrapper $env rc.exe {{defines}} {{include_dirs}} /fo{{output}} {{source}}"
67      outputs = [
68        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.res",
69      ]
70      description = "RC {{output}}"
71    }
72
73    tool("asm") {
74      command = "$python_path gyp-win-tool asm-wrapper $env ml.exe {{defines}} {{include_dirs}} /c /Fo {{output}} {{source}}"
75      description = "ASM {{output}}"
76      outputs = [
77        "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
78      ]
79    }
80
81    tool("alink") {
82      rspfile = "{{output}}.rsp"
83      command = "$python_path gyp-win-tool link-wrapper $env False lib.exe /nologo /ignore:4221 /OUT:{{output}} @$rspfile"
84      description = "LIB {{output}}"
85      outputs = [
86        # Ignore {{output_extension}} and always use .lib, there's no reason to
87        # allow targets to override this extension on Windows.
88        "{{target_out_dir}}/{{target_output_name}}.lib",
89      ]
90      default_output_extension = ".lib"
91      # The use of inputs_newline is to work around a fixed per-line buffer
92      # size in the linker.
93      rspfile_content = "{{inputs_newline}}"
94    }
95
96    tool("solink") {
97      dllname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"  # e.g. foo.dll
98      libname = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.lib"  # e.g. foo.dll.lib
99      rspfile = "${dllname}.rsp"
100
101      link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:${dllname}.pdb @$rspfile"
102
103      # TODO(brettw) support manifests
104      #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:${dllname}.manifest"
105      #command = "cmd /c $link_command && $manifest_command"
106      command = link_command
107
108      default_output_extension = ".dll"
109      description = "LINK(DLL) {{output}}"
110      outputs = [
111        dllname,
112        libname,
113      ]
114      link_output = libname
115      depend_output = libname
116      # The use of inputs_newline is to work around a fixed per-line buffer
117      # size in the linker.
118      rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}"
119    }
120
121    tool("link") {
122      rspfile = "{{output}}.rsp"
123
124      link_command = "$python_path gyp-win-tool link-wrapper $env False link.exe /nologo /OUT:{{output}} /PDB:{{output}}.pdb @$rspfile"
125
126      # TODO(brettw) support manifests
127      #manifest_command = "$python_path gyp-win-tool manifest-wrapper $env mt.exe -nologo -manifest $manifests -out:{{output}}.manifest"
128      #command = "cmd /c $link_command && $manifest_command"
129      command = link_command
130
131      default_output_extension = ".exe"
132      description = "LINK {{output}}"
133      outputs = [
134        "{{root_out_dir}}/{{target_output_name}}{{output_extension}}",
135      ]
136      # The use of inputs_newline is to work around a fixed per-line buffer
137      # size in the linker.
138      rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
139    }
140
141    tool("stamp") {
142      command = "$python_path gyp-win-tool stamp {{output}}"
143      description = "STAMP {{output}}"
144    }
145
146    tool("copy") {
147      command =  "$python_path gyp-win-tool recursive-mirror {{source}} {{output}}"
148      description = "COPY {{source}} {{output}}"
149    }
150
151    # When invoking this toolchain not as the default one, these args will be
152    # passed to the build. They are ignored when this is the default toolchain.
153    toolchain_args() {
154      cpu_arch = invoker.cpu_arch
155
156      # Normally the build config resets the CPU architecture to 32-bits. Setting
157      # this flag overrides that behavior.
158      if (defined(invoker.force_win64)) {
159        force_win64 = invoker.force_win64
160      }
161    }
162  }
163}
164
165msvc_toolchain("32") {
166  environment = "environment.x86"
167  cpu_arch = "x64"
168}
169
170msvc_toolchain("64") {
171  environment = "environment.x64"
172  cpu_arch = "x64"
173  force_win64 = true
174}
175