Refactor: extract platform abstraction for subprocess spawning
Move all Unix-specific syscalls (fork, execvp, waitpid, strerror, /tmp) into a platform layer so the same spectrogram.c can target Windows (CreateProcess) and WebAssembly (stubs). Key changes: - src/platform.h: public API with spawn handle, error codes, path helpers - src/platform_linux.c: fork/execvp implementation, /tmp, strerror - src/platform_win32.c: CreateProcess implementation, temp dir lookup - src/platform_web.c: stub implementations (no subprocess support on web) - src/spectrogram.c: consume only platform.h; replace pid_t/fork/execvp with Platform_SpawnChild/WaitForChild; use Platform_GetTempDir() for /tmp path; replace strdup with malloc/memcpy for portability - Build: add platform_*.c to gmake, Premake, and build_web.sh
This commit is contained in:
+16
-2
@@ -42,9 +42,22 @@ cd "$RAYLIB_BUILD"
|
||||
emar rcs libraylib.a rcore.o rshapes.o rtextures.o rtext.o rmodels.o raudio.o
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
echo "=== Step 2: Compiling spectrogram for web ==="
|
||||
# Compile spectrogram (web version — no subprocess support)
|
||||
# platform_web.c provides stub implementations for spawn/error functions
|
||||
echo "=== Step 2: Compiling spectrogram + platform for web ==="
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Compile platform_web.o (handles fork/execvp stubs for web)
|
||||
emcc -c -Os -Wall -DPLATFORM_WEB "$SRC_DIR/platform_web.c" -o "$RAYLIB_BUILD/platform_web.o"
|
||||
|
||||
# Compile spectrogram
|
||||
emcc -c -Os -Wall -DPLATFORM_WEB "$SRC_DIR/spectrogram.c" \
|
||||
-I"$RAYLIB_DIR/src" \
|
||||
-I"$RAYLIB_DIR/src/external" \
|
||||
-I"$RAYLIB_DIR/src/external/glfw/include" \
|
||||
-Iinclude \
|
||||
-o "$RAYLIB_BUILD/spectrogram.o"
|
||||
|
||||
# Linker flags
|
||||
LDFLAGS="-s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 -s FORCE_FILESYSTEM=1 --preload-file resources@resources --preload-file fonts/DejaVuSansMono.ttf@fonts/DejaVuSansMono.ttf --shell-file $SCRIPT_DIR/web_shell.html -s NO_EXIT_RUNTIME=1"
|
||||
|
||||
@@ -56,7 +69,8 @@ fi
|
||||
|
||||
# Compile and link
|
||||
emcc -o "$OUTPUT" \
|
||||
"$SRC_DIR/spectrogram.c" \
|
||||
"$RAYLIB_BUILD/platform_web.o" \
|
||||
"$RAYLIB_BUILD/spectrogram.o" \
|
||||
-I"$RAYLIB_DIR/src" \
|
||||
-I"$RAYLIB_DIR/src/external" \
|
||||
-I"$RAYLIB_DIR/src/external/glfw/include" \
|
||||
|
||||
Reference in New Issue
Block a user