Files @ r27836:e1c1dfbccca2
Branch filter:

Location: cpp/openttd-patchpack/source/os/emscripten/emsdk-nlohmann-json.patch

Patric Stout
Fix: [CI] Allow release-flow to run in forks (while skipping survey-key) (#11241)
From 0edcedbea375e59f41df10acaee0c483d245751f Mon Sep 17 00:00:00 2001
From: Patric Stout <truebrain@openttd.org>
Date: Tue, 2 May 2023 21:48:08 +0200
Subject: [PATCH] Add nlohmmann-json port

---
 src/settings.js              |  4 ++++
 tools/ports/nlohmann_json.py | 46 ++++++++++++++++++++++++++++++++++++
 tools/settings.py            |  1 +
 3 files changed, 51 insertions(+)
 create mode 100644 tools/ports/nlohmann_json.py

diff --git a/src/settings.js b/src/settings.js
index f93140d..39f4366 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -1483,6 +1483,10 @@ var USE_MPG123 = false;
 // [compile+link]
 var USE_FREETYPE = false;

+// 1 = use nlohmann-json from emscripten-ports
+// [compile+link]
+var USE_NLOHMANN_JSON = false;
+
 // Specify the SDL_mixer version that is being linked against.
 // Doesn't *have* to match USE_SDL, but a good idea.
 // [compile+link]
diff --git a/tools/ports/nlohmann_json.py b/tools/ports/nlohmann_json.py
new file mode 100644
index 0000000..9e44297
--- /dev/null
+++ b/tools/ports/nlohmann_json.py
@@ -0,0 +1,46 @@
+# Copyright 2023 The Emscripten Authors.  All rights reserved.
+# Emscripten is available under two separate licenses, the MIT license and the
+# University of Illinois/NCSA Open Source License.  Both these licenses can be
+# found in the LICENSE file.
+
+import os
+
+TAG = '3.11.2'
+HASH = '99d9e6d588cabe8913a37437f86acb5d4b8b98bce12423e633c11c13b61e6c7f92ef8f9a4e991baa590329ee2b5c09ca9db9894bee1e54bdd68e8d09d83cc245'
+
+
+def needed(settings):
+  return settings.USE_NLOHMANN_JSON
+
+
+def get(ports, settings, shared):
+  ports.fetch_project('nlohmann_json',
+                      f'https://github.com/nlohmann/json/releases/download/v{TAG}/include.zip',
+                      sha512hash=HASH)
+
+  def create(final):
+    source_path = os.path.join(ports.get_dir(), 'nlohmann_json')
+    source_path_include = os.path.join(source_path, 'include', 'nlohmann')
+    ports.install_header_dir(source_path_include, 'nlohmann')
+
+    # write out a dummy cpp file, to create an empty library
+    # this is needed as emscripten ports expect this, even if it is not used
+    dummy_file = os.path.join(source_path, 'dummy.cpp')
+    shared.safe_ensure_dirs(os.path.dirname(dummy_file))
+    ports.write_file(dummy_file, 'static void dummy() {}')
+
+    ports.build_port(source_path, final, 'nlohmann_json', srcs=['dummy.cpp'])
+
+  return [shared.cache.get_lib('libnlohmann_json.a', create, what='port')]
+
+
+def clear(ports, settings, shared):
+  shared.cache.erase_lib('libnlohmann_json.a')
+
+
+def process_args(ports):
+  return []
+
+
+def show():
+  return 'nlohmann-json'
diff --git a/tools/settings.py b/tools/settings.py
index 10d6ca0..8536092 100644
--- a/tools/settings.py
+++ b/tools/settings.py
@@ -47,6 +47,7 @@ PORTS_SETTINGS = {
     'USE_MPG123',
     'USE_GIFLIB',
     'USE_FREETYPE',
+    'USE_NLOHMANN_JSON',
     'SDL2_MIXER_FORMATS',
     'SDL2_IMAGE_FORMATS',
     'USE_SQLITE3',
--
2.34.1