Statically link SourcePawn. (#2459)

This removes the SourcePawn shared library from the distrubtion, and
statically links the VM to sourcemod.logic instead. This means we can
stop designing public APIs that only SourceMod will ever use, since now
SourceMod can just peek directly inside the VM.

We still need a public API for extensions (and the "core" binary). But
that API surface is a lot smaller than what the logic binary needs.

Remove unused DebugReporter::GenerateCodeError function while we're
here, since this will allow removing IPluginDebugInfo.
This commit is contained in:
David Anderson
2026-05-13 21:09:15 -07:00
committed by GitHub
parent 5288927964
commit fba9d713b7
13 changed files with 51 additions and 140 deletions
+6 -73
View File
@@ -58,7 +58,6 @@ SH_DECL_HOOK0(IVEngineServer, GetMapEntitiesString, SH_NOATTRIB, 0, const char *
SourceModBase g_SourceMod;
ke::RefPtr<ke::SharedLib> g_JIT;
SourceHook::String g_BaseDir;
ISourcePawnEngine *g_pSourcePawn = NULL;
ISourcePawnEngine2 *g_pSourcePawn2 = NULL;
@@ -79,20 +78,6 @@ ConVar sm_basepath("sm_basepath", "addons\\sourcemod", 0, "SourceMod base path (
ConVar sm_basepath("sm_basepath", "addons/sourcemod", 0, "SourceMod base path (set via command line)");
#endif
void ShutdownJIT()
{
if (g_pPawnEnv) {
g_pPawnEnv->Shutdown();
delete g_pPawnEnv;
g_pPawnEnv = NULL;
g_pSourcePawn2 = NULL;
g_pSourcePawn = NULL;
}
g_JIT = nullptr;
}
SourceModBase::SourceModBase()
{
m_IsMapLoading = false;
@@ -210,64 +195,11 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
return false;
}
sCoreProviderImpl.InitializeBridge();
/* There will always be a path by this point, since it was force-set above. */
m_GotBasePath = true;
#if defined KE_ARCH_X86
# define SOURCEPAWN_DLL "sourcepawn.jit.x86"
#else
# define SOURCEPAWN_DLL "sourcepawn.vm"
#endif
/* Attempt to load the JIT! */
char file[PLATFORM_MAX_PATH];
char myerror[255];
g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/" PLATFORM_ARCH_FOLDER SOURCEPAWN_DLL ".%s",
GetSourceModPath(),
PLATFORM_LIB_EXT
);
g_JIT = ke::SharedLib::Open(file, myerror, sizeof(myerror));
if (!g_JIT)
{
if (error && maxlength)
{
ke::SafeSprintf(error, maxlength, "%s (failed to load bin/" PLATFORM_ARCH_FOLDER SOURCEPAWN_DLL ".%s)",
myerror,
PLATFORM_LIB_EXT);
}
return false;
}
GetSourcePawnFactoryFn factoryFn =
g_JIT->get<decltype(factoryFn)>("GetSourcePawnFactory");
if (!factoryFn) {
if (error && maxlength)
ke::SafeStrcpy(error, maxlength, "SourcePawn library is out of date");
ShutdownJIT();
return false;
}
ISourcePawnFactory *factory = factoryFn(SOURCEPAWN_API_VERSION);
if (!factory) {
if (error && maxlength)
ke::SafeStrcpy(error, maxlength, "SourcePawn library is out of date");
ShutdownJIT();
return false;
}
g_pPawnEnv = factory->NewEnvironment();
if (!g_pPawnEnv) {
if (error && maxlength)
ke::SafeStrcpy(error, maxlength, "Could not create a SourcePawn environment!");
ShutdownJIT();
return false;
}
g_pSourcePawn = g_pPawnEnv->APIv1();
g_pSourcePawn2 = g_pPawnEnv->APIv2();
g_pSourcePawn2->SetDebugListener(logicore.debugger);
if (sm_disable_jit)
@@ -298,8 +230,6 @@ void SourceModBase::StartSourceMod(bool late)
enginePatch = SH_GET_CALLCLASS(engine);
gamedllPatch = SH_GET_CALLCLASS(gamedll);
sCoreProviderImpl.InitializeBridge();
/* Initialize CoreConfig to get the SourceMod base path properly - this parses core.cfg */
g_CoreConfig.Initialize();
@@ -575,7 +505,10 @@ void SourceModBase::CloseSourceMod()
/* Rest In Peace */
sCoreProviderImpl.ShutdownBridge();
ShutdownJIT();
g_pPawnEnv = NULL;
g_pSourcePawn2 = NULL;
g_pSourcePawn = NULL;
}
void SourceModBase::ShutdownServices()