What's the best way of laying out executables, libraries, files in a filesystem using gn?

38 views
Skip to first unread message

Pedro Falcato

unread,
Apr 4, 2022, 2:32:23 PM4/4/22
to gn-dev
Hi,

I'm looking into using gn for a project of mine but I'm trying to figure something out: What's the best/most idiomatic way of laying things out such that, at the end, you end up with a mini-filesystem (under e.g sysroot/) that can be just tarballed into a package? I essentially want to put all executable targets' output into sysroot/bin/,  all libraries into sysroot/lib/, same with includes, and other miscellaneous files, but the problem is that each target has its own destination directory for the output. Am I overlooking something here?

Sorry for the newb question by the way!

Thanks,
Pedro

Brett Wilson

unread,
Apr 4, 2022, 2:35:20 PM4/4/22
to Pedro Falcato, gn-dev
You can mess with the toolchain to output things to different directories. But I would recommend adding a separate "package" target that in turn depends on a sequence of copy rules (each depending on building their corresponding thing) to copy them from the build directory to the final destination structure you want.

Brett

David Turner

unread,
Apr 4, 2022, 4:47:55 PM4/4/22
to Brett Wilson, Pedro Falcato, gn-dev
FWIW, we solve two similar problems in the Fuchsia build:

1) To construct the sysroot, whose content rarely changes, we have global lists of scopes that describe exactly which files should be copied into the sysroot, with appropriate dependencies. Then we process them directly in GN to create copy() targets.
2) For installing binaries into Fuchsia packages, we add metadata to each target of interest, collect these using a generated_file() target that produces a JSON distribution manifest file, then have another action process the manifest as input to generate the final archive.

Either method should work for you, depending on how often your mini-filesystem changes. I assume it would be far less complex than our implementation for you too :)

--
To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.
Reply all
Reply to author
Forward
0 new messages