how do I pass --whole-archive and --no-whole-archive to dub?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.com
Thu Aug 6 18:10:07 UTC 2020
So this project has a registration function that associates pointers to
functions to functionality architecture.
The current approach is to have a file, say everything.d, that imports
all modules in the project and then for each module calls the function
(inside that module) that carries the registration.
Of course that makes everything.d a large dependency knot that takes
long to compile and also makes incremental/modular/parallel compilation
unduly difficult.
This is a classic problem with a classic solution: build a little
registry and have each module register itself in the shared static
this() module constructor. The code in each module would go:
shared static this() {
addRegistration(&myRegistrationFunction);
}
That way everything does not depend on anything, and the onus is on each
module to register itself. That way modules can be changed (or even
added!) literally without a need to touch or recompile anything else in
the project. Neat!
Except, the project is a static library. When linking the library with
an executable, the linker is motivated to cull unused modules. And for
good reason. (You don't want to initialize the fpga library in
hello_world, etc.) So the module finds that each of those
self-registering modules is not used from the outside (the module
constructor is beautifully/damnedly self-referential) and eliminates the
entire module. So no more registration and the scheme doesn't work.
This is another classic problem with a classic solution: when linking
anything with mylib.a, send the linker the --whole-archive flag just
before it and the --no-whole-archive flag right after it. (Other OSs
have similar flags.)
How can I do that in dub?
More information about the Digitalmars-d
mailing list