How do I get the extension of a shared / static library?

39 views
Skip to first unread message

Charles Nicholson

unread,
Sep 28, 2023, 11:00:01 AM9/28/23
to gn-dev
Hi GN folks-

Library file (shared or static) seem to be the domain of the toolchain + tools. But, sometimes I want to copy a built target to package it up inside of another task.

When I have to do that, it's cumbersome to re-express the logic at every site where I assemble the filename:

if (host_os == "mac") {
  _dll_extension = "dylib"
} else if (host_os == "linux") {
  _dll_extension = "so"
} else if (host_os == "win") {
  _dll_extension = "dll"
} else {
  assert(0, "Unknown host os")
}

This isn't great to drop in all over the place; the extensions don't really change much but it's duplicating the logic on "both sides" of the target, and it's verbose and distracting to read.

If get_target_outputs() worked across the build for all target types, of course this problem would go away. But, in the absence of that feature, is there any other more convenient way to express this logic?

I guess it could be tucked away in a .gni file, that seems reasonable enough, but I'm wondering if there's just a first-class GN feature that I've missed that helps here.

Best,
Charles

Charles Nicholson

unread,
Sep 28, 2023, 11:02:05 AM9/28/23
to gn-dev
Sorry, that first sentence should read:

"Library file (shared or static) file extensions seem to be the domain of the toolchain + tools".

Brett Wilson

unread,
Sep 28, 2023, 11:39:29 AM9/28/23
to Charles Nicholson, gn-dev
Sorry, I don't think you are missing anything here.

Brett

Charles Nicholson

unread,
Sep 28, 2023, 1:15:37 PM9/28/23
to Brett Wilson, gn-dev
Well, thanks for the confirmation at least :)

Have there been any internal discussions about whether an enhanced get_target_outputs() is something that might happen someday? I remember you gave some implementation strategy details back in February, which gave me hope. I appreciate that it's (clearly) not a high-priority item, but it would be, IMO, such an ergonomic win for a ton of little cases like this.


Best,
Charles

Brett Wilson

unread,
Sep 28, 2023, 1:22:44 PM9/28/23
to Charles Nicholson, gn-dev
On Thu, Sep 28, 2023 at 10:15 AM Charles Nicholson <charles....@gmail.com> wrote:
Well, thanks for the confirmation at least :)

Have there been any internal discussions about whether an enhanced get_target_outputs() is something that might happen someday? I remember you gave some implementation strategy details back in February, which gave me hope. I appreciate that it's (clearly) not a high-priority item, but it would be, IMO, such an ergonomic win for a ton of little cases like this.

I think it might happen someday but there have been no recent discussions to my knowledge. It would require that somebody want it badly enough to implement it and check for subtle ordering problems between toolchain loads and this code executing.

Brett 
Reply all
Reply to author
Forward
0 new messages