-
-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
warning when adding generated include dirs and files from dependency target #838
Comments
Please add/set target infos, e.g. includedirs in target('generate_files')
-- @see https://xmake.io/#/manual/project_target?id=targetadd_includedirs
add_includedirs("xxx", {public = true})
on_load(function (target)
-- same as add_includedirs("", {public = true})
target:add("includedirs", output_dir, {public = true})
target:data_add("myobjs", "xxx.obj")
end)
target('foo')
add_deps('generate_files')
on_load(function (target)
local dep = target:dep("generate_files")
table.join2(target:objectfiles(), dep:data("myobjs"))
end) |
And please uses https://xmake.io/#/manual/custom_rule?id=rule
|
Thanks for the solution. add_includedirs works fine now, but I still have problem with adding object files. I cannot find a proper event (on_load, before_build, on_build, etc) to insert the generated object file. Since the generator is also a dependency target, so I cannot use on_load/before_build because the generator has not been built at that time. The on_build event cannot be used because it overrides the default build process, although I can insert object file here but there's no build action. I can insert the object file in the generator's on_build event, but it's ignored by the target and does not appear in the final library. What I want to do is to build luajit with xmake, below is the code of xmake.lua, any suggestions are appreciated:
|
Please insert to target('luajit')
add_deps('luajit-vm')
before_build(function (target)
local buildvm = target:dep("luajit-buildvm"):targetfile()
os.runv(buildvm, {'-m', 'peobj', '-o', lj_vm_obj})
os.runv(buildvm, {'-m', 'bcdef', '-o', path.join(outputdir, 'lj_bcdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'ffdef', '-o', path.join(outputdir, 'lj_ffdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'libdef', '-o', path.join(outputdir, 'lj_libdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'recdef', '-o', path.join(outputdir, 'lj_recdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'vmdef', '-o', path.join(outputdir, 'lj_vmdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'folddef', '-o', path.join(outputdir, 'lj_folddef.h'), 'deps/LuaJIT/src/lj_opt_fold.c'})
table.join2(target:objectfiles(), objs)
end) |
Or you should use And add_deps('luajit-buildvm'), rule("luajit-vm") to target("luajit") rule('luajit-vm')
before_build(function (target)
-- NOTE, this target is luajit if you apply rule to target("luajit")
local buildvm = target:dep("luajit-buildvm"):targetfile()
os.runv(buildvm, {'-m', 'peobj', '-o', lj_vm_obj})
os.runv(buildvm, {'-m', 'bcdef', '-o', path.join(outputdir, 'lj_bcdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'ffdef', '-o', path.join(outputdir, 'lj_ffdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'libdef', '-o', path.join(outputdir, 'lj_libdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'recdef', '-o', path.join(outputdir, 'lj_recdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'vmdef', '-o', path.join(outputdir, 'lj_vmdef.h'), unpack(all_lib)})
os.runv(buildvm, {'-m', 'folddef', '-o', path.join(outputdir, 'lj_folddef.h'), 'deps/LuaJIT/src/lj_opt_fold.c'})
table.join2(target:objectfiles(), objs)
end)
target('luajit')
set_policy("build.across_targets_in_parallel", false)
set_kind('static')
add_options('disable-jit')
-- NOTE this ..
add_deps('luajit-buildvm')
add_rules("luajit-vm") |
Because before_build runs before the actual build process, buildvm is not available at that time thus os.runv(buildvm,...) failed:
|
add_deps('luajit-buildvm') and set_policy("build.across_targets_in_parallel", false) will ensure that buildvm has been built before |
already did that, you may try attached file with xmake.lua and dependent source files. |
You can try it local function array_append(a, v, ...)
if v ~= nil then
if type(v) ~= 'table' then
a[#a + 1] = v
else
array_append(a, unpack(v))
end
array_append(a, ...)
end
end
local function array(...)
local r = {}; array_append(r, ...); return r
end
set_policy("build.across_targets_in_parallel", false)
option('disable-jit')
set_default(false)
set_showmenu(true)
add_defines('LUAJIT_DISABLE_JIT', 'LUAJIT_DISABLE_FFI')
target('luajit-minilua')
set_kind('binary')
add_files('deps/LuaJIT/src/host/minilua.c')
target('luajit-buildvm-arch')
add_deps('luajit-minilua')
on_build(function(target)
import("core.base.option")
import("core.project.depend")
import("core.project.project")
local sourcefile = 'deps/LuaJIT/src/vm_x64.dasc'
local outputdir = target:objectdir()
local outputfile = path.join(outputdir, 'buildvm_arch.h')
target:add("includedirs", outputdir, {public = true})
local dependfile = target:dependfile(outputfile)
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
if not depend.is_changed(dependinfo, {lastmtime = os.mtime(outputfile)}) then
return
end
local hasjit = not project.option('disable-jit'):enabled()
local minilua = target:deps()['luajit-minilua']:targetfile()
local dasm = 'deps/LuaJIT/dynasm/dynasm.lua'
local flags = {'-D', 'WIN', '-D', 'P64'}; if hasjit then
flags = {'-D', 'JIT', '-D', 'FFI', unpack(flags)}
end
local args = array(dasm, '-LN', flags, '-o', outputfile, sourcefile)
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
print('compiling', sourcefile)
os.runv(minilua, args)
dependinfo.files = {sourcefile}
depend.save(dependinfo, dependfile)
end)
target('luajit-buildvm')
add_deps('luajit-buildvm-arch')
set_kind('binary')
add_options('disable-jit')
add_includedirs('deps/LuaJIT/src')
add_files('deps/LuaJIT/src/host/buildvm*.c')
after_build(function (target)
import("core.base.option")
import("core.project.project")
local outputdir = target:objectdir()
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
local lj_vm_h = path.join(outputdir, 'lj_vmdef.h')
local lj_vm_obj = path.join(outputdir, 'lj_vm.obj')
if os.exists(lj_vm_obj) and (not option.get("rebuild")) then
return
end
local buildvm = target:targetfile()
local all_lib = {
'deps/LuaJIT/src/lib_base.c',
'deps/LuaJIT/src/lib_math.c',
'deps/LuaJIT/src/lib_bit.c',
'deps/LuaJIT/src/lib_string.c',
'deps/LuaJIT/src/lib_table.c',
'deps/LuaJIT/src/lib_io.c',
'deps/LuaJIT/src/lib_os.c',
'deps/LuaJIT/src/lib_package.c',
'deps/LuaJIT/src/lib_debug.c',
'deps/LuaJIT/src/lib_jit.c',
'deps/LuaJIT/src/lib_ffi.c'
}
print('building vm...')
os.vrunv(buildvm, {'-m', 'peobj', '-o', lj_vm_obj})
os.vrunv(buildvm, {'-m', 'bcdef', '-o', path.join(outputdir, 'lj_bcdef.h'), unpack(all_lib)})
os.vrunv(buildvm, {'-m', 'ffdef', '-o', path.join(outputdir, 'lj_ffdef.h'), unpack(all_lib)})
os.vrunv(buildvm, {'-m', 'libdef', '-o', path.join(outputdir, 'lj_libdef.h'), unpack(all_lib)})
os.vrunv(buildvm, {'-m', 'recdef', '-o', path.join(outputdir, 'lj_recdef.h'), unpack(all_lib)})
os.vrunv(buildvm, {'-m', 'vmdef', '-o', path.join(outputdir, 'lj_vmdef.h'), unpack(all_lib)})
os.vrunv(buildvm, {'-m', 'folddef', '-o', path.join(outputdir, 'lj_folddef.h'), 'deps/LuaJIT/src/lj_opt_fold.c'})
end)
target('luajit')
set_kind('static')
add_options('disable-jit')
add_deps('luajit-buildvm')
add_defines('LUAJIT_USE_SYSMALLOC', 'LUAJIT_ENABLE_LUA52COMPAT')
if is_mode('debug') then
add_defines('LUA_USE_ASSERT')
end
add_files('deps/LuaJIT/src/ljamalg.c')
on_load(function (target)
local buildvm = target:dep("luajit-buildvm")
local lj_vm_obj = path.join(buildvm:objectdir(), 'lj_vm.obj')
target:add("includedirs", buildvm:objectdir())
table.join2(target:objectfiles(), lj_vm_obj)
end) |
When the across_targets_in_parallel strategy is disabled, before_build is currently executed before all dependent target builds. This seems to have some problems, and I need to fix it. And I will improve rule to support it better. You can try the above code first |
I have improve rule to support You can update to dev and try the following code. local function array_append(a, v, ...)
if v ~= nil then
if type(v) ~= 'table' then
a[#a + 1] = v
else
array_append(a, unpack(v))
end
array_append(a, ...)
end
end
local function array(...)
local r = {}; array_append(r, ...); return r
end
set_policy("build.across_targets_in_parallel", false)
option('disable-jit')
set_default(false)
set_showmenu(true)
add_defines('LUAJIT_DISABLE_JIT', 'LUAJIT_DISABLE_FFI')
target('luajit-minilua')
set_kind('binary')
add_files('deps/LuaJIT/src/host/minilua.c')
target('luajit-buildvm-arch')
add_deps('luajit-minilua')
on_build(function(target)
import("core.base.option")
import("core.project.depend")
import("core.project.project")
local sourcefile = 'deps/LuaJIT/src/vm_x64.dasc'
local outputdir = target:objectdir()
local outputfile = path.join(outputdir, 'buildvm_arch.h')
target:add("includedirs", outputdir, {public = true})
local dependfile = target:dependfile(outputfile)
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
if not depend.is_changed(dependinfo, {lastmtime = os.mtime(outputfile)}) then
return
end
local hasjit = not project.option('disable-jit'):enabled()
local minilua = target:deps()['luajit-minilua']:targetfile()
local dasm = 'deps/LuaJIT/dynasm/dynasm.lua'
local flags = {'-D', 'WIN', '-D', 'P64'}; if hasjit then
flags = {'-D', 'JIT', '-D', 'FFI', unpack(flags)}
end
local args = array(dasm, '-LN', flags, '-o', outputfile, sourcefile)
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
print('compiling', sourcefile)
os.runv(minilua, args)
dependinfo.files = {sourcefile}
depend.save(dependinfo, dependfile)
end)
target('luajit-buildvm')
add_deps('luajit-buildvm-arch')
set_kind('binary')
add_options('disable-jit')
add_includedirs('deps/LuaJIT/src')
add_files('deps/LuaJIT/src/host/buildvm*.c')
rule("luajit-vm")
before_build_files(function (target, sourcefiles)
import("core.base.option")
import("core.project.project")
local buildvm = target:dep("luajit-buildvm")
local outputdir = buildvm:objectdir()
if not os.isdir(outputdir) then
os.mkdir(outputdir)
end
target:add("includedirs", buildvm:objectdir())
local lj_vm_obj = path.join(outputdir, 'lj_vm.obj')
table.join2(target:objectfiles(), lj_vm_obj)
if os.exists(lj_vm_obj) and (not option.get("rebuild")) then
return
end
print('building vm...')
buildvm = buildvm:targetfile()
os.vrunv(buildvm, {'-m', 'peobj', '-o', lj_vm_obj})
os.vrunv(buildvm, {'-m', 'bcdef', '-o', path.join(outputdir, 'lj_bcdef.h'), unpack(sourcefiles)})
os.vrunv(buildvm, {'-m', 'ffdef', '-o', path.join(outputdir, 'lj_ffdef.h'), unpack(sourcefiles)})
os.vrunv(buildvm, {'-m', 'libdef', '-o', path.join(outputdir, 'lj_libdef.h'), unpack(sourcefiles)})
os.vrunv(buildvm, {'-m', 'recdef', '-o', path.join(outputdir, 'lj_recdef.h'), unpack(sourcefiles)})
os.vrunv(buildvm, {'-m', 'vmdef', '-o', path.join(outputdir, 'lj_vmdef.h'), unpack(sourcefiles)})
os.vrunv(buildvm, {'-m', 'folddef', '-o', path.join(outputdir, 'lj_folddef.h'), 'deps/LuaJIT/src/lj_opt_fold.c'})
end)
target('luajit')
set_kind('static')
add_options('disable-jit')
add_deps('luajit-buildvm')
add_defines('LUAJIT_USE_SYSMALLOC', 'LUAJIT_ENABLE_LUA52COMPAT')
if is_mode('debug') then
add_defines('LUA_USE_ASSERT')
end
add_files('deps/LuaJIT/src/ljamalg.c')
add_files('deps/LuaJIT/src/lib_base.c',
'deps/LuaJIT/src/lib_math.c',
'deps/LuaJIT/src/lib_bit.c',
'deps/LuaJIT/src/lib_string.c',
'deps/LuaJIT/src/lib_table.c',
'deps/LuaJIT/src/lib_io.c',
'deps/LuaJIT/src/lib_os.c',
'deps/LuaJIT/src/lib_package.c',
'deps/LuaJIT/src/lib_debug.c',
'deps/LuaJIT/src/lib_jit.c',
'deps/LuaJIT/src/lib_ffi.c', {rules = {"luajit-vm", override = true}})
|
I have fixed xmake update -s dev
|
thanks for the update and it almost works, only two small issues:
Below is the rule('luajit-vm') with some modifications and then build succeeded:
the full xmake.lua is attached. thanks |
I'm sorry, my mistake. It should be rule('luajit-vm')
before_build_files(function (target, sourcebatch, opt)
import("core.base.option")
import("core.project.project")
local sourcefiles = sourcebatch.sourcefiles
print(sourcefiles) see https://xmake.io/#/manual/custom_rule?id=ruleon_build_files
I have fixed the order of files. You can update to dev and try it again. xmake update -s dev |
local function array_append(a, v, ...)
if v ~= nil then
if type(v) ~= 'table' then
a[#a + 1] = v
else
array_append(a, unpack(v))
end
array_append(a, ...)
end
end
local function array(...)
local r = {}; array_append(r, ...); return r
end
local args = array(dasm, '-LN', flags, '-o', outputfile, sourcefile) You can use |
Thanks, now everything works smoothly, great! |
ok |
luajit building works in windows, but there's a problem in linux. In linux the luajit vm is generated as a .S file, so I insert the .S file using the xmake.lua is attached, any suggestions are appreciated. |
It's terrific to have a ready to use xmake.lua for luajit, thanks! |
I am porting luajit to xmake-repo, you can use xmake.lua directly, and I will provide it on xmake-repo/master after finishing. And we can use add_requires("luajit")
target("test")
add_files("src/*.c")
add_packages("luajit") |
I've tried it in windows and linux without any problem, thanks. |
I have merged luajit/port to xmake-repo/master. You can use it directly. It can also support iphoneos/android. add_requires("luajit")
target("test")
add_files("src/*.c")
add_packages("luajit") https://github.com/xmake-io/xmake-repo/blob/master/packages/l/luajit/port/xmake.lua |
xmake 2.3.4
sample xmake.lua:
So what's the correct way to add include dirs and files generated from dependency target?
thanks
The text was updated successfully, but these errors were encountered: