]> git.tdb.fi Git - builder.git/commitdiff
Explicitly create import libraries from BinaryComponent
authorMikko Rasa <tdb@tdb.fi>
Tue, 3 Jan 2023 17:04:22 +0000 (19:04 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 3 Jan 2023 17:23:00 +0000 (19:23 +0200)
They should not be created for modules.  The linker is still used to
create them since the process is quite different between toolchains.

plugins/gnu/gnulinker.cpp
plugins/msvc/msvclinker.cpp
plugins/msvc/msvclinker.h
source/lib/binary.h
source/lib/binarycomponent.cpp

index c8e6606d8d540691692c361bc4efd8e3995a463e..3d81fcca6156236a58d9f943dc05136eb1d8ff9b 100644 (file)
@@ -37,6 +37,19 @@ Target *GnuLinker::create_target(const vector<Target *> &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<SharedLibrary &>(*sources.front());
+               if(architecture->get_system()!="windows")
+                       return 0;
+
+               Tool &dlltool = builder.get_toolchain().get_tool("DLL");
+               return dlltool.create_target(shlib);
+       }
+
        vector<ObjectFile *> objs;
        objs.reserve(sources.size());
        for(Target *s: sources)
@@ -45,15 +58,7 @@ Target *GnuLinker::create_target(const vector<Target *> &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 &copy = builder.get_toolchain().get_tool("CP");
                InstalledFile *inst_tgt = dynamic_cast<InstalledFile *>(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<SharedLibrary>(shlib->get_libname());
                        if(link_name!=FS::basename(inst_tgt->get_path()))
index d768b236cbb5d7dd7b80812af8776ed0688295e4..31f9a4f8189f8ff9be0549edbb88751e7767b72e 100644 (file)
@@ -34,6 +34,20 @@ Target *MsvcLinker::create_target(const vector<Target *> &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<SharedLibrary &>(*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<ObjectFile *> objs;
        objs.reserve(sources.size());
        for(Target *s: sources)
@@ -42,34 +56,13 @@ Target *MsvcLinker::create_target(const vector<Target *> &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<SharedLibrary *>(&target))
-       {
-               Tool &copy = builder.get_toolchain().get_tool("CP");
-               InstalledFile *inst_tgt = dynamic_cast<InstalledFile *>(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);
index fc9e9df364b68fd79972fadc7280603df232e9c4..fe98c7d8501460f77d3ccb2aaa43c88d733369d8 100644 (file)
@@ -15,7 +15,6 @@ public:
        MsvcLinker(Builder &, const Architecture &, const MicrosoftTools &);
 
        Target *create_target(const std::vector<Target *> &, const std::string &) override;
-       Target *create_install(Target &) const override;
        std::string create_build_signature(const BuildInfo &) const override;
 
 protected:
index 143835cea7c408101e3a2e22a358c6cb733d4848..8f401c5e7aa58a6e89a4feb3ae58880b2d3b2bfc 100644 (file)
@@ -24,6 +24,7 @@ protected:
        Binary(Builder &, const Component &, const std::string &, const std::vector<ObjectFile *> &);
 
 public:
+       const std::vector<ObjectFile *> &get_objects() const { return objects; }
        void collect_build_info(BuildInfo &) const override;
 
 protected:
index d29673a73761e72420dc398cae16044c435fd942..0b5d3cf84d067c63b554af9c05f063415ca17074 100644 (file)
@@ -112,11 +112,14 @@ void BinaryComponent::create_targets() const
        }
 
        vector<Target *> 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)