Skip to content

Commit d0baae9

Browse files
authored
Add support for windows with MSVC toolchain (#97)
* Add nmake file for building with windows MSVC * Fix function export for msvc build * Add MSVC target to test matrix * [ci] Use patched luarocks to fix msvc setup * [ci] Add workaround for missing compat53 * [ci] Use patched luarocks to avoid compat53 issue * [ci] Update to upstream version of luarocks The patch for the lua compat53 issue has been merged now
1 parent 3b62d49 commit d0baae9

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ jobs:
4646
fail-fast: false
4747
matrix:
4848
lua: [lua=5.1, lua=5.2, lua=5.3, lua=5.4, luajit=2.0, luajit=2.1]
49+
target: [mingw,vs]
4950
runs-on: windows-2022
5051
steps:
5152
# Checks-out the repository under $GITHUB_WORKSPACE.
5253
- uses: actions/checkout@v4
5354
- name: Install Lua (${{ matrix.lua }})
5455
run: |
5556
pip install hererocks
56-
hererocks lua_install -r@3a142ce --${{ matrix.lua }}
57+
hererocks lua_install -r@28f9d98 --${{ matrix.lua }} --target ${{ matrix.target }}
5758
- name: Build lua-simdjson
5859
run: |
5960
.\lua_install\bin\activate

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ test/
33
*.dll
44
*.o
55
*.d
6+
7+
# msvc
8+
*.obj
9+
*.lib
10+
*.exp

Makefile.win

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
OBJ = src/luasimdjson.obj src/simdjson.obj
2+
CPPFLAGS = -I$(LUA_INCDIR)
3+
CXXFLAGS = -EHsc -std:c++17 $(CFLAGS)
4+
LDFLAGS = $(LIBFLAG)
5+
6+
!ifdef LUA_LIBDIR
7+
LDLIBS = $(LUA_LIBDIR)/$(LUALIB)
8+
!endif
9+
10+
TARGET = simdjson.dll
11+
12+
all: $(TARGET)
13+
14+
src/luasimdjson.obj: src/luasimdjson.h src/simdjson.h
15+
src/simdjson.obj: src/simdjson.h
16+
17+
.cpp.obj::
18+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -Fo:"src\\"
19+
20+
$(TARGET): $(OBJ)
21+
$(LD) $(LDFLAGS) $** -out:$@ $(LDLIBS)
22+
23+
clean:
24+
del *.dll src\*.obj *.lib *.exp 2>nul
25+
26+
install: $(TARGET)
27+
copy $(TARGET) $(INST_LIBDIR)

lua-simdjson-0.0.6-1.rockspec

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ build = {
3636
build_variables = {
3737
LUA_LIBDIR="$(LUA_LIBDIR)",
3838
LUALIB="$(LUALIB)",
39+
LD="$(LD)",
3940
}
4041
}
4142
}

src/luasimdjson.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
#include <lua.hpp>
2+
3+
#ifdef _MSC_VER
4+
#define LUASIMDJSON_EXPORT __declspec(dllexport)
5+
#else
6+
#define LUASIMDJSON_EXPORT extern
7+
#endif
8+
29
extern "C" {
310
static int parse(lua_State*);
411
static int parse_file(lua_State*);
512
static int active_implementation(lua_State*);
613
static int ParsedObject_open(lua_State*);
714
static int ParsedObject_open_file(lua_State*);
815

9-
1016
static const struct luaL_Reg luasimdjson[] = {
1117
{"parse", parse},
1218
{"parseFile", parse_file},
1319
{"activeImplementation", active_implementation},
1420
{"open", ParsedObject_open},
1521
{"openFile", ParsedObject_open_file},
16-
22+
1723
{NULL, NULL},
1824
};
19-
int luaopen_simdjson (lua_State*);
25+
LUASIMDJSON_EXPORT int luaopen_simdjson(lua_State*);
2026
}

0 commit comments

Comments
 (0)