Last active
April 10, 2016 21:50
-
-
Save moteus/7042134 to your computer and use it in GitHub Desktop.
lake file for luaffi library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
J = path.join | |
function dasc_target(t) | |
local DASC = LUA_EXE .. ' ' .. path.join('dynasm', 'dynasm.lua') | |
local dasc_h = {} | |
for name, args in pairs(t) do | |
local dasc = target(name .. ".h", args[1] .. ".dasc", DASC .. ' ' .. (args[2] or "") .. ' -o $(TARGET) $(DEPENDS) ') | |
table.insert(dasc_h, dasc) | |
end | |
return dasc_h | |
end | |
function run(runner, file, cwd) | |
print() | |
print("run " .. file) | |
if not TESTING then | |
if cwd then lake.chdir(cwd) end | |
local status, code = utils.execute( runner .. ' ' .. file ) | |
if cwd then lake.chdir("<") end | |
print() | |
return status, code | |
end | |
return true, 0 | |
end | |
function run_test(runner, name, params) | |
local test_dir = '.' | |
local cmd = J(test_dir, name) | |
if params then cmd = cmd .. ' ' .. params end | |
local ok = run(runner, cmd, test_dir) | |
print("TEST " .. name .. (ok and ' - pass!' or ' - fail!')) | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local INCDIR = IF(MSVC, "msvc") | |
local DEFINES = L{ | |
IF(MSVC, "_CRT_SECURE_NO_DEPRECATE"), | |
IF(WINDOWS and not MSVC, "_WIN32_WINNT=0x0501"), -- mingw | |
} | |
local DYNAMIC = false | |
dasc_h = dasc_target{ | |
call_x86 = {"call_x86", "-LNE -D X32WIN" }; | |
call_x64 = {"call_x86", "-LNE -D X64" }; | |
call_x64win = {"call_x86", "-LNE -D X64 -D X64WIN" }; | |
call_arm = {"call_arm", "-LNE" }; | |
} | |
ffi = c.shared{"ffi", | |
src = {"call", "ctype", "ffi", "parser"}; | |
needs = {"lua"}; | |
defines = L{"LUA_FFI_BUILD_AS_DLL", DEFINES}; | |
incdir = INCDIR; | |
dynamic = DYNAMIC; | |
compile_deps = dasc_h; | |
libflags = IF(MSVC and not DYNAMIC, {"/EXPORT:sprintf", "/EXPORT:strncmp"}); | |
} | |
target("build", ffi) | |
if MSVC then | |
local copy = function(dst, src) | |
return target(dst, src, '$(COPY) $(DEPENDS) $(TARGET)') | |
end | |
test_cdecl = c.shared{"test_cdecl", | |
src = copy("test_cdecl.c", "test.c"); | |
cflags = "/Gd"; | |
defines = DEFINES; | |
incdir = INCDIR; | |
dynamic = DYNAMIC; | |
} | |
test_stdcall = c.shared{"test_stdcall", | |
src = copy("test_stdcall.c", "test.c"); | |
cflags = "/Gz", | |
defines = DEFINES; | |
incdir = INCDIR; | |
dynamic = DYNAMIC; | |
} | |
test_fastcall = c.shared{"test_fastcall", | |
src = copy("test_fastcall.c", "test.c"); | |
cflags = "/Gr", | |
defines = DEFINES; | |
incdir = INCDIR; | |
dynamic = DYNAMIC; | |
} | |
test_deps = {test_cdecl, test_stdcall, test_fastcall} | |
else | |
test_cdecl = c.shared{"test_cdecl", | |
src = "test"; | |
defines = DEFINES; | |
incdir = INCDIR; | |
dynamic = DYNAMIC; | |
} | |
test_deps = {test_cdecl} | |
end | |
table.insert(test_deps, 1, ffi) | |
target("test", test_deps, function() | |
run_test(LUA_EXE, "test.lua") | |
end) | |
default(ffi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment