-
Notifications
You must be signed in to change notification settings - Fork 5
/
emscripten.lua
298 lines (232 loc) · 6.3 KB
/
emscripten.lua
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
--
-- emscripten.lua
--
local p = premake
p.tools.emscripten = {}
local emscripten = p.tools.emscripten
local clang = p.tools.clang
local config = p.config
local api = p.api
api.addAllowed("architecture", "wasm")
--
-- Build a list of flags for the C preprocessor corresponding to the
-- settings in a particular project configuration.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C preprocessor flags.
--
function emscripten.getcppflags(cfg)
-- Just pass through to clang for now
local flags = clang.getcppflags(cfg)
return flags
end
--
-- Build a list of C compiler flags corresponding to the settings in
-- a particular project configuration. These flags are exclusive
-- of the C++ compiler flags, there is no overlap.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C compiler flags.
--
emscripten.shared = table.merge(clang.shared, {
})
emscripten.cflags = table.merge(clang.cflags, {
})
function emscripten.getcflags(cfg)
local shared = config.mapFlags(cfg, emscripten.shared)
local cflags = config.mapFlags(cfg, emscripten.cflags)
local flags = table.join(shared, cflags)
flags = table.join(flags, emscripten.getwarnings(cfg))
return flags
end
function emscripten.getwarnings(cfg)
return clang.getwarnings(cfg)
end
--
-- Build a list of C++ compiler flags corresponding to the settings
-- in a particular project configuration. These flags are exclusive
-- of the C compiler flags, there is no overlap.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C++ compiler flags.
--
emscripten.cxxflags = table.merge(clang.cxxflags, {
})
function emscripten.getcxxflags(cfg)
local shared = config.mapFlags(cfg, emscripten.shared)
local cxxflags = config.mapFlags(cfg, emscripten.cxxflags)
local flags = table.join(shared, cxxflags)
flags = table.join(flags, emscripten.getwarnings(cfg))
return flags
end
--
-- Returns a list of defined preprocessor symbols, decorated for
-- the compiler command line.
--
-- @param defines
-- An array of preprocessor symbols to define; as an array of
-- string values.
-- @return
-- An array of symbols with the appropriate flag decorations.
--
function emscripten.getdefines(defines)
-- Just pass through to clang for now
local flags = clang.getdefines(defines)
return flags
end
function emscripten.getundefines(undefines)
-- Just pass through to clang for now
local flags = clang.getundefines(undefines)
return flags
end
--
-- Returns a list of forced include files, decorated for the compiler
-- command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of force include files with the appropriate flags.
--
function emscripten.getforceincludes(cfg)
-- Just pass through to clang for now
local flags = clang.getforceincludes(cfg)
return flags
end
--
-- Returns a list of include file search directories, decorated for
-- the compiler command line.
--
-- @param cfg
-- The project configuration.
-- @param dirs
-- An array of include file search directories; as an array of
-- string values.
-- @return
-- An array of symbols with the appropriate flag decorations.
--
function emscripten.getincludedirs(cfg, dirs, sysdirs)
-- Just pass through to clang for now
local flags = clang.getincludedirs(cfg, dirs, sysdirs)
return flags
end
emscripten.getrunpathdirs = clang.getrunpathdirs
--
-- get the right output flag.
--
function emscripten.getsharedlibarg(cfg)
return clang.getsharedlibarg(cfg)
end
--
-- Build a list of linker flags corresponding to the settings in
-- a particular project configuration.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of linker flags.
--
emscripten.ldflags = {
architecture = {
wasm = "",
},
flags = {
LinkTimeOptimization = "-flto",
},
kind = {
SharedLib = function(cfg)
local r = { emscripten.getsharedlibarg(cfg) }
return r
end,
},
system = {
wii = "$(MACHDEP)",
},
optimize = {
On = "-O2",
Size = "-Os",
},
}
function emscripten.getldflags(cfg)
local flags = config.mapFlags(cfg, emscripten.ldflags)
return flags
end
--
-- Build a list of additional library directories for a particular
-- project configuration, decorated for the tool command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of decorated additional library directories.
--
function emscripten.getLibraryDirectories(cfg)
-- Just pass through to clang for now
local flags = clang.getLibraryDirectories(cfg)
return flags
end
--
-- Build a list of libraries to be linked for a particular project
-- configuration, decorated for the linker command line.
--
-- @param cfg
-- The project configuration.
-- @param systemOnly
-- Boolean flag indicating whether to link only system libraries,
-- or system libraries and sibling projects as well.
-- @return
-- A list of libraries to link, decorated for the linker.
--
function emscripten.getlinks(cfg, systemonly, nogroups)
return clang.getlinks(cfg, systemonly, nogroups)
end
--
-- Return a list of makefile-specific configuration rules. This will
-- be going away when I get a chance to overhaul these adapters.
--
-- @param cfg
-- The project configuration.
-- @return
-- A list of additional makefile rules.
--
function emscripten.getmakesettings(cfg)
-- Just pass through to clang for now
local flags = clang.getmakesettings(cfg)
return flags
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment. I will
-- be moving these into global configuration blocks when I get
-- the chance.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
emscripten.tools = {
cc = "emcc",
cxx = "em++",
ar = "emar"
}
function emscripten.gettoolname(cfg, tool)
return emscripten.tools[tool]
end
filter { "architecture:wasm" }
toolset "emscripten"
filter { "architecture:wasm" }
targetextension ".js"
filter { "architecture:wasm", "kind:StaticLib" }
targetextension ".bc"
filter {}