digitalmars.D - Enhancement on `export` symbol
- Hipreme (31/31) Mar 13 Currently, my engine is using `export` for debug builds, while I
- Richard (Rikki) Andrew Cattermole (1/1) Mar 13 https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1045.md#export-a...
- Johan (21/22) Mar 14 My intuition says that it'll be more broadly useful if attributes
- Hipreme (5/27) Mar 14 Seconded. I believe having those core language attributes
- kinke (10/10) Mar 14 With LDC, you can use `-fvisibility={public,hidden}` to control
Currently, my engine is using `export` for debug builds, while I wanted to not `export` things for release build. That happens because I structured the engine to load a game as a DLL when in development. But for releases, it gets all built together. The problem is that the symbols are still `export`ed. And exporting a symbol increases binary size needlessly and also (possibly) losing some optimization opportunities since that symbol is exposed. ```d version(Standalone) { extern(System): } else version(dll): export extern(System): int[2] getWindowSize(){return [HipRenderer.width, HipRenderer.height];} void setWindowSize(uint width, uint height) { HipRenderer.setWindowSize(width, height); HipRenderer.setViewport(viewport); camera.setSize(cast(int)viewport.worldWidth,cast(int)viewport.worldHeight); } ``` This is basically what I'm needing. I know that asking for that may be a chaos. But it would be good to at least have something like `export(dll)` or something like that, so, at least I would be able to use `version` for identifying if I need that exported or not. That would basically mean, if I'm specifying `-version=dll`, `export` would work, else, it won't matter.
Mar 13
On Friday, 14 March 2025 at 02:46:08 UTC, Richard (Rikki) Andrew Cattermole wrote:https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1045.md#export-annotationMy intuition says that it'll be more broadly useful if attributes can be combined and aliased. Something like this: ``` version(X) { // some arbitrary list of attributes alias attribs = AliasSeq!(export, extern(C), ldc.attributes.weak); } else { // some arbitrary list of attributes alias attribs = AliasSeq!(extern(D), ldc.attributes.hidden); } attribs void foo() {} ``` You can already do this for the LDC attributes (because they are implemented as magic types), but not for D core language attributes. -Johan
Mar 14
On Friday, 14 March 2025 at 12:07:00 UTC, Johan wrote:On Friday, 14 March 2025 at 02:46:08 UTC, Richard (Rikki) Andrew Cattermole wrote:Seconded. I believe having those core language attributes transformed into magic types would definitely solve a long standing issue on the language and would make more C/C++ behaviors (such as `#define dllimport`) available in the language.https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1045.md#export-annotationMy intuition says that it'll be more broadly useful if attributes can be combined and aliased. Something like this: ``` version(X) { // some arbitrary list of attributes alias attribs = AliasSeq!(export, extern(C), ldc.attributes.weak); } else { // some arbitrary list of attributes alias attribs = AliasSeq!(extern(D), ldc.attributes.hidden); } attribs void foo() {} ``` You can already do this for the LDC attributes (because they are implemented as magic types), but not for D core language attributes. -Johan
Mar 14
With LDC, you can use `-fvisibility={public,hidden}` to control the default visibility (for symbols without explicit `export` visibility / ` hidden` UDA). It defaults to `public` when compiling & linking a DLL in a single step via `-shared`; when compiling the DLL separately without linking, you need to specify it yourself. Recent DMD has that CLI option too, `-visibility` (no leading `f`). For (a lot of) context, see https://forum.dlang.org/post/dobouzmhwabquswguunk forum.dlang.org.
Mar 14
On Friday, 14 March 2025 at 16:32:55 UTC, kinke wrote:With LDC, you can use `-fvisibility={public,hidden}` to control the default visibility (for symbols without explicit `export` visibility / ` hidden` UDA). It defaults to `public` when compiling & linking a DLL in a single step via `-shared`; when compiling the DLL separately without linking, you need to specify it yourself. Recent DMD has that CLI option too, `-visibility` (no leading `f`). For (a lot of) context, see https://forum.dlang.org/post/dobouzmhwabquswguunk forum.dlang.org.I'm already using that since it reduces a lot the binary size. I would say that it is almost difficult to not use it, but still doesn't solve that issue I'm having unfortunately
Mar 14
On Friday, 14 March 2025 at 16:41:05 UTC, Hipreme wrote:I'm already using that since it reduces a lot the binary size. I would say that it is almost difficult to not use it, but still doesn't solve that issue I'm having unfortunatelyHave you tried compiling your DLL with `-fvisibility=public -d-version=Standalone`? That shouldn't reduce the binary size at all, but avoid having to uglify the code with `export` everywhere.
Mar 14