diff options
| author | ruki <[email protected]> | 2021-03-22 12:41:42 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-22 12:41:42 +0800 |
| commit | 131800db6dfc7447e85958a4aef887ffb3bedf7f (patch) | |
| tree | 8ac6f4a7970ece5e22098b8e0a8a9e7afb2bd6b0 | |
| parent | bfd116d2e53d9836fe42a6a1b13d6d6986baa8ad (diff) | |
| parent | 7e37f40d47668f01b8d21255caa40b1b153f5c30 (diff) | |
Merge pull request #1294 from xmake-io/ndk
support to use remote ndk to build bpf program on linux
| -rw-r--r-- | tests/projects/bpf/minimal/test.lua | 6 | ||||
| -rw-r--r-- | tests/projects/bpf/minimal/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/config/main.lua | 9 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 75 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 46 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 1 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/linker.lua | 28 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 66 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 8 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 40 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 52 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/install_packages.lua | 12 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/platform/linux/bpf/xmake.lua | 19 | ||||
| -rw-r--r-- | xmake/toolchains/msvc/xmake.lua | 12 | ||||
| -rw-r--r-- | xmake/toolchains/ndk/check.lua | 30 | ||||
| -rw-r--r-- | xmake/toolchains/ndk/xmake.lua | 12 |
19 files changed, 247 insertions, 190 deletions
diff --git a/tests/projects/bpf/minimal/test.lua b/tests/projects/bpf/minimal/test.lua new file mode 100644 index 000000000..2856a3831 --- /dev/null +++ b/tests/projects/bpf/minimal/test.lua @@ -0,0 +1,6 @@ +function main(t) + if is_host("linux") and os.arch() == "x86_64" then + os.vrun("xmake f -y -p android -vD") + os.vrun("xmake -y -vD") + end +end diff --git a/tests/projects/bpf/minimal/xmake.lua b/tests/projects/bpf/minimal/xmake.lua index ed9a0dd0c..8507b8aa1 100644 --- a/tests/projects/bpf/minimal/xmake.lua +++ b/tests/projects/bpf/minimal/xmake.lua @@ -3,7 +3,10 @@ add_rules("platform.linux.bpf") add_requires("linux-tools", {configs = {bpftool = true}}) add_requires("libbpf") -if not is_plat("android") then +if is_plat("android") then + add_requires("ndk >=22.x") + set_toolchains("@ndk", {sdkver = "23"}) +else add_requires("llvm >=10.x") set_toolchains("@llvm") add_requires("linux-headers") diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index d17b93c15..8b4098ca5 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -148,6 +148,15 @@ function _check_target_toolchains() raise(errors) end end + else + -- we only abort it when we know that toolchains of platform and target do not found + local toolchain_found + for _, toolchain_inst in pairs(target:toolchains()) do + if toolchain_inst:is_standalone() then + toolchain_found = true + end + end + assert(toolchain_found, "target(%s): toolchain not found!", target:name()) end end end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 7c6d0b3d6..033503580 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -60,6 +60,11 @@ function _instance:name() return self._NAME end +-- get the type: package +function _instance:type() + return "package" +end + -- get the package configure function _instance:get(name) @@ -677,11 +682,14 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if toolchains == nil then + local project = package._project() for _, name in ipairs(table.wrap(self:config("toolchains"))) do - local toolchain_opt = {plat = self:plat(), arch = self:arch()} + local toolchain_opt = project and project.extraconf("target.toolchains", name) or {} + toolchain_opt.plat = self:plat() + toolchain_opt.arch = self:arch() local toolchain_inst, errors = toolchain.load(name, toolchain_opt) - if not toolchain_inst and os.isfile(os.projectfile()) then - toolchain_inst = require("base/project").toolchain(name, toolchain_opt) + if not toolchain_inst and project then + toolchain_inst = project.toolchain(name, toolchain_opt) end if not toolchain_inst then os.raise(errors) @@ -1362,11 +1370,8 @@ end -- @return true or false -- function _instance:has_cfuncs(funcs, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.has_cfuncs", {anonymous = true})(funcs, opt) end @@ -1379,11 +1384,8 @@ end -- @return true or false -- function _instance:has_cxxfuncs(funcs, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.has_cxxfuncs", {anonymous = true})(funcs, opt) end @@ -1396,11 +1398,8 @@ end -- @return true or false -- function _instance:has_ctypes(types, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.has_ctypes", {anonymous = true})(types, opt) end @@ -1413,11 +1412,8 @@ end -- @return true or false -- function _instance:has_cxxtypes(types, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.has_cxxtypes", {anonymous = true})(types, opt) end @@ -1430,11 +1426,8 @@ end -- @return true or false -- function _instance:has_cincludes(includes, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.has_cincludes", {anonymous = true})(includes, opt) end @@ -1447,11 +1440,8 @@ end -- @return true or false -- function _instance:has_cxxincludes(includes, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.has_cxxincludes", {anonymous = true})(includes, opt) end @@ -1464,11 +1454,8 @@ end -- @return true or false -- function _instance:check_csnippets(snippets, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.check_csnippets", {anonymous = true})(snippets, opt) end @@ -1481,11 +1468,8 @@ end -- @return true or false -- function _instance:check_cxxsnippets(snippets, opt) - if self:plat() ~= config.get("plat") then - -- TODO - return true - end opt = opt or {} + opt.target = self opt.configs = self:_generate_build_configs(opt.configs) return sandbox_module.import("lib.detect.check_cxxsnippets", {anonymous = true})(snippets, opt) end @@ -1550,13 +1534,23 @@ function package._memcache() return memcache.cache("core.base.package") end +-- get project +function package._project() + local project = package._PROJECT + if not project then + if os.isfile(os.projectfile()) then + project = require("project/project") + end + end + return project +end + -- get global target platform of package function package._target_plat() local plat = package._memcache():get("target_plat") if plat == nil then - if not plat and os.isfile(os.projectfile()) then - local project = require("project/project") - local targetplat_root = project.get("target.plat") + if not plat and package._project() then + local targetplat_root = package._project().get("target.plat") if targetplat_root then plat = targetplat_root end @@ -1573,9 +1567,8 @@ end function package._target_arch() local arch = package._memcache():get("target_arch") if arch == nil then - if not arch and os.isfile(os.projectfile()) then - local project = require("project/project") - local targetarch_root = project.get("target.arch") + if not arch and package._project() then + local targetarch_root = package._project().get("target.arch") if targetarch_root then arch = targetarch_root end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 86990a2cb..e1e328914 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -194,10 +194,8 @@ function project._load(force, disable_filter) end -- save the root info - for name, value in pairs(rootinfo_target:info()) do - rootinfo:set("target." .. name, value) - end project._memcache():set("rootinfo", rootinfo) + project._memcache():set("rootinfo_target", rootinfo_target) -- leave the project directory oldir, errors = os.cd(oldir) @@ -360,26 +358,6 @@ function project._load_target(t, requires) return false, errors end - -- load toolchains - local toolchains = t:get("toolchains") - if toolchains then - t._TOOLCHAINS = {} - for _, name in ipairs(table.wrap(toolchains)) do - local toolchain_opt = table.copy(t:extraconf("toolchains", name)) - toolchain_opt.arch = t:arch() - toolchain_opt.plat = t:plat() - local toolchain_inst, errors = toolchain.load(name, toolchain_opt) - -- attempt to load toolchain from project - if not toolchain_inst then - toolchain_inst = project.toolchain(name, toolchain_opt) - end - if not toolchain_inst then - return false, errors - end - table.insert(t._TOOLCHAINS, toolchain_inst) - end - end - -- do after_load() for target and all rules ok, errors = t:_load_after() if not ok then @@ -864,12 +842,30 @@ function project.filelock() return filelock, errors end --- get the project info from the given name +-- get the root configuration function project.get(name) - local rootinfo = project._memcache():get("rootinfo") + local rootinfo + if name and name:startswith("target.") then + name = name:sub(8) + rootinfo = project._memcache():get("rootinfo_target") + else + rootinfo = project._memcache():get("rootinfo") + end return rootinfo and rootinfo:get(name) or nil end +-- get the root extra configuration +function project.extraconf(name, item, key) + local rootinfo + if name and name:startswith("target.") then + name = name:sub(8) + rootinfo = project._memcache():get("rootinfo_target") + else + rootinfo = project._memcache():get("rootinfo") + end + return rootinfo and rootinfo:extraconf(name, item, key) or nil +end + -- get the project name function project.name() local name = project.get("project") diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index e65c12c32..1c3503667 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -450,7 +450,7 @@ function _instance:info() return self._INFO:info() end --- get the type: option +-- get the type: target function _instance:type() return "target" end diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 3d36e7463..52f38e68c 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -37,6 +37,7 @@ local import = require("sandbox/modules/import") -- export some readonly interfaces sandbox_core_project.get = project.get +sandbox_core_project.extraconf = project.extraconf sandbox_core_project.rule = project.rule sandbox_core_project.rules = project.rules sandbox_core_project.toolchain = project.toolchain diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index 2511d309b..015e4ab73 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -28,14 +28,10 @@ local raise = require("sandbox/modules/raise") -- load the linker from the given target kind function sandbox_core_tool_linker.load(targetkind, sourcekinds, opt) - - -- get the linker instance local instance, errors = linker.load(targetkind, sourcekinds, opt and opt.target or nil) if not instance then raise(errors) end - - -- ok return instance end @@ -46,14 +42,8 @@ end -- make arguments list for linking target file function sandbox_core_tool_linker.linkargv(targetkind, sourcekinds, objectfiles, targetfile, opt) - - -- init options opt = opt or {} - - -- get the linker instance local instance = sandbox_core_tool_linker.load(targetkind, sourcekinds, opt) - - -- make arguments list return instance:linkargv(objectfiles, targetfile, opt) end @@ -78,14 +68,8 @@ end -- link target file function sandbox_core_tool_linker.link(targetkind, sourcekinds, objectfiles, targetfile, opt) - - -- init options opt = opt or {} - - -- get the linker instance local instance = sandbox_core_tool_linker.load(targetkind, sourcekinds, opt) - - -- link it local ok, errors = instance:link(objectfiles, targetfile, opt) if not ok then raise(errors) @@ -102,14 +86,8 @@ end -- @return the supported flags or nil -- function sandbox_core_tool_linker.has_flags(targetkind, sourcekinds, flags, opt) - - -- init options opt = opt or {} - - -- get the linker instance local instance = sandbox_core_tool_linker.load(targetkind, sourcekinds, opt) - - -- has flags? return instance:has_flags(flags) end @@ -123,14 +101,8 @@ end -- @return flags or nil -- function sandbox_core_tool_linker.map_flags(targetkind, sourcekinds, name, values, opt) - - -- init options opt = opt or {} - - -- get the linker instance local instance = sandbox_core_tool_linker.load(targetkind, sourcekinds, opt) - - -- map flags return instance:map_flags(name, values, opt) end diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 48ba6777e..33733eaab 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -155,17 +155,21 @@ function builder:_add_flags_from_config(flags) end end --- add flags from the option -function builder:_add_flags_from_option(flags, opt) - for _, flagkind in ipairs(self:_flagkinds()) do - self:_add_flags_from_flagkind(flags, opt, flagkind) +-- add flags from the target options +function builder:_add_flags_from_targetopts(flags, target) + for _, opt in ipairs(target:orderopts()) do + for _, flagkind in ipairs(self:_flagkinds()) do + self:_add_flags_from_flagkind(flags, opt, flagkind) + end end end --- add flags from the package -function builder:_add_flags_from_package(flags, pkg, target) - for _, flagkind in ipairs(self:_flagkinds()) do - table.join2(flags, self:_mapflags(pkg:get(flagkind), flagkind, target)) +-- add flags from the target packages +function builder:_add_flags_from_targetpkgs(flags, target) + for _, pkg in ipairs(target:orderpkgs()) do + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, self:_mapflags(pkg:get(flagkind), flagkind, target)) + end end end @@ -177,6 +181,12 @@ function builder:_add_flags_from_target(flags, target) return end + -- only for target and option + local target_type = target:type() + if target_type ~= "target" and target_type ~= "option" then + return + end + -- init cache self._TARGETFLAGS = self._TARGETFLAGS or {} local cache = self._TARGETFLAGS @@ -191,17 +201,13 @@ function builder:_add_flags_from_target(flags, target) self:_add_flags_from_language(targetflags, target) -- add flags for the target - if target:type() == "target" then + if target_type == "target" then -- add flags from options - for _, opt in ipairs(target:orderopts()) do - self:_add_flags_from_option(targetflags, opt) - end + self:_add_flags_from_targetopts(targetflags, target) -- add flags from packages - for _, pkg in ipairs(target:orderpkgs()) do - self:_add_flags_from_package(targetflags, pkg, target) - end + self:_add_flags_from_targetpkgs(targetflags, target) -- inherit flags (public/interface) from all dependent targets self:_inherit_flags_from_targetdeps(targetflags, target) @@ -211,12 +217,8 @@ function builder:_add_flags_from_target(flags, target) for _, flagkind in ipairs(self:_flagkinds()) do self:_add_flags_from_flagkind(targetflags, target, flagkind) end - - -- cache it cache[key] = targetflags end - - -- add flags table.join2(flags, targetflags) end @@ -225,11 +227,7 @@ function builder:_add_flags_from_argument(flags, target, args) -- add flags from the flag kinds (cxflags, ..) for _, flagkind in ipairs(self:_flagkinds()) do - - -- add auto mapping flags table.join2(flags, self:_mapflags(args[flagkind], flagkind, target)) - - -- add original flags local original_flags = (args.force or {})[flagkind] if original_flags then table.join2(flags, original_flags) @@ -237,16 +235,18 @@ function builder:_add_flags_from_argument(flags, target, args) end -- add flags (named) from the language - if target then - local key = target:type() - self:_add_flags_from_language(flags, target, { - [key] = function (name) return args[name] end, - toolchain = function (name) return platform.toolconfig(name) end}) - else - self:_add_flags_from_language(flags, nil, { - target = function (name) return args[name] end, - toolchain = function (name) return platform.toolconfig(name) end}) - end + self:_add_flags_from_language(flags, nil, { + target = function (name) return args[name] end, + toolchain = function (name) + local plat, arch + if target and target.plat then + plat = target:plat() + end + if target and target.arch then + arch = target:arch() + end + return platform.toolconfig(name, plat, arch) + end}) end -- add flags from the language diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index b896d04b6..0e64de8c3 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -46,7 +46,7 @@ function compiler:_add_flags_from_toolchains(flags, targetkind, target) -- add flags for platform with the given target kind, e.g. binary.gcc.cxflags or binary.cxflags if targetkind then local toolname = self:name() - if target and target:type() == "target" then + if target and target.toolconfig then for _, flagkind in ipairs(self:_flagkinds()) do local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. flagkind)) @@ -79,7 +79,7 @@ function compiler._load_tool(sourcekind, target) -- get program from target local program, toolname, toolchain_info - if target and target:type() == "target" then + if target and target.tool then program, toolname, toolchain_info = target:tool(sourcekind) end @@ -138,7 +138,7 @@ function compiler.load(sourcekind, target) -- add toolchains flags to the compiler tool, e.g. gcc.cxflags or cxflags local toolname = compiler_tool:name() - if target and target:type() == "target" then + if target and target.toolconfig then for _, flagkind in ipairs(instance:_flagkinds()) do compiler_tool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind)) end @@ -296,7 +296,7 @@ function compiler:compflags(opt) -- get target kind local targetkind = opt.targetkind - if not targetkind and target and target.targetkind then + if not targetkind and target and target:type() == "target" then targetkind = target:kind() end diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index a90dba8c1..25276bdce 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -43,7 +43,7 @@ function linker:_add_flags_from_toolchains(flags, targetkind, target) if targetkind then local toolkind = self:kind() local toolname = self:name() - if target and target:type() == "target" then + if target and target.toolconfig then for _, flagkind in ipairs(self:_flagkinds()) do local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. toolkind .. 'flags') or target:toolconfig(targetkind .. '.' .. flagkind)) @@ -86,7 +86,7 @@ function linker._load_tool(targetkind, sourcekinds, target) -- get program from target local program, toolname, toolchain_info - if target and target:type() == "target" then + if target and target.tool then program, toolname, toolchain_info = target:tool(_linkerinfo.linkerkind) end @@ -185,7 +185,7 @@ function linker.load(targetkind, sourcekinds, target) -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags local toolkind = linkertool:kind() local toolname = linkertool:name() - if target and target:type() == "target" then + if target and target.toolconfig then for _, flagkind in ipairs(instance:_flagkinds()) do linkertool:add(toolkind .. 'flags', target:toolconfig(toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(toolkind .. 'flags')) linkertool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind)) @@ -230,7 +230,7 @@ function linker:linkflags(opt) -- get target kind local targetkind = opt.targetkind - if not targetkind and target and target.targetkind then + if not targetkind and target and target:type() == "target" then targetkind = target:kind() end diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 3bfa23181..c40fbafda 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -41,6 +41,16 @@ function _translate_windows_bin_path(bin_path) end end +-- map compiler flags +function _map_compflags(package, langkind, name, values) + return compiler.map_flags(langkind, name, values, {target = package}) +end + +-- map linker flags +function _map_linkflags(package, targetkind, sourcekinds, name, values) + return linker.map_flags(targetkind, sourcekinds, name, values, {target = package}) +end + -- get configs function _get_configs(package, configs) @@ -142,21 +152,21 @@ function buildenvs(package, opt) table.join2(asflags, opt.asflags) table.join2(ldflags, opt.ldflags) table.join2(shflags, opt.shflags) - table.join2(cflags, compiler.map_flags("c", "define", defines)) - table.join2(cflags, compiler.map_flags("c", "includedir", includedirs)) - table.join2(cflags, compiler.map_flags("c", "sysincludedir", sysincludedirs)) - table.join2(asflags, compiler.map_flags("as", "define", defines)) - table.join2(asflags, compiler.map_flags("as", "includedir", includedirs)) - table.join2(asflags, compiler.map_flags("as", "sysincludedir", sysincludedirs)) - table.join2(cxxflags, compiler.map_flags("cxx", "define", defines)) - table.join2(cxxflags, compiler.map_flags("cxx", "includedir", includedirs)) - table.join2(cxxflags, compiler.map_flags("cxx", "sysincludedir", sysincludedirs)) - table.join2(ldflags, linker.map_flags("binary", {"cxx"}, "link", links)) - table.join2(ldflags, linker.map_flags("binary", {"cxx"}, "syslink", syslinks)) - table.join2(ldflags, linker.map_flags("binary", {"cxx"}, "linkdir", linkdirs)) - table.join2(shflags, linker.map_flags("shared", {"cxx"}, "link", links)) - table.join2(shflags, linker.map_flags("shared", {"cxx"}, "syslink", syslinks)) - table.join2(shflags, linker.map_flags("shared", {"cxx"}, "linkdir", linkdirs)) + table.join2(cflags, _map_compflags(package, "c", "define", defines)) + table.join2(cflags, _map_compflags(package, "c", "includedir", includedirs)) + table.join2(cflags, _map_compflags(package, "c", "sysincludedir", sysincludedirs)) + table.join2(asflags, _map_compflags(package, "as", "define", defines)) + table.join2(asflags, _map_compflags(package, "as", "includedir", includedirs)) + table.join2(asflags, _map_compflags(package, "as", "sysincludedir", sysincludedirs)) + table.join2(cxxflags, _map_compflags(package, "cxx", "define", defines)) + table.join2(cxxflags, _map_compflags(package, "cxx", "includedir", includedirs)) + table.join2(cxxflags, _map_compflags(package, "cxx", "sysincludedir", sysincludedirs)) + table.join2(ldflags, _map_linkflags(package, "binary", {"cxx"}, "link", links)) + table.join2(ldflags, _map_linkflags(package, "binary", {"cxx"}, "syslink", syslinks)) + table.join2(ldflags, _map_linkflags(package, "binary", {"cxx"}, "linkdir", linkdirs)) + table.join2(shflags, _map_linkflags(package, "shared", {"cxx"}, "link", links)) + table.join2(shflags, _map_linkflags(package, "shared", {"cxx"}, "syslink", syslinks)) + table.join2(shflags, _map_linkflags(package, "shared", {"cxx"}, "linkdir", linkdirs)) envs.CC = package:build_getenv("cc") envs.AS = package:build_getenv("as") envs.AR = package:build_getenv("ar") diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua index e4d77e3b2..6281372f9 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -52,6 +52,16 @@ function _translate_bin_path(bin_path) return bin_path end +-- map compiler flags +function _map_compflags(package, langkind, name, values) + return compiler.map_flags(langkind, name, values, {target = package}) +end + +-- map linker flags +function _map_linkflags(package, targetkind, sourcekinds, name, values) + return linker.map_flags(targetkind, sourcekinds, name, values, {target = package}) +end + -- get cflags from package deps function _get_cflags_from_packagedeps(package, opt) local result = {} @@ -60,9 +70,9 @@ function _get_cflags_from_packagedeps(package, opt) if dep then local fetchinfo = dep:fetch({external = false}) if fetchinfo then - table.join2(result, compiler.map_flags("cxx", "define", fetchinfo.defines)) - table.join2(result, _translate_paths(compiler.map_flags("cxx", "includedir", fetchinfo.includedirs))) - table.join2(result, _translate_paths(compiler.map_flags("cxx", "sysincludedir", fetchinfo.sysincludedirs))) + table.join2(result, _map_compflags(package, "cxx", "define", fetchinfo.defines)) + table.join2(result, _translate_paths(_map_compflags(package, "cxx", "includedir", fetchinfo.includedirs))) + table.join2(result, _translate_paths(_map_compflags(package, "cxx", "sysincludedir", fetchinfo.sysincludedirs))) end end end @@ -77,9 +87,9 @@ function _get_ldflags_from_packagedeps(package, opt) if dep then local fetchinfo = dep:fetch({external = false}) if fetchinfo then - table.join2(result, _translate_paths(linker.map_flags("binary", {"cxx"}, "linkdir", fetchinfo.linkdirs))) - table.join2(result, linker.map_flags("binary", {"cxx"}, "link", fetchinfo.links)) - table.join2(result, _translate_paths(linker.map_flags("binary", {"cxx"}, "syslink", fetchinfo.syslinks))) + table.join2(result, _translate_paths(_map_linkflags(package, "binary", {"cxx"}, "linkdir", fetchinfo.linkdirs))) + table.join2(result, _map_linkflags(package, "binary", {"cxx"}, "link", fetchinfo.links)) + table.join2(result, _translate_paths(_map_linkflags(package, "binary", {"cxx"}, "syslink", fetchinfo.syslinks))) end end end @@ -93,9 +103,9 @@ function _get_cflags(package, opt) if opt.cross then table.join2(result, package:build_getenv("cflags")) table.join2(result, package:build_getenv("cxflags")) - table.join2(result, compiler.map_flags("c", "define", package:build_getenv("defines"))) - table.join2(result, compiler.map_flags("c", "includedir", package:build_getenv("includedirs"))) - table.join2(result, compiler.map_flags("c", "sysincludedir", package:build_getenv("sysincludedirs"))) + table.join2(result, _map_compflags(package, "c", "define", package:build_getenv("defines"))) + table.join2(result, _map_compflags(package, "c", "includedir", package:build_getenv("includedirs"))) + table.join2(result, _map_compflags(package, "c", "sysincludedir", package:build_getenv("sysincludedirs"))) end table.join2(result, package:config("cflags")) table.join2(result, package:config("cxflags")) @@ -118,9 +128,9 @@ function _get_cxxflags(package, opt) if opt.cross then table.join2(result, package:build_getenv("cxxflags")) table.join2(result, package:build_getenv("cxflags")) - table.join2(result, compiler.map_flags("cxx", "define", package:build_getenv("defines"))) - table.join2(result, compiler.map_flags("cxx", "includedir", package:build_getenv("includedirs"))) - table.join2(result, compiler.map_flags("cxx", "sysincludedir", package:build_getenv("sysincludedirs"))) + table.join2(result, _map_compflags(package, "cxx", "define", package:build_getenv("defines"))) + table.join2(result, _map_compflags(package, "cxx", "includedir", package:build_getenv("includedirs"))) + table.join2(result, _map_compflags(package, "cxx", "sysincludedir", package:build_getenv("sysincludedirs"))) end table.join2(result, package:config("cxxflags")) table.join2(result, package:config("cxflags")) @@ -142,9 +152,9 @@ function _get_asflags(package, opt) local result = {} if opt.cross then table.join2(result, package:build_getenv("asflags")) - table.join2(result, compiler.map_flags("as", "define", package:build_getenv("defines"))) - table.join2(result, compiler.map_flags("as", "includedir", package:build_getenv("includedirs"))) - table.join2(result, compiler.map_flags("as", "sysincludedir", package:build_getenv("sysincludedirs"))) + table.join2(result, _map_compflags(package, "as", "define", package:build_getenv("defines"))) + table.join2(result, _map_compflags(package, "as", "includedir", package:build_getenv("includedirs"))) + table.join2(result, _map_compflags(package, "as", "sysincludedir", package:build_getenv("sysincludedirs"))) end table.join2(result, package:config("asflags")) if opt.asflags then @@ -161,9 +171,9 @@ function _get_ldflags(package, opt) local result = {} if opt.cross then table.join2(result, package:build_getenv("ldflags")) - table.join2(result, linker.map_flags("binary", {"cxx"}, "link", package:build_getenv("links"))) - table.join2(result, linker.map_flags("binary", {"cxx"}, "syslink", package:build_getenv("syslinks"))) - table.join2(result, linker.map_flags("binary", {"cxx"}, "linkdir", package:build_getenv("linkdirs"))) + table.join2(result, _map_linkflags(package, "binary", {"cxx"}, "link", package:build_getenv("links"))) + table.join2(result, _map_linkflags(package, "binary", {"cxx"}, "syslink", package:build_getenv("syslinks"))) + table.join2(result, _map_linkflags(package, "binary", {"cxx"}, "linkdir", package:build_getenv("linkdirs"))) end table.join2(result, _get_ldflags_from_packagedeps(package, opt)) if opt.ldflags then @@ -180,9 +190,9 @@ function _get_shflags(package, opt) local result = {} if opt.cross then table.join2(result, package:build_getenv("shflags")) - table.join2(result, linker.map_flags("shared", {"cxx"}, "link", package:build_getenv("links"))) - table.join2(result, linker.map_flags("shared", {"cxx"}, "syslink", package:build_getenv("syslinks"))) - table.join2(result, linker.map_flags("shared", {"cxx"}, "linkdir", package:build_getenv("linkdirs"))) + table.join2(result, _map_linkflags(package, "shared", {"cxx"}, "link", package:build_getenv("links"))) + table.join2(result, _map_linkflags(package, "shared", {"cxx"}, "syslink", package:build_getenv("syslinks"))) + table.join2(result, _map_linkflags(package, "shared", {"cxx"}, "linkdir", package:build_getenv("linkdirs"))) end table.join2(result, _get_ldflags_from_packagedeps(package, opt)) if opt.shflags then diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index fbedc2bc9..096190945 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -392,14 +392,14 @@ function _get_package_installdeps(packages) end for _, instance in ipairs(packages) do local deps = {} - if instance:deps() then - deps = table.copy(instance:deps()) + if instance:orderdeps() then + deps = table.copy(instance:orderdeps()) end -- patch toolchain/packages to installdeps, because we need install toolchain package first - if instance:is_toplevel() then - for _, toolchain in ipairs(instance:toolchains()) do - for _, packagename in ipairs(toolchain:config("packages")) do - deps[packagename] = packagesmap[packagename] + for _, toolchain in ipairs(instance:toolchains()) do + for _, packagename in ipairs(toolchain:config("packages")) do + if packagesmap[packagename] ~= instance then -- avoid loop recursion + table.insert(deps, packagesmap[packagename]) end end end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index dc6720eb5..cc6d43afd 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -43,6 +43,7 @@ end -- -- semver -- - add_requires("tbox >=1.5.1", "zlib >=1.2.11") +-- - add_requires("tbox", {version = ">=1.5.1"}) -- -- git branch/tag -- - add_requires("zlib master") @@ -149,7 +150,7 @@ function _parse_require(require_str, requires_extra, parentinfo) { originstr = require_str, reponame = reponame, - version = version, + version = require_extra.version or version, plat = require_extra.plat, -- require package in the given platform arch = require_extra.arch, -- require package in the given architecture targetos = require_extra.targetos, -- require package in the given target os @@ -340,8 +341,9 @@ end -- init requireinfo function _init_requireinfo(requireinfo, package, opt) -- pass root toolchains to top library package - if opt.is_toplevel and package:is_plat("cross") and package:is_library() then + if opt.is_toplevel and package:is_cross() and package:is_library() then requireinfo.configs = requireinfo.configs or {} + -- TODO get extra configs of toolchain requireinfo.configs.toolchains = requireinfo.configs.toolchains or project.get("target.toolchains") or get_config("toolchain") end end diff --git a/xmake/rules/platform/linux/bpf/xmake.lua b/xmake/rules/platform/linux/bpf/xmake.lua index 9a67c32cf..d2afd9160 100644 --- a/xmake/rules/platform/linux/bpf/xmake.lua +++ b/xmake/rules/platform/linux/bpf/xmake.lua @@ -25,17 +25,32 @@ rule("platform.linux.bpf") on_config(function (target) assert(is_host("linux"), 'rule("platform.linux.bpf"): only supported on linux!') local headerdir = path.join(target:autogendir(), "rules", "bpf") + if not os.isdir(headerdir) then + os.mkdir(headerdir) + end target:add("includedirs", headerdir) end) before_buildcmd_file(function (target, batchcmds, sourcefile, opt) local headerfile = path.join(target:autogendir(), "rules", "bpf", (path.filename(sourcefile):gsub("%.bpf%.c", ".skel.h"))) local objectfile = path.join(target:autogendir(), "rules", "bpf", (path.filename(sourcefile):gsub("%.bpf%.c", ".bpf.o"))) + local targetarch + if target:is_arch("x86_64", "i386") then + targetarch = "__TARGET_ARCH_x86" + elseif target:is_arch("arm64", "arm64-v8a") then + targetarch = "__TARGET_ARCH_arm64" + elseif target:is_arch("arm.*") then + targetarch = "__TARGET_ARCH_arm" + elseif target:is_arch("mips64", "mips") then + targetarch = "__TARGET_ARCH_mips" + elseif target:is_arch("ppc64", "ppc") then + targetarch = "__TARGET_ARCH_powerpc" + end target:add("includedirs", path.directory(headerfile)) batchcmds:show_progress(opt.progress, "${color.build.object}compiling.bpf %s", sourcefile) batchcmds:mkdir(path.directory(objectfile)) - batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g"}, defines = "__TARGET_ARCH_x86"}}}) + batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g"}}, defines = targetarch}}) batchcmds:mkdir(path.directory(headerfile)) - batchcmds:vrunv("bpftool", {"gen", "skeleton", objectfile}, {stdout = headerfile}) + batchcmds:execv("bpftool", {"gen", "skeleton", objectfile}, {stdout = headerfile}) batchcmds:add_depfiles(sourcefile) batchcmds:set_depmtime(os.mtime(headerfile)) batchcmds:set_depcache(target:dependfile(headerfile)) diff --git a/xmake/toolchains/msvc/xmake.lua b/xmake/toolchains/msvc/xmake.lua index 2b9f4eb1e..a79cb4268 100644 --- a/xmake/toolchains/msvc/xmake.lua +++ b/xmake/toolchains/msvc/xmake.lua @@ -18,7 +18,17 @@ -- @file xmake.lua -- --- define toolchain +-- msvc toolchain +-- +-- @param vs the vs version +-- +-- @code +-- target("test") +-- ... +-- set_toolchains("msvc") +-- set_toolchains("msvc", {vs = "2019"}) +-- @endcode +-- toolchain("msvc") -- set homepage diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index fe8183277..aaf1d609a 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -19,13 +19,32 @@ -- -- imports +import("core.base.option") import("core.project.config") import("detect.sdks.find_ndk") import("detect.sdks.find_android_sdk") -- check the ndk toolchain function _check_ndk(toolchain) - local ndk = find_ndk(toolchain:config("ndk") or config.get("ndk"), {force = true, verbose = true}) + local ndk + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir and os.isdir(installdir) then + ndk = find_ndk(installdir, {force = true, verbose = option.get("verbose"), + plat = toolchain:plat(), + arch = toolchain:arch(), + sdkver = toolchain:config("sdkver")}) + if ndk then + break + end + end + end + if not ndk then + ndk = find_ndk(toolchain:config("ndk") or config.get("ndk"), {force = true, verbose = true, + plat = toolchain:plat(), + arch = toolchain:arch(), + sdkver = toolchain:config("sdkver")}) + end if ndk then toolchain:config_set("ndk", ndk.sdkdir) toolchain:config_set("bindir", ndk.bindir) @@ -36,18 +55,20 @@ function _check_ndk(toolchain) toolchain:config_set("ndk_toolchains_ver", ndk.toolchains_ver) toolchain:config_set("ndk_sysroot", ndk.sysroot) toolchain:configs_save() + return true else + --[[TODO we need also add this tips when use remote ndk toolchain -- failed cprint("${bright color.error}please run:") cprint(" - xmake config --ndk=xxx") cprint("or - xmake global --ndk=xxx") - raise() + raise()]] end end -- check the android sdk function _check_android_sdk(toolchain) - local sdk = find_android_sdk(toolchain:config("android_sdk") or config.get("android_sdk"), {force = true, verbose = true}) + local sdk = find_android_sdk(toolchain:config("android_sdk") or config.get("android_sdk"), {force = true, verbose = toolchain:is_global()}) if sdk then toolchain:config_set("android_sdk", sdk.sdkdir) toolchain:config_set("build_toolver", sdk.build_toolver) @@ -58,6 +79,5 @@ end -- main entry function main(toolchain) _check_android_sdk(toolchain) - _check_ndk(toolchain) - return true + return _check_ndk(toolchain) end diff --git a/xmake/toolchains/ndk/xmake.lua b/xmake/toolchains/ndk/xmake.lua index 099deeae9..609efb4a2 100644 --- a/xmake/toolchains/ndk/xmake.lua +++ b/xmake/toolchains/ndk/xmake.lua @@ -18,7 +18,17 @@ -- @file xmake.lua -- --- define toolchain +-- android ndk toolchain +-- +-- @param sdkver the platform sdk version +-- +-- @code +-- target("test") +-- ... +-- set_toolchains("ndk") +-- set_toolchains("ndk", {sdkver = "23"}) +-- @endcode +-- toolchain("ndk") -- set homepage |
