diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-08-08 21:18:41 -0400 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-08-13 01:53:03 +0530 |
commit | 62a95eff3e75a80ecddc12a15cf2be60627d52c2 (patch) | |
tree | 1262f1c4e00adcfc084c0ddb5a807043a2f66766 | |
parent | ce9364d5dd3a085686f05f51bdfd1fbf465be7d6 (diff) | |
download | meson-62a95eff3e75a80ecddc12a15cf2be60627d52c2.zip meson-62a95eff3e75a80ecddc12a15cf2be60627d52c2.tar.gz meson-62a95eff3e75a80ecddc12a15cf2be60627d52c2.tar.bz2 |
add compilers from extracted objects directly to build targets
In order to reliably link to static libraries or individual object
files, we need to take their languages into account as well. For static
libraries this is easy: we just add the static library's list of
compilers to the build target. For extracted objects, we need to only
add the ones for the objects we use.
But we did this really inefficiently -- in fact, downright terribly. We
iterated over all source files from the extracted objects, then tried to
look up a new compiler for them. Even though the extracted objects
already had a list of compilers! This broke once compilers were made
per-subproject, because while the extracted objects have a reference to
all the compilers it needs (just like static archives do, actually) we
might not actually be able to look up that compiler from scratch inside
the current subproject.
Fix this by asking the extracted objects to categorize all its own
sources and return the compilers we want.
Fixes #10579
7 files changed, 49 insertions, 4 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 11bd21e..641e5f3 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -39,7 +39,7 @@ from .mesonlib import ( MesonBugException ) from .compilers import ( - Compiler, is_object, clink_langs, sort_clink, lang_suffixes, all_languages, + Compiler, is_object, clink_langs, sort_clink, all_languages, is_known_suffix, detect_static_linker ) from .linkers import StaticLinker @@ -948,12 +948,15 @@ class BuildTarget(Target): for o in self.objects: if not isinstance(o, ExtractedObjects): continue - for s in o.srclist: + compsrcs = o.classify_all_sources(o.srclist, []) + for comp in compsrcs: # Don't add Vala sources since that will pull in the Vala # compiler even though we will never use it since we are # dealing with compiled C code. - if not s.endswith(lang_suffixes['vala']): - sources.append(s) + if comp.language == 'vala': + continue + if comp.language not in self.compilers: + self.compilers[comp.language] = comp if sources: # For each source, try to add one compiler that can compile it. # diff --git a/test cases/common/253 subproject extracted objects/foo.c b/test cases/common/253 subproject extracted objects/foo.c new file mode 100644 index 0000000..f6c7aeb --- /dev/null +++ b/test cases/common/253 subproject extracted objects/foo.c @@ -0,0 +1,11 @@ +#if defined _WIN32 || defined __CYGWIN__ + #define DLL_IMPORT __declspec(dllimport) +#else + #define DLL_IMPORT +#endif + +int DLL_IMPORT cppfunc(void); + +int otherfunc(void) { + return cppfunc() != 42; +} diff --git a/test cases/common/253 subproject extracted objects/meson.build b/test cases/common/253 subproject extracted objects/meson.build new file mode 100644 index 0000000..bad450f --- /dev/null +++ b/test cases/common/253 subproject extracted objects/meson.build @@ -0,0 +1,5 @@ +project('link to extracted objects', 'c') + +sublib = subproject('myobjects').get_variable('sublib') + +mainlib = static_library('foo', 'foo.c', install: true, link_with: sublib) diff --git a/test cases/common/253 subproject extracted objects/subprojects/myobjects/cpplib.cpp b/test cases/common/253 subproject extracted objects/subprojects/myobjects/cpplib.cpp new file mode 100644 index 0000000..12ef756 --- /dev/null +++ b/test cases/common/253 subproject extracted objects/subprojects/myobjects/cpplib.cpp @@ -0,0 +1,6 @@ +#define BUILDING_DLL +#include "cpplib.h" + +extern "C" int DLL_PUBLIC cppfunc(void) { + return 42; +} diff --git a/test cases/common/253 subproject extracted objects/subprojects/myobjects/cpplib.h b/test cases/common/253 subproject extracted objects/subprojects/myobjects/cpplib.h new file mode 100644 index 0000000..a1c38b3 --- /dev/null +++ b/test cases/common/253 subproject extracted objects/subprojects/myobjects/cpplib.h @@ -0,0 +1,12 @@ +/* See http://gcc.gnu.org/wiki/Visibility#How_to_use_the_new_C.2B-.2B-_visibility_support */ +#if defined(_WIN32) || defined(__CYGWIN__) + #ifdef BUILDING_DLL + #define DLL_PUBLIC __declspec(dllexport) + #else + #define DLL_PUBLIC __declspec(dllimport) + #endif +#else + #define DLL_PUBLIC __attribute__ ((visibility ("default"))) +#endif + +extern "C" int DLL_PUBLIC cppfunc(void); diff --git a/test cases/common/253 subproject extracted objects/subprojects/myobjects/meson.build b/test cases/common/253 subproject extracted objects/subprojects/myobjects/meson.build new file mode 100644 index 0000000..1c2729b --- /dev/null +++ b/test cases/common/253 subproject extracted objects/subprojects/myobjects/meson.build @@ -0,0 +1,3 @@ +project('myobjects', 'cpp') + +sublib = static_library('sublib', 'cpplib.cpp') diff --git a/test cases/common/253 subproject extracted objects/test.json b/test cases/common/253 subproject extracted objects/test.json new file mode 100644 index 0000000..baa5dfb --- /dev/null +++ b/test cases/common/253 subproject extracted objects/test.json @@ -0,0 +1,5 @@ +{ + "installed": [ + { "type": "file", "file": "usr/lib/libfoo.a" } + ] +} |