From 13b1dda53dfe34b24982f1f3c436a860fd257aa1 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 3 Apr 2024 03:52:29 +0200 Subject: add test fix test indent --- .../my-repo/packages/b/bar/src/include/bar.hpp | 8 ++++++++ .../my-repo/packages/b/bar/src/src/bar.cpp | 5 +++++ .../my-repo/packages/b/bar/src/xmake.lua | 6 ++++++ .../snippet_runtimes/my-repo/packages/b/bar/xmake.lua | 15 +++++++++++++++ tests/projects/c++/snippet_runtimes/src/main.cpp | 7 +++++++ tests/projects/c++/snippet_runtimes/test.lua | 19 +++++++++++++++++++ tests/projects/c++/snippet_runtimes/xmake.lua | 18 ++++++++++++++++++ 7 files changed, 78 insertions(+) create mode 100644 tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp create mode 100644 tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp create mode 100644 tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua create mode 100644 tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua create mode 100644 tests/projects/c++/snippet_runtimes/src/main.cpp create mode 100644 tests/projects/c++/snippet_runtimes/test.lua create mode 100644 tests/projects/c++/snippet_runtimes/xmake.lua diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp new file mode 100644 index 000000000..e712aebe0 --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/include/bar.hpp @@ -0,0 +1,8 @@ +#ifndef BAR_HPP +#define BAR_HPP + +#include + +std::string foo(); + +#endif diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp new file mode 100644 index 000000000..1dc99de3c --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/src/bar.cpp @@ -0,0 +1,5 @@ +#include + +std::string foo() { + return "bar"; +} diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua new file mode 100644 index 000000000..8393aed87 --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/src/xmake.lua @@ -0,0 +1,6 @@ +target("bar") + set_kind("$(kind)") + add_files("src/*.cpp") + add_headerfiles("include/(**.hpp)") + add_includedirs("include") + diff --git a/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua new file mode 100644 index 000000000..173fc1427 --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/my-repo/packages/b/bar/xmake.lua @@ -0,0 +1,15 @@ +package("bar") + set_sourcedir(path.join(os.scriptdir(), "src")) + + on_install(function(package) + import("package.tools.xmake").install(package, {}) + end) + + on_test(function(package) + assert(package:check_cxxsnippets({test = [[ + #include + void test() { + std::cout << _LIBCPP_VERSION << std::endl; + } + ]]}, {configs = {languages = "c++17"}})) + end) diff --git a/tests/projects/c++/snippet_runtimes/src/main.cpp b/tests/projects/c++/snippet_runtimes/src/main.cpp new file mode 100644 index 000000000..1c8e6bf02 --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/src/main.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() { + std::cout << foo(); + return 0; +} diff --git a/tests/projects/c++/snippet_runtimes/test.lua b/tests/projects/c++/snippet_runtimes/test.lua new file mode 100644 index 000000000..753cab958 --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/test.lua @@ -0,0 +1,19 @@ +import("lib.detect.find_tool") +import("core.base.semver") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +function _build() + if ci_is_running() then + assert(os.iorun("xmake -rvD")) + else + assert(os.iorun("xmake -r")) + end +end + +function main(t) + local clang = find_tool("clang") + if clang and not is_subhost("windows") then + os.exec("xmake f --toolchain=clang --runtimes=c++_shared --yes") + _build() + end +end diff --git a/tests/projects/c++/snippet_runtimes/xmake.lua b/tests/projects/c++/snippet_runtimes/xmake.lua new file mode 100644 index 000000000..1e5436ba4 --- /dev/null +++ b/tests/projects/c++/snippet_runtimes/xmake.lua @@ -0,0 +1,18 @@ +add_repositories("my-repo my-repo") +add_requires("bar") + +target("foo") + set_kind("binary") + add_files("src/*.cpp") + + add_packages("bar") + + on_config(function(target) + assert(target:check_cxxsnippets({test = [[ + #include + void test() { + std::cout << _LIBCPP_VERSION << std::endl; + } + ]]}, {configs = {languages = "c++17"}})) + end) + -- cgit v1.3.1 From 3319219a1a2fc26520f0e1760d953e9c0352a91b Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Wed, 3 Apr 2024 04:49:45 +0200 Subject: apply runtime to package targets (for check_cxxsnippet support) --- xmake/core/package/package.lua | 56 ++++++++++++++++++++++++++------------ xmake/modules/core/tools/clang.lua | 5 ++-- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 4fbfa635a..014d8a82a 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -39,6 +39,7 @@ local is_cross = require("base/private/is_cross") local memcache = require("cache/memcache") local toolchain = require("tool/toolchain") local compiler = require("tool/compiler") +local linker = require("tool/linker") local sandbox = require("sandbox/sandbox") local config = require("project/config") local policy = require("project/policy") @@ -2268,27 +2269,46 @@ end function _instance:_generate_build_configs(configs, opt) opt = opt or {} configs = table.join(self:fetch_librarydeps(), configs) - if self:is_plat("windows") then - local ld = self:build_getenv("ld") - local runtimes = self:runtimes() - -- since we are ignoring the runtimes of the headeronly library, - -- we can only get the runtimes from the dependency library to detect the link. - if self:is_headeronly() and not runtimes and self:librarydeps() then - for _, dep in ipairs(self:librarydeps()) do - if dep:is_plat("windows") and dep:runtimes() then - runtimes = dep:runtimes() - break - end + -- since we are ignoring the runtimes of the headeronly library, + -- we can only get the runtimes from the dependency library to detect the link. + local runtimes = self:config("runtimes") or self:runtimes() + if self:is_headeronly() and not runtimes and self:librarydeps() then + for _, dep in ipairs(self:librarydeps()) do + if dep:is_plat("windows") and dep:runtimes() then + runtimes = dep:runtimes() + break end end - if runtimes and ld and path.basename(ld:lower()) == "link" then -- for msvc? - configs.cxflags = table.wrap(configs.cxflags) - table.insert(configs.cxflags, "/" .. runtimes) - if runtimes:startswith("MT") then - configs.ldflags = table.wrap(configs.ldflags) - table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib") - end + end + if runtimes then + local sourcekind = opt.sourcekind or "cxx" + local tool, name = self:tool("ld") + local linker, errors = linker.load("binary", sourcekind, {target = package}) + if not linker then + os.raise(errors) end + local fake_target = {is_shared = function(_) return false end, + sourcekinds = function(_) return sourcekind end} + local compiler = self:compiler(sourcekind) + local cxflags = compiler:map_flags("runtime", runtimes, {target = fake_target}) + configs.cxflags = table.wrap(configs.cxflags) + table.join2(configs.cxflags, cxflags) + + local ldflags = linker:map_flags("runtime", runtimes, {target = fake_target}) + configs.ldflags = table.wrap(configs.ldflags) + table.join2(configs.ldflags, ldflags) + + -- if self:is_plat("windows") then + -- local ld = self:build_getenv("ld") + -- if ld and path.basename(ld:lower()) == "link" then -- for msvc? + -- configs.cxflags = table.wrap(configs.cxflags) + -- table.insert(configs.cxflags, "/" .. runtimes) + -- if runtimes:startswith("MT") then + -- configs.ldflags = table.wrap(configs.ldflags) + -- table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib") + -- end + -- end + -- end end if self:config("lto") then local configs_lto = self:_generate_lto_configs(opt.sourcekind or "cxx") diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index 76f553829..76a1f773b 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -268,8 +268,9 @@ function nf_runtime(self, runtime, opt) maps["c++_shared"] = table.join(maps["c++_shared"], "-cxx-isystem" .. path.join(llvm_rootdir, "include", "c++", "v1")) end elseif kind == "ld" or kind == "sh" then - local target = opt.target - if target and target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx") then + local target = opt.target or opt + local is_cxx = target and (target.sourcekinds and table.contains(table.wrap(target:sourcekinds()), "cxx")) + if is_cxx then maps["c++_static"] = "-stdlib=libc++" maps["c++_shared"] = "-stdlib=libc++" maps["stdc++_static"] = "-stdlib=libstdc++" -- cgit v1.3.1 From b739f307b9f86ce0c3d4cc41adf079e1d148cf3d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 6 Apr 2024 15:53:38 +0200 Subject: remove comments --- xmake/core/package/package.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 014d8a82a..9c57dc1f6 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2297,18 +2297,6 @@ function _instance:_generate_build_configs(configs, opt) local ldflags = linker:map_flags("runtime", runtimes, {target = fake_target}) configs.ldflags = table.wrap(configs.ldflags) table.join2(configs.ldflags, ldflags) - - -- if self:is_plat("windows") then - -- local ld = self:build_getenv("ld") - -- if ld and path.basename(ld:lower()) == "link" then -- for msvc? - -- configs.cxflags = table.wrap(configs.cxflags) - -- table.insert(configs.cxflags, "/" .. runtimes) - -- if runtimes:startswith("MT") then - -- configs.ldflags = table.wrap(configs.ldflags) - -- table.insert(configs.ldflags, "-nodefaultlib:msvcrt.lib") - -- end - -- end - -- end end if self:config("lto") then local configs_lto = self:_generate_lto_configs(opt.sourcekind or "cxx") -- cgit v1.3.1 From 15ded5361b44cc6ffa456f64ce079c6e6f6604d9 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 6 Apr 2024 15:54:13 +0200 Subject: use only self:runtimes() --- xmake/core/package/package.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 9c57dc1f6..c777d3ec8 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2271,7 +2271,7 @@ function _instance:_generate_build_configs(configs, opt) configs = table.join(self:fetch_librarydeps(), configs) -- since we are ignoring the runtimes of the headeronly library, -- we can only get the runtimes from the dependency library to detect the link. - local runtimes = self:config("runtimes") or self:runtimes() + local runtimes = self:runtimes() if self:is_headeronly() and not runtimes and self:librarydeps() then for _, dep in ipairs(self:librarydeps()) do if dep:is_plat("windows") and dep:runtimes() then -- cgit v1.3.1