Merge branch 'luajit' into dev

pull/49/head
ruki 5 years ago
commit c511fdcaab
No known key found for this signature in database
GPG Key ID: 809EF06AD42725BD
  1. 219
      packages/l/luajit/port/xmake.lua
  2. 57
      packages/l/luajit/xmake.lua
  3. 220
      packages/m/moonjit/port/xmake.lua
  4. 39
      packages/m/moonjit/xmake.lua

@ -0,0 +1,219 @@
set_xmakever("2.3.4")
set_policy("build.across_targets_in_parallel", false)
add_rules("mode.debug", "mode.release")
if is_mode("release") then
add_cflags("-fomit-frame-pointer")
add_cflags("-fno-stack-protector")
end
option("nojit")
set_default(false)
set_showmenu(true)
add_defines("LUAJIT_DISABLE_JIT", "LUAJIT_DISABLE_FFI")
option("fpu")
set_default(true)
set_showmenu(true)
add_defines("LJ_ARCH_HASFPU=1", "LJ_ABI_SOFTFP=0")
rule("dasc")
set_extensions(".dasc")
before_build_file(function(target, sourcefile)
local outputdir = target:objectdir()
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
local argv = {"dynasm/dynasm.lua", "-LN"}
if is_arch("x64", "x86_64", "arm64", "arm64-v8a", "mips64") then
-- 64bits pointer
table.insert(argv, "-D")
table.insert(argv, "P64")
end
if target:opt("fpu") then
table.insert(argv, "-D")
table.insert(argv, "FPU")
table.insert(argv, "-D")
table.insert(argv, "HFABI")
end
-- jit is not supported on ios
if not target:opt("nojit") and not is_plat("iphoneos", "watchos") then
table.insert(argv, "-D")
table.insert(argv, "JIT")
table.insert(argv, "-D")
table.insert(argv, "FFI")
end
if is_plat("windows", "mingw") then
table.insert(argv, "-D")
table.insert(argv, "WIN")
end
table.insert(argv, "-o")
table.insert(argv, path.join(outputdir, "buildvm_arch.h"))
table.insert(argv, sourcefile)
os.vrunv(target:dep("minilua"):targetfile(), argv)
target:add("includedirs", outputdir, {public = true})
end)
rule("buildvm")
before_build_files(function (target, sourcebatch)
local buildvm = target:dep("buildvm")
local outputdir = buildvm:objectdir()
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
local buildvm_bin = buildvm:targetfile()
local sourcefiles = sourcebatch.sourcefiles
os.vrunv(buildvm_bin, {"-m", "bcdef", "-o", "src/lj_bcdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "ffdef", "-o", "src/lj_ffdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "libdef", "-o", "src/lj_libdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "recdef", "-o", "src/lj_recdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "vmdef", "-o", "src/lj_vmdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "folddef", "-o", "src/lj_folddef.h", "src/lj_opt_fold.c"})
if is_plat("windows", "mingw") then
local lj_vm_obj = path.join(outputdir, "lj_vm.obj")
os.vrunv(buildvm_bin, {"-m", "peobj", "-o", lj_vm_obj})
table.join2(target:objectfiles(), lj_vm_obj)
else
import("core.tool.compiler")
local lj_vm_asm = path.join(outputdir, "lj_vm.S")
local lj_vm_obj = path.join(outputdir, "lj_vm.o")
local march
if is_plat("macosx", "iphoneos", "watchos") then
march = "machasm"
else
march = "elfasm"
end
os.vrunv(buildvm_bin, {"-m", march, "-o", lj_vm_asm})
print(compiler.compcmd(lj_vm_asm, lj_vm_obj, {target = target}))
compiler.compile(lj_vm_asm, lj_vm_obj, {target = target})
table.join2(target:objectfiles(), lj_vm_obj)
end
end)
function set_host_toolchains()
-- only for cross-compliation
if is_plat(os.host()) then
return
end
local arch
if is_arch("arm64", "arm64-v8a", "mips64", "x86_64") then
arch = is_host("windows") and "x64" or "x86_64"
else
arch = is_host("windows") and "x86" or "i386"
end
set_plat(os.host())
set_arch(arch)
end
target("minilua")
set_kind("binary")
set_default(false)
add_files("src/host/minilua.c")
set_host_toolchains()
if is_host("windows") then
add_defines("_CRT_SECURE_NO_DEPRECATE", "_CRT_STDIO_INLINE=__declspec(dllexport)__inline")
end
target("buildvm")
set_kind("binary")
set_default(false)
add_deps("minilua")
add_rules("dasc")
add_options("nojit", "fpu")
add_includedirs("src")
set_host_toolchains()
add_files("src/host/buildvm*.c")
if is_host("windows") then
add_defines("_CRT_SECURE_NO_DEPRECATE", "_CRT_STDIO_INLINE=__declspec(dllexport)__inline")
end
if is_arch("x86", "i386") then
add_files("src/vm_x86.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86", {public = true})
elseif is_arch("x64", "x86_64") then
--FIXME will crash
--add_files("src/vm_x64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64", {public = true})
add_files("src/vm_x86.dasc")
elseif is_arch("arm64", "arm64-v8a") then
add_files("src/vm_arm64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64", {public = true})
elseif is_arch("arm.*") then
add_files("src/vm_arm.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM", {public = true})
elseif is_arch("mips64") then
add_files("src/vm_mips64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64", {public = true})
elseif is_arch("mips") then
add_files("src/vm_mips.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS", {public = true})
elseif is_arch("ppc") then
add_files("src/vm_ppc.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC", {public = true})
end
if is_plat("macosx", "iphoneos", "watchos") then
add_defines("LUAJIT_OS=LUAJIT_OS_OSX", {public = true})
elseif is_plat("windows") then
add_defines("LUAJIT_OS=LUAJIT_OS_WINDOWS", {public = true})
elseif is_plat("linux", "android") then
add_defines("LUAJIT_OS=LUAJIT_OS_LINUX", {public = true})
else
add_defines("LUAJIT_OS=LUAJIT_OS_OTHER", {public = true})
end
before_build("@windows", function (target)
if not is_arch("x86", "x64", "mips", "mips64") then
-- @note we need fix `illegal zero-sized array` errors for msvc
io.gsub("src/lj_jit.h", " LJ_K32__MAX\n", " LJ_K32__MAX=1\n")
io.gsub("src/lj_jit.h", " LJ_K64__MAX,\n", " LJ_K64__MAX=1\n")
end
end)
target("luajit")
set_kind("$(kind)")
add_deps("buildvm")
add_options("nojit", "fpu")
if is_mode("debug") then
add_defines("LUA_USE_ASSERT")
end
add_defines("LUAJIT_ENABLE_LUA52COMPAT", {public = true})
add_defines("_FILE_OFFSET_BITS=64", "LARGEFILE_SOURCE", {public = true})
add_undefines("_FORTIFY_SOURCE", {public = true})
add_headerfiles("src/*.h", {prefixdir = "luajit"})
add_files("src/ljamalg.c")
add_files("src/lib_base.c",
"src/lib_math.c",
"src/lib_bit.c",
"src/lib_string.c",
"src/lib_table.c",
"src/lib_io.c",
"src/lib_os.c",
"src/lib_package.c",
"src/lib_debug.c",
"src/lib_jit.c",
"src/lib_ffi.c", {rules = {"buildvm", override = true}})
target("luajit_bin")
set_kind("binary")
add_deps("luajit")
set_basename("luajit")
add_files("src/luajit.c")
add_options("nojit", "fpu")
if is_plat("windows") then
add_links("advapi32", "shell32")
if is_arch("x86") then
add_ldflags("/subsystem:console,5.01")
else
add_ldflags("/subsystem:console,5.02")
end
elseif is_plat("android") then
add_links("m", "c")
elseif is_plat("macosx") then
add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000")
elseif is_plat("mingw") then
add_ldflags("-static-libgcc", {force = true})
else
add_links("pthread", "dl", "m", "c")
end

@ -7,12 +7,10 @@ package("luajit")
"http://luajit.org/git/luajit-2.0.git",
"http://repo.or.cz/luajit-2.0.git")
add_versions("2.0.0", "deaed645c4a093c5fb250c30c9933c9131ee05c94b13262d58f6e0b60b338c15")
add_versions("2.0.1", "2371cceb53453d8a7b36451e6a0ccdb66236924545d6042ddd4c34e9668990c0")
add_versions("2.0.2", "c05202974a5890e777b181908ac237625b499aece026654d7cc33607e3f46c38")
add_versions("2.0.3", "55be6cb2d101ed38acca32c5b1f99ae345904b365b642203194c585d27bebd79")
add_versions("2.0.4", "620fa4eb12375021bef6e4f237cbd2dd5d49e56beb414bee052c746beef1807d")
add_versions("2.0.5", "874b1f8297c697821f561f9b73b57ffd419ed8f4278c82e05b48806d30c1e979")
add_versions("2.1.0-beta3", "1ad2e34b111c802f9d0cdf019e986909123237a28c746b21295b63c9e785d9c3")
add_configs("nojit", { description = "Disable JIT.", default = false, type = "boolean"})
add_configs("fpu", { description = "Enable FPU.", default = true, type = "boolean"})
add_includedirs("include/luajit")
if not is_plat("windows") then
@ -20,50 +18,23 @@ package("luajit")
end
on_load(function (package)
if is_plat("windows") then
package:addenv("PATH", "lib")
end
package:addenv("PATH", "bin")
end)
on_install("windows", function (package)
os.cd("src")
if not package:config("shared") then
os.vrun("msvcbuild.bat static")
elseif package:debug() then
os.vrun("msvcbuild.bat debug")
else
os.vrun("msvcbuild.bat")
end
os.cp("luajit.exe", package:installdir("bin"))
os.cp("lua51.lib", package:installdir("lib"))
on_install("windows", "linux", "macosx", "bsd", "android", "iphoneos", function (package)
local configs = {}
if package:config("shared") then
os.cp("lua51.dll", package:installdir("lib"))
configs.kind = "shared"
end
os.cp("*.h", package:installdir("include/luajit"))
end)
on_install("macosx", "linux", function (package)
io.gsub("./Makefile", "export PREFIX= /usr/local", "export PREFIX=" .. package:installdir())
if package:debug() then
io.gsub("./src/Makefile", "CCDEBUG=", "CCDEBUG= -g")
end
if package:config("shared") then
io.gsub("./src/Makefile", "BUILDMODE= mixed", "BUILDMODE= dynamic")
else
io.gsub("./src/Makefile", "BUILDMODE= mixed", "BUILDMODE= static")
end
os.vrun("make")
os.cp("src/luajit", package:installdir("bin"))
if package:config("shared") then
os.cp("src/*" .. (is_plat("macosx") and ".dylib" or ".so"), package:installdir("lib"))
else
os.cp("src/*.a", package:installdir("lib"))
end
os.cp("src/*.h", package:installdir("include/luajit"))
configs.fpu = package:config("fpu")
configs.nojit = package:config("nojit")
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
import("package.tools.xmake").install(package, configs)
end)
on_test(function (package)
os.vrun("luajit -e \"print('hello xmake!')\"")
if package:is_plat(os.host()) then
os.vrun("luajit -e \"print('hello xmake!')\"")
end
assert(package:has_cfuncs("lua_pcall", {includes = "luajit.h"}))
end)

@ -0,0 +1,220 @@
set_xmakever("2.3.4")
set_policy("build.across_targets_in_parallel", false)
add_rules("mode.debug", "mode.release")
if is_mode("release") then
add_cflags("-fomit-frame-pointer")
add_cflags("-fno-stack-protector")
end
option("nojit")
set_default(false)
set_showmenu(true)
add_defines("LUAJIT_DISABLE_JIT", "LUAJIT_DISABLE_FFI")
option("fpu")
set_default(true)
set_showmenu(true)
add_defines("LJ_ARCH_HASFPU=1", "LJ_ABI_SOFTFP=0")
rule("dasc")
set_extensions(".dasc")
before_build_file(function(target, sourcefile)
local outputdir = target:objectdir()
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
local argv = {"dynasm/dynasm.lua", "-LN"}
if is_arch("x64", "x86_64", "arm64", "arm64-v8a", "mips64") then
-- 64bits pointer
table.insert(argv, "-D")
table.insert(argv, "P64")
end
if target:opt("fpu") then
table.insert(argv, "-D")
table.insert(argv, "FPU")
table.insert(argv, "-D")
table.insert(argv, "HFABI")
end
-- jit is not supported on ios
if not target:opt("nojit") and not is_plat("iphoneos", "watchos") then
table.insert(argv, "-D")
table.insert(argv, "JIT")
table.insert(argv, "-D")
table.insert(argv, "FFI")
end
if is_plat("windows", "mingw") then
table.insert(argv, "-D")
table.insert(argv, "WIN")
end
table.insert(argv, "-o")
table.insert(argv, path.join(outputdir, "buildvm_arch.h"))
table.insert(argv, sourcefile)
os.vrunv(target:dep("minilua"):targetfile(), argv)
target:add("includedirs", outputdir, {public = true})
end)
rule("buildvm")
before_build_files(function (target, sourcebatch)
local buildvm = target:dep("buildvm")
local outputdir = buildvm:objectdir()
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
local buildvm_bin = buildvm:targetfile()
local sourcefiles = sourcebatch.sourcefiles
os.vrunv(buildvm_bin, {"-m", "bcdef", "-o", "src/lj_bcdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "ffdef", "-o", "src/lj_ffdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "libdef", "-o", "src/lj_libdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "recdef", "-o", "src/lj_recdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "vmdef", "-o", "src/lj_vmdef.h", unpack(sourcefiles)})
os.vrunv(buildvm_bin, {"-m", "folddef", "-o", "src/lj_folddef.h", "src/lj_opt_fold.c"})
if is_plat("windows", "mingw") then
local lj_vm_obj = path.join(outputdir, "lj_vm.obj")
os.vrunv(buildvm_bin, {"-m", "peobj", "-o", lj_vm_obj})
table.join2(target:objectfiles(), lj_vm_obj)
else
import("core.tool.compiler")
local lj_vm_asm = path.join(outputdir, "lj_vm.S")
local lj_vm_obj = path.join(outputdir, "lj_vm.o")
local march
if is_plat("macosx", "iphoneos", "watchos") then
march = "machasm"
else
march = "elfasm"
end
os.vrunv(buildvm_bin, {"-m", march, "-o", lj_vm_asm})
print(compiler.compcmd(lj_vm_asm, lj_vm_obj, {target = target}))
compiler.compile(lj_vm_asm, lj_vm_obj, {target = target})
table.join2(target:objectfiles(), lj_vm_obj)
end
end)
function set_host_toolchains()
-- only for cross-compliation
if is_plat(os.host()) then
return
end
local arch
if is_arch("arm64", "arm64-v8a", "mips64", "x86_64") then
arch = is_host("windows") and "x64" or "x86_64"
else
arch = is_host("windows") and "x86" or "i386"
end
set_plat(os.host())
set_arch(arch)
end
target("minilua")
set_kind("binary")
set_default(false)
add_files("src/host/minilua.c")
set_host_toolchains()
if is_host("windows") then
add_defines("_CRT_SECURE_NO_DEPRECATE", "_CRT_STDIO_INLINE=__declspec(dllexport)__inline")
end
target("buildvm")
set_kind("binary")
set_default(false)
add_deps("minilua")
add_rules("dasc")
add_options("nojit", "fpu")
add_includedirs("src")
set_host_toolchains()
add_files("src/host/buildvm*.c")
if is_host("windows") then
add_defines("_CRT_SECURE_NO_DEPRECATE", "_CRT_STDIO_INLINE=__declspec(dllexport)__inline")
end
if is_arch("x86", "i386") then
add_files("src/vm_x86.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86", {public = true})
elseif is_arch("x64", "x86_64") then
--FIXME will crash
--add_files("src/vm_x64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64", {public = true})
add_files("src/vm_x86.dasc")
elseif is_arch("arm64", "arm64-v8a") then
add_files("src/vm_arm64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64", {public = true})
elseif is_arch("arm.*") then
add_files("src/vm_arm.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM", {public = true})
elseif is_arch("mips64") then
add_files("src/vm_mips64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64", {public = true})
elseif is_arch("mips") then
add_files("src/vm_mips.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS", {public = true})
elseif is_arch("ppc") then
add_files("src/vm_ppc.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC", {public = true})
end
if is_plat("macosx", "iphoneos", "watchos") then
add_defines("LUAJIT_OS=LUAJIT_OS_OSX", {public = true})
elseif is_plat("windows") then
add_defines("LUAJIT_OS=LUAJIT_OS_WINDOWS", {public = true})
elseif is_plat("linux", "android") then
add_defines("LUAJIT_OS=LUAJIT_OS_LINUX", {public = true})
else
add_defines("LUAJIT_OS=LUAJIT_OS_OTHER", {public = true})
end
before_build("@windows", function (target)
if not is_arch("x86", "x64", "mips", "mips64") then
-- @note we need fix `illegal zero-sized array` errors for msvc
io.gsub("src/lj_jit.h", " LJ_K32__MAX\n", " LJ_K32__MAX=1\n")
io.gsub("src/lj_jit.h", " LJ_K64__MAX,\n", " LJ_K64__MAX=1\n")
end
end)
target("luajit")
set_kind("$(kind)")
add_deps("buildvm")
add_options("nojit", "fpu")
if is_mode("debug") then
add_defines("LUA_USE_ASSERT")
end
add_defines("LUAJIT_ENABLE_LUA52COMPAT", {public = true})
add_defines("_FILE_OFFSET_BITS=64", "LARGEFILE_SOURCE", {public = true})
add_undefines("_FORTIFY_SOURCE", {public = true})
add_headerfiles("src/*.h", {prefixdir = "luajit"})
add_cflags("-msse4.2")
add_files("src/ljamalg.c", "src/lj_str_hash.c")
add_files("src/lib_base.c",
"src/lib_math.c",
"src/lib_bit.c",
"src/lib_string.c",
"src/lib_table.c",
"src/lib_io.c",
"src/lib_os.c",
"src/lib_package.c",
"src/lib_debug.c",
"src/lib_jit.c",
"src/lib_ffi.c", {rules = {"buildvm", override = true}})
target("luajit_bin")
set_kind("binary")
add_deps("luajit")
set_basename("luajit")
add_files("src/luajit.c")
add_options("nojit", "fpu")
if is_plat("windows") then
add_links("advapi32", "shell32")
if is_arch("x86") then
add_ldflags("/subsystem:console,5.01")
else
add_ldflags("/subsystem:console,5.02")
end
elseif is_plat("android") then
add_links("m", "c")
elseif is_plat("macosx") then
add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000")
elseif is_plat("mingw") then
add_ldflags("-static-libgcc", {force = true})
else
add_links("pthread", "dl", "m", "c")
end

@ -0,0 +1,39 @@
package("moonjit")
set_homepage("https://github.com/moonjit/moonjit")
set_description("A Just-In-Time Compiler (JIT) for the Lua programming language.")
set_urls("https://github.com/moonjit/moonjit/archive/$(version).tar.gz",
"https://github.com:moonjit/moonjit.git")
add_versions("2.2.0", "83deb2c880488dfe7dd8ebf09e3b1e7613ef4b8420de53de6f712f01aabca2b6")
add_configs("nojit", { description = "Disable JIT.", default = false, type = "boolean"})
add_configs("fpu", { description = "Enable FPU.", default = true, type = "boolean"})
add_includedirs("include/luajit")
if not is_plat("windows") then
add_syslinks("dl")
end
on_load(function (package)
package:addenv("PATH", "bin")
end)
on_install("windows", "linux", "macosx", "bsd", "android", "iphoneos", function (package)
local configs = {}
if package:config("shared") then
configs.kind = "shared"
end
configs.fpu = package:config("fpu")
configs.nojit = package:config("nojit")
os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
import("package.tools.xmake").install(package, configs)
end)
on_test(function (package)
if package:is_plat(os.host()) then
os.vrun("luajit -e \"print('hello xmake!')\"")
end
assert(package:has_cfuncs("lua_pcall", {includes = "luajit.h"}))
end)
Loading…
Cancel
Save