Uploaded image for project: 'Qbs ("Cubes")'
  1. Qbs ("Cubes")
  2. QBS-1834

Add support for new library type as `objectlibrary`

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 2.6.0
    • General
    • None
    • All

    Description

      It would be nice to have something like an `objectlibrary` type, similar to CMake's feature: https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries

      A main advantages points in use of the `objectlibrary`:

      1. It increases a compilation speed, against, e.g. a `staticlibrary`, because the `staticlibrary` generation pipeline includes this chain: `cpp -> obj -> lib`, but the `objectlibrary` includes only this chain: `cpp -> obj`. So, for a very big projects, with the heavy templates, which generates a many and a big `obj` files, the archiving all `obj` files into a `lib` file may take a long time.

      2. On Windows && MSVC there is a limitation on a size of a generated static library `lib` file is about ~4GB. This forces you to break the project into smaller sub-libraries and constantly monitor their size, that's increases a development time, complexity, and so on.

      I tried to do something like an `objectlibrary`, just imitate this feature, just setting the `obj` type to some Product. And then add dependency to this product in a resulting application. In results, this product compiles `cpp` -> `obj`, but that `obj` files does not passed to the `app` linker. So, maybe need to do something else harder:

      == app.qbs ==

      Application {
          Depends { name: "cpp" }
          Depends { name: "myobj" } // I assumed that `obj` from `myob` be passed to this `app` linker.. But unsuccessfull.
          consoleApplication: true
          files : [ "main.cpp" ]
      }
      

      == obj.qbs ==

      Product {
          Depends { name: "cpp" }
          type: "obj" // Imitate a `objectlibrary`
          name: "myobj"
          files: ["obj.cpp", "obj.h"]
          Export {
              Depends { name: "cpp" }
              cpp.includePaths: [exportingProduct.sourceDirectory]
          }
      }
      

      Any suggestions are welcomed!

      UPD: One workaround I found is to use this as an imitation of an `objectlibrary`:

      == obj.qbs ==

      Product {
          Depends { name: "cpp" }
          name: "myobj"
          files: ["obj.cpp", "obj.h"]
          Export {
              Depends { name: "cpp" }
              cpp.includePaths: [exportingProduct.sourceDirectory]
              Group { // This, just export an sources... But, it is ugly...
                  files: exportingProduct.files
              }
          }
      }
      

      UPD2: Other workaround it is something like this:

      == obj.qbs ==

      Product {
          Depends { name: "cpp" }
          name: "myobj"
          type: "objectlibrary"
          files: ["obj1.cpp", "obj1.h", "obj2.cpp", "obj2.h"]
      
          Group {
              fileTagsFilter: ["obj"]
              fileTags: ["objectlibrary"]
          }
      
          Export {
              Depends { name: "cpp" }
              cpp.includePaths: [exportingProduct.sourceDirectory]
          }
      }
      

      == app.qbs ==

      import qbs.File
      
      CppApplication {
          Depends { name: "myobj" }
          consoleApplication: true
          files: ["main.cpp"]
      
          Rule {
              inputsFromDependencies: ["objectlibrary"]
              Artifact {
                  fileTags: ["obj"]
                  filePath: input.completeBaseName + ".obj"
              }
              prepare: {
                  var cmd = new JavaScriptCommand();
                  cmd.src = input.filePath;
                  cmd.dst = output.filePath;
                  cmd.sourceCode = function () {
                      File.copy(src, dst);
                  };
                  return [cmd];
              }
          }
      }
      

      but in this case we need to use a File.copy() that's duplicates an object files... Maybe we can create a sym-links instead, or maybe to use some `aliases` .... I don't know.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kandeler Christian Kandeler
            kuzulis Denis Shienkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes