Comment #0 by alphaglosined — 2024-09-18T06:47:42Z
Sometimes it is useful to have modules that are always compiled into each binary that uses them.
These import-only modules should be able to be imported by setting the import path, and the compiler will if it is used compile it in.
A pragma in the module can specify this behaviour ``pragma(compileonimport);``.
The existing solution for this is to use the ``-i`` switch.
This may be a useful addition wrt. the proposed phobos.sys.* package, that could be import only.
The only catch is the object file will need to enable multiple definitions to prevent linker errors.
Comment #1 by snarwin+bugzilla — 2024-09-18T12:22:56Z
Where is the proposal for "the proposed phobos.sys.* package"?
Comment #2 by alphaglosined — 2024-09-18T12:28:37Z
It is part of PhobosV3, see Adam Wilson's DConf 2024 talk.
A more concrete example of a module that would benefit from it is core.int128, but there are others such as the WinAPI bindings that have symbols declared that are not a binding.
Oh and I've implemented it https://github.com/dlang/dmd/pull/16848
Comment #3 by destructionator — 2024-09-18T18:37:20Z
When is this actually useful? The case of the windows bindings' helper functions is already solved by a linker.
If you try to separate compile anything with this pragma two things that depend on it in a diamond shape, you're liable to get duplicate symbols. Easy to solve with -i, but to clear how it would be solved with this pragma.
Comment #4 by alphaglosined — 2024-09-19T08:22:43Z
With dmd everything is weak, and will handle duplicates by-default.
It is ldc and gdc which I have concerns with for duplicates.
Comment #5 by alphaglosined — 2024-09-19T08:32:03Z
The -i switch suffers the same duplicate issues as the pragma, you should not have to be altering your compile command to remove this, nor tell the linker how to handle duplicates.
Solving it for one, solves it for both.
Comment #6 by robert.schadek — 2024-12-13T19:37:23Z