From: Mikko Rasa Date: Tue, 3 Jan 2023 17:04:22 +0000 (+0200) Subject: Explicitly create import libraries from BinaryComponent X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=865a70b99b5551a1bdbbda74539ee2dbeec15253;p=builder.git Explicitly create import libraries from BinaryComponent They should not be created for modules. The linker is still used to create them since the process is quite different between toolchains. --- diff --git a/plugins/gnu/gnulinker.cpp b/plugins/gnu/gnulinker.cpp index c8e6606..3d81fcc 100644 --- a/plugins/gnu/gnulinker.cpp +++ b/plugins/gnu/gnulinker.cpp @@ -37,6 +37,19 @@ Target *GnuLinker::create_target(const vector &sources, const string & { if(sources.empty()) throw invalid_argument("GnuLinker::create_target"); + + if(arg=="import") + { + if(sources.size()!=1) + throw invalid_argument("GnuLinker::create_target"); + SharedLibrary &shlib = dynamic_cast(*sources.front()); + if(architecture->get_system()!="windows") + return 0; + + Tool &dlltool = builder.get_toolchain().get_tool("DLL"); + return dlltool.create_target(shlib); + } + vector objs; objs.reserve(sources.size()); for(Target *s: sources) @@ -45,15 +58,7 @@ Target *GnuLinker::create_target(const vector &sources, const string & const Component &comp = *objs.front()->get_component(); Binary *bin = 0; if(arg=="shared") - { - SharedLibrary *shlib = new SharedLibrary(builder, comp, objs); - if(architecture->get_system()=="windows") - { - Tool &dlltool = builder.get_toolchain().get_tool("DLL"); - dlltool.create_target(*shlib); - } - bin = shlib; - } + bin = new SharedLibrary(builder, comp, objs); else bin = new Executable(builder, comp, objs); bin->set_tool(*this); @@ -66,9 +71,7 @@ Target *GnuLinker::create_install(Target &target) const { Tool © = builder.get_toolchain().get_tool("CP"); InstalledFile *inst_tgt = dynamic_cast(copy.create_target(target)); - if(architecture->get_system()=="windows") - builder.get_build_graph().add_installed_target(*shlib->get_import_library()); - else + if(architecture->get_system()!="windows") { string link_name = architecture->create_filename(shlib->get_libname()); if(link_name!=FS::basename(inst_tgt->get_path())) diff --git a/plugins/msvc/msvclinker.cpp b/plugins/msvc/msvclinker.cpp index d768b23..31f9a4f 100644 --- a/plugins/msvc/msvclinker.cpp +++ b/plugins/msvc/msvclinker.cpp @@ -34,6 +34,20 @@ Target *MsvcLinker::create_target(const vector &sources, const string if(sources.empty()) throw invalid_argument("MsvcLinker::create_target"); + if(arg=="import") + { + if(sources.size()!=1) + throw invalid_argument("MsvcLinker::create_target"); + SharedLibrary &shlib = dynamic_cast(*sources.front()); + + ImportLibrary *imp = new ImportLibrary(builder, *shlib.get_component(), shlib); + for(ObjectFile *o: shlib.get_objects()) + imp->add_dependency(*o); + shlib.add_side_effect(*imp); + + return imp; + } + vector objs; objs.reserve(sources.size()); for(Target *s: sources) @@ -42,34 +56,13 @@ Target *MsvcLinker::create_target(const vector &sources, const string const Component &comp = *objs.front()->get_component(); Binary *bin = 0; if(arg=="shared") - { - SharedLibrary *shlib = new SharedLibrary(builder, comp, objs); - bin = shlib; - ImportLibrary *imp = new ImportLibrary(builder, comp, *shlib); - for(ObjectFile *o: objs) - imp->add_dependency(*o); - imp->set_tool(*this); - shlib->add_side_effect(*imp); - } + bin = new SharedLibrary(builder, comp, objs); else bin = new Executable(builder, comp, objs); bin->set_tool(*this); return bin; } -Target *MsvcLinker::create_install(Target &target) const -{ - if(SharedLibrary *shlib = dynamic_cast(&target)) - { - Tool © = builder.get_toolchain().get_tool("CP"); - InstalledFile *inst_tgt = dynamic_cast(copy.create_target(target)); - builder.get_build_graph().add_installed_target(*shlib->get_import_library()); - return inst_tgt; - } - else - return 0; -} - string MsvcLinker::create_build_signature(const BuildInfo &binfo) const { string result = Tool::create_build_signature(binfo); diff --git a/plugins/msvc/msvclinker.h b/plugins/msvc/msvclinker.h index fc9e9df..fe98c7d 100644 --- a/plugins/msvc/msvclinker.h +++ b/plugins/msvc/msvclinker.h @@ -15,7 +15,6 @@ public: MsvcLinker(Builder &, const Architecture &, const MicrosoftTools &); Target *create_target(const std::vector &, const std::string &) override; - Target *create_install(Target &) const override; std::string create_build_signature(const BuildInfo &) const override; protected: diff --git a/source/lib/binary.h b/source/lib/binary.h index 143835c..8f401c5 100644 --- a/source/lib/binary.h +++ b/source/lib/binary.h @@ -24,6 +24,7 @@ protected: Binary(Builder &, const Component &, const std::string &, const std::vector &); public: + const std::vector &get_objects() const { return objects; } void collect_build_info(BuildInfo &) const override; protected: diff --git a/source/lib/binarycomponent.cpp b/source/lib/binarycomponent.cpp index d29673a..0b5d3cf 100644 --- a/source/lib/binarycomponent.cpp +++ b/source/lib/binarycomponent.cpp @@ -112,11 +112,14 @@ void BinaryComponent::create_targets() const } vector results; - results.reserve(2); + results.reserve(3); if(type==LIBRARY) { Tool &archiver = toolchain.get_tool("AR"); - results.push_back(linker.create_target(objs, "shared")); + Target *shlib = linker.create_target(objs, "shared"); + results.push_back(shlib); + if(Target *imp = linker.create_target(*shlib, "import")) + results.push_back(imp); results.push_back(archiver.create_target(objs)); } else if(type==MODULE)