third_pary/zlib static library (component) omits optional procedures (ANGLE)

119 views
Skip to first unread message

Mick Pearson

unread,
Jun 11, 2021, 7:31:18 AM6/11/21
to gn-dev
Can anybody help me with trying to add a static library option to ANGLE (https://groups.google.com/g/angleproject/c/xKmUgKZFpgY) ? Currently the angleproject Google-group is quiet and from what I can tell GN is a weak point for it.

I'm trying to use GN without any history in it or want to invest in it. I am making progress towards linking ANGLE. Right now I have a problem with its zlib dependency that looks like this (https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/zlib/BUILD.gn) one for Chrome.

It uses a "component" function which seems output a LIB file when "is_component_build = false" (which is nice) however this LIB is missing optional OBJ files like adler32_simd (adler32_simd_) that is added as a "deps". To be more clear, zlib.lib can't link because these aren't defined, but I believe they're supposed to be inside zlib.lib. (IOW maybe this BUILD.gn doesn't actually produce a valid static library?)

P.S. I've observed that "deps" seem to have side-effects that go beyond build-target dependency. I wish I could somehow convert source_set definitions into static_library. Can "deps" do that? I feel like I might be missing something fundamental about GN. Anyway, the idea off packing these zlib OBJ definitions into a "libANGLE_static.lib" isn't appealing!

Brett Wilson

unread,
Jun 11, 2021, 10:51:39 AM6/11/21
to Mick Pearson, gn-dev
You can change "component" to "static_library" and things should just work as far as the GN build goes. But it sounds like you might be trying to generate a static library that you would use in a different build system. In that case you want to generate a "complete" static library. To get that set:

  complete_static_lib = true

somewhere in the static_library definition you want to use.

Brett

Mick Pearson

unread,
Jun 11, 2021, 1:07:10 PM6/11/21
to gn-dev, Brett Wilson, gn-dev, Mick Pearson
On "complete_static_lib" (component doesn't produce libraries?) while... surely this zlib dependency is shared by all Chrome projects and so would have to be changed "upstream" if I understand this concept correctly it might be ideal for making this libANGLE_static.lib file. [Actually that would be my ideal scenario and I even thought of floating something like that when I opened the discussion except I wanted to be as narrow as possible. Tips are very welcome since I'm completely out of my depth.] I will let you know how this goes tomorrow.

David Turner

unread,
Jun 11, 2021, 5:35:23 PM6/11/21
to Mick Pearson, gn-dev, Brett Wilson
Le ven. 11 juin 2021 à 19:07, Mick Pearson <ho...@swordofmoonlight.net> a écrit :
On "complete_static_lib" (component doesn't produce libraries?) while... surely this zlib dependency is shared by all Chrome projects and so would have to be changed "upstream" if I understand this concept correctly it might be ideal for making this libANGLE_static.lib file. [Actually that would be my ideal scenario and I even thought of floating something like that when I opened the discussion except I wanted to be as narrow as possible. Tips are very welcome since I'm completely out of my depth.] I will let you know how this goes tomorrow.


component() is really a Chromium-specific function that will create either a shared_library() or a static_library() depending on is_component_build. I assume it already is building static libraries in your case, otherwise you wouldn't even see a libzlip.a file.

By default static_library() generates an archive that only includes the object files of its own sources, but it has dependencies that GN knows about.
For example, if you have something like:

   source_set("foo") {
      sources = [ "foo.c" ]
   }

  static_library("bar") {
     sources = [ "bar.c" ]
     deps = [ ":foo" ]
  }

  executable("program") {
    sources = [ "main.c" ]
    deps = [ ":bar" ]
  }

Then libbar.a will be generated but will only contain bar.o. When program is generated though, its link command will include both libbar.a and foo.o, so the link will succeed.

The "complete_static_lib = true" option is designed to generate a libbar.a that contains all the objects needed by the library (i.e. bar.o and foo.o) in this case.

It looks like what you need is to modify the angle_static_library() declaration of the Angle library you're interested in, to include "complete_static_lib = true" in it.
That should generate a libangle_xxxx.a file that contains everything you need to link it in a different build system (though there may be additional runtime-dependencies to add to the final link command like -lpthread and others).
 
On Friday, June 11, 2021 at 9:51:39 AM UTC-5 Brett Wilson wrote:
You can change "component" to "static_library" and things should just work as far as the GN build goes. But it sounds like you might be trying to generate a static library that you would use in a different build system. In that case you want to generate a "complete" static library. To get that set:

  complete_static_lib = true

somewhere in the static_library definition you want to use.

Brett

On Fri, Jun 11, 2021 at 4:31 AM Mick Pearson <ho...@swordofmoonlight.net> wrote:
Can anybody help me with trying to add a static library option to ANGLE (https://groups.google.com/g/angleproject/c/xKmUgKZFpgY) ? Currently the angleproject Google-group is quiet and from what I can tell GN is a weak point for it.

I'm trying to use GN without any history in it or want to invest in it. I am making progress towards linking ANGLE. Right now I have a problem with its zlib dependency that looks like this (https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/zlib/BUILD.gn) one for Chrome.

It uses a "component" function which seems output a LIB file when "is_component_build = false" (which is nice) however this LIB is missing optional OBJ files like adler32_simd (adler32_simd_) that is added as a "deps". To be more clear, zlib.lib can't link because these aren't defined, but I believe they're supposed to be inside zlib.lib. (IOW maybe this BUILD.gn doesn't actually produce a valid static library?)

P.S. I've observed that "deps" seem to have side-effects that go beyond build-target dependency. I wish I could somehow convert source_set definitions into static_library. Can "deps" do that? I feel like I might be missing something fundamental about GN. Anyway, the idea off packing these zlib OBJ definitions into a "libANGLE_static.lib" isn't appealing!

--
To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.

Mick Pearson

unread,
Jun 12, 2021, 4:13:32 AM6/12/21
to gn-dev, David Turner, gn-dev, Brett Wilson, Mick Pearson
Hey guys, I did find (seemingly) instant success yesterday, and shared my experience here (https://groups.google.com/g/angleproject/c/f7i0kucc5xM/m/ANzo95TmBwAJ) and noted it in the older "static library" troubles linked to in the OP.

It works great (or seems to, it passes linking, I still have to build/test the app) although I'm still a little confused if the zlib BUILD.gn is in a bug state (doesn't support static builds) because it seems to not include its own cpp/OBJ files that aren't declared in its sources. I.e. it seems it can't support apps that use this static build mode via "component". I take it shared libraries act like "complete_static_lib" by default or else this wouldn't fly for any consumer of zlib/BUILD.gn.

I'm glad to be over this speed bump, a little sad I sunk many days of work into it, but glad I eventually caught a break. If the zlib set up was functional I might have carried on trying to patch together a build without complete_static_lib to the end! I don't think the ANGLE guys know about this feature. It seems like its static libraries would be compatible with this. They're currently not functional I think because they're missing the core of ANGLE's internal, but with this core library built with deps rolled in they fill in the gaps. (I'm not sure why it builds those static libraries or if they still work, I think they're mentioned in a debugging tips document. I don't know how recent it was but maybe converting its build files to GN from GYP was an upheaval. It still references GPY in python scripts. I don't know if Chromium has expert GN people but maybe someone who is expert should be reviewing the build scripts of Chromium's various components.)
Reply all
Reply to author
Forward
0 new messages