Skip to content

Commit

Permalink
Merge branch 'master' into windows-support-again
Browse files Browse the repository at this point in the history
  • Loading branch information
dargueta committed Sep 22, 2024
2 parents d77fbe6 + de922a5 commit 60504a6
Show file tree
Hide file tree
Showing 36 changed files with 124 additions and 116 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
matrix:
operating-system:
- ubuntu-latest
- macos-13
- macos-latest
lua-version:
- "5.1"
- "5.2"
Expand All @@ -23,6 +23,26 @@ jobs:
unicorn-version:
- "1.0.3"
- "2.0.1.post1"
exclude:
# Unicorn 1.x breaks on macOS 14+
- operating-system: macos-latest
unicorn-version: "1.0.3"
include:
- operating-system: macos-13
unicorn-version: "1.0.3"
lua-version: "5.1"
- operating-system: macos-13
unicorn-version: "1.0.3"
lua-version: "5.2"
- operating-system: macos-13
unicorn-version: "1.0.3"
lua-version: "5.3"
- operating-system: macos-13
unicorn-version: "1.0.3"
lua-version: "5.4"
- operating-system: macos-13
unicorn-version: "1.0.3"
lua-version: "luajit-openresty"
steps:
- uses: actions/[email protected]
with:
Expand All @@ -43,8 +63,12 @@ jobs:
run: luarocks config
- name: Install Binding
run: luarocks build
env:
USER_CXX_FLAGS: -Wall -Wextra -Werror -Wpedantic -pedantic-errors
- name: Run tests
run: luarocks test
env:
USER_CXX_FLAGS: -Wall -Wextra -Werror -Wpedantic -pedantic-errors

testing-windows:
runs-on: windows-latest
Expand Down
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
*.a
*.lib
.git/
build/
tests/c/doctest.h
.idea/
.vscode/

# Autogenerated files:
src/constants/
src/basic_control_functions.cpp
src/registers.cpp
src/registers_const.cpp
src/unicornlua/register_types.hpp
csrc/*_const.cpp
csrc/cpp_test
csrc/basic_control_functions.cpp
csrc/registers.cpp
csrc/registers_const.cpp
csrc/unicornlua/register_types.hpp

# Other garbage
core*
Expand Down
129 changes: 56 additions & 73 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# WARNING: This makefile is intended to be invoked by LuaRocks, not manually.
# WARNING: This makefile is intended to be invoked by LuaRocks, not manually. Only use
# it form `clean`, `format` and if your IDE is grumpy, `autogen-files` might work.

# Disable all default build rules so that we have full control.
# If we don't disable suffixes, Make fails to detect our default %.o rule because it has
# extra prerequisites. Because of this, it falls back to its internal built-in recipe for
# %.o from %.cpp. This default rule doesn't have any of the header search paths, and will
# fail.
.SUFFIXES:

################################################################################
# DEFAULTS
# These are only used when this Makefile is run manually. You should only be
# doing that for `make clean`. Use `luarocks` for everything else.

CP = cp
CURL = curl
LIB_EXTENSION = so
LUAROCKS = luarocks
get_luarocks_var = $(shell $(LUAROCKS) config variables.$1)

BUSTED := $(call get_luarocks_var,SCRIPTS_DIR)/busted
CC := $(call get_luarocks_var,CC)
CXXFLAGS := $(call get_luarocks_var,CFLAGS)
CURL := $(call get_luarocks_var,CURL)
LD := $(call get_luarocks_var,LD)
LIBFLAG := $(call get_luarocks_var,LIBFLAG)
LIB_EXTENSION := $(call get_luarocks_var,LIB_EXTENSION)
LUA := $(call get_luarocks_var,LUA)
LUA_DIR := $(call get_luarocks_var,LUA_DIR)
LUA_INCDIR := $(call get_luarocks_var,LUA_INCDIR)
LUA_LIBDIR := $(call get_luarocks_var,LUA_LIBDIR)
LUA_VERSION := $(call get_luarocks_var,LUA_VERSION)
MKDIR := $(call get_luarocks_var,MKDIR)
OBJ_EXTENSION := $(call get_luarocks_var,OBJ_EXTENSION)
MKDIR = mkdir
OBJ_EXTENSION = o
UNICORN_INCDIR = /usr/include

BUSTED := $(shell $(LUAROCKS) config variables.SCRIPTS_DIR)/busted
LIBFLAG := $(shell $(LUAROCKS) config variables.LIBFLAG)
LUA := $(shell $(LUAROCKS) config variables.LUA)
LUA_DIR := $(shell $(LUAROCKS) config variables.LUA_DIR)
LUA_INCDIR = $(LUA_DIR)/include
LUA_LIBDIR = $(LUA_DIR)/lib
LUA_VERSION = $(shell $(LUA) -e 'print(_VERSION:sub(5))')

################################################################################

# Disable 64-bit integer tests for Lua <5.3
Expand All @@ -53,52 +54,47 @@ else
FALLBACK_LUA_INCDIR = $(LUA_DIR)/include
endif

BUILD_DIR = $(CURDIR)/build

ARCHITECTURE_HEADERS = $(wildcard $(UNICORN_INCDIR)/unicorn/*.h)
ARCHITECTURE_SLUGS = $(filter-out platform,$(basename $(notdir $(ARCHITECTURE_HEADERS))))

CONSTS_DIR = src/constants
CONSTANT_FILES = $(foreach s,$(ARCHITECTURE_SLUGS),$(CONSTS_DIR)/$(s)_const.cpp)
SOURCE_DIR = csrc
CONSTANT_FILES = $(foreach s,$(ARCHITECTURE_SLUGS),$(SOURCE_DIR)/$(s)_const.cpp)

CPP_TEMPLATE_SOURCES = $(wildcard src/*.template)
CPP_TEMPLATE_SOURCES = $(wildcard $(SOURCE_DIR)/*.template)
AUTOGENERATED_CPP_FILES = $(CPP_TEMPLATE_SOURCES:.template=.cpp)

HEADER_TEMPLATE_SOURCES = $(wildcard src/unicornlua/*.template)
HEADER_TEMPLATE_SOURCES = $(wildcard $(SOURCE_DIR)/unicornlua/*.template)
AUTOGENERATED_HPP_FILES = $(HEADER_TEMPLATE_SOURCES:.template=.hpp)

LIB_BUILD_TARGET = $(BUILD_DIR)/unicorn.$(LIB_EXTENSION)
LIB_CPP_SOURCES = $(wildcard src/*.cpp) $(CONSTANT_FILES) $(AUTOGENERATED_CPP_FILES)
LIB_BUILD_TARGET = $(SOURCE_DIR)/unicorn.$(LIB_EXTENSION)
LIB_CPP_SOURCES = $(wildcard $(SOURCE_DIR)/*.cpp) $(CONSTANT_FILES) $(AUTOGENERATED_CPP_FILES)
LIB_OBJECT_FILES = $(LIB_CPP_SOURCES:.cpp=.$(OBJ_EXTENSION))

TEST_EXECUTABLE = $(BUILD_DIR)/cpp_test
TEST_EXECUTABLE = $(SOURCE_DIR)/cpp_test
TEST_CPP_SOURCES = $(wildcard tests/c/*.cpp)
TEST_LUA_SOURCES = $(wildcard tests/lua/*.lua)
TEST_HEADERS = $(wildcard tests/c/*.hpp)
TEST_CPP_OBJECT_FILES = $(TEST_CPP_SOURCES:.cpp=.$(OBJ_EXTENSION))

TEMPLATE_DATA_FILES = $(wildcard src/template_data/*.lua)
TEMPLATE_DATA_FILES = $(wildcard $(SOURCE_DIR)/template_data/*.lua)

# Unicorn 1.x gets put into places not on the typical linker search path, so we need to
# hardcode these additional directories it could appear in.
LIBRARY_DIRECTORIES = $(strip $(LUA_LIBDIR) $(UNICORN_LIBDIR) $(PTHREAD_LIBDIR) /usr/lib64 /usr/local/lib)

# The hardcoded version-specific paths here are fallbacks because my IDE can't find the
# Lua headers without them. Is it necessary? No. Will it cause problems? Unlikely. But
# without it, every file is a sea of red squiggles and I'm. Losing. My. Mind.
HEADER_DIRECTORIES = $(strip \
src \
$(SOURCE_DIR) \
$(LUA_INCDIR) \
$(FALLBACK_LUA_INCDIR) \
$(UNICORN_INCDIR) \
/usr/local/include \
/usr/include/lua$(LUA_VERSION) \
/usr/local/include/lua$(LUA_VERSION))

ifndef USER_CXX_FLAGS
USER_CXX_FLAGS =
endif

OTHER_CXXFLAGS = -std=c++11 -DIS_LUAJIT=$(IS_LUAJIT)
WARN_FLAGS = -Wall -Wextra -Werror -Wpedantic -pedantic-errors
INCLUDE_PATH_FLAGS = $(addprefix -I,$(HEADER_DIRECTORIES))
LIB_PATH_FLAGS = $(addprefix -L,$(LIBRARY_DIRECTORIES))
REQUIRED_LIBS = unicorn pthread stdc++
Expand All @@ -110,11 +106,7 @@ REQUIRED_LIBS_FLAGS = $(addprefix -l,$(REQUIRED_LIBS))
LINK_TO_LUA_FLAG = $(if $(LUALIB),-l:$(LUALIB),-l$(DEFAULT_LUA_LIB_NAME))

# https://github.com/PowerDNS/pdns/issues/4295
ifndef OS
OS = $(shell uname -s)
endif

ifeq ($(OS),Darwin)
ifeq ($(shell uname -s),Darwin)
ifeq ($(IS_LUAJIT),1)
# This workaround isn't needed for LuaJIT 2.1+
ifeq ($(LUAJIT_VERSION),2.0)
Expand All @@ -123,7 +115,10 @@ ifeq ($(OS),Darwin)
endif
endif

CXX_CMD = $(CC) $(OTHER_CXXFLAGS) $(USER_CXX_FLAGS) $(WARN_FLAGS) $(INCLUDE_PATH_FLAGS)

# On MacOS, we need to explicitly tell the compiler to use C++11 because it defaults to an
# older standard. GCC on Linux appears to work fine without it.
CXX_CMD = $(CXX) $(USER_CXX_FLAGS) $(INCLUDE_PATH_FLAGS) -std=c++11
LINK_CMD = $(LD) $(LIB_PATH_FLAGS) $(LDFLAGS)

DOCTEST_TAG = v2.4.11
Expand All @@ -144,28 +139,24 @@ _space = $(_empty) $(_empty)

LIBRARY_COLON_PATHS = $(subst $(_space),:,$(LIBRARY_DIRECTORIES))

# DYLD_FALLBACK_LIBRARY_PATH is for MacOS, LD_LIBRARY_PATH is for all other *NIX systems.
export LD_LIBRARY_PATH := $(LIBRARY_COLON_PATHS):$(LD_LIBRARY_PATH)
export DYLD_FALLBACK_LIBRARY_PATH := $(LIBRARY_COLON_PATHS):$(DYLD_FALLBACK_LIBRARY_PATH)
export LUA_PATH := $(shell $(LUAROCKS) path --lr-path)
export LUA_CPATH := $(shell $(LUAROCKS) path --lr-cpath)
export PATH := $(shell $(LUAROCKS) path --lr-bin):$(PATH)
# DYLD_FALLBACK_LIBRARY_PATH is for MacOS, LD_LIBRARY_PATH is for all other *NIX systems.
export LD_LIBRARY_PATH := $(LIBRARY_COLON_PATHS):$(LD_LIBRARY_PATH)
export DYLD_FALLBACK_LIBRARY_PATH := $(LIBRARY_COLON_PATHS):$(DYLD_FALLBACK_LIBRARY_PATH)


$(LIB_BUILD_TARGET): $(LIB_OBJECT_FILES) | $(BUILD_DIR)
# This must be the first rule, don't move it.
$(LIB_BUILD_TARGET): $(LIB_OBJECT_FILES)
$(LINK_CMD) $(LIBFLAG) -o $@ $^ $(REQUIRED_LIBS_FLAGS)


.PHONY: install
install: $(LIB_BUILD_TARGET)
install $^ $(INST_LIBDIR)


$(TEST_EXECUTABLE): $(TEST_CPP_OBJECT_FILES) $(LIB_OBJECT_FILES) | $(BUILD_DIR)
$(TEST_EXECUTABLE): $(TEST_CPP_OBJECT_FILES) $(LIB_OBJECT_FILES)
$(LINK_CMD) -o $@ $^ $(REQUIRED_LIBS_FLAGS) $(LINK_TO_LUA_FLAG) -lm


$(CONSTS_DIR)/%_const.cpp: $(UNICORN_INCDIR)/unicorn/%.h | $(CONSTS_DIR)
$(SOURCE_DIR)/%_const.cpp: $(UNICORN_INCDIR)/unicorn/%.h
$(LUA) tools/generate_constants.lua $< $@


Expand All @@ -189,12 +180,9 @@ $(DOCTEST_HEADER):
$(CURL) -sSo $@ https://raw.githubusercontent.com/doctest/doctest/$(DOCTEST_TAG)/doctest/doctest.h


$(CONSTS_DIR) $(BUILD_DIR):
$(MKDIR) $@


$(BUSTED):
$(LUAROCKS) install --local busted
.PHONY: __install
__install: $(LIB_BUILD_TARGET)
$(CP) $^ $(INST_LIBDIR)


.PHONY: all
Expand All @@ -203,27 +191,16 @@ all: $(LIB_BUILD_TARGET) $(TEST_EXECUTABLE)

.PHONY: clean
clean:
$(RM) $(LIB_OBJECT_FILES) $(CONSTANT_FILES) $(LIB_BUILD_TARGET)
$(RM) $(TEST_EXECUTABLE) $(TEST_CPP_OBJECT_FILES) $(DOCTEST_HEADER)
$(RM) -r $(BUILD_DIR) $(CONSTS_DIR) $(AUTOGENERATED_CPP_FILES) $(AUTOGENERATED_HPP_FILES)


.PHONY: test
test: $(TEST_EXECUTABLE) $(TEST_LUA_SOURCES) | $(BUSTED)
$(TEST_EXECUTABLE)
$(BUSTED) $(BUSTED_FLAGS) \
--cpath="$(BUILD_DIR)/?.$(LIB_EXTENSION)" \
--lua=$(LUA) \
--shuffle \
-p lua \
tests/lua
$(RM) $(LIB_OBJECT_FILES) $(CONSTANT_FILES) $(LIB_BUILD_TARGET) \
$(TEST_EXECUTABLE) $(TEST_CPP_OBJECT_FILES) $(DOCTEST_HEADER) \
$(AUTOGENERATED_CPP_FILES) $(AUTOGENERATED_HPP_FILES)


.PHONY: format
format:
@clang-format --Werror -i --verbose \
$(filter-out $(AUTOGENERATED_CPP_FILES),$(wildcard src/*.cpp)) \
$(filter-out $(AUTOGENERATED_HPP_FILES),$(wildcard src/unicornlua/*.hpp)) \
$(filter-out $(AUTOGENERATED_CPP_FILES),$(wildcard $(SOURCE_DIR)/*.cpp)) \
$(filter-out $(AUTOGENERATED_HPP_FILES),$(wildcard $(SOURCE_DIR)/unicornlua/*.hpp)) \
$(wildcard tests/c/*.cpp) \
$(wildcard tests/c/*.hpp)

Expand All @@ -232,3 +209,9 @@ format:
# making IDEs and linters shut up about "missing" files.
.PHONY: autogen-files
autogen-files: $(AUTOGENERATED_CPP_FILES) $(AUTOGENERATED_HPP_FILES) $(CONSTANT_FILES)


.PHONY: __test
__test: $(TEST_EXECUTABLE) $(TEST_LUA_SOURCES) | $(BUSTED)
$(TEST_EXECUTABLE)
$(BUSTED) $(BUSTED_FLAGS) --lua=$(LUA) --shuffle --pattern lua tests/lua
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/control_functions.cpp → csrc/control_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


#include <stdexcept>
#include <unicorn/unicorn.h>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/unicornlua/compat.hpp → csrc/unicornlua/compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ LUALIB_API void lua_rawsetp(lua_State *L, int index, const void *p);

// http://lua-users.org/lists/lua-l/2011-11/msg01149.html
#ifndef IS_LUAJIT
# ifdef LUA_JDIR
# if defined(LUA_JDIR) || defined(LUA_JROOT)
# define IS_LUAJIT 1
# else
# define IS_LUAJIT 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 60504a6

Please sign in to comment.