Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Fix/cross platform sim build (#395)

Jacob Cohen77505e4e7bcf
diff --git a/BUILDING.md b/BUILDING.md
index f7ab5dab8..4089b6026 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -16,7 +16,7 @@ Hub install command, is in [`docs/dev-setup.md`](docs/dev-setup.md).
```bash
git clone https://github.com/eyalgolan/statecraft-israel.git && cd statecraft-israel
-tools/build_sim_for_unity.sh # the sim DLLs Unity loads (build output, not committed)
+uv run tools/build_sim_for_unity.py # the sim DLLs Unity loads (build output, not committed)
export UNITY="/Applications/Unity/Hub/Editor/6000.3.25f1/Unity.app/Contents/MacOS/Unity" # macOS path
# Windows: "C:\Program Files\Unity\Hub\Editor\6000.3.25f1\Editor\Unity.exe"; Linux: ~/Unity/Hub/Editor/6000.3.25f1/Editor/Unity
"$UNITY" -batchmode -CI false -GITHUB_ACTIONS false -TF_BUILD false -quit -projectPath unity -buildTarget WebGL -executeMethod Statecraft.Game.EditorTools.Build.Web -compression disabled -logFile "$PWD/unity-build-web.log"
@@ -28,7 +28,8 @@ A build rewrites some cached settings. Drop them afterwards with
## In the editor
-Unity Hub → **Add** → select `unity/`. Run `tools/build_sim_for_unity.sh` again after every change under `sim/`.
+Unity Hub → **Add** → select `unity/`. Run `uv run tools/build_sim_for_unity.py` again after every change under `sim/`.
+`tools/build_sim_for_unity.sh` is a thin wrapper that runs the same script.
### First open in Unity
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b967d8fe..db901615a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -263,6 +263,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
brighter, so they stand out at the gameplay zoom; the sleepers run every 100 m, a fine texture instead of a coarse ladder; the
ballast is a cooler stone grey; roads have darker worn verges, so they read on pale ground. No mesh, data or boot change
(refs #35).
+- The Unity sim build helper is now `uv run tools/build_sim_for_unity.py`, usable on Windows, macOS and Linux without
+ a shell. It preserves the Release publish and required DLL checks. `tools/build_sim_for_unity.sh` stays as a thin
+ wrapper that runs the Python script.
- Land round 2 (refs #33): the ground's colours move from yellow-olive and gold to promo 03's warm dry ground, in the
biome palette and the land-use bake. Hedges, tree lines and farm tracks are drawn about 150 m wide, so the fields read
at the gameplay zoom. The hills get round bushes with a soft shadow, a stronger garrigue and clearer terraces. It is a
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4d61fda06..820039d00 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -28,7 +28,7 @@ There is no CLA and no sign-off. By opening a pull request you agree that your c
Follow [docs/dev-setup.md](docs/dev-setup.md). In short:
- **Sim and tools only:** .NET SDK 10 and `uv`. Unity is not needed.
-- **Unity work:** Unity 6000.3.25f1 (6.3 LTS) with Web Build Support, a free Unity account, and running `tools/build_sim_for_unity.sh` before you open `unity/`.
+- **Unity work:** Unity 6000.3.25f1 (6.3 LTS) with Web Build Support, a free Unity account, and running `uv run tools/build_sim_for_unity.py` before you open `unity/`.
## Rules every change follows
diff --git a/README.md b/README.md
index c5c6b2dd4..a4cca6564 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,7 @@ It is an early, honest prototype.
There is no hosted build yet; one is planned for M4. To run it locally:
1. Install the tools in [docs/dev-setup.md](docs/dev-setup.md): .NET 10, Unity 6000.3.25f1 with Web Build Support, and `uv`.
-2. Run `tools/build_sim_for_unity.sh`.
+2. Run `uv run tools/build_sim_for_unity.py`.
3. Build the web version. The command is in [docs/dev-setup.md](docs/dev-setup.md).
4. Run `python3 -m http.server 8000 --directory unity/Builds/Web-disabled`, then open http://localhost:8000/.
@@ -132,7 +132,7 @@ Looking for a first task? Browse the [good first issue](https://github.com/eyalg
## Build from source
-You need Unity **6000.3.25f1 (6.3 LTS)** with Web Build Support; the exact version is in [`unity/ProjectSettings/ProjectVersion.txt`](unity/ProjectSettings/ProjectVersion.txt). Clone, run `tools/build_sim_for_unity.sh`, add `unity/` in Unity Hub and open `Assets/Map.unity`. The batch build, the tests and the browser check are in [BUILDING.md](BUILDING.md).
+You need Unity **6000.3.25f1 (6.3 LTS)** with Web Build Support; the exact version is in [`unity/ProjectSettings/ProjectVersion.txt`](unity/ProjectSettings/ProjectVersion.txt). Clone, run `uv run tools/build_sim_for_unity.py`, add `unity/` in Unity Hub and open `Assets/Map.unity`. The batch build, the tests and the browser check are in [BUILDING.md](BUILDING.md).
## AI use
diff --git a/docs/determinism.md b/docs/determinism.md
index f5c8f4773..586464e62 100644
--- a/docs/determinism.md
+++ b/docs/determinism.md
@@ -116,7 +116,7 @@ compare against it. These places must agree with it, and `GoldenManifestTests` f
`tools/art_checkpoint.sh` reads its expected hashes from the manifest, so it needs no edit.
`unity/Assets/Tests/EditMode/SimSmokeTests.cs` runs the same playthroughs inside Unity against `GoldenRun`'s constants
-(run `tools/build_sim_for_unity.sh` first so Unity has the current DLLs).
+(run `uv run tools/build_sim_for_unity.py` first so Unity has the current DLLs).
Verified on .NET, Unity editor Mono, a macOS IL2CPP player (Apple clang, no `-ffp-contract=off` needed) and a WebGL
IL2CPP player in Chrome (M3 Task 22). The platform checks below used the prior `73590e32` 1952 baseline. The issue #2
diff --git a/docs/dev-setup.md b/docs/dev-setup.md
index 166ea6f5a..ba9f7356b 100644
--- a/docs/dev-setup.md
+++ b/docs/dev-setup.md
@@ -10,7 +10,10 @@
- ffmpeg (Homebrew) is used for flythrough videos.
## After cloning
-- Run `tools/build_sim_for_unity.sh` before opening `unity/`. The sim DLLs are build output and are git-ignored.
+- Run `uv run tools/build_sim_for_unity.py` before opening `unity/`. The sim DLLs are build output and are git-ignored.
+ The helper works on Windows, macOS and Linux; with Python already installed, `python tools/build_sim_for_unity.py`
+ also works without `uv` (use `python3` if that is your interpreter's command).
+ `tools/build_sim_for_unity.sh` is a thin wrapper that runs the same Python script, for older plans and scripts.
## Without Unity (Linux, a container, a sandbox)
diff --git a/tools/build_sim_for_unity.py b/tools/build_sim_for_unity.py
new file mode 100644
index 000000000..cfc6fab12
--- /dev/null
+++ b/tools/build_sim_for_unity.py
@@ -0,0 +1,36 @@
+"""Publish the netstandard2.1 sim and YamlDotNet into Unity's plugin folder.
+
+Run with `uv run tools/build_sim_for_unity.py` (or Python directly).
+Requires the .NET SDK on PATH; no Python packages or shell are needed.
+"""
+import subprocess
+import sys
+from pathlib import Path
+
+REPO = Path(__file__).resolve().parents[1]
+
+
+def main() -> int:
+ output = REPO / "unity/Assets/Plugins/Statecraft"
+ try:
+ subprocess.run(["dotnet", "publish", str(REPO / "sim/Statecraft.Sim"),
+ "-c", "Release", "-o", str(output)], cwd=REPO, check=True)
+ except FileNotFoundError:
+ print("Cannot find dotnet. Install the .NET SDK and add it to PATH (see docs/dev-setup.md).",
+ file=sys.stderr)
+ return 1
+ except subprocess.CalledProcessError as error:
+ return error.returncode
+
+ dlls = [output / name for name in ("Statecraft.Sim.dll", "YamlDotNet.dll")]
+ missing = [str(dll) for dll in dlls if not dll.is_file()]
+ if missing:
+ print("Publish did not produce the required DLLs: " + ", ".join(missing), file=sys.stderr)
+ return 1
+ for dll in dlls:
+ print(dll)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/build_sim_for_unity.sh b/tools/build_sim_for_unity.sh
index fd765a460..6f42a9ef7 100755
--- a/tools/build_sim_for_unity.sh
+++ b/tools/build_sim_for_unity.sh
@@ -1,6 +1,3 @@
#!/usr/bin/env bash
-# Publishes the pure C# sim (netstandard2.1) plus YamlDotNet into Unity's plugin folder.
-set -euo pipefail
-cd "$(dirname "$0")/.."
-dotnet publish sim/Statecraft.Sim -c Release -o unity/Assets/Plugins/Statecraft
-ls unity/Assets/Plugins/Statecraft/Statecraft.Sim.dll unity/Assets/Plugins/Statecraft/YamlDotNet.dll
+# Kept for existing plans and scripts: runs tools/build_sim_for_unity.py, the single implementation.
+exec python3 "$(dirname "$0")/build_sim_for_unity.py" "$@"
diff --git a/tools/tests/test_build_sim_for_unity.py b/tools/tests/test_build_sim_for_unity.py
new file mode 100644
index 000000000..f01d73d69
--- /dev/null
+++ b/tools/tests/test_build_sim_for_unity.py
@@ -0,0 +1,56 @@
+import subprocess
+import unittest
+from contextlib import redirect_stderr, redirect_stdout
+from io import StringIO
+from pathlib import Path
+from tempfile import TemporaryDirectory
+from unittest.mock import patch
+
+import build_sim_for_unity as build
+
+
+class BuildSimForUnityTests(unittest.TestCase):
+ def test_publish_uses_repo_paths_even_from_another_directory(self):
+ with TemporaryDirectory(prefix="sim build ") as directory:
+ repo = Path(directory)
+ output = repo / "unity/Assets/Plugins/Statecraft"
+
+ def publish(command, **kwargs):
+ self.assertEqual(command, ["dotnet", "publish", str(repo / "sim/Statecraft.Sim"),
+ "-c", "Release", "-o", str(output)])
+ self.assertEqual(kwargs, {"cwd": repo, "check": True})
+ output.mkdir(parents=True)
+ for name in ("Statecraft.Sim.dll", "YamlDotNet.dll"):
+ (output / name).write_bytes(b"dll")
+
+ with patch.object(build, "REPO", repo), patch.object(build.subprocess, "run", side_effect=publish), \
+ redirect_stdout(StringIO()) as stdout:
+ self.assertEqual(build.main(), 0)
+ self.assertIn(str(output / "Statecraft.Sim.dll"), stdout.getvalue())
+ self.assertIn(str(output / "YamlDotNet.dll"), stdout.getvalue())
+
+ def test_publish_failure_keeps_its_exit_code_and_does_not_report_success(self):
+ with patch.object(build.subprocess, "run", side_effect=subprocess.CalledProcessError(7, ["dotnet"])), \
+ redirect_stdout(StringIO()) as stdout:
+ self.assertEqual(build.main(), 7)
+ self.assertEqual(stdout.getvalue(), "")
+
+ def test_missing_dotnet_has_an_actionable_error(self):
+ with patch.object(build.subprocess, "run", side_effect=FileNotFoundError), \
+ redirect_stderr(StringIO()) as stderr:
+ self.assertNotEqual(build.main(), 0)
+ self.assertIn(".NET SDK", stderr.getvalue())
+
+ def test_successful_publish_must_produce_both_dlls(self):
+ for missing in ("Statecraft.Sim.dll", "YamlDotNet.dll"):
+ with self.subTest(missing=missing), TemporaryDirectory() as directory:
+ repo = Path(directory)
+ output = repo / "unity/Assets/Plugins/Statecraft"
+ output.mkdir(parents=True)
+ for name in ("Statecraft.Sim.dll", "YamlDotNet.dll"):
+ if name != missing:
+ (output / name).write_bytes(b"dll")
+ with patch.object(build, "REPO", repo), patch.object(build.subprocess, "run"), \
+ redirect_stderr(StringIO()) as stderr:
+ self.assertNotEqual(build.main(), 0)
+ self.assertIn(missing, stderr.getvalue())
diff --git a/unity/Assets/Tests/EditMode/SimSmokeTests.cs b/unity/Assets/Tests/EditMode/SimSmokeTests.cs
index 5a9713878..ee6fc15cd 100644
--- a/unity/Assets/Tests/EditMode/SimSmokeTests.cs
+++ b/unity/Assets/Tests/EditMode/SimSmokeTests.cs
@@ -19,7 +19,7 @@ public class SimSmokeTests
/// <summary>The golden playthroughs of docs/determinism.md, run on the Unity editor's Mono runtime. The constants are
/// GoldenRun's, which sim/Statecraft.Sim.Tests/DeterminismTests.cs pins on .NET; rebuild the DLLs
- /// (tools/build_sim_for_unity.sh) after changing them.</summary>
+ /// (uv run tools/build_sim_for_unity.py) after changing them.</summary>
[Test]
public void GoldenPlaythroughTo1950MatchesDotNet()
{