From e4fd777d6ad41d338125b095abc98e4dd54c05d7 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Tue, 21 Jan 2025 10:59:32 -0600 Subject: [PATCH] Fix build kinks on windows --- .gitignore | 22 ++++++++++++ README.md | 2 +- xmake.lua | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 xmake.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7897c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Ignore build outputs +/build/ + +# Ignore xmake temporary files +.xmake/ + +# Ignore LuaJIT generated files (if any) +luajit/src/*.o +luajit/src/*.obj +luajit/src/*.exe +luajit/src/*.so +luajit/src/*.dll +luajit/src/*.dylib + +# Ignore log files +*.log + +# Ignore editor/IDE-specific files +.vscode/ +.idea/ +*.swp +.DS_Store diff --git a/README.md b/README.md index ef0728e..94fe1aa 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # LuaJIT -Need to be able to build LuaJIT cross-platform for the Go wrapper. \ No newline at end of file +A way to build static and dynamic libraries for LuaJIT. Uses xmake and gcc to build and copy over linkable headers/libraries. \ No newline at end of file diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..d3e733c --- /dev/null +++ b/xmake.lua @@ -0,0 +1,102 @@ +-- Project setup +set_project("LuaJIT") +set_version("2.1.0") +set_config("buildir", "build") + +target("luajit") + set_kind("phony") + + on_build(function (target) + import("core.tool.toolchain") + import("lib.detect.find_tool") + import("core.project.config") + + -- Change to LuaJIT src dir first + os.cd("luajit/src") + + -- Get number of CPU cores for parallel build + local cpu_num = os.cpuinfo().ncpu + + -- Use gcc + os.setenv("CC", "gcc") + + -- Use make/mingw32-make based on platform + if is_plat("windows") then + local make = find_tool("mingw32-make") + if not make then + raise("mingw32-make not found!") + end + + -- Build with CMD shell + os.execv(make.program, {"-j" .. cpu_num, "SHELL=cmd.exe"}) + else + local make = find_tool("make") + if not make then + raise("make not found!") + end + os.exec(string.format("%s -j%d", make.program, cpu_num)) + end + + -- Copy build outputs to /build + os.mkdir("../../build") + if is_plat("windows") then + -- Dynamic libraries and executable + os.cp("*.dll", "../../build") + os.cp("luajit.exe", "../../build") + -- Static libraries + os.cp("*.lib", "../../build") + os.cp("*.exp", "../../build") + os.cp("*.a", "../../build") + -- Headers for embedding + os.cp("lua.h", "../../build") + os.cp("luaconf.h", "../../build") + os.cp("lualib.h", "../../build") + os.cp("luajit.h", "../../build") + os.cp("lauxlib.h", "../../build") + else + os.cp("libluajit.so", "../../build", {force = true}) + os.cp("libluajit.a", "../../build") + os.cp("luajit", "../../build") + -- Headers for embedding + os.cp("lua.h", "../../build") + os.cp("luaconf.h", "../../build") + os.cp("lualib.h", "../../build") + os.cp("luajit.h", "../../build") + os.cp("lauxlib.h", "../../build") + end + + os.cd("../../") + end) + + on_clean(function (target) + -- Clean build directory + os.rm("build") + + -- Clean generated files in LuaJIT src directory + os.cd("luajit/src") + os.rm("*.o") + os.rm("*.obj") + os.rm("*.lib") + os.rm("*.exp") + os.rm("*.dll") + os.rm("*.exe") + os.rm("*.manifest") + os.rm("*.pdb") + os.rm("*.ilk") + os.rm("*.a") + os.rm("host/*.o") + os.rm("host/*.obj") + os.rm("host/minilua.exe") + os.rm("host/buildvm.exe") + os.rm("lj_vm.S") + os.rm("lj_bcdef.h") + os.rm("lj_ffdef.h") + os.rm("lj_libdef.h") + os.rm("lj_recdef.h") + os.rm("lj_folddef.h") + os.rm("host/buildvm_arch.h") + os.rm("luajit.h") + os.rm("luajit_relver.txt") + os.rm("jit/vmdef.lua") + os.cd("../../") + end) \ No newline at end of file