From 5f4104bb7c5b188965f30d401762162294764b73 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 22:54:20 +0800 Subject: support ndk package --- .../modules/private/action/require/impl/install_packages.lua | 12 +++++------- xmake/modules/private/action/require/impl/package.lua | 2 +- xmake/toolchains/ndk/check.lua | 12 ++++++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index fbedc2bc9..8757de282 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -392,15 +392,13 @@ 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] - end + for _, toolchain in ipairs(instance:toolchains()) do + for _, packagename in ipairs(toolchain:config("packages")) do + table.insert(deps, packagesmap[packagename]) end end installdeps[tostring(instance)] = deps diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index dc6720eb5..091984643 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -340,7 +340,7 @@ 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 {} requireinfo.configs.toolchains = requireinfo.configs.toolchains or project.get("target.toolchains") or get_config("toolchain") end diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index fe8183277..583e6d591 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -26,6 +26,18 @@ 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}) + if not ndk then + -- find it from packages + 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 = true}) + if ndk then + break + end + end + end + end if ndk then toolchain:config_set("ndk", ndk.sdkdir) toolchain:config_set("bindir", ndk.bindir) -- cgit v1.3.1 From 6c5d06600df7b859791fafb8ea87fd87f63fb825 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 23:29:20 +0800 Subject: improve ndk toolchain --- tests/projects/bpf/minimal/xmake.lua | 5 +++- xmake/core/package/package.lua | 32 +++++++++++----------- .../private/action/require/impl/package.lua | 1 + xmake/toolchains/msvc/xmake.lua | 12 +++++++- xmake/toolchains/ndk/check.lua | 7 +++-- xmake/toolchains/ndk/xmake.lua | 12 +++++++- 6 files changed, 47 insertions(+), 22 deletions(-) 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/core/package/package.lua b/xmake/core/package/package.lua index 7c6d0b3d6..f2c437924 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1362,8 +1362,8 @@ end -- @return true or false -- function _instance:has_cfuncs(funcs, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1379,8 +1379,8 @@ end -- @return true or false -- function _instance:has_cxxfuncs(funcs, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1396,8 +1396,8 @@ end -- @return true or false -- function _instance:has_ctypes(types, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1413,8 +1413,8 @@ end -- @return true or false -- function _instance:has_cxxtypes(types, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1430,8 +1430,8 @@ end -- @return true or false -- function _instance:has_cincludes(includes, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1447,8 +1447,8 @@ end -- @return true or false -- function _instance:has_cxxincludes(includes, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1464,8 +1464,8 @@ end -- @return true or false -- function _instance:check_csnippets(snippets, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} @@ -1481,8 +1481,8 @@ end -- @return true or false -- function _instance:check_cxxsnippets(snippets, opt) - if self:plat() ~= config.get("plat") then - -- TODO + if not self:is_plat(config.get("plat")) or self:config("toolchains") then + -- TODO we also need check it later for package with custom toolchains return true end opt = opt or {} diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 091984643..c70a933cc 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -342,6 +342,7 @@ function _init_requireinfo(requireinfo, package, opt) -- pass root toolchains to top library package 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/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 583e6d591..9f54cdb9a 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -25,13 +25,13 @@ 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 = find_ndk(toolchain:config("ndk") or config.get("ndk"), {force = true, verbose = true, sdkver = toolchain:config("sdkver")}) if not ndk then -- find it from packages 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 = true}) + ndk = find_ndk(installdir, {force = true, verbose = true, sdkver = toolchain:config("sdkver")}) if ndk then break end @@ -49,11 +49,12 @@ function _check_ndk(toolchain) toolchain:config_set("ndk_sysroot", ndk.sysroot) toolchain:configs_save() else + --[[TODO -- failed cprint("${bright color.error}please run:") cprint(" - xmake config --ndk=xxx") cprint("or - xmake global --ndk=xxx") - raise() + raise()]] end 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 -- cgit v1.3.1 From 694f96c172b967362df42c201963d04f224819c5 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 23:29:47 +0800 Subject: improve test --- tests/projects/bpf/minimal/test.lua | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/projects/bpf/minimal/test.lua diff --git a/tests/projects/bpf/minimal/test.lua b/tests/projects/bpf/minimal/test.lua new file mode 100644 index 000000000..76adbaecf --- /dev/null +++ b/tests/projects/bpf/minimal/test.lua @@ -0,0 +1,6 @@ +function main(t) + if is_host("linux") then + os.vrun("xmake f -p android -vD") + os.vrun("xmake -vD") + end +end -- cgit v1.3.1 From f762654a5b85301a71b752754e4c036a20eb6399 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 23:31:25 +0800 Subject: fix test --- tests/projects/bpf/minimal/test.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/projects/bpf/minimal/test.lua b/tests/projects/bpf/minimal/test.lua index 76adbaecf..1769a2927 100644 --- a/tests/projects/bpf/minimal/test.lua +++ b/tests/projects/bpf/minimal/test.lua @@ -1,6 +1,6 @@ function main(t) if is_host("linux") then - os.vrun("xmake f -p android -vD") - os.vrun("xmake -vD") + os.vrun("xmake f -y -p android -vD") + os.vrun("xmake -y -vD") end end -- cgit v1.3.1 From 926e80670c1ac3048dcffe207ed4d32571b10363 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 23:35:44 +0800 Subject: fix test again --- tests/projects/bpf/minimal/test.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/projects/bpf/minimal/test.lua b/tests/projects/bpf/minimal/test.lua index 1769a2927..2856a3831 100644 --- a/tests/projects/bpf/minimal/test.lua +++ b/tests/projects/bpf/minimal/test.lua @@ -1,5 +1,5 @@ function main(t) - if is_host("linux") then + if is_host("linux") and os.arch() == "x86_64" then os.vrun("xmake f -y -p android -vD") os.vrun("xmake -y -vD") end -- cgit v1.3.1 From 7852d9f59e26ea7a357a4c9434bbfbb32729094a Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 23:46:20 +0800 Subject: improve to check ndk --- xmake/toolchains/ndk/check.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index 9f54cdb9a..d7ecb4113 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -25,19 +25,19 @@ 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, sdkver = toolchain:config("sdkver")}) - if not ndk then - -- find it from packages - 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 = true, sdkver = toolchain:config("sdkver")}) - if ndk then - break - end + 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 = true, 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, sdkver = toolchain:config("sdkver")}) + end if ndk then toolchain:config_set("ndk", ndk.sdkdir) toolchain:config_set("bindir", ndk.bindir) -- cgit v1.3.1 From 7adbba0c3b57e0a58eaf00b8ab21db5bcffdf1fc Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 18 Mar 2021 23:48:41 +0800 Subject: fix require version --- xmake/modules/private/action/require/impl/package.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index c70a933cc..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 -- cgit v1.3.1 From 66a47b5aa01fc5ccd4897f6d81da4f9b6baab428 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 00:39:25 +0800 Subject: add some TODO comments --- xmake/actions/config/main.lua | 10 ++++++++++ xmake/modules/package/tools/autoconf.lua | 2 +- xmake/toolchains/ndk/check.lua | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index d17b93c15..9d56baac4 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -148,6 +148,16 @@ 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 + print(toolchain_inst:name()) + 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/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index 3bfa23181..dbc7e2140 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -142,7 +142,7 @@ 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", "define", defines)) -- TODO we need use package/toolchains 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)) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index d7ecb4113..907d652c6 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -48,8 +48,9 @@ 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 + --[[TODO we need also add this tips when use remote ndk toolchain -- failed cprint("${bright color.error}please run:") cprint(" - xmake config --ndk=xxx") @@ -72,5 +73,7 @@ end function main(toolchain) _check_android_sdk(toolchain) _check_ndk(toolchain) + -- TODO we should return the check result, but we need support builder with package first + -- so we need improve remote ndk toolchain return true end -- cgit v1.3.1 From ca8ee5890b4dc9fcb06dd5700c78210fc3c1076e Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 00:42:25 +0800 Subject: remove unused codes --- xmake/core/project/project.lua | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 86990a2cb..aa2c36ff2 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -360,26 +360,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 -- cgit v1.3.1 From 81a4f2b294648ea78bec1d67d5d35672b608e67e Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 00:54:30 +0800 Subject: improve verbose info --- xmake/toolchains/ndk/check.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index 907d652c6..117c44ac6 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -19,6 +19,7 @@ -- -- imports +import("core.base.option") import("core.project.config") import("detect.sdks.find_ndk") import("detect.sdks.find_android_sdk") @@ -29,7 +30,7 @@ function _check_ndk(toolchain) 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 = true, sdkver = toolchain:config("sdkver")}) + ndk = find_ndk(installdir, {force = true, verbose = option.get("verbose"), sdkver = toolchain:config("sdkver")}) if ndk then break end -- cgit v1.3.1 From 3b27d07da4a9b5156bac808fab0a826d5e02d63c Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 00:57:28 +0800 Subject: fix tips --- xmake/toolchains/ndk/check.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index 117c44ac6..b80e1423c 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -62,7 +62,7 @@ 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) -- cgit v1.3.1 From 820d692e187cf2955db810314b6df02c9d093dc4 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 00:58:44 +0800 Subject: fix bpf rule --- xmake/rules/platform/linux/bpf/xmake.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xmake/rules/platform/linux/bpf/xmake.lua b/xmake/rules/platform/linux/bpf/xmake.lua index 9a67c32cf..165e71dce 100644 --- a/xmake/rules/platform/linux/bpf/xmake.lua +++ b/xmake/rules/platform/linux/bpf/xmake.lua @@ -25,6 +25,9 @@ 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) @@ -35,7 +38,7 @@ rule("platform.linux.bpf") batchcmds:mkdir(path.directory(objectfile)) batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g"}, defines = "__TARGET_ARCH_x86"}}}) 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)) -- cgit v1.3.1 From d3a4bea52c5a022472133368b6f002f285144d36 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 22:33:05 +0800 Subject: avoid loop recursion --- xmake/modules/private/action/require/impl/install_packages.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 8757de282..096190945 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -398,7 +398,9 @@ function _get_package_installdeps(packages) -- patch toolchain/packages to installdeps, because we need install toolchain package first for _, toolchain in ipairs(instance:toolchains()) do for _, packagename in ipairs(toolchain:config("packages")) do - table.insert(deps, packagesmap[packagename]) + if packagesmap[packagename] ~= instance then -- avoid loop recursion + table.insert(deps, packagesmap[packagename]) + end end end installdeps[tostring(instance)] = deps -- cgit v1.3.1 From 75aeab68cd10fd361547fb7da23151ede22c70f1 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 19 Mar 2021 23:19:29 +0800 Subject: remove unused codes --- xmake/actions/config/main.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 9d56baac4..8b4098ca5 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -152,7 +152,6 @@ function _check_target_toolchains() -- 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 - print(toolchain_inst:name()) if toolchain_inst:is_standalone() then toolchain_found = true end -- cgit v1.3.1 From c1261619d8e7330a1a99e50a73b5baddf2dd66f4 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Mar 2021 00:40:01 +0800 Subject: improve ndk --- xmake/toolchains/ndk/check.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index b80e1423c..605fa250a 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -30,14 +30,20 @@ function _check_ndk(toolchain) 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"), sdkver = toolchain:config("sdkver")}) + 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, sdkver = toolchain:config("sdkver")}) + 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) -- cgit v1.3.1 From 7556e19a1193841aa49871ffab35bc3e56bd481e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Mar 2021 00:50:56 +0800 Subject: pass extraconf to package --- xmake/core/package/package.lua | 30 +++++++++++++++------- xmake/core/project/project.lua | 26 +++++++++++++++---- .../modules/import/core/project/project.lua | 1 + 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f2c437924..a59ee7c5d 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -677,11 +677,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) @@ -1550,13 +1553,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 +1586,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 aa2c36ff2..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) @@ -844,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/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 -- cgit v1.3.1 From 03b2656fb77fb3339e43bf8871398b0e2f052a80 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 09:24:00 +0800 Subject: improve builder --- xmake/core/package/package.lua | 5 +++++ xmake/core/project/target.lua | 2 +- xmake/core/tool/builder.lua | 49 +++++++++++++++--------------------------- xmake/core/tool/linker.lua | 2 +- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index a59ee7c5d..d609c907d 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) 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/tool/builder.lua b/xmake/core/tool/builder.lua index 48ba6777e..08a6080c7 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 @@ -194,14 +198,10 @@ function builder:_add_flags_from_target(flags, target) 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 +211,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 +221,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 +229,9 @@ 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) return platform.toolconfig(name) end}) end -- add flags from the language diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index a90dba8c1..65eabce46 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -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 -- cgit v1.3.1 From efa052bcecd4203dfce0fda26a297f3ce45ed47d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 12:55:10 +0800 Subject: improve linker and compiler for package --- xmake/core/package/package.lua | 40 ++++++++-------------------------------- xmake/core/tool/builder.lua | 8 +++++++- xmake/core/tool/compiler.lua | 8 ++++---- xmake/core/tool/linker.lua | 4 ++-- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index d609c907d..033503580 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1370,11 +1370,8 @@ end -- @return true or false -- function _instance:has_cfuncs(funcs, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1387,11 +1384,8 @@ end -- @return true or false -- function _instance:has_cxxfuncs(funcs, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1404,11 +1398,8 @@ end -- @return true or false -- function _instance:has_ctypes(types, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1421,11 +1412,8 @@ end -- @return true or false -- function _instance:has_cxxtypes(types, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1438,11 +1426,8 @@ end -- @return true or false -- function _instance:has_cincludes(includes, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1455,11 +1440,8 @@ end -- @return true or false -- function _instance:has_cxxincludes(includes, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1472,11 +1454,8 @@ end -- @return true or false -- function _instance:check_csnippets(snippets, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 @@ -1489,11 +1468,8 @@ end -- @return true or false -- function _instance:check_cxxsnippets(snippets, opt) - if not self:is_plat(config.get("plat")) or self:config("toolchains") then - -- TODO we also need check it later for package with custom toolchains - 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 diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 08a6080c7..9b59de413 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -181,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 @@ -195,7 +201,7 @@ 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 self:_add_flags_from_targetopts(targetflags, target) 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 65eabce46..cc67088a2 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -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)) -- cgit v1.3.1 From f4333905bba49775a03def29e7b588246aaef4bf Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 14:42:43 +0800 Subject: improve map_flags --- .../sandbox/modules/import/core/tool/linker.lua | 28 ------------ xmake/modules/package/tools/autoconf.lua | 40 ++++++++++------- xmake/modules/package/tools/cmake.lua | 52 +++++++++++++--------- xmake/toolchains/ndk/check.lua | 5 +-- 4 files changed, 57 insertions(+), 68 deletions(-) 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/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index dbc7e2140..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)) -- TODO we need use package/toolchains - 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/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index 605fa250a..aaf1d609a 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -79,8 +79,5 @@ end -- main entry function main(toolchain) _check_android_sdk(toolchain) - _check_ndk(toolchain) - -- TODO we should return the check result, but we need support builder with package first - -- so we need improve remote ndk toolchain - return true + return _check_ndk(toolchain) end -- cgit v1.3.1 From 84967845ae815d903e2c120b9b05bc7dc7da0a89 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 14:44:02 +0800 Subject: improve linker --- xmake/core/tool/linker.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index cc67088a2..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)) -- cgit v1.3.1 From ac6d791223fda0ddd698a4d940f57bde569a7c9a Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 15:12:46 +0800 Subject: fix builder --- xmake/core/tool/builder.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 9b59de413..33733eaab 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -237,7 +237,16 @@ function builder:_add_flags_from_argument(flags, target, args) -- add flags (named) from the language self:_add_flags_from_language(flags, nil, { target = function (name) return args[name] end, - toolchain = function (name) return platform.toolconfig(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 -- cgit v1.3.1 From e646f772b78da7fdac107e497970fdd51ba098eb Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 21:23:08 +0800 Subject: improve bpf rule --- xmake/rules/platform/linux/bpf/xmake.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xmake/rules/platform/linux/bpf/xmake.lua b/xmake/rules/platform/linux/bpf/xmake.lua index 165e71dce..df4de7c1d 100644 --- a/xmake/rules/platform/linux/bpf/xmake.lua +++ b/xmake/rules/platform/linux/bpf/xmake.lua @@ -33,10 +33,22 @@ rule("platform.linux.bpf") 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:execv("bpftool", {"gen", "skeleton", objectfile}, {stdout = headerfile}) batchcmds:add_depfiles(sourcefile) -- cgit v1.3.1 From 7e37f40d47668f01b8d21255caa40b1b153f5c30 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 21 Mar 2021 21:26:34 +0800 Subject: fix bpf rule --- xmake/rules/platform/linux/bpf/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/platform/linux/bpf/xmake.lua b/xmake/rules/platform/linux/bpf/xmake.lua index df4de7c1d..d2afd9160 100644 --- a/xmake/rules/platform/linux/bpf/xmake.lua +++ b/xmake/rules/platform/linux/bpf/xmake.lua @@ -48,7 +48,7 @@ rule("platform.linux.bpf") 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 = targetarch}}}) + batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g"}}, defines = targetarch}}) batchcmds:mkdir(path.directory(headerfile)) batchcmds:execv("bpftool", {"gen", "skeleton", objectfile}, {stdout = headerfile}) batchcmds:add_depfiles(sourcefile) -- cgit v1.3.1