diff options
| author | ruki <[email protected]> | 2021-02-04 22:50:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-02-04 22:50:04 +0800 |
| commit | 21f54de18ca93ef952e5c5711fa491330cf9f49f (patch) | |
| tree | 7ca2ab9a95c2021ad6c494802b7edc4212498b33 | |
| parent | b90547ab8d1436d268b09ec424df3069d77ecb35 (diff) | |
add packages toolchain
| -rw-r--r-- | tests/projects/package/toolchain_gnu_rm/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/package/toolchain_llvm_mingw/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/package/toolchain_muslcc/src/main.c | 2 | ||||
| -rw-r--r-- | tests/projects/package/toolchain_muslcc/xmake.lua | 13 | ||||
| -rw-r--r-- | tests/projects/package/toolchain_zig/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 11 | ||||
| -rw-r--r-- | xmake/toolchains/cross/check.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/gnu-rm/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/mingw/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/muslcc/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/zig/xmake.lua | 3 |
13 files changed, 41 insertions, 12 deletions
diff --git a/tests/projects/package/toolchain_gnu_rm/xmake.lua b/tests/projects/package/toolchain_gnu_rm/xmake.lua index 712114dbe..d00bc859c 100644 --- a/tests/projects/package/toolchain_gnu_rm/xmake.lua +++ b/tests/projects/package/toolchain_gnu_rm/xmake.lua @@ -4,4 +4,4 @@ add_requires("gnu-rm") target("test") set_kind("binary") add_files("src/*.c") - set_toolchains("gnu-rm", {packages = "gnu-rm"}) + set_toolchains("gnu-rm") diff --git a/tests/projects/package/toolchain_llvm_mingw/xmake.lua b/tests/projects/package/toolchain_llvm_mingw/xmake.lua index 0cb0d01b9..0373bd96b 100644 --- a/tests/projects/package/toolchain_llvm_mingw/xmake.lua +++ b/tests/projects/package/toolchain_llvm_mingw/xmake.lua @@ -4,4 +4,4 @@ add_requires("llvm-mingw") target("test") set_kind("binary") add_files("src/*.c") - set_toolchains("mingw", {packages = "llvm-mingw"}) + set_toolchains("mingw") diff --git a/tests/projects/package/toolchain_muslcc/src/main.c b/tests/projects/package/toolchain_muslcc/src/main.c index c8b1209a0..9ec3e9c6d 100644 --- a/tests/projects/package/toolchain_muslcc/src/main.c +++ b/tests/projects/package/toolchain_muslcc/src/main.c @@ -1,9 +1,11 @@ #include <stdio.h> #include <zlib.h> +#include <pcre2.h> int main(int argc, char** argv) { printf("hello world!\n"); inflate(0, 0); + pcre2_compile(0, 0, 0, 0, 0, 0); return 0; } diff --git a/tests/projects/package/toolchain_muslcc/xmake.lua b/tests/projects/package/toolchain_muslcc/xmake.lua index 4b4904427..9bfa0de28 100644 --- a/tests/projects/package/toolchain_muslcc/xmake.lua +++ b/tests/projects/package/toolchain_muslcc/xmake.lua @@ -1,9 +1,16 @@ add_rules("mode.debug", "mode.release") + +-- set muslcc as global toolchain add_requires("muslcc") -add_requires("zlib") +set_toolchains("muslcc") + +-- explicitly specify the package toolchain +add_requires("zlib", {configs = {toolchains = "muslcc"}}) + +-- use global toolchain: muslcc +add_requires("pcre2") target("test") set_kind("binary") add_files("src/*.c") - add_packages("zlib") - set_toolchains("muslcc", {packages = "muslcc"}) + add_packages("zlib", "pcre2") diff --git a/tests/projects/package/toolchain_zig/xmake.lua b/tests/projects/package/toolchain_zig/xmake.lua index c08fdca16..095e2cba0 100644 --- a/tests/projects/package/toolchain_zig/xmake.lua +++ b/tests/projects/package/toolchain_zig/xmake.lua @@ -3,5 +3,5 @@ add_requires("zig 0.7.x") target("test") set_kind("binary") - add_files("src/*.zig") - set_toolchains("zig", {packages = "zig"}) + add_files("src/*.zig") -- we use builtin zig toolchain + diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index daecf34f1..16a0acb4d 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -226,6 +226,7 @@ end -- add some builtin configurations to package function _add_package_configurations(package) local vs_runtime = project.get("target.runtimes") or get_config("vs_runtime") or "MT" + local toolchains = project.get("target.toolchains") or get_config("toolchain") package:add("configs", "debug", {builtin = true, description = "Enable debug symbols.", default = false, type = "boolean"}) package:add("configs", "shared", {builtin = true, description = "Enable shared library.", default = false, type = "boolean"}) package:add("configs", "cflags", {builtin = true, description = "Set the C compiler flags."}) @@ -234,6 +235,7 @@ function _add_package_configurations(package) package:add("configs", "asflags", {builtin = true, description = "Set the assembler flags."}) package:add("configs", "pic", {builtin = true, description = "Enable the position independent code.", default = true, type = "boolean"}) package:add("configs", "vs_runtime", {builtin = true, description = "Set vs compiler runtime.", default = vs_runtime, values = {"MT", "MTd", "MD", "MDd"}}) + package:add("configs", "toolchains", {builtin = true, description = "Set package toolchains.", default = toolchains}) end -- select package version diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 31daea468..cd71245bf 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -273,20 +273,21 @@ end function _instance:packages() local packages = self._PACKAGES if packages == nil then - packages = {} local project = require("project/project") - for _, pkgname in ipairs(table.wrap(self:config("packages"))) do + -- we will get packages from `set_toolchains("", {packages})` or `toolchain().add_packages()` + for _, pkgname in ipairs(table.wrap(self:config("packages") or self:info():get("packages"))) do local requires = project.requires() if requires then local pkginfo = requires[pkgname] if pkginfo then + packages = packages or {} table.insert(packages, pkginfo) end end end - self._PACKAGES = packages + self._PACKAGES = packages or false end - return packages + return packages or nil end -- on check (builtin) @@ -466,8 +467,10 @@ function toolchain.apis() , "toolchain.set_bindir" , "toolchain.set_sdkdir" , "toolchain.set_archs" + , "toolchain.set_packages" , "toolchain.set_homepage" , "toolchain.set_description" + , "toolchain.add_packages" } , keyvalues = { diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua index 6904e304d..98cda65cc 100644 --- a/xmake/toolchains/cross/check.lua +++ b/xmake/toolchains/cross/check.lua @@ -29,7 +29,7 @@ function main(toolchain) local sdkdir = toolchain:sdkdir() local bindir = toolchain:bindir() local cross = toolchain:cross() - if not sdkdir and not bindir and not cross and not toolchain:config("packages") then + if not sdkdir and not bindir and not cross and not toolchain:packages() then return end diff --git a/xmake/toolchains/gnu-rm/xmake.lua b/xmake/toolchains/gnu-rm/xmake.lua index 4a1751172..492b00caa 100644 --- a/xmake/toolchains/gnu-rm/xmake.lua +++ b/xmake/toolchains/gnu-rm/xmake.lua @@ -28,6 +28,9 @@ toolchain("gnu-rm") -- mark as cross-complation toolchain set_kind("cross") + -- add packages + add_packages("gnu-rm") + -- on load on_load(function (toolchain) diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index 86ab4a13d..37915d7d2 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -28,6 +28,9 @@ toolchain("llvm") -- mark as standalone toolchain set_kind("standalone") + -- add packages + add_packages("llvm") + -- set toolset set_toolset("cc", "clang") set_toolset("cxx", "clang", "clang++") diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua index 3007093ea..0d80cc643 100644 --- a/xmake/toolchains/mingw/xmake.lua +++ b/xmake/toolchains/mingw/xmake.lua @@ -28,6 +28,9 @@ toolchain("mingw") -- mark as standalone toolchain set_kind("standalone") + -- add packages, TODO maybe we still add mingw package in xmake-repo + add_packages("llvm-mingw") + -- check toolchain on_check("check") diff --git a/xmake/toolchains/muslcc/xmake.lua b/xmake/toolchains/muslcc/xmake.lua index cec5ecbdb..c3dcb50a9 100644 --- a/xmake/toolchains/muslcc/xmake.lua +++ b/xmake/toolchains/muslcc/xmake.lua @@ -28,6 +28,9 @@ toolchain("muslcc") -- mark as cross-compilation toolchain set_kind("cross") + -- add packages + add_packages("muslcc") + -- on load on_load(function (toolchain) diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua index 97dd940b7..f7717938a 100644 --- a/xmake/toolchains/zig/xmake.lua +++ b/xmake/toolchains/zig/xmake.lua @@ -25,6 +25,9 @@ toolchain("zig") set_homepage("https://ziglang.org/") set_description("Zig Programming Language Compiler") + -- add packages + add_packages("zig") + -- on check on_check(function (toolchain) import("lib.detect.find_tool") |
