From 94a6b023db6125970a062002d416c1ea322684fb Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Wed, 5 Feb 2025 15:04:14 +0100
Subject: [PATCH] Add TARGET_ENVIRONMENT and WASM_USE_FS options to wasm_build
 job template

---
 templates/wasm_build.gitlab-ci.yml | 44 +++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/templates/wasm_build.gitlab-ci.yml b/templates/wasm_build.gitlab-ci.yml
index a5c8f70..9dc461d 100644
--- a/templates/wasm_build.gitlab-ci.yml
+++ b/templates/wasm_build.gitlab-ci.yml
@@ -1,6 +1,33 @@
 include:
   - local: templates/npm_projects.gitlab-ci.yml
 
+.wasm_compare_job_template:
+  extends: .npm_based_job_base
+  variables:
+    # The directory containing sources to be built - it should be overrided by derived job
+    SOURCE_DIR: ""
+    # Output directory where should be stored binaries - it should be overrided by derived job
+    BINARIES_DIR: ""
+
+  script:
+    - |
+      first_checksum=""
+      find "${BINARIES_DIR}" -type f -name '*.wasm' | while read -r wasm_file; do
+        checksum=$(sha256sum "$wasm_file" | awk '{ print $1 }')
+
+        echo "Checksum for file $wasm_file: $checksum"
+
+        if [[ -z "$first_checksum" ]]; then
+          first_checksum="$checksum"
+        fi
+
+        if [[ "$checksum" != "$first_checksum" ]]; then
+          echo "Error: Checksum mismatch found for file $wasm_file"
+          exit 1
+        fi
+      done
+      echo "All .wasm files have the same SHA-256 checksum: $first_checksum"
+
 .wasm_build_job_template:
   extends: .npm_based_job_base
   variables:
@@ -8,17 +35,26 @@ include:
     SOURCE_DIR: ""
     # Output directory where should be stored binaries - it should be overrided by derived job
     BINARIES_DIR: ""
+    # Target component name from client cmake to be installed in the BINARIES_DIR
+    COMPONENT_INSTALL_NAME: ""
+    # Target environment for WASM to build - shouble be either web or node
+    TARGET_ENVIRONMENT: "web"
+    # Should include filesystem support based on the target environment (idbfs or node fs) - set to either 1 (enabled) or 0 (disabled)
+    WASM_USE_FS: "0"
 
   script:
-    - mkdir -vp "${BINARIES_DIR}"
-    - cd "${BINARIES_DIR}"
-    - cmake -DBoost_NO_WARN_NEW_VERSIONS=1 -DBoost_USE_STATIC_RUNTIME=ON -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -S "${SOURCE_DIR}" -B "${BINARIES_DIR}"
+    - mkdir -vp "${BINARIES_DIR}/${TARGET_ENVIRONMENT}"
+    - cd "${BINARIES_DIR}/${TARGET_ENVIRONMENT}"
+    - cmake -DBoost_NO_WARN_NEW_VERSIONS=1 -DBoost_USE_STATIC_RUNTIME=ON -DCMAKE_TOOLCHAIN_FILE=/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DWASM_USE_FS="${WASM_USE_FS}" -DTARGET_ENVIRONMENT="${TARGET_ENVIRONMENT}" -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -S "${SOURCE_DIR}" -B "${BINARIES_DIR}/${TARGET_ENVIRONMENT}"
     - make -j 8
+    - cmake --install "${BINARIES_DIR}/${TARGET_ENVIRONMENT}" --component "${COMPONENT_INSTALL_NAME}.common_runtime" --prefix "${BINARIES_DIR}"
 
   artifacts:
     paths:
+      - "${BINARIES_DIR}/${TARGET_ENVIRONMENT}/*.d.ts"
+      - "${BINARIES_DIR}/${TARGET_ENVIRONMENT}/*.js"
+      - "${BINARIES_DIR}/${TARGET_ENVIRONMENT}/*.wasm"
       - "${BINARIES_DIR}/*.d.ts"
-      - "${BINARIES_DIR}/*.mjs"
       - "${BINARIES_DIR}/*.js"
       - "${BINARIES_DIR}/*.wasm"
     when: always
-- 
GitLab