Skip to content
This repository was archived by the owner on Feb 10, 2023. It is now read-only.

Commit 784a38b

Browse files
Fix DLL initialization and linking on Windows
1 parent 8a2be2b commit 784a38b

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
test:
77
name: Test
88
strategy:
9+
fail-fast: false
910
matrix:
1011
os: [ubuntu-18.04, windows-latest]
1112
dc: [dmd-latest, ldc-latest]

src/godot/d/register.d

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ mixin template GodotNativeLibrary(string symbolPrefix, Args...)
9090

9191
/// HACK: empty main to force the compiler to add emulated TLS.
9292
version(Android) void main() { }
93+
94+
// Windows DLL entry points handle TLS+DRuntime initialization and thread attachment
95+
version(Windows)
96+
{
97+
version(D_BetterC) {}
98+
else
99+
{
100+
import core.sys.windows.dll : SimpleDllMain;
101+
mixin SimpleDllMain;
102+
}
103+
}
93104

94105
pragma(mangle, symbolPrefix~"gdnative_init")
95106
export extern(C) static void godot_gdnative_init(godot.c.godot_gdnative_init_options* options)
@@ -100,9 +111,13 @@ mixin template GodotNativeLibrary(string symbolPrefix, Args...)
100111
import core.runtime : Runtime;
101112
import godot.d.output;
102113
import godot.d.traits;
103-
version(D_BetterC) enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.yes, Args) != -1;
104-
else enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.no, Args) == -1;
105-
static if(loadDRuntime) Runtime.initialize();
114+
version(Windows) {}
115+
else
116+
{
117+
version(D_BetterC) enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.yes, Args) != -1;
118+
else enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.no, Args) == -1;
119+
static if(loadDRuntime) Runtime.initialize();
120+
}
106121

107122
godot_gdnative_api_struct_init(options.api_struct);
108123

@@ -208,10 +223,14 @@ mixin template GodotNativeLibrary(string symbolPrefix, Args...)
208223

209224
_GODOT_library.unref();
210225

211-
import core.runtime : Runtime;
212-
version(D_BetterC) enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.yes, Args) != -1;
213-
else enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.no, Args) == -1;
214-
static if(loadDRuntime) Runtime.terminate();
226+
version(Windows) {}
227+
else
228+
{
229+
import core.runtime : Runtime;
230+
version(D_BetterC) enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.yes, Args) != -1;
231+
else enum bool loadDRuntime = staticIndexOf!(LoadDRuntime.no, Args) == -1;
232+
static if(loadDRuntime) Runtime.terminate();
233+
}
215234
}
216235
}
217236

0 commit comments

Comments
 (0)