improve luajit and moonjit

pull/49/head
ruki 4 years ago
parent 4d075bbf2d
commit 434221a285
No known key found for this signature in database
GPG Key ID: 809EF06AD42725BD
  1. 65
      packages/l/luajit/port/xmake.lua
  2. 6
      packages/l/luajit/xmake.lua
  3. 65
      packages/m/moonjit/port/xmake.lua
  4. 6
      packages/m/moonjit/xmake.lua

@ -1,3 +1,4 @@
set_xmakever("2.3.4")
set_policy("build.across_targets_in_parallel", false) set_policy("build.across_targets_in_parallel", false)
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
@ -24,9 +25,8 @@ rule("dasc")
if not os.isdir(outputdir) then if not os.isdir(outputdir) then
os.mkdir(outputdir) os.mkdir(outputdir)
end end
local argv = {"dynasm/dynasm.lua", "-LN"} local argv = {"dynasm/dynasm.lua", "-LN"}
if is_arch("x64", "x86_64", "arm64", "mips64") then if is_arch("x64", "x86_64", "arm64", "arm64-v8a", "mips64") then
-- 64bits pointer -- 64bits pointer
table.insert(argv, "-D") table.insert(argv, "-D")
table.insert(argv, "P64") table.insert(argv, "P64")
@ -37,7 +37,8 @@ rule("dasc")
table.insert(argv, "-D") table.insert(argv, "-D")
table.insert(argv, "HFABI") table.insert(argv, "HFABI")
end end
if not target:opt("nojit") then -- 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, "-D")
table.insert(argv, "JIT") table.insert(argv, "JIT")
table.insert(argv, "-D") table.insert(argv, "-D")
@ -86,46 +87,88 @@ rule("buildvm")
march = "elfasm" march = "elfasm"
end end
os.vrunv(buildvm_bin, {"-m", march, "-o", lj_vm_asm}) 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}) compiler.compile(lj_vm_asm, lj_vm_obj, {target = target})
table.join2(target:objectfiles(), lj_vm_obj) table.join2(target:objectfiles(), lj_vm_obj)
end end
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") target("minilua")
set_kind("binary") set_kind("binary")
set_default(false)
add_files("src/host/minilua.c") 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") target("buildvm")
set_kind("binary") set_kind("binary")
set_default(false)
add_deps("minilua") add_deps("minilua")
add_rules("dasc") add_rules("dasc")
add_options("nojit", "fpu") add_options("nojit", "fpu")
add_includedirs("src") add_includedirs("src")
set_host_toolchains()
add_files("src/host/buildvm*.c") 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 if is_arch("x86", "i386") then
add_files("src/vm_x86.dasc") add_files("src/vm_x86.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86", {public = true})
elseif is_arch("x64", "x86_64") then elseif is_arch("x64", "x86_64") then
--FIXME will crash --FIXME will crash
--add_files("src/vm_x64.dasc") --add_files("src/vm_x64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64", {public = true})
add_files("src/vm_x86.dasc") add_files("src/vm_x86.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64")
elseif is_arch("arm64", "arm64-v8a") then elseif is_arch("arm64", "arm64-v8a") then
add_files("src/vm_arm64.dasc") add_files("src/vm_arm64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64", {public = true})
elseif is_arch("arm*") then elseif is_arch("arm.*") then
add_files("src/vm_arm.dasc") add_files("src/vm_arm.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM", {public = true})
elseif is_arch("mips64") then elseif is_arch("mips64") then
add_files("src/vm_mips64.dasc") add_files("src/vm_mips64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64", {public = true})
elseif is_arch("mips") then elseif is_arch("mips") then
add_files("src/vm_mips.dasc") add_files("src/vm_mips.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS", {public = true})
elseif is_arch("ppc") then elseif is_arch("ppc") then
add_files("src/vm_ppc.dasc") add_files("src/vm_ppc.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC", {public = true})
end 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") target("luajit")
set_kind("$(kind)") set_kind("$(kind)")

@ -21,7 +21,7 @@ package("luajit")
package:addenv("PATH", "bin") package:addenv("PATH", "bin")
end) end)
on_install("windows", "linux", "macosx", "bsd", function (package) on_install("windows", "linux", "macosx", "bsd", "android", "iphoneos", function (package)
local configs = {} local configs = {}
if package:config("shared") then if package:config("shared") then
configs.kind = "shared" configs.kind = "shared"
@ -33,6 +33,8 @@ package("luajit")
end) end)
on_test(function (package) 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"})) assert(package:has_cfuncs("lua_pcall", {includes = "luajit.h"}))
end) end)

@ -1,3 +1,4 @@
set_xmakever("2.3.4")
set_policy("build.across_targets_in_parallel", false) set_policy("build.across_targets_in_parallel", false)
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
@ -24,9 +25,8 @@ rule("dasc")
if not os.isdir(outputdir) then if not os.isdir(outputdir) then
os.mkdir(outputdir) os.mkdir(outputdir)
end end
local argv = {"dynasm/dynasm.lua", "-LN"} local argv = {"dynasm/dynasm.lua", "-LN"}
if is_arch("x64", "x86_64", "arm64", "mips64") then if is_arch("x64", "x86_64", "arm64", "arm64-v8a", "mips64") then
-- 64bits pointer -- 64bits pointer
table.insert(argv, "-D") table.insert(argv, "-D")
table.insert(argv, "P64") table.insert(argv, "P64")
@ -37,7 +37,8 @@ rule("dasc")
table.insert(argv, "-D") table.insert(argv, "-D")
table.insert(argv, "HFABI") table.insert(argv, "HFABI")
end end
if not target:opt("nojit") then -- 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, "-D")
table.insert(argv, "JIT") table.insert(argv, "JIT")
table.insert(argv, "-D") table.insert(argv, "-D")
@ -86,46 +87,88 @@ rule("buildvm")
march = "elfasm" march = "elfasm"
end end
os.vrunv(buildvm_bin, {"-m", march, "-o", lj_vm_asm}) 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}) compiler.compile(lj_vm_asm, lj_vm_obj, {target = target})
table.join2(target:objectfiles(), lj_vm_obj) table.join2(target:objectfiles(), lj_vm_obj)
end end
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") target("minilua")
set_kind("binary") set_kind("binary")
set_default(false)
add_files("src/host/minilua.c") 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") target("buildvm")
set_kind("binary") set_kind("binary")
set_default(false)
add_deps("minilua") add_deps("minilua")
add_rules("dasc") add_rules("dasc")
add_options("nojit", "fpu") add_options("nojit", "fpu")
add_includedirs("src") add_includedirs("src")
set_host_toolchains()
add_files("src/host/buildvm*.c") 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 if is_arch("x86", "i386") then
add_files("src/vm_x86.dasc") add_files("src/vm_x86.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86", {public = true})
elseif is_arch("x64", "x86_64") then elseif is_arch("x64", "x86_64") then
--FIXME will crash --FIXME will crash
--add_files("src/vm_x64.dasc") --add_files("src/vm_x64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64", {public = true})
add_files("src/vm_x86.dasc") add_files("src/vm_x86.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64")
elseif is_arch("arm64", "arm64-v8a") then elseif is_arch("arm64", "arm64-v8a") then
add_files("src/vm_arm64.dasc") add_files("src/vm_arm64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64", {public = true})
elseif is_arch("arm*") then elseif is_arch("arm.*") then
add_files("src/vm_arm.dasc") add_files("src/vm_arm.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM", {public = true})
elseif is_arch("mips64") then elseif is_arch("mips64") then
add_files("src/vm_mips64.dasc") add_files("src/vm_mips64.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64", {public = true})
elseif is_arch("mips") then elseif is_arch("mips") then
add_files("src/vm_mips.dasc") add_files("src/vm_mips.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS", {public = true})
elseif is_arch("ppc") then elseif is_arch("ppc") then
add_files("src/vm_ppc.dasc") add_files("src/vm_ppc.dasc")
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC") add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC", {public = true})
end 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") target("luajit")
set_kind("$(kind)") set_kind("$(kind)")

@ -20,7 +20,7 @@ package("moonjit")
package:addenv("PATH", "bin") package:addenv("PATH", "bin")
end) end)
on_install("windows", "linux", "macosx", "bsd", function (package) on_install("windows", "linux", "macosx", "bsd", "android", "iphoneos", function (package)
local configs = {} local configs = {}
if package:config("shared") then if package:config("shared") then
configs.kind = "shared" configs.kind = "shared"
@ -32,6 +32,8 @@ package("moonjit")
end) end)
on_test(function (package) 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"})) assert(package:has_cfuncs("lua_pcall", {includes = "luajit.h"}))
end) end)

Loading…
Cancel
Save