Skip to content

Commit

Permalink
Funnier workaround for dlang/dmd#20578
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed Dec 19, 2024
1 parent 2f91b3e commit 94b499d
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions source/serverino/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,29 @@ template ServerinoLoop(Modules...)
import std.traits : getSymbolsByUDA, isFunction, ReturnType, Parameters;
ServerinoConfig config = ServerinoConfig.create();

// NOTE: workaround for issue https://github.com/dlang/dmd/issues/20578
// This should be `if (!ServerinoProcess.isDynamicComponent) { static foreach(m; allModules) { ... } }`
if (ServerinoProcess.isDynamicComponent)
goto issue20578;

// Call ServerinoConfig func(); or ServerinoConfig func(args);
static foreach(m; allModules)
if (!ServerinoProcess.isDynamicComponent)
{
static foreach(f; getSymbolsByUDA!(m, onServerInit))
static foreach(m; allModules)
{
// NOTE: this is a workaround for issue https://github.com/dlang/dmd/issues/20578
{ int _; }

static foreach(f; getSymbolsByUDA!(m, onServerInit))
{

static assert(isFunction!f, "`" ~ __traits(identifier, f) ~ "` is marked with @onServerInit but it is not a function");
static assert(is(ReturnType!f == ServerinoConfig), "`" ~ __traits(identifier, f) ~ "` is " ~ ReturnType!f.toString ~ " but should be `ServerinoConfig`");
static assert(isFunction!f, "`" ~ __traits(identifier, f) ~ "` is marked with @onServerInit but it is not a function");
static assert(is(ReturnType!f == ServerinoConfig), "`" ~ __traits(identifier, f) ~ "` is " ~ ReturnType!f.toString ~ " but should be `ServerinoConfig`");

static if (is(Parameters!f == AliasSeq!(string[]))) config = f(args);
else static if (is(Parameters!f == AliasSeq!())) config = f();
else static assert(0, "`" ~ __traits(identifier, f) ~ "` is marked with @onServerInit but it is not callable");
static if (is(Parameters!f == AliasSeq!(string[]))) config = f(args);
else static if (is(Parameters!f == AliasSeq!())) config = f();
else static assert(0, "`" ~ __traits(identifier, f) ~ "` is marked with @onServerInit but it is not callable");

static if (!__traits(compiles, hasSetup)) { enum hasSetup; }
else static assert(0, "You can't mark more than one function with @onServerInit");
static if (!__traits(compiles, hasSetup)) { enum hasSetup; }
else static assert(0, "You can't mark more than one function with @onServerInit");
}
}
}

issue20578:

static if (runAsSecondaryThread == false) return wakeServerino!allModules(config);
else
{
Expand Down

0 comments on commit 94b499d

Please sign in to comment.