Skip to content

Commit 41264cb

Browse files
committed
build lua on Windows
1 parent 1d46b79 commit 41264cb

11 files changed

Lines changed: 106 additions & 0 deletions

File tree

build.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ fn addLua(
365365
lua_exe.addIncludePath("inc" ++ std.fs.path.sep_str ++ "libc");
366366
lua_exe.linkLibrary(libc_only_std_static);
367367
lua_exe.linkLibrary(zig_start);
368+
// TODO: should libc_only_std_static and zig_start be able to add library dependencies?
369+
if (target.getOs().tag == .windows) {
370+
lua_exe.addIncludePath("inc/win32");
371+
lua_exe.linkSystemLibrary("ntdll");
372+
lua_exe.linkSystemLibrary("kernel32");
373+
}
368374

369375
const step = b.step("lua", "build the LUA interpreter");
370376
step.dependOn(&lua_exe.install_step.?.step);

inc/libc/stdio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,8 @@ void perror(const char *s);
100100
#define FOPEN_MAX 999
101101
#endif
102102

103+
#ifdef _WIN32
104+
FILE *_popen(const char *command, const char *mode);
105+
#endif
103106

104107
#endif /* _STDIO_H */

inc/win32/basetcsd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _BASETSD_H
2+
#define _BASETSD_H
3+
4+
#include "private/types.h"
5+
6+
#endif /* _BASETSD_H */

inc/win32/errhandlingapi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef _ERRHANDLINGAPI_H
2+
#define _ERRHANDLINGAPI_H
3+
4+
#include "private/types.h"
5+
DWORD GetLastError();
6+
7+
#endif /* _ERRHANDLINGAPI_H */

inc/win32/io.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef _IO_H
2+
#define _IO_H
3+
4+
// NOTE: I'm not sure if Windows even provides this header but
5+
// lua wants it if compiling for windows I guess?
6+
7+
#endif /* _IO_H */

inc/win32/libloaderapi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef _LIBLOADERAPI_H
2+
#define _LIBLOADERAPI_H
3+
4+
HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
5+
BOOL FreeLibrary(HMODULE hLibModule);
6+
DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
7+
8+
#endif /* _LIBLOADERAPI_H */

inc/win32/private/types.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef _WIN32_PRIVATE_TYPES_H
2+
#define _WIN32_PRIVATE_TYPES_H
3+
4+
#include "../../libc/private/int32_t.h"
5+
6+
#define _nullterminated
7+
8+
typedef int BOOL;
9+
typedef void *PVOID;
10+
typedef const void *LPCVOID;
11+
typedef int32_t DWORD;
12+
typedef char CHAR;
13+
typedef CHAR *LPSTR;
14+
typedef _nullterminated const char *LPCSTR;
15+
typedef void *HMODULE;
16+
typedef PVOID HANDLE;
17+
18+
#ifdef UNICODE
19+
typedef LPWSTR LPTSTR;
20+
#else
21+
typedef LPSTR LPTSTR;
22+
#endif
23+
24+
#endif /* _WIN32_PRIVATE_TYPES_H */

inc/win32/winbase.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef _WINBASE_H
2+
#define _WINBASE_H
3+
4+
DWORD FormatMessageA(
5+
DWORD dwFlags,
6+
LPCVOID lpSource,
7+
DWORD dwMessageId,
8+
DWORD dwLanguageId,
9+
LPTSTR lpBuffer,
10+
DWORD nSize,
11+
va_list *Arguments);
12+
13+
#define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x00000100
14+
#define FORMAT_MESSAGE_ARGUMENT_ARRAY 0x00002000
15+
#define FORMAT_MESSAGE_FROM_HMODULE 0x00000800
16+
#define FORMAT_MESSAGE_FROM_STRING 0x00000400
17+
#define FORMAT_MESSAGE_FROM_SYSTEM 0x00001000
18+
#define FORMAT_MESSAGE_IGNORE_INSERTS 0x00000200
19+
#define FORMAT_MESSAGE_FROM_SYSTEM 0x00001000
20+
21+
#endif /* _WINBASE_H */

inc/win32/windef.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _WINDEF_H
2+
#define _WINDEF_H
3+
4+
#include "private/types.h"
5+
6+
#endif /* _WINDEF_H */

inc/win32/windows.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef _WINDOWS_H
2+
#define _WINDOWS_H
3+
4+
#include "private/types.h"
5+
6+
#include "winbase.h"
7+
#include "errhandlingapi.h"
8+
#include "libloaderapi.h"
9+
10+
#define MAX_PATH 260
11+
12+
#endif /* _WINDOWS_H */

0 commit comments

Comments
 (0)