Header-Only Library - pragma(root)
Adam D. Ruppe
destructionator at gmail.com
Mon Jun 15 00:55:59 UTC 2020
On Sunday, 14 June 2020 at 16:05:39 UTC, Andrei Alexandrescu
wrote:
> What code wouldn't it work with?
It isn't so much code as it is some build paradigms.
If you are forced to do separate compilation (like if dmd is
eating 30 GB of RAM...), you can't enjoy dmd -i just working. But
you can still use it in individual pieces then link the result
together normally, so it doesn't get in your way, it just doesn't
help as much. If you do it wrong in these cases, you are liable
to get duplicate symbol problems with a diamond dependency (two
packages compiled separately that both include a common third
package).
All manageable and -i can still help in these cases with
appropriate inclusion/exclusion patterns, just -i's biggest
strength is when you are doing an all-at-once build.
Ditto with non-module based dependency versions or compilation
flags, since those again bring you back to separate compilation.
The other semi-tricky thing is dub's default source layout
doesn't follow the convention -i expects due to having the extra
source/ directory. So you need to add it with -Iproject/source
each time. Or you can automatically rearrange files from a
package upon downloading it (just read the `module` declaration
and sort it into directories from that under a common `lib`
top-level thing. This is actually what I do on my computer and
why my arsd repo has most its files at top-level - if you clone
the repo in your lib dir, the files are now right at `arsd/cgi.d`
etc... which automatically works with the compiler. Zero extra
config needed, it all just works. I get a lot of complaints about
that layout but this is an objective advantage I don't think a
lot of people really realize!)
I've been tempted before to write a competing package manager
that does stuff like this all automatically. Imagine you just
write some D and `import foo.bar;` then the compiler (or, more
specifically, the helper program that works with the compiler)
tells you "module foo.bar is not installed but can be found in
package `footech`, install now? (y/n)". And if you made the major
version part of the module names instead of git tags, that'd all
magically just work too. I'd be kinda fun and very efficient
thanks to dmd -i.
More information about the Digitalmars-d
mailing list