From bd9ca1e55dc1396da73c4699ccc021dc1f604fe6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 15 Jun 2020 08:12:41 +0200 Subject: Diagnose building of module or ad hoc C++ recipe using static build system --- libbuild2/buildfile | 4 +++- libbuild2/module.cxx | 42 +++++++++++++++++++++++++++++------------- libbuild2/parser.cxx | 8 ++++++-- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libbuild2/buildfile b/libbuild2/buildfile index 29a559c..ce5a090 100644 --- a/libbuild2/buildfile +++ b/libbuild2/buildfile @@ -167,8 +167,10 @@ if ($cxx.target.class != 'windows') { libul{build2}: cxx.libs += -lpthread + # Note: only linking libdl in shared build. + # if ($cxx.target.class != "bsd") - libul{build2}: cxx.libs += -ldl + libus{build2}: cxx.libs += -ldl } # Export options. diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx index 4c663a3..d45ceed 100644 --- a/libbuild2/module.cxx +++ b/libbuild2/module.cxx @@ -3,7 +3,7 @@ #include -#ifndef BUILD2_BOOTSTRAP +#if !defined(BUILD2_BOOTSTRAP) && !defined(LIBBUILD2_STATIC_BUILD) # ifndef _WIN32 # include # else @@ -181,6 +181,7 @@ namespace build2 // Note: also used by ad hoc recipes thus not static. // +#if !defined(BUILD2_BOOTSTRAP) && !defined(LIBBUILD2_STATIC_BUILD) pair load_module_library (const path& lib, const string& sym, string& err) { @@ -190,8 +191,6 @@ namespace build2 void* h (nullptr); void* s (nullptr); -#ifndef BUILD2_BOOTSTRAP - #ifndef _WIN32 // Use RTLD_NOW instead of RTLD_LAZY to both speed things up (we are going // to use this module now) and to detect any symbol mismatches. @@ -218,17 +217,27 @@ namespace build2 err = win32::last_error_msg (); #endif -#endif // BUILD2_BOOTSTRAP - return make_pair (h, s); } +#else + pair + load_module_library (const path&, const string&, string&) + { + return pair (nullptr, nullptr); + } +#endif static module_load_function* - import_module (scope& bs, - const string& mod, - const location& loc, - bool boot, - bool opt) + import_module ( +#if defined(BUILD2_BOOTSTRAP) || defined(LIBBUILD2_STATIC_BUILD) + scope&, +#else + scope& bs, +#endif + const string& mod, + const location& loc, + bool boot, + bool opt) { tracer trace ("import_module"); @@ -256,13 +265,20 @@ namespace build2 module_load_function* r (nullptr); - // No dynamic loading of build system modules during bootstrap. + // No dynamic loading of build system modules during bootstrap or if + // statically-linked.. // -#ifdef BUILD2_BOOTSTRAP +#if defined(BUILD2_BOOTSTRAP) || defined(LIBBUILD2_STATIC_BUILD) if (!opt) + { fail (loc) << "unknown build system module " << mod << +#ifdef BUILD2_BOOTSTRAP info << "running bootstrap build system"; #else + info << "running statically-linked build system"; +#endif + } +#else context& ctx (bs.ctx); // See if we can import a target for this module. @@ -458,7 +474,7 @@ namespace build2 else l5 ([&]{trace << "unable to load " << lib << ": " << err;}); -#endif // BUILD2_BOOTSTRAP +#endif // BUILD2_BOOTSTRAP || LIBBUILD2_STATIC_BUILD return r; } diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index c2decd3..6d34a11 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1143,10 +1143,14 @@ namespace build2 { // C++ // -#ifdef BUILD2_BOOTSTRAP +#if defined(BUILD2_BOOTSTRAP) || defined(LIBBUILD2_STATIC_BUILD) fail (loc) << "ad hoc c++ recipe" << +#ifdef BUILD2_BOOTSTRAP info << "running bootstrap build system"; #else + info << "running statically-linked build system"; +#endif +#else // Parse recipe version and optional fragment separator. // if (tt == type::newline || tt == type::eos) @@ -1191,7 +1195,7 @@ namespace build2 ar.reset ( new adhoc_cxx_rule (loc, st.value.size (), ver, move (sep))); -#endif +#endif // BUILD2_BOOTSTRAP || LIBBUILD2_STATIC_BUILD } else fail (lloc) << "unknown recipe language '" << *lang << "'"; -- cgit v1.1