rev: release-0.13 scopes/genie.lua -rw-r--r-- 10.1 KiB View raw Log this file
ece1aff350d0 — Leonard Ritter * clang bridge: only print alignment/size mismatch warnings in debug mode 2 years ago
                                                                                
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
local THISDIR = os.getcwd()
local CLANG_PATH
local MSYS_BASE_PATH = "C:/msys64"
local MINGW_BASE_PATH = MSYS_BASE_PATH .. "/mingw64"
local MSYS_BIN_PATH = MSYS_BASE_PATH .. "/usr/bin"
if os.is("linux") then
    CLANG_PATH = THISDIR .. "/clang/bin:/usr/local/bin:/usr/bin"
elseif os.is("windows") then
    CLANG_PATH = MINGW_BASE_PATH .. "/bin"
elseif os.is("macosx") then
    CLANG_PATH = THISDIR .. "/clang/bin:/usr/local/opt/llvm/bin:/usr/local/bin:/usr/bin"
else
    error("unsupported os")
end
local BINDIR = THISDIR .. "/bin"

local USE_ASAN_UBSAN = false

local function flatten(t)
    local result = {}
    local function iterate(t)
        for _,k in pairs(t) do
            if type(k) == "table" then
                iterate(k)
            elseif k ~= nil and k ~= "" then
                table.insert(result, k)
            end
        end
    end
    iterate(t)
    return result
end

local function pkg_config(cmd)
    local args = os.outputof(cmd)
    --print(cmd, "=>", args)
    return flatten(string.explode(args, "[ \n]+"))
end

local function finddir(name, searchpath)
    searchpath = searchpath or CLANG_PATH
    local path = os.pathsearch(name, searchpath)
    assert(path, name .. " not found in path " .. searchpath)
    return path .. "/" .. name
end

local function dllpath(name, searchpath)
    searchpath = searchpath or CLANG_PATH
    assert(os.is("windows"))
    name = name .. ".dll"
    local path = os.pathsearch(name, searchpath)
    assert(path, name .. " not found in path " .. searchpath)
    return path .. "/" .. name
end

local function toolpath(name, searchpath)
    searchpath = searchpath or CLANG_PATH
    if os.is("windows") then
        name = name .. ".exe"
    end
    local path = os.pathsearch(name, searchpath)
    assert(path, name .. " not found in path " .. searchpath)
    return path .. "/" .. name
end

local function print_list(l)
    for k,v in pairs(l) do
        print(k,v)
    end
end

local CLANG_CXX = toolpath("clang++", CLANG_PATH)
local CLANG_CC = toolpath("clang", CLANG_PATH)
local LLVM_CONFIG = toolpath("llvm-config", CLANG_PATH)

local LLVM_LDFLAGS = pkg_config(LLVM_CONFIG .. " --ldflags")
local LLVM_CXXFLAGS = pkg_config(LLVM_CONFIG .. " --cxxflags")
local LLVM_LIBS = pkg_config(LLVM_CONFIG .. " --link-static --libs engine passes option objcarcopts coverage support lto coroutines")

if not os.is("windows") then
    premake.gcc.cxx = CLANG_CXX
    premake.gcc.cc = CLANG_CC
    premake.gcc.llvm = true
end

solution "scopes"
    location "build"
    configurations { "debug", "release" }
    platforms { "native", "x64" }

project "scopes"
    kind "ConsoleApp"
    language "C++"
    files {
        "src/scopes.cpp",
        "external/linenoise-ng/src/linenoise.cpp",
        "external/linenoise-ng/src/ConvertUTF.cpp",
        "external/linenoise-ng/src/wcwidth.cpp",
        "external/glslang/SpvBuilder.cpp",
        "external/glslang/Logger.cpp",
        "external/glslang/InReadableOrder.cpp",
        "external/glslang/disassemble.cpp",
        "external/glslang/doc.cpp",
        "SPIRV-Cross/spirv_glsl.cpp",
        "SPIRV-Cross/spirv_cross.cpp",
        "SPIRV-Cross/spirv_cfg.cpp",
    }
    includedirs {
        "external/linenoise-ng/include",
        "external",
        "libffi/include",
        "SPIRV-Tools/include",
        "."
    }
    libdirs {
        --"bin",
        --"build/src/nanovg/build",
        --"build/src/tess2/Build",
        --"build/src/stk/src",
        --"build/src/nativefiledialog/src",
    }
    targetdir "bin"
    defines {
        "SCOPES_CPP_IMPL",
        "SCOPES_MAIN_CPP_IMPL",
        "SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS",
    }

    configuration { "linux" }
        defines { "SCOPES_LINUX" }

        includedirs {
            "clang/include"
        }

        buildoptions_cpp {
            "-std=c++11",
            "-fno-rtti",
            "-fno-exceptions",
            "-ferror-limit=1",
            "-pedantic",
            "-Wall",
            "-Wno-keyword-macro",
            "-Wno-gnu-redeclared-enum"
        }

        if USE_ASAN_UBSAN then
            local opts = {
                "-fsanitize=address",
                "-fsanitize-address-use-after-scope",
                "-fno-omit-frame-pointer",
                "-fsanitize=undefined",
                "-fno-common",
            }
            buildoptions_cpp(opts)
            buildoptions_c(opts)
            linkoptions(opts)
        end

        defines {
            --"_GLIBCXX_USE_CXX11_ABI=0",
        }

        links {
            "pthread", "m", "tinfo", "dl", "z",
        }

        linkoptions {
            --"-Wl,--stack,8388608"
            --"-Wl,--stack,16777216"
        }
        linkoptions {
            --"-Wl,--whole-archive",
            --"-l...",
            --"-Wl,--no-whole-archive",

            -- can't use this or our LLVM will collide with LLVM in other libs
            --"-Wl,--export-dynamic",
            --"-rdynamic",

            THISDIR .. "/libffi/.libs/libffi.a",
            THISDIR .. "/SPIRV-Tools/build/source/libSPIRV-Tools.a",
            THISDIR .. "/SPIRV-Tools/build/source/opt/libSPIRV-Tools-opt.a",
        }
        linkoptions(LLVM_LDFLAGS)
        linkoptions {
            "-lclangFrontend",
            "-lclangDriver",
            "-lclangSerialization",
            "-lclangCodeGen",
            "-lclangParse",
            "-lclangSema",
            "-lclangAnalysis",
            "-lclangEdit",
            "-lclangAST",
            "-lclangLex",
            "-lclangBasic"
        }
        --linkoptions { "-Wl,--whole-archive" }
        linkoptions(LLVM_LIBS)
        --linkoptions { "-Wl,--no-whole-archive" }

        postbuildcommands {
            -- BINDIR .. "/scopes " .. THISDIR .. "/testing/test_all.sc"
        }

    configuration { "windows" }
        buildoptions_cpp {
            "-D_GNU_SOURCE",
            "-Wa,-mbig-obj",
            "-std=gnu++11",
            "-fno-exceptions",
            "-fno-rtti",
            "-fno-strict-aliasing",
            "-D__STDC_CONSTANT_MACROS",
            "-D__STDC_FORMAT_MACROS",
            "-D__STDC_LIMIT_MACROS",
        }

        buildoptions_cpp {
            "-Wall",
        }

        -- gcc-only options
        buildoptions_cpp {
            "-Wno-error=date-time",
            "-fmax-errors=1",
            "-Wno-vla",
            "-Wno-enum-compare",
            "-Wno-comment",
            "-Wno-misleading-indentation",
            "-Wno-pragmas",
            "-Wno-return-type",
            "-Wno-variadic-macros",
            "-Wno-int-in-bool-context"
        }

        buildoptions_cpp {
            "-Wno-unused-variable",
            "-Wno-unused-function",
        }

        includedirs {
            "src/win32",
            MINGW_BASE_PATH .. "/lib/libffi-3.2.1/include"
        }

        files {
            "src/win32/mman.c",
            "src/win32/realpath.c",
            "src/win32/dlfcn.c",
        }

        defines {
            "SCOPES_WIN32",
        }

        buildoptions_c {
            "-Wno-shift-count-overflow"
        }

        links {
            "ffi", "uuid", "ole32", "psapi", "version", "stdc++",
        }

        linkoptions {
            "-Wl,--stack,8388608"
        }
        linkoptions {
            THISDIR .. "/SPIRV-Tools/build/source/libSPIRV-Tools.a",
            THISDIR .. "/SPIRV-Tools/build/source/opt/libSPIRV-Tools-opt.a",
        }
        linkoptions(LLVM_LDFLAGS)
        linkoptions {
            "-lclangFrontend",
            "-lclangDriver",
            "-lclangSerialization",
            "-lclangCodeGen",
            "-lclangParse",
            "-lclangSema",
            "-lclangAnalysis",
            "-lclangEdit",
            "-lclangAST",
            "-lclangLex",
            "-lclangBasic"
        }
        linkoptions(LLVM_LIBS)

        if os.is("windows") then
            local CP = toolpath("cp", MSYS_BIN_PATH)

            postbuildcommands {
                CP .. " -v " .. dllpath("libffi-6") .. " " .. BINDIR,
                CP .. " -v " .. dllpath("libgcc_s_seh-1") .. " " .. BINDIR,
                CP .. " -v " .. dllpath("libstdc++-6") .. " " .. BINDIR,
                CP .. " -v " .. dllpath("libwinpthread-1") .. " " .. BINDIR,
            }
        end

        postbuildcommands {
            -- BINDIR .. "/scopes " .. THISDIR .. "/testing/test_all.sc"
        }

    configuration { "macosx" }
        defines { "SCOPES_MACOS" }

        includedirs {
            "clang/include",
            "/usr/local/opt/llvm/include"
        }

        buildoptions_cpp {
            "-std=c++11",
            "-fno-rtti",
            "-fno-exceptions",
            "-ferror-limit=1",
            "-pedantic",
            "-Wall",
            "-Wno-keyword-macro",
            "-Wno-gnu-redeclared-enum",
        }

        if USE_ASAN_UBSAN then
            local opts = {
                "-fsanitize=address",
                "-fsanitize-address-use-after-scope",
                "-fno-omit-frame-pointer",
                "-fsanitize=undefined",
                "-fno-common",
            }
            buildoptions_cpp(opts)
            buildoptions_c(opts)
            linkoptions(opts)
        end

        links {
            "pthread", "m", "ncurses", "dl", "z",
        }

        linkoptions {
            THISDIR .. "/libffi/lib/libffi.a",
            THISDIR .. "/SPIRV-Tools/build/source/libSPIRV-Tools.a",
            THISDIR .. "/SPIRV-Tools/build/source/opt/libSPIRV-Tools-opt.a",
        }

        linkoptions(LLVM_LDFLAGS)

        linkoptions {
            "-lclangFrontend",
            "-lclangDriver",
            "-lclangSerialization",
            "-lclangCodeGen",
            "-lclangParse",
            "-lclangSema",
            "-lclangAnalysis",
            "-lclangEdit",
            "-lclangAST",
            "-lclangLex",
            "-lclangBasic"
        }

        linkoptions(LLVM_LIBS)

        postbuildcommands {
            -- BINDIR .. "/scopes " .. THISDIR .. "/testing/test_all.sc"
        }

    configuration "debug"
        defines { "SCOPES_DEBUG" }
        flags { "Symbols" }

        buildoptions_cpp {
            "-O0"
        }

    configuration "release"
        defines { "NDEBUG" }
        flags { "Optimize" }