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
build / toolchain / win / midl.gni [blame]
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
assert(is_win)
import("//build/config/win/visual_studio_version.gni")
# This template defines a rule to invoke the MS IDL compiler. The generated
# source code will be compiled and linked into targets that depend on this.
#
# Parameters
#
# sources
# List of .idl file to process.
#
# header_file (optional)
# File name of generated header file. Defaults to the basename of the
# source idl file with a .h extension.
#
# out_dir (optional)
# Directory to write the generated files to. Defaults to target_gen_dir.
#
# generated_dir (optional)
# Directory where generated files were previously persisted.
# Defaults to third_party\win_build_output\midl\|out_dir|.
#
# dynamic_guids (optional)
# If the GUIDs are not constant across builds, the current GUID
# substitutions.
# |dynamic_guids| is of the form:
# "PLACEHOLDER-GUID-158428a4-6014-4978-83ba-9fad0dabe791="
# "3d852661-c795-4d20-9b95-5561e9a1d2d9,"
# "PLACEHOLDER-GUID-63B8FFB1-5314-48C9-9C57-93EC8BC6184B="
# "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83".
# See midl.py for more details.
#
# writes_tlb (optional)
# Whether a .tlb file should be added to outputs. Defaults to false.
#
# writes_proxy(optional)
# Whether a _p.c file should be added to outputs. Defaults to true.
#
# writes_dlldata(optional)
# Whether a .dlldata.c file should be added to outputs. Defaults to true.
#
# deps (optional)
#
# defines (optional)
# Build time defines to be passed to midl.exe as /D parameter.
#
# testonly (optional)
#
# visibility (optional)
template("midl") {
action_name = "${target_name}_idl_action"
source_set_name = target_name
assert(defined(invoker.sources), "Source must be defined for $target_name")
if (defined(invoker.out_dir)) {
out_dir = invoker.out_dir
} else {
out_dir = target_gen_dir
}
if (defined(invoker.generated_dir)) {
generated_dir = rebase_path(invoker.generated_dir, root_build_dir)
} else {
# midl.py expects 'gen' to be replaced with 'midl'.
generated_dir =
rebase_path("//third_party/win_build_output", root_build_dir) +
"/midl/" + rebase_path(out_dir, root_gen_dir)
}
if (defined(invoker.dynamic_guids)) {
dynamic_guids = invoker.dynamic_guids
} else {
dynamic_guids = "none"
}
if (defined(invoker.header_file)) {
header_file = invoker.header_file
} else {
header_file = "{{source_name_part}}.h"
}
if (defined(invoker.writes_tlb)) {
writes_tlb = invoker.writes_tlb
} else {
writes_tlb = false
}
if (defined(invoker.writes_proxy)) {
writes_proxy = invoker.writes_proxy
} else {
writes_proxy = true
}
if (defined(invoker.writes_dlldata)) {
writes_dlldata = invoker.writes_dlldata
} else {
writes_dlldata = true
}
if (writes_tlb) {
type_library_file = "{{source_name_part}}.tlb"
} else {
type_library_file = "none"
}
if (writes_dlldata) {
dlldata_file = "{{source_name_part}}.dlldata.c"
} else {
dlldata_file = "none"
}
if (writes_proxy) {
proxy_file = "{{source_name_part}}_p.c"
} else {
proxy_file = "none"
}
interface_identifier_file = "{{source_name_part}}_i.c"
action_foreach(action_name) {
visibility = [ ":$source_set_name" ]
script = "//build/toolchain/win/midl.py"
sources = invoker.sources
outputs = [
"$out_dir/$header_file",
"$out_dir/$interface_identifier_file",
]
# These files are only added to outputs if the invoker so desires, as it
# they are not always generated depending on the content of the input idl
# file.
if (writes_tlb) {
outputs += [ "$out_dir/$type_library_file" ]
}
if (writes_dlldata) {
outputs += [ "$out_dir/$dlldata_file" ]
}
if (writes_proxy) {
outputs += [ "$out_dir/$proxy_file" ]
}
if (current_cpu == "x86") {
win_tool_arch = "environment.x86"
idl_target_platform = "win32"
} else if (current_cpu == "x64") {
win_tool_arch = "environment.x64"
idl_target_platform = "x64"
} else if (current_cpu == "arm64") {
win_tool_arch = "environment.arm64"
idl_target_platform = "arm64"
} else {
assert(false, "Need environment for this arch")
}
args = [
win_tool_arch,
generated_dir,
rebase_path(out_dir, root_build_dir),
dynamic_guids,
type_library_file,
header_file,
dlldata_file,
interface_identifier_file,
proxy_file,
rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang-cl.exe",
root_build_dir),
"{{source}}",
"/char",
"signed",
"/env",
idl_target_platform,
"/Oicf",
]
if (defined(invoker.defines)) {
foreach(define, invoker.defines) {
args += [ "/D" + define ]
}
}
forward_variables_from(invoker,
[
"deps",
"testonly",
])
}
source_set(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
# We only compile the IID files from the IDL tool rather than all outputs.
sources = process_file_template(invoker.sources,
[ "$out_dir/$interface_identifier_file" ])
public_deps = [ ":$action_name" ]
}
}