Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions freeciv/apply_wasm_server_patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash


declare -a PATCHLIST=(
"create_virtual_sockets_interface"
"disable_curl"
"switch_netintf_to_virtual"
"switch_sernet_to_virtual"
"fix_missing_type_declaration"
"add_breaks_into_loops_for_js"
"update-cross-file"
"make_emsbuild_for_server"
"update-meson-build"
)

apply_patch() {
echo "*** Applying $1.patch ***"
if ! patch -u -p1 -d freeciv < patches-wasm-server/$1.patch ; then
echo "APPLYING PATCH $1.patch FAILED!"
return 1
fi
echo "=== $1.patch applied ==="
}

for patch in "${PATCHLIST[@]}"
do
if test "${patch}.patch" = "$APPLY_UNTIL" ; then
echo "$patch not applied as requested to stop"
break
fi
if ! apply_patch $patch ; then
echo "Patching failed ($patch.patch)" >&2
exit 1
fi
done
14 changes: 14 additions & 0 deletions freeciv/build_jansson_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Build Jansson library for emscripten
if ! test -f "freeciv/jansson/jansson_private_config.h.in" ; then
echo "Jansson source not found in \"${JANSSON_ROOT}\"" >&2
exit 1
fi
cd freeciv/jansson || exit 1
export CFLAGS="-pthread"
export CXXFLAGS="-pthread"
export LDFLAGS="-pthread"
emconfigure ./configure
emmake make

cd ../.. || exit 1

9 changes: 9 additions & 0 deletions freeciv/dl_jansson_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S bash -e
# Downloads and places the Jansson library source code in jansson/
# Remove old version
rm -Rf jansson
# Download Jansson source code
wget https://github.com/akheron/jansson/releases/download/v2.15.0/jansson-2.15.0.tar.gz
tar -xzf jansson-2.15.0.tar.gz
mv jansson-2.15.0 freeciv/jansson
rm jansson-2.15.0.tar.gz
74 changes: 74 additions & 0 deletions freeciv/patches-wasm-server/add_breaks_into_loops_for_js.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
diff -ruN freeciv-base/server/srv_main.c freeciv/server/srv_main.c
--- freeciv-base/server/srv_main.c 2026-02-03 10:52:54.223187745 +1000
+++ freeciv/server/srv_main.c 2026-02-04 16:02:16.111647221 +1000
@@ -41,6 +41,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef __EMSCRIPTEN__
+#include <emscripten.h>
+#endif

/* dependencies/lua */
#include "lua.h" /* lua_Integer */
@@ -2064,6 +2067,9 @@
int retries = 0;

while (identity_number_is_used(increment_identity_number())) {
+ #ifdef __EMSCRIPTEN__
+ emscripten_sleep(0);
+ #endif
/* Try again */
if (++retries >= IDENTITY_NUMBER_SIZE) {
/* Always fails. */
@@ -2925,6 +2931,9 @@

fc_assert(S_S_RUNNING == server_state());
while (S_S_RUNNING == server_state()) {
+ #ifdef __EMSCRIPTEN__
+ emscripten_sleep(0);
+ #endif
/* The beginning of a turn.
*
* We have to initialize data as well as do some actions. However when
@@ -2998,6 +3007,9 @@
}

while (server_sniff_all_input() == S_E_OTHERWISE) {
+ #ifdef __EMSCRIPTEN__
+ emscripten_sleep(0);
+ #endif
/* Nothing */
}

@@ -3583,6 +3595,9 @@

/* Run server loop */
do {
+ #ifdef __EMSCRIPTEN__
+ emscripten_sleep(0);
+ #endif
set_server_state(S_S_INITIAL);

/* Load a script file. */
@@ -3600,6 +3615,9 @@
srvarg.port);
/* Remain in S_S_INITIAL until all players are ready. */
while (S_E_FORCE_END_OF_SNIFF != server_sniff_all_input()) {
+ #ifdef __EMSCRIPTEN__
+ emscripten_sleep(0);
+ #endif
/* When force_end_of_sniff is used in pregame, it means that the server
* is ready to start (usually set within start_game()). */
}
@@ -3614,6 +3632,9 @@

/* Remain in S_S_OVER until players log out */
while (conn_list_size(game.est_connections) > 0) {
+ #ifdef __EMSCRIPTEN__
+ emscripten_sleep(0);
+ #endif
server_sniff_all_input();
}


Loading