From 4cf87fa84a6938e262fd6122e654e5a483a78abe Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 Dec 2020 07:20:18 +0200 Subject: Add support for module interface-only libraries Also suppress generation of the object file in cases where we don't need it. --- libbuild2/bin/init.cxx | 21 ++++++++++++++++----- libbuild2/bin/utility.cxx | 16 ++++++++++------ libbuild2/bin/utility.hxx | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) (limited to 'libbuild2/bin') diff --git a/libbuild2/bin/init.cxx b/libbuild2/bin/init.cxx index 9c16432..49ba518 100644 --- a/libbuild2/bin/init.cxx +++ b/libbuild2/bin/init.cxx @@ -116,12 +116,23 @@ namespace build2 // // If unspecified, defaults to false for liba{} and to true for libu*{}. // - vp.insert ("bin.whole", variable_visibility::target); + vp.insert ("bin.whole", variable_visibility::target); - vp.insert ("bin.exe.prefix"); - vp.insert ("bin.exe.suffix"); - vp.insert ("bin.lib.prefix"); - vp.insert ("bin.lib.suffix"); + // Mark library as binless. + // + // For example, the user can mark a C++ library consisting of only + // module interfaces as binless so it becomes a modules equivalent to + // header-only library (which we will call a module interface-only + // library). + // + vp.insert ("bin.binless", variable_visibility::target); + + // Executable and library name prefixes and suffixes. + // + vp.insert ("bin.exe.prefix"); + vp.insert ("bin.exe.suffix"); + vp.insert ("bin.lib.prefix"); + vp.insert ("bin.lib.suffix"); // The optional custom clean patterns should be just the pattern stem, // without the library prefix/name or extension. For example, `-[A-Z]` diff --git a/libbuild2/bin/utility.cxx b/libbuild2/bin/utility.cxx index 6b0c4de..11230cd 100644 --- a/libbuild2/bin/utility.cxx +++ b/libbuild2/bin/utility.cxx @@ -47,9 +47,11 @@ namespace build2 return lmembers {a, s}; } - const target* + const file* link_member (const libx& x, action a, linfo li, bool exist) { + const target* r; + if (x.is_a ()) { // For libul{} that is linked to an executable the member choice @@ -72,7 +74,7 @@ namespace build2 // Called by the compile rule during execute. // - return x.ctx.phase == run_phase::match && !exist + r = x.ctx.phase == run_phase::match && !exist ? &search (x, tt, x.dir, x.out, x.name) : search_existing (x.ctx, tt, x.dir, x.out, x.name); } @@ -87,15 +89,17 @@ namespace build2 group_view gv (resolve_members (a, l)); assert (gv.members != nullptr); - pair r ( + pair p ( link_member (lmembers {l.a != nullptr, l.s != nullptr}, li.order)); - if (!r.second) - fail << (r.first == otype::s ? "shared" : "static") + if (!p.second) + fail << (p.first == otype::s ? "shared" : "static") << " variant of " << l << " is not available"; - return r.first == otype::s ? static_cast (l.s) : l.a; + r = p.first == otype::s ? static_cast (l.s) : l.a; } + + return static_cast (r); } pattern_paths diff --git a/libbuild2/bin/utility.hxx b/libbuild2/bin/utility.hxx index 5d7eed4..e12bb5f 100644 --- a/libbuild2/bin/utility.hxx +++ b/libbuild2/bin/utility.hxx @@ -59,7 +59,7 @@ namespace build2 // If existing is true, then only return the member target if it exists // (currently only used and supported for utility libraries). // - LIBBUILD2_BIN_SYMEXPORT const target* + LIBBUILD2_BIN_SYMEXPORT const file* link_member (const libx&, action, linfo, bool existing = false); // As above but return otype::a or otype::s as well as an indication if -- cgit v1.1