aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2024-09-26 21:02:12 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2024-09-28 18:28:13 +0100
commit3503fa80c02e19a718245f92eba31f6b0a5cf45c (patch)
treee1e1d5913d4cf3ddb07dff7f42c5176447daa5d2
parentbc9198ba9b654117118a06399d4dbf273262501d (diff)
downloadsst-3503fa80c02e19a718245f92eba31f6b0a5cf45c.tar.gz
sst-3503fa80c02e19a718245f92eba31f6b0a5cf45c.zip
Enable rebuilding the plugin while it is loaded
-rwxr-xr-xcompile3
-rw-r--r--compile.bat19
2 files changed, 20 insertions, 2 deletions
diff --git a/compile b/compile
index 9045f53..31e4b8f 100755
--- a/compile
+++ b/compile
@@ -46,7 +46,8 @@ cc() {
ld() {
$CC -shared -flto -fpic -fuse-ld=lld $ldflags -L.build -ldl \
- -ltier0 -lvstdlib -o sst.so$objs
+ -ltier0 -lvstdlib -o .build/sst.so$objs
+ mv .build/sst.so sst.so
}
src="\
diff --git a/compile.bat b/compile.bat
index 11d0aac..1eebb59 100644
--- a/compile.bat
+++ b/compile.bat
@@ -137,10 +137,27 @@ if "%dbg%"=="1" (
)
%CC% -fuse-ld=lld -shared -flto %ldflags% -Wl,/IMPLIB:.build/sst.lib,/Brepro,/nodefaultlib ^
-L.build %clibs% -lkernel32 -luser32 -lbcryptprimitives -lshlwapi -ld3d9 -ldsound ^
--ltier0 -lvstdlib -lntdll -o sst.dll%objs% .build/dll.res || goto :end
+-ltier0 -lvstdlib -lntdll -o .build/sst.dll%objs% .build/dll.res || goto :end
:: get rid of another useless file (can we just not create this???)
del .build\sst.lib
+:: awkward logic to replace sst.dll while it's potentially loaded, because
+:: windows likes to lock things and/or doesn't have atomic rename.
+:: very TOCTOU-ish code, not good at all, but sometimes bad is good enough
+move /y .build\sst.dll sst.dll >nul 2>nul || (
+ move /y sst.dll .build\sst.old.dll >nul 2>nul || (
+ echo:ERROR: couldn't remove sst.dll OR .build/sst.old.dll - are both loaded?>&2
+ goto :end
+ )
+ move .build\sst.dll sst.dll >nul 2>nul || (
+ echo:ERROR: couldn't replace sst.dll - did something just try to load it?>&2
+ goto :end
+ )
+)
+:: try to cleanup the .old again - it'll fail if we just moved it but may work
+:: in some eventual future invocation
+if exist .build\sst.old.dll del .build\sst.old.dll >nul 2>nul
+
%HOSTCC% -fuse-ld=lld -O2 -g -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || goto :end
.build\bitbuf.test.exe || goto :end
:: special case: test must be 32-bit