From 5ca926f33b922eb13018ded9ab52605deea4c565 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= <jerome.vouillon@gmail.com>
Date: Thu, 14 Mar 2024 11:58:42 +0100
Subject: [PATCH] Check that the right version of Binaryen tools are in the
 path when building

---
 runtime/wasm/dune | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/runtime/wasm/dune b/runtime/wasm/dune
index 520fb664e..5f662069a 100644
--- a/runtime/wasm/dune
+++ b/runtime/wasm/dune
@@ -7,9 +7,12 @@
    (target runtime.wasm)
    (deps args (glob_files *.wat))
    (action
-      (pipe-stdout
-         (run wasm-merge -g --enable-gc --enable-exception-handling --enable-reference-types --enable-tail-call --enable-strings --enable-multivalue --enable-bulk-memory %{read-lines:args} -o -)
-         (run wasm-opt -g --enable-gc --enable-exception-handling --enable-reference-types --enable-tail-call --enable-strings --enable-multivalue --enable-bulk-memory - -O3 -o %{target}))))
+      (progn
+         (system "which wasm-merge > /dev/null || (echo 'Error: Binaryen tools not found in the PATH'; false)")
+         (system "wasm-merge --version | grep -q 'version 116' || (echo 'Error: Binaryen version 116 is currently required'; false)")
+         (pipe-stdout
+            (run wasm-merge -g --enable-gc --enable-exception-handling --enable-reference-types --enable-tail-call --enable-strings --enable-multivalue --enable-bulk-memory %{read-lines:args} -o -)
+            (run wasm-opt -g --enable-gc --enable-exception-handling --enable-reference-types --enable-tail-call --enable-strings --enable-multivalue --enable-bulk-memory - -O3 -o %{target})))))
 
 (rule (target args)
    (deps args.ml (glob_files *.wat))