From 93c4196c4c23c139ac289c910a6bcfb90544518e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 12:59:20 -0800 Subject: [PATCH 01/47] star --- scripts/fuzz_shell.js | 82 +++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 2c7681cb501..f587e7f7c23 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -387,27 +387,12 @@ function hashCombine(seed, value) { /* async */ function callExports(ordering) { // Call the exports we were told, or if we were not given an explicit list, // call them all. - var relevantExports = exportsToCall || exportList; - - if (ordering !== undefined) { - // Copy the list, and sort it in the simple Fisher-Yates manner. - // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm - relevantExports = relevantExports.slice(0); - for (var i = 0; i < relevantExports.length - 1; i++) { - // Pick the index of the item to place at index |i|. - ordering = hashCombine(ordering, i); - // The number of items to pick from begins at the full length, then - // decreases with i. - var j = i + (ordering % (relevantExports.length - i)); - // Swap the item over here. - var t = relevantExports[j]; - relevantExports[j] = relevantExports[i]; - relevantExports[i] = t; - } - } + let relevantExports = exportsToCall || exportList; - for (var e of relevantExports) { - var name, value; + // Build the list of call tasks to run, one for each relevant export. + let tasks = []; + for (let e of relevantExports) { + let name, value; if (typeof e === 'string') { // We are given a string name to call. Look it up in the global namespace. name = e; @@ -423,16 +408,59 @@ function hashCombine(seed, value) { continue; } + // A task is a name + a function to call. For an export, the function is + // simply a call of the export. + tasks.push({ name: name, func: /* async */ () => callFunc(value) }); + } + + // Reverse the array, so the first task is at the end, for efficient + // popping in the common case. + tasks.reverse(); // TODO chak without, see errar + + // Execute tasks while they remain. + while (tasks.length) { + let task; + if (ordering === undefined) { + // Use the natural order. + task = tasks.pop(); + } else { + // Pick a random task. + ordering = hashCombine(ordering, tasks.length); + let i = ordering % tasks.length; + task = tasks.splice(i, 1)[0]; + } + + // Execute the task. + let result; try { - console.log('[fuzz-exec] calling ' + name); - // TODO: Based on |ordering|, do not always await, leaving a promise - // for later, so we interleave stacks. - var result = /* await */ callFunc(value); - if (typeof result !== 'undefined') { - console.log('[fuzz-exec] note result: ' + name + ' => ' + printed(result)); - } + console.log('[fuzz-exec] calling ' + task.name); + result = func(); } catch (e) { console.log('exception thrown: ' + e); + continue; + } + + if (JSPI) { + if (result?.then === 'function') { + // The task returned a promise. We can either await it right now to get + // the full result, or defer it for later. (Note we hash with -1 here, + // just to get something different than the hashing a few lines above.) + ordering = hashCombine(ordering, -1); + if (ordering & 1) { + // Await it right now. + result = /* await */ result; + } else { + // Defer it for later. Reuse the existing task for simplicity. + task.func = /* async */ () => { /* await */ result }; + tasks.push(task); // XXX chak without, see errar + continue; + } + } + } + + // Log the result. + if (typeof result !== 'undefined') { + console.log('[fuzz-exec] note result: ' + task.name + ' => ' + printed(result)); } } } From e2204324d91f90e0638677cb8984a2e4219f5815 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 13:04:45 -0800 Subject: [PATCH 02/47] work --- scripts/fuzz_shell.js | 6 +++--- test/lit/node/fuzz_shell_orders.wast | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index f587e7f7c23..dcb2c2000f3 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -434,15 +434,15 @@ function hashCombine(seed, value) { let result; try { console.log('[fuzz-exec] calling ' + task.name); - result = func(); + result = task.func(); } catch (e) { console.log('exception thrown: ' + e); continue; } if (JSPI) { - if (result?.then === 'function') { - // The task returned a promise. We can either await it right now to get + if (result && (typeof result.then === 'function')) { + // The task returned a Promise. We can either await it right now to get // the full result, or defer it for later. (Note we hash with -1 here, // just to get something different than the hashing a few lines above.) ordering = hashCombine(ordering, -1); diff --git a/test/lit/node/fuzz_shell_orders.wast b/test/lit/node/fuzz_shell_orders.wast index 6d51c4e1b2c..76fd40f4548 100644 --- a/test/lit/node/fuzz_shell_orders.wast +++ b/test/lit/node/fuzz_shell_orders.wast @@ -32,7 +32,7 @@ ;; Append another run with a seed that leads to a different order ;; ;; RUN: cp %S/../../../scripts/fuzz_shell.js %t.js -;; RUN: echo "callExports(1337);" >> %t.js +;; RUN: echo "callExports(34);" >> %t.js ;; RUN: node %t.js %t.wasm | filecheck %s --check-prefix=APPENDED ;; ;; The original order: a,b,c From 211d5859170caa5553a78182a36bc3fc709119dd Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 13:05:45 -0800 Subject: [PATCH 03/47] chak --- scripts/fuzz_shell.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index dcb2c2000f3..c35419c360f 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -415,7 +415,7 @@ function hashCombine(seed, value) { // Reverse the array, so the first task is at the end, for efficient // popping in the common case. - tasks.reverse(); // TODO chak without, see errar + tasks.reverse(); // Execute tasks while they remain. while (tasks.length) { From 9610d8551e212c001f2e05dfc935a25039ece7af Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 13:23:16 -0800 Subject: [PATCH 04/47] fixes --- scripts/fuzz_shell.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index c35419c360f..7893f2df15e 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -433,32 +433,39 @@ function hashCombine(seed, value) { // Execute the task. let result; try { - console.log('[fuzz-exec] calling ' + task.name); result = task.func(); } catch (e) { + console.log('[fuzz-exec] calling ' + task.name); console.log('exception thrown: ' + e); continue; } - if (JSPI) { - if (result && (typeof result.then === 'function')) { - // The task returned a Promise. We can either await it right now to get - // the full result, or defer it for later. (Note we hash with -1 here, - // just to get something different than the hashing a few lines above.) + // When we are changing up the order, in JSPI we can also leave some + // Promises unresolved until later, which lets us interleave them. + if (JSPI && ordering !== undefined) { + if (result && typeof result == 'object' && + typeof result.then === 'function') { + // Hash with -1 here, just to get something different than the hashing a + // few lines above. ordering = hashCombine(ordering, -1); if (ordering & 1) { // Await it right now. result = /* await */ result; } else { // Defer it for later. Reuse the existing task for simplicity. - task.func = /* async */ () => { /* await */ result }; - tasks.push(task); // XXX chak without, see errar + console.log(`(defer ${task.name})`); + task.func = /* async */ () => { + console.log(`(finish ${task.name})`); + return /* await */ result + }; + tasks.push(task); continue; } } } // Log the result. + console.log('[fuzz-exec] calling ' + task.name); if (typeof result !== 'undefined') { console.log('[fuzz-exec] note result: ' + task.name + ' => ' + printed(result)); } From ade1ebea186a4e0e4c699d16ff949259bccffe58 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 13:28:12 -0800 Subject: [PATCH 05/47] fixes --- scripts/fuzz_shell.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 7893f2df15e..9d679c6b446 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -441,8 +441,9 @@ function hashCombine(seed, value) { } // When we are changing up the order, in JSPI we can also leave some - // Promises unresolved until later, which lets us interleave them. - if (JSPI && ordering !== undefined) { + // Promises unresolved until later, which lets us interleave them. Note we + // never defer a task more than once (which would be pointless). + if (JSPI && ordering !== undefined && !task.deferred) { if (result && typeof result == 'object' && typeof result.then === 'function') { // Hash with -1 here, just to get something different than the hashing a @@ -453,11 +454,12 @@ function hashCombine(seed, value) { result = /* await */ result; } else { // Defer it for later. Reuse the existing task for simplicity. - console.log(`(defer ${task.name})`); + console.log(`(jspi: defer ${task.name})`); task.func = /* async */ () => { - console.log(`(finish ${task.name})`); - return /* await */ result + console.log(`(jspi: finish ${task.name})`); + return /* await */ result; }; + task.deferred = true; tasks.push(task); continue; } From bf5d537d3f7b5fe7e2faa65e307057ac352757c3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 13:40:36 -0800 Subject: [PATCH 06/47] fix --- scripts/fuzz_shell.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 9d679c6b446..16d1e45c6a6 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -433,9 +433,9 @@ function hashCombine(seed, value) { // Execute the task. let result; try { + console.log('[fuzz-exec] calling ' + task.name); result = task.func(); } catch (e) { - console.log('[fuzz-exec] calling ' + task.name); console.log('exception thrown: ' + e); continue; } @@ -467,7 +467,6 @@ function hashCombine(seed, value) { } // Log the result. - console.log('[fuzz-exec] calling ' + task.name); if (typeof result !== 'undefined') { console.log('[fuzz-exec] note result: ' + task.name + ' => ' + printed(result)); } From 8b254758fdc69b40f468545d3164ad3bccbcb763 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 13:40:55 -0800 Subject: [PATCH 07/47] temp --- scripts/fuzz_opt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py index 037cfab63ae..4a40d267e85 100755 --- a/scripts/fuzz_opt.py +++ b/scripts/fuzz_opt.py @@ -235,7 +235,7 @@ def randomize_fuzz_settings(): # Test JSPI somewhat rarely, as it may be slower. global JSPI - JSPI = random.random() < 0.25 + JSPI = random.random() < 0.5 # XXX 0.25 print('randomized settings (NaNs, OOB, legalize, JSPI):', NANS, OOB, LEGALIZE, JSPI) From 5514a2cf6044761dc7e5f921be099206a30a542c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 14:05:05 -0800 Subject: [PATCH 08/47] fix --- scripts/fuzz_shell.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 16d1e45c6a6..e037fa4836d 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -440,19 +440,17 @@ function hashCombine(seed, value) { continue; } - // When we are changing up the order, in JSPI we can also leave some - // Promises unresolved until later, which lets us interleave them. Note we - // never defer a task more than once (which would be pointless). - if (JSPI && ordering !== undefined && !task.deferred) { - if (result && typeof result == 'object' && - typeof result.then === 'function') { + if (JSPI) { + // When we are changing up the order, in JSPI we can also leave some + // promises unresolved until later, which lets us interleave them. Note we + // never defer a task more than once (which would be pointless), and we + // also only defer a promise (which we check for using .then). + if (ordering !== undefined && !task.deferred && result && + typeof result == 'object' && typeof result.then === 'function') { // Hash with -1 here, just to get something different than the hashing a // few lines above. ordering = hashCombine(ordering, -1); if (ordering & 1) { - // Await it right now. - result = /* await */ result; - } else { // Defer it for later. Reuse the existing task for simplicity. console.log(`(jspi: defer ${task.name})`); task.func = /* async */ () => { @@ -463,7 +461,11 @@ function hashCombine(seed, value) { tasks.push(task); continue; } + // Otherwise, continue down. } + + // Await it right now. + result = /* await */ result; } // Log the result. From 96df91347484da5bb8812408cdb0acc1dbdb62e9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 14:11:37 -0800 Subject: [PATCH 09/47] sad --- scripts/fuzz_shell.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index e037fa4836d..7a498043052 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -484,4 +484,4 @@ if (secondBinary) { } // Run. -callExports(); +callExports(); // XXX this needs to be awaited, but can't at the top level :( From 02b6bfdb6b1da756bb8c83552659352889bb5782 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 14:15:30 -0800 Subject: [PATCH 10/47] fix --- scripts/fuzz_shell.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 7a498043052..f269340d0c8 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -431,9 +431,9 @@ function hashCombine(seed, value) { } // Execute the task. + console.log('[fuzz-exec] calling ' + task.name); let result; try { - console.log('[fuzz-exec] calling ' + task.name); result = task.func(); } catch (e) { console.log('exception thrown: ' + e); @@ -465,7 +465,12 @@ function hashCombine(seed, value) { } // Await it right now. - result = /* await */ result; + try { + result = /* await */ result; + } catch (e) { + console.log('exception thrown: ' + e); + continue; + } } // Log the result. From 824908c65857670f1781d7c5ec7a0633bc4ae72e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 14:27:12 -0800 Subject: [PATCH 11/47] work --- scripts/fuzz_shell.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index f269340d0c8..26cefd4c56a 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -489,4 +489,5 @@ if (secondBinary) { } // Run. -callExports(); // XXX this needs to be awaited, but can't at the top level :( +callExports(); + From ef26967f8c49041ca5a608805d11775add6f4c48 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 14:27:28 -0800 Subject: [PATCH 12/47] work --- scripts/fuzz_shell.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 26cefd4c56a..4f15bc18cfc 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -490,4 +490,3 @@ if (secondBinary) { // Run. callExports(); - From 1ef833a220eb0c3c7e45c60c0b519aaf9191826b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 15:22:30 -0800 Subject: [PATCH 13/47] test --- test/lit/node/fuzz_shell_jspi.wast | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/lit/node/fuzz_shell_jspi.wast diff --git a/test/lit/node/fuzz_shell_jspi.wast b/test/lit/node/fuzz_shell_jspi.wast new file mode 100644 index 00000000000..afac45a909f --- /dev/null +++ b/test/lit/node/fuzz_shell_jspi.wast @@ -0,0 +1,42 @@ +(module + (import "fuzzing-support" "log-i32" (func $log (param i32))) + + (func $a (export "a") (result i32) + (i32.const 10) + ) + + (func $b (export "b") (result i32) + (i32.const 20) + ) + + (func $c (export "c") (result i32) + (i32.const 30) + ) + + (func $d (export "d") (result i32) + (i32.const 40) + ) + + (func $e (export "e") (result i32) + (i32.const 50) + ) +) + +;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. +;; RUN: echo "JSPI = 1;" > %t.js +;; RUN: node -e "process.stdout.write(require('fs').readFileSync(process.stdin.fd, 'utf-8').replaceAll('/* async */', 'async').replaceAll('/* await */', 'await'))" + +;; Append another run with a random seed, so we reorder and delay execution. +;; RUN: echo "callExports(42);" >> %t.js +;; RUN: node %t.js %t.wasm | filecheck %s +;; +;; The first part is unchanged from before. +;; CHECK: [fuzz-exec] calling errors +;; CHECK: [LoggingExternalInterface logging 0] +;; CHECK: [fuzz-exec] calling call0 +;; CHECK: [LoggingExternalInterface logging 0] +;; CHECK: [LoggingExternalInterface logging 0] +;; CHECK: [fuzz-exec] calling call3 +;; CHECK: [LoggingExternalInterface logging -1] +;; CHECK: [LoggingExternalInterface logging 1] + From 70046a782688b4dfdd29a0a6d2234fc04318e394 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 15:30:04 -0800 Subject: [PATCH 14/47] work --- test/lit/node/fuzz_shell_jspi.wast | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/lit/node/fuzz_shell_jspi.wast b/test/lit/node/fuzz_shell_jspi.wast index afac45a909f..2828414572e 100644 --- a/test/lit/node/fuzz_shell_jspi.wast +++ b/test/lit/node/fuzz_shell_jspi.wast @@ -24,11 +24,14 @@ ;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. ;; RUN: echo "JSPI = 1;" > %t.js -;; RUN: node -e "process.stdout.write(require('fs').readFileSync(process.stdin.fd, 'utf-8').replaceAll('/* async */', 'async').replaceAll('/* await */', 'await'))" +;; RUN: node -e "process.stdout.write(require('fs').readFileSync('%S/../../../scripts/fuzz_shell.js', 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js ;; Append another run with a random seed, so we reorder and delay execution. ;; RUN: echo "callExports(42);" >> %t.js -;; RUN: node %t.js %t.wasm | filecheck %s + +;; Run that JS shell with our wasm. +;; RUN: wasm-opt %s -o %t.wasm -q +;; RUN: d8 --wasm-staging %t.js -- %t.wasm | filecheck %s ;; ;; The first part is unchanged from before. ;; CHECK: [fuzz-exec] calling errors From ba381d452d7c3d57d412600acd837a85f4a2a39d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 16:27:41 -0800 Subject: [PATCH 15/47] test --- test/lit/node/fuzz_shell_jspi.wast | 48 ++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/test/lit/node/fuzz_shell_jspi.wast b/test/lit/node/fuzz_shell_jspi.wast index 2828414572e..c69f44ee422 100644 --- a/test/lit/node/fuzz_shell_jspi.wast +++ b/test/lit/node/fuzz_shell_jspi.wast @@ -33,13 +33,43 @@ ;; RUN: wasm-opt %s -o %t.wasm -q ;; RUN: d8 --wasm-staging %t.js -- %t.wasm | filecheck %s ;; -;; The first part is unchanged from before. -;; CHECK: [fuzz-exec] calling errors -;; CHECK: [LoggingExternalInterface logging 0] -;; CHECK: [fuzz-exec] calling call0 -;; CHECK: [LoggingExternalInterface logging 0] -;; CHECK: [LoggingExternalInterface logging 0] -;; CHECK: [fuzz-exec] calling call3 -;; CHECK: [LoggingExternalInterface logging -1] -;; CHECK: [LoggingExternalInterface logging 1] +;; The output here looks a little out of order, in particular because we do not +;; |await| the toplevel callExports() calls. That |await| is only valid if we +;; pass --module, which we do not fuzz with. As a result, the first await +;; operation in the first callExports() leaves that function and continues to +;; the next, but we do get around to executing all the things we need. In +;; particular, the output here should contain two "node result" lines for each +;; of the 5 functions (one from each callExports()). The important thing is that +;; we get a random-like ordering, which includes some defers (each of which has +;; a later finish), showing that we interleave stacks. +;; +;; CHECK: [fuzz-exec] calling a +;; CHECK: [fuzz-exec] calling b +;; CHECK: [fuzz-exec] note result: a => 10 +;; CHECK: [fuzz-exec] calling b +;; CHECK: [fuzz-exec] note result: b => 20 +;; CHECK: [fuzz-exec] calling a +;; CHECK: (jspi: defer a) +;; CHECK: [fuzz-exec] calling d +;; CHECK: (jspi: defer d) +;; CHECK: [fuzz-exec] calling e +;; CHECK: [fuzz-exec] note result: b => 20 +;; CHECK: [fuzz-exec] calling c +;; CHECK: [fuzz-exec] note result: e => 50 +;; CHECK: [fuzz-exec] calling c +;; CHECK: (jspi: defer c) +;; CHECK: [fuzz-exec] calling c +;; CHECK: (jspi: finish c) +;; CHECK: [fuzz-exec] note result: c => 30 +;; CHECK: [fuzz-exec] calling d +;; CHECK: [fuzz-exec] note result: c => 30 +;; CHECK: [fuzz-exec] calling d +;; CHECK: (jspi: finish d) +;; CHECK: [fuzz-exec] note result: d => 40 +;; CHECK: [fuzz-exec] calling e +;; CHECK: [fuzz-exec] note result: d => 40 +;; CHECK: [fuzz-exec] calling a +;; CHECK: (jspi: finish a) +;; CHECK: [fuzz-exec] note result: a => 10 +;; CHECK: [fuzz-exec] note result: e => 50 From adc74f2d20763be932f00355349d778a975fb490 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 16:28:06 -0800 Subject: [PATCH 16/47] moof --- test/lit/node/fuzz_shell_jspi.wast | 75 ------------------------------ 1 file changed, 75 deletions(-) delete mode 100644 test/lit/node/fuzz_shell_jspi.wast diff --git a/test/lit/node/fuzz_shell_jspi.wast b/test/lit/node/fuzz_shell_jspi.wast deleted file mode 100644 index c69f44ee422..00000000000 --- a/test/lit/node/fuzz_shell_jspi.wast +++ /dev/null @@ -1,75 +0,0 @@ -(module - (import "fuzzing-support" "log-i32" (func $log (param i32))) - - (func $a (export "a") (result i32) - (i32.const 10) - ) - - (func $b (export "b") (result i32) - (i32.const 20) - ) - - (func $c (export "c") (result i32) - (i32.const 30) - ) - - (func $d (export "d") (result i32) - (i32.const 40) - ) - - (func $e (export "e") (result i32) - (i32.const 50) - ) -) - -;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. -;; RUN: echo "JSPI = 1;" > %t.js -;; RUN: node -e "process.stdout.write(require('fs').readFileSync('%S/../../../scripts/fuzz_shell.js', 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js - -;; Append another run with a random seed, so we reorder and delay execution. -;; RUN: echo "callExports(42);" >> %t.js - -;; Run that JS shell with our wasm. -;; RUN: wasm-opt %s -o %t.wasm -q -;; RUN: d8 --wasm-staging %t.js -- %t.wasm | filecheck %s -;; -;; The output here looks a little out of order, in particular because we do not -;; |await| the toplevel callExports() calls. That |await| is only valid if we -;; pass --module, which we do not fuzz with. As a result, the first await -;; operation in the first callExports() leaves that function and continues to -;; the next, but we do get around to executing all the things we need. In -;; particular, the output here should contain two "node result" lines for each -;; of the 5 functions (one from each callExports()). The important thing is that -;; we get a random-like ordering, which includes some defers (each of which has -;; a later finish), showing that we interleave stacks. -;; -;; CHECK: [fuzz-exec] calling a -;; CHECK: [fuzz-exec] calling b -;; CHECK: [fuzz-exec] note result: a => 10 -;; CHECK: [fuzz-exec] calling b -;; CHECK: [fuzz-exec] note result: b => 20 -;; CHECK: [fuzz-exec] calling a -;; CHECK: (jspi: defer a) -;; CHECK: [fuzz-exec] calling d -;; CHECK: (jspi: defer d) -;; CHECK: [fuzz-exec] calling e -;; CHECK: [fuzz-exec] note result: b => 20 -;; CHECK: [fuzz-exec] calling c -;; CHECK: [fuzz-exec] note result: e => 50 -;; CHECK: [fuzz-exec] calling c -;; CHECK: (jspi: defer c) -;; CHECK: [fuzz-exec] calling c -;; CHECK: (jspi: finish c) -;; CHECK: [fuzz-exec] note result: c => 30 -;; CHECK: [fuzz-exec] calling d -;; CHECK: [fuzz-exec] note result: c => 30 -;; CHECK: [fuzz-exec] calling d -;; CHECK: (jspi: finish d) -;; CHECK: [fuzz-exec] note result: d => 40 -;; CHECK: [fuzz-exec] calling e -;; CHECK: [fuzz-exec] note result: d => 40 -;; CHECK: [fuzz-exec] calling a -;; CHECK: (jspi: finish a) -;; CHECK: [fuzz-exec] note result: a => 10 -;; CHECK: [fuzz-exec] note result: e => 50 - From 5fbb4d584d5376366ffea8e160a064318dc66dc8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 16:29:25 -0800 Subject: [PATCH 17/47] todo --- test/lit/lit.cfg.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lit/lit.cfg.py b/test/lit/lit.cfg.py index b337bddcd9f..e451a909d74 100644 --- a/test/lit/lit.cfg.py +++ b/test/lit/lit.cfg.py @@ -25,3 +25,5 @@ tool_file = config.binaryen_src_root + '/scripts/' + tool + '.py' python = sys.executable.replace('\\', '/') config.substitutions.append((tool, python + ' ' + tool_file)) + +# likely we need to enable d8 here for v8, if only v8 exists. also on ci From 5af6120c9a5dbe2267a75347ba53a109aece7f93 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 16:44:33 -0800 Subject: [PATCH 18/47] start --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b826c840bac..c0052ebc688 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,6 +75,11 @@ jobs: run: choco install ninja if: matrix.os == 'windows-latest' + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: mkdir run: mkdir -p out @@ -125,6 +130,10 @@ jobs: submodules: true - name: install ninja run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 - name: install Python dev dependencies run: pip3 install -r requirements-dev.txt - name: cmake @@ -161,6 +170,10 @@ jobs: sudo ./llvm.sh 18 - name: install ninja run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 - name: install Python dev dependencies run: pip3 install -r requirements-dev.txt - name: cmake @@ -196,6 +209,11 @@ jobs: ./alpine.sh apk update ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja + - name: install v8 + run: | + ./alpine.sh npm install jsvu -g + ./alpine.sh jsvu --os=default --engines=v8 + - name: install python dev dependencies run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt @@ -227,6 +245,10 @@ jobs: submodules: true - name: install ninja run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 - name: install Python dev dependencies run: pip3 install -r requirements-dev.txt - name: cmake @@ -261,6 +283,10 @@ jobs: sudo ./llvm.sh 18 - name: install ninja run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 - name: install Python dev dependencies run: pip3 install -r requirements-dev.txt - name: cmake @@ -378,6 +404,10 @@ jobs: submodules: true - name: install ninja run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 - name: install Python dev dependencies run: pip3 install -r requirements-dev.txt - name: cmake From 9e68a3b1db23b6acdc0da101342359e0048dc66c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 16:44:50 -0800 Subject: [PATCH 19/47] test --- test/lit/d8/fuzz_shell_jspi.wast | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/lit/d8/fuzz_shell_jspi.wast diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast new file mode 100644 index 00000000000..c69f44ee422 --- /dev/null +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -0,0 +1,75 @@ +(module + (import "fuzzing-support" "log-i32" (func $log (param i32))) + + (func $a (export "a") (result i32) + (i32.const 10) + ) + + (func $b (export "b") (result i32) + (i32.const 20) + ) + + (func $c (export "c") (result i32) + (i32.const 30) + ) + + (func $d (export "d") (result i32) + (i32.const 40) + ) + + (func $e (export "e") (result i32) + (i32.const 50) + ) +) + +;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. +;; RUN: echo "JSPI = 1;" > %t.js +;; RUN: node -e "process.stdout.write(require('fs').readFileSync('%S/../../../scripts/fuzz_shell.js', 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js + +;; Append another run with a random seed, so we reorder and delay execution. +;; RUN: echo "callExports(42);" >> %t.js + +;; Run that JS shell with our wasm. +;; RUN: wasm-opt %s -o %t.wasm -q +;; RUN: d8 --wasm-staging %t.js -- %t.wasm | filecheck %s +;; +;; The output here looks a little out of order, in particular because we do not +;; |await| the toplevel callExports() calls. That |await| is only valid if we +;; pass --module, which we do not fuzz with. As a result, the first await +;; operation in the first callExports() leaves that function and continues to +;; the next, but we do get around to executing all the things we need. In +;; particular, the output here should contain two "node result" lines for each +;; of the 5 functions (one from each callExports()). The important thing is that +;; we get a random-like ordering, which includes some defers (each of which has +;; a later finish), showing that we interleave stacks. +;; +;; CHECK: [fuzz-exec] calling a +;; CHECK: [fuzz-exec] calling b +;; CHECK: [fuzz-exec] note result: a => 10 +;; CHECK: [fuzz-exec] calling b +;; CHECK: [fuzz-exec] note result: b => 20 +;; CHECK: [fuzz-exec] calling a +;; CHECK: (jspi: defer a) +;; CHECK: [fuzz-exec] calling d +;; CHECK: (jspi: defer d) +;; CHECK: [fuzz-exec] calling e +;; CHECK: [fuzz-exec] note result: b => 20 +;; CHECK: [fuzz-exec] calling c +;; CHECK: [fuzz-exec] note result: e => 50 +;; CHECK: [fuzz-exec] calling c +;; CHECK: (jspi: defer c) +;; CHECK: [fuzz-exec] calling c +;; CHECK: (jspi: finish c) +;; CHECK: [fuzz-exec] note result: c => 30 +;; CHECK: [fuzz-exec] calling d +;; CHECK: [fuzz-exec] note result: c => 30 +;; CHECK: [fuzz-exec] calling d +;; CHECK: (jspi: finish d) +;; CHECK: [fuzz-exec] note result: d => 40 +;; CHECK: [fuzz-exec] calling e +;; CHECK: [fuzz-exec] note result: d => 40 +;; CHECK: [fuzz-exec] calling a +;; CHECK: (jspi: finish a) +;; CHECK: [fuzz-exec] note result: a => 10 +;; CHECK: [fuzz-exec] note result: e => 50 + From ed017513d2b16aeacdf4b347773957435fed4345 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jan 2025 16:46:14 -0800 Subject: [PATCH 20/47] test --- test/lit/d8/fuzz_shell.wast | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/lit/d8/fuzz_shell.wast diff --git a/test/lit/d8/fuzz_shell.wast b/test/lit/d8/fuzz_shell.wast new file mode 100644 index 00000000000..99d8ea989c6 --- /dev/null +++ b/test/lit/d8/fuzz_shell.wast @@ -0,0 +1,19 @@ +;; Test running a wasm file in fuzz_shell.js. + +(module + (func $test (export "test") (result i32) + (i32.const 42) + ) +) + +;; Build to a binary wasm. +;; +;; RUN: wasm-opt %s -o %t.wasm -q + +;; Run in d8. +;; +;; RUN: v8 %S/../../../scripts/fuzz_shell.js -- %t.wasm | filecheck %s +;; +;; CHECK: [fuzz-exec] calling test +;; CHECK: [fuzz-exec] note result: test => 42 + From d01a6053ef755d9f1c76e61526c5fbd82462fb5c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 15 Jan 2025 16:32:52 -0800 Subject: [PATCH 21/47] fix? --- test/lit/lit.cfg.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/lit/lit.cfg.py b/test/lit/lit.cfg.py index b337bddcd9f..5a79938ed2a 100644 --- a/test/lit/lit.cfg.py +++ b/test/lit/lit.cfg.py @@ -25,3 +25,36 @@ tool_file = config.binaryen_src_root + '/scripts/' + tool + '.py' python = sys.executable.replace('\\', '/') config.substitutions.append((tool, python + ' ' + tool_file)) + +# Finds the given executable 'program' in PATH. +# Operates like the Unix tool 'which'. +# This is similar to script/test/shared.py, but does not use binaryen_root, and +# instead is tuned to jsvu's install dir. +def which(program): + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + # Prefer the path, or jsvu's install dir. + paths = os.environ['PATH'].split(os.pathsep) + [ + os.path.expanduser('~/.jsvu/bin'), + ] + for path in paths: + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + if '.' not in fname: + if is_exe(exe_file + '.exe'): + return exe_file + '.exe' + if is_exe(exe_file + '.cmd'): + return exe_file + '.cmd' + if is_exe(exe_file + '.bat'): + return exe_file + '.bat' + +# v8 may be provided by jsvu, or it may be "d8". +V8 = os.environ.get('V8') or which('v8') or which('d8') +config.substitutions.append(('v8', V8)) From bfb4d38ade767196c22a922deba4559b37b963de Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 16 Jan 2025 11:59:05 -0800 Subject: [PATCH 22/47] coverage run too --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0052ebc688..1a61f84c820 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -370,6 +370,9 @@ jobs: submodules: true - name: install ninja run: sudo apt-get install ninja-build + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 - name: install Python dev dependencies run: pip3 install -r requirements-dev.txt - name: cmake From 8d1a559094806ad7e16ada9a7ed3853d3d8dfca8 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 16 Jan 2025 15:34:28 -0800 Subject: [PATCH 23/47] no errors on invalid yml, very sad --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a61f84c820..c65535a0211 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -370,6 +370,7 @@ jobs: submodules: true - name: install ninja run: sudo apt-get install ninja-build + - name: install v8 run: | npm install jsvu -g jsvu --os=default --engines=v8 From d806a950013a181ab55d1604a3c5b0ed79bfc307 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 16 Jan 2025 16:36:26 -0800 Subject: [PATCH 24/47] jsvu needs bash --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c65535a0211..327035f7779 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,7 +207,7 @@ jobs: - name: install packages run: | ./alpine.sh apk update - ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja + ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja bash - name: install v8 run: | From 7b00d011a94b49ba240cca212a854c33ef16854b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 11:50:19 -0800 Subject: [PATCH 25/47] DEBUG-REVERTME --- .github/workflows/ci.yml | 385 +-------------------------------------- 1 file changed, 1 insertion(+), 384 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 327035f7779..e39f832136e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,180 +11,6 @@ on: jobs: - lint: - name: lint - if: ${{ github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - env: - # Keep this in sync with clang-format-diff.sh - LLVM_VERSION: 17 - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - fetch-depth: 0 - - name: install tools - run: | - pip3 install -r requirements-dev.txt - sudo apt install lsb-release wget software-properties-common gnupg - wget https://apt.llvm.org/llvm.sh - sudo chmod +x llvm.sh - sudo ./llvm.sh ${LLVM_VERSION} - sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} - - run: flake8 - - run: ./scripts/clang-format-diff.sh - - name: clang-tidy - run: | - # clang-tidy requires compile_commands.json generated by cmake - cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - ./scripts/clang-tidy-diff.sh - - build: - name: build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - - name: gen-s-parser - run: ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc - - if: matrix.os == 'ubuntu-latest' - - - name: install ninja (linux) - run: sudo apt-get install ninja-build - if: matrix.os == 'ubuntu-latest' - - - name: install ninja (macos) - run: brew install ninja - if: matrix.os == 'macos-latest' - - - name: install ninja (win) - run: choco install ninja - if: matrix.os == 'windows-latest' - - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - - name: mkdir - run: mkdir -p out - - - name: cmake (linux) - run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install - if: matrix.os == 'ubuntu-latest' - - - name: cmake (macos) - run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' - if: matrix.os == 'macos-latest' - - - name: cmake (win) - # -G "Visual Studio 15 2017" - run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install - if: matrix.os == 'windows-latest' - - - name: build - run: cmake --build out --config Release -v - - - name: install - run: cmake --install out --config Release - - - name: strip - run: find out/install/ -type f -perm -u=x -exec strip -x {} + - if: matrix.os != 'windows-latest' - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: build-${{ matrix.os }} - path: out/install - - - name: test binaryen-lit - run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast - - - name: test - run: python check.py --binaryen-bin=out/bin - - build-clang: - name: clang (LTO) - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBYN_ENABLE_LTO=ON - - name: build - run: cmake --build out -v - - name: test binaryen-lit - run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast - - name: test - run: python check.py --binaryen-bin=out/bin - - # TODO(sbc): Find a way to reduce the duplicate between these sanitizer jobs - build-asan: - name: asan - runs-on: ubuntu-latest - env: - ASAN_OPTIONS: "symbolize=1" - COMPILER_FLAGS: "-fsanitize=address" - CC: "clang-18" - CXX: "clang++-18" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install clang 18 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot). # Note: Alpine uses musl libc. # Keep in sync with build_release.yml @@ -213,214 +39,5 @@ jobs: run: | ./alpine.sh npm install jsvu -g ./alpine.sh jsvu --os=default --engines=v8 + ./alpine.sh file ~/.jsvu/engines/v8/v8 - - name: install python dev dependencies - run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt - - - name: cmake - run: | - ./alpine.sh cmake . -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static" -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=install - - - name: build - run: | - ./alpine.sh ninja install - - - name: test - run: ./alpine.sh python3 ./check.py - - # Duplicates build-asan. Please keep in sync - build-ubsan: - name: ubsan - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fsanitize=undefined -fno-sanitize-recover=all" - CC: "clang" - CXX: "clang++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -fsanitize-blacklist=$PWD/ubsan.blacklist" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Duplicates build-asan. Please keep in sync - build-tsan: - name: tsan - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fsanitize=thread" - LINKER_FLAGS: "-fsanitize=thread" - CC: "clang-18" - CXX: "clang++-18" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install clang 18 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Build the .js outputs using emcc - build-emscripten: - name: emscripten - runs-on: ubuntu-latest - env: - # Set this environment variable to test a specific Emscripten branch. - # Format: https://github.com//emscripten/tree/ - EMSCRIPTEN_REPO: "" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: emsdk install - run: | - mkdir $HOME/emsdk - git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk - $HOME/emsdk/emsdk update-tags - $HOME/emsdk/emsdk install tot - $HOME/emsdk/emsdk activate tot - - name: override emscripten repository - if: ${{ env.EMSCRIPTEN_REPO != '' }} - run: | - $HOME/emsdk/emsdk install emscripten-main-64bit \ - --override-repository emscripten-main-64bit@$EMSCRIPTEN_REPO - $HOME/emsdk/emsdk activate emscripten-main-64bit - - name: update path - run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV - - name: emcc-tests - run: | - source $HOME/emsdk/emsdk_env.sh - ./scripts/emcc-tests.sh - - # Windows + gcc needs work before the tests will run, so just test the compile - build-mingw: - name: mingw - runs-on: windows-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G "MSYS Makefiles" - - name: build - run: cmake --build out - - # Duplicates build-asan. Please keep in sync - build-gcov: - name: coverage - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fprofile-arcs -ftest-coverage" - CC: "gcc" - CXX: "g++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -DCMAKE_BUILD_TYPE=Debug" - - name: build - run: cmake --build out - - name: test - run: | - python check.py --binaryen-bin=out/bin lit - python check.py --binaryen-bin=out/bin gtest - - name: upload coverage - uses: codecov/codecov-action@v3 - with: - gcov: true - - # Duplicates build-asan. Please keep in sync - build-cxx20: - name: c++20 - # Make sure we can still build on older Ubuntu - runs-on: ubuntu-20.04 - env: - CC: "gcc" - CXX: "g++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 - - name: build - run: cmake --build out - - name: test - run: | - python check.py --binaryen-bin=out/bin lit - python check.py --binaryen-bin=out/bin gtest From 5bf375638c984920ee96d365ff570c690405c61e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 11:55:52 -0800 Subject: [PATCH 26/47] work around alpine testing REVERTME --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e39f832136e..bb331f20342 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,5 +39,9 @@ jobs: run: | ./alpine.sh npm install jsvu -g ./alpine.sh jsvu --os=default --engines=v8 + + - name: check v8 + run: | ./alpine.sh file ~/.jsvu/engines/v8/v8 + From 0d7668aeccbc8a50b74f4c22321c624828342ff1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 12:03:05 -0800 Subject: [PATCH 27/47] Revert "work around alpine testing REVERTME" This reverts commit 5bf375638c984920ee96d365ff570c690405c61e. --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb331f20342..e39f832136e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,9 +39,5 @@ jobs: run: | ./alpine.sh npm install jsvu -g ./alpine.sh jsvu --os=default --engines=v8 - - - name: check v8 - run: | ./alpine.sh file ~/.jsvu/engines/v8/v8 - From e7c55e337e0ffa7551349664ca14937f4ee18ead Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 12:03:07 -0800 Subject: [PATCH 28/47] Revert "DEBUG-REVERTME" This reverts commit 7b00d011a94b49ba240cca212a854c33ef16854b. --- .github/workflows/ci.yml | 385 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 384 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e39f832136e..327035f7779 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,180 @@ on: jobs: + lint: + name: lint + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + env: + # Keep this in sync with clang-format-diff.sh + LLVM_VERSION: 17 + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + - name: install tools + run: | + pip3 install -r requirements-dev.txt + sudo apt install lsb-release wget software-properties-common gnupg + wget https://apt.llvm.org/llvm.sh + sudo chmod +x llvm.sh + sudo ./llvm.sh ${LLVM_VERSION} + sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} + - run: flake8 + - run: ./scripts/clang-format-diff.sh + - name: clang-tidy + run: | + # clang-tidy requires compile_commands.json generated by cmake + cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + ./scripts/clang-tidy-diff.sh + + build: + name: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + + - name: gen-s-parser + run: ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc - + if: matrix.os == 'ubuntu-latest' + + - name: install ninja (linux) + run: sudo apt-get install ninja-build + if: matrix.os == 'ubuntu-latest' + + - name: install ninja (macos) + run: brew install ninja + if: matrix.os == 'macos-latest' + + - name: install ninja (win) + run: choco install ninja + if: matrix.os == 'windows-latest' + + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + + - name: mkdir + run: mkdir -p out + + - name: cmake (linux) + run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install + if: matrix.os == 'ubuntu-latest' + + - name: cmake (macos) + run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' + if: matrix.os == 'macos-latest' + + - name: cmake (win) + # -G "Visual Studio 15 2017" + run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install + if: matrix.os == 'windows-latest' + + - name: build + run: cmake --build out --config Release -v + + - name: install + run: cmake --install out --config Release + + - name: strip + run: find out/install/ -type f -perm -u=x -exec strip -x {} + + if: matrix.os != 'windows-latest' + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: build-${{ matrix.os }} + path: out/install + + - name: test binaryen-lit + run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast + + - name: test + run: python check.py --binaryen-bin=out/bin + + build-clang: + name: clang (LTO) + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBYN_ENABLE_LTO=ON + - name: build + run: cmake --build out -v + - name: test binaryen-lit + run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast + - name: test + run: python check.py --binaryen-bin=out/bin + + # TODO(sbc): Find a way to reduce the duplicate between these sanitizer jobs + build-asan: + name: asan + runs-on: ubuntu-latest + env: + ASAN_OPTIONS: "symbolize=1" + COMPILER_FLAGS: "-fsanitize=address" + CC: "clang-18" + CXX: "clang++-18" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install clang 18 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot). # Note: Alpine uses musl libc. # Keep in sync with build_release.yml @@ -39,5 +213,214 @@ jobs: run: | ./alpine.sh npm install jsvu -g ./alpine.sh jsvu --os=default --engines=v8 - ./alpine.sh file ~/.jsvu/engines/v8/v8 + - name: install python dev dependencies + run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt + + - name: cmake + run: | + ./alpine.sh cmake . -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static" -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=install + + - name: build + run: | + ./alpine.sh ninja install + + - name: test + run: ./alpine.sh python3 ./check.py + + # Duplicates build-asan. Please keep in sync + build-ubsan: + name: ubsan + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fsanitize=undefined -fno-sanitize-recover=all" + CC: "clang" + CXX: "clang++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -fsanitize-blacklist=$PWD/ubsan.blacklist" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Duplicates build-asan. Please keep in sync + build-tsan: + name: tsan + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fsanitize=thread" + LINKER_FLAGS: "-fsanitize=thread" + CC: "clang-18" + CXX: "clang++-18" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install clang 18 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Build the .js outputs using emcc + build-emscripten: + name: emscripten + runs-on: ubuntu-latest + env: + # Set this environment variable to test a specific Emscripten branch. + # Format: https://github.com//emscripten/tree/ + EMSCRIPTEN_REPO: "" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: emsdk install + run: | + mkdir $HOME/emsdk + git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk + $HOME/emsdk/emsdk update-tags + $HOME/emsdk/emsdk install tot + $HOME/emsdk/emsdk activate tot + - name: override emscripten repository + if: ${{ env.EMSCRIPTEN_REPO != '' }} + run: | + $HOME/emsdk/emsdk install emscripten-main-64bit \ + --override-repository emscripten-main-64bit@$EMSCRIPTEN_REPO + $HOME/emsdk/emsdk activate emscripten-main-64bit + - name: update path + run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV + - name: emcc-tests + run: | + source $HOME/emsdk/emsdk_env.sh + ./scripts/emcc-tests.sh + + # Windows + gcc needs work before the tests will run, so just test the compile + build-mingw: + name: mingw + runs-on: windows-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G "MSYS Makefiles" + - name: build + run: cmake --build out + + # Duplicates build-asan. Please keep in sync + build-gcov: + name: coverage + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fprofile-arcs -ftest-coverage" + CC: "gcc" + CXX: "g++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -DCMAKE_BUILD_TYPE=Debug" + - name: build + run: cmake --build out + - name: test + run: | + python check.py --binaryen-bin=out/bin lit + python check.py --binaryen-bin=out/bin gtest + - name: upload coverage + uses: codecov/codecov-action@v3 + with: + gcov: true + + # Duplicates build-asan. Please keep in sync + build-cxx20: + name: c++20 + # Make sure we can still build on older Ubuntu + runs-on: ubuntu-20.04 + env: + CC: "gcc" + CXX: "g++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 + - name: build + run: cmake --build out + - name: test + run: | + python check.py --binaryen-bin=out/bin lit + python check.py --binaryen-bin=out/bin gtest From b7935950ed5926523fce02c767fa60944fd79c1c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 12:05:20 -0800 Subject: [PATCH 29/47] try to delete rather than skip --- .github/workflows/ci.yml | 374 +-------------------------------------- 1 file changed, 2 insertions(+), 372 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 327035f7779..261a177670e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,180 +11,6 @@ on: jobs: - lint: - name: lint - if: ${{ github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - env: - # Keep this in sync with clang-format-diff.sh - LLVM_VERSION: 17 - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - fetch-depth: 0 - - name: install tools - run: | - pip3 install -r requirements-dev.txt - sudo apt install lsb-release wget software-properties-common gnupg - wget https://apt.llvm.org/llvm.sh - sudo chmod +x llvm.sh - sudo ./llvm.sh ${LLVM_VERSION} - sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} - - run: flake8 - - run: ./scripts/clang-format-diff.sh - - name: clang-tidy - run: | - # clang-tidy requires compile_commands.json generated by cmake - cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - ./scripts/clang-tidy-diff.sh - - build: - name: build - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - - name: gen-s-parser - run: ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc - - if: matrix.os == 'ubuntu-latest' - - - name: install ninja (linux) - run: sudo apt-get install ninja-build - if: matrix.os == 'ubuntu-latest' - - - name: install ninja (macos) - run: brew install ninja - if: matrix.os == 'macos-latest' - - - name: install ninja (win) - run: choco install ninja - if: matrix.os == 'windows-latest' - - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - - name: mkdir - run: mkdir -p out - - - name: cmake (linux) - run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install - if: matrix.os == 'ubuntu-latest' - - - name: cmake (macos) - run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' - if: matrix.os == 'macos-latest' - - - name: cmake (win) - # -G "Visual Studio 15 2017" - run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install - if: matrix.os == 'windows-latest' - - - name: build - run: cmake --build out --config Release -v - - - name: install - run: cmake --install out --config Release - - - name: strip - run: find out/install/ -type f -perm -u=x -exec strip -x {} + - if: matrix.os != 'windows-latest' - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: build-${{ matrix.os }} - path: out/install - - - name: test binaryen-lit - run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast - - - name: test - run: python check.py --binaryen-bin=out/bin - - build-clang: - name: clang (LTO) - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBYN_ENABLE_LTO=ON - - name: build - run: cmake --build out -v - - name: test binaryen-lit - run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast - - name: test - run: python check.py --binaryen-bin=out/bin - - # TODO(sbc): Find a way to reduce the duplicate between these sanitizer jobs - build-asan: - name: asan - runs-on: ubuntu-latest - env: - ASAN_OPTIONS: "symbolize=1" - COMPILER_FLAGS: "-fsanitize=address" - CC: "clang-18" - CXX: "clang++-18" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install clang 18 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot). # Note: Alpine uses musl libc. # Keep in sync with build_release.yml @@ -209,10 +35,9 @@ jobs: ./alpine.sh apk update ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja bash - - name: install v8 + - name: avoid d8 tests (jsvu is not compatible with alpine) run: | - ./alpine.sh npm install jsvu -g - ./alpine.sh jsvu --os=default --engines=v8 + ./alpine.sh rm -Rf test/lit/d8 - name: install python dev dependencies run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt @@ -228,199 +53,4 @@ jobs: - name: test run: ./alpine.sh python3 ./check.py - # Duplicates build-asan. Please keep in sync - build-ubsan: - name: ubsan - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fsanitize=undefined -fno-sanitize-recover=all" - CC: "clang" - CXX: "clang++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -fsanitize-blacklist=$PWD/ubsan.blacklist" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Duplicates build-asan. Please keep in sync - build-tsan: - name: tsan - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fsanitize=thread" - LINKER_FLAGS: "-fsanitize=thread" - CC: "clang-18" - CXX: "clang++-18" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install clang 18 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Build the .js outputs using emcc - build-emscripten: - name: emscripten - runs-on: ubuntu-latest - env: - # Set this environment variable to test a specific Emscripten branch. - # Format: https://github.com//emscripten/tree/ - EMSCRIPTEN_REPO: "" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: emsdk install - run: | - mkdir $HOME/emsdk - git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk - $HOME/emsdk/emsdk update-tags - $HOME/emsdk/emsdk install tot - $HOME/emsdk/emsdk activate tot - - name: override emscripten repository - if: ${{ env.EMSCRIPTEN_REPO != '' }} - run: | - $HOME/emsdk/emsdk install emscripten-main-64bit \ - --override-repository emscripten-main-64bit@$EMSCRIPTEN_REPO - $HOME/emsdk/emsdk activate emscripten-main-64bit - - name: update path - run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV - - name: emcc-tests - run: | - source $HOME/emsdk/emsdk_env.sh - ./scripts/emcc-tests.sh - - # Windows + gcc needs work before the tests will run, so just test the compile - build-mingw: - name: mingw - runs-on: windows-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G "MSYS Makefiles" - - name: build - run: cmake --build out - - # Duplicates build-asan. Please keep in sync - build-gcov: - name: coverage - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fprofile-arcs -ftest-coverage" - CC: "gcc" - CXX: "g++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -DCMAKE_BUILD_TYPE=Debug" - - name: build - run: cmake --build out - - name: test - run: | - python check.py --binaryen-bin=out/bin lit - python check.py --binaryen-bin=out/bin gtest - - name: upload coverage - uses: codecov/codecov-action@v3 - with: - gcov: true - # Duplicates build-asan. Please keep in sync - build-cxx20: - name: c++20 - # Make sure we can still build on older Ubuntu - runs-on: ubuntu-20.04 - env: - CC: "gcc" - CXX: "g++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 - - name: build - run: cmake --build out - - name: test - run: | - python check.py --binaryen-bin=out/bin lit - python check.py --binaryen-bin=out/bin gtest From a44418fb708ee97e1637a9e0730b93af4125dc8e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 13:06:44 -0800 Subject: [PATCH 30/47] undo.moar --- .github/workflows/ci.yml | 2 +- test/lit/lit.cfg.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 261a177670e..c4eadb08e3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: install packages run: | ./alpine.sh apk update - ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja bash + ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja - name: avoid d8 tests (jsvu is not compatible with alpine) run: | diff --git a/test/lit/lit.cfg.py b/test/lit/lit.cfg.py index 5a79938ed2a..9b70b7824b1 100644 --- a/test/lit/lit.cfg.py +++ b/test/lit/lit.cfg.py @@ -26,6 +26,7 @@ python = sys.executable.replace('\\', '/') config.substitutions.append((tool, python + ' ' + tool_file)) +''' # Finds the given executable 'program' in PATH. # Operates like the Unix tool 'which'. # This is similar to script/test/shared.py, but does not use binaryen_root, and @@ -58,3 +59,4 @@ def is_exe(fpath): # v8 may be provided by jsvu, or it may be "d8". V8 = os.environ.get('V8') or which('v8') or which('d8') config.substitutions.append(('v8', V8)) +''' From d479e9965bfe4cac11905bc87aabaf2103951d0d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 14:05:52 -0800 Subject: [PATCH 31/47] try --- .github/workflows/ci.yml | 2 +- test/lit/lit.cfg.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4eadb08e3a..363345dd78a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,6 @@ jobs: ./alpine.sh ninja install - name: test - run: ./alpine.sh python3 ./check.py + run: ./alpine.sh python3 ./check.py lit diff --git a/test/lit/lit.cfg.py b/test/lit/lit.cfg.py index 9b70b7824b1..f47ec3dc782 100644 --- a/test/lit/lit.cfg.py +++ b/test/lit/lit.cfg.py @@ -26,7 +26,6 @@ python = sys.executable.replace('\\', '/') config.substitutions.append((tool, python + ' ' + tool_file)) -''' # Finds the given executable 'program' in PATH. # Operates like the Unix tool 'which'. # This is similar to script/test/shared.py, but does not use binaryen_root, and @@ -59,4 +58,4 @@ def is_exe(fpath): # v8 may be provided by jsvu, or it may be "d8". V8 = os.environ.get('V8') or which('v8') or which('d8') config.substitutions.append(('v8', V8)) -''' + From 14816eec9926430206d613cb0fe9d93cd9e0ee97 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 14:09:26 -0800 Subject: [PATCH 32/47] finish --- .github/workflows/ci.yml | 371 ++++++++++++++++++++++++++++++++++++++- test/lit/lit.cfg.py | 7 +- 2 files changed, 374 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 363345dd78a..5bb8aef00c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,180 @@ on: jobs: + lint: + name: lint + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + env: + # Keep this in sync with clang-format-diff.sh + LLVM_VERSION: 17 + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + - name: install tools + run: | + pip3 install -r requirements-dev.txt + sudo apt install lsb-release wget software-properties-common gnupg + wget https://apt.llvm.org/llvm.sh + sudo chmod +x llvm.sh + sudo ./llvm.sh ${LLVM_VERSION} + sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} + - run: flake8 + - run: ./scripts/clang-format-diff.sh + - name: clang-tidy + run: | + # clang-tidy requires compile_commands.json generated by cmake + cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + ./scripts/clang-tidy-diff.sh + + build: + name: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + + - name: gen-s-parser + run: ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc - + if: matrix.os == 'ubuntu-latest' + + - name: install ninja (linux) + run: sudo apt-get install ninja-build + if: matrix.os == 'ubuntu-latest' + + - name: install ninja (macos) + run: brew install ninja + if: matrix.os == 'macos-latest' + + - name: install ninja (win) + run: choco install ninja + if: matrix.os == 'windows-latest' + + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + + - name: mkdir + run: mkdir -p out + + - name: cmake (linux) + run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install + if: matrix.os == 'ubuntu-latest' + + - name: cmake (macos) + run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' + if: matrix.os == 'macos-latest' + + - name: cmake (win) + # -G "Visual Studio 15 2017" + run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install + if: matrix.os == 'windows-latest' + + - name: build + run: cmake --build out --config Release -v + + - name: install + run: cmake --install out --config Release + + - name: strip + run: find out/install/ -type f -perm -u=x -exec strip -x {} + + if: matrix.os != 'windows-latest' + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: build-${{ matrix.os }} + path: out/install + + - name: test binaryen-lit + run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast + + - name: test + run: python check.py --binaryen-bin=out/bin + + build-clang: + name: clang (LTO) + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBYN_ENABLE_LTO=ON + - name: build + run: cmake --build out -v + - name: test binaryen-lit + run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast + - name: test + run: python check.py --binaryen-bin=out/bin + + # TODO(sbc): Find a way to reduce the duplicate between these sanitizer jobs + build-asan: + name: asan + runs-on: ubuntu-latest + env: + ASAN_OPTIONS: "symbolize=1" + COMPILER_FLAGS: "-fsanitize=address" + CC: "clang-18" + CXX: "clang++-18" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install clang 18 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot). # Note: Alpine uses musl libc. # Keep in sync with build_release.yml @@ -51,6 +225,201 @@ jobs: ./alpine.sh ninja install - name: test - run: ./alpine.sh python3 ./check.py lit + run: ./alpine.sh python3 ./check.py + + # Duplicates build-asan. Please keep in sync + build-ubsan: + name: ubsan + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fsanitize=undefined -fno-sanitize-recover=all" + CC: "clang" + CXX: "clang++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -fsanitize-blacklist=$PWD/ubsan.blacklist" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Duplicates build-asan. Please keep in sync + build-tsan: + name: tsan + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fsanitize=thread" + LINKER_FLAGS: "-fsanitize=thread" + CC: "clang-18" + CXX: "clang++-18" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install clang 18 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Build the .js outputs using emcc + build-emscripten: + name: emscripten + runs-on: ubuntu-latest + env: + # Set this environment variable to test a specific Emscripten branch. + # Format: https://github.com//emscripten/tree/ + EMSCRIPTEN_REPO: "" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: emsdk install + run: | + mkdir $HOME/emsdk + git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk + $HOME/emsdk/emsdk update-tags + $HOME/emsdk/emsdk install tot + $HOME/emsdk/emsdk activate tot + - name: override emscripten repository + if: ${{ env.EMSCRIPTEN_REPO != '' }} + run: | + $HOME/emsdk/emsdk install emscripten-main-64bit \ + --override-repository emscripten-main-64bit@$EMSCRIPTEN_REPO + $HOME/emsdk/emsdk activate emscripten-main-64bit + - name: update path + run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV + - name: emcc-tests + run: | + source $HOME/emsdk/emsdk_env.sh + ./scripts/emcc-tests.sh + + # Windows + gcc needs work before the tests will run, so just test the compile + build-mingw: + name: mingw + runs-on: windows-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G "MSYS Makefiles" + - name: build + run: cmake --build out + # Duplicates build-asan. Please keep in sync + build-gcov: + name: coverage + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fprofile-arcs -ftest-coverage" + CC: "gcc" + CXX: "g++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -DCMAKE_BUILD_TYPE=Debug" + - name: build + run: cmake --build out + - name: test + run: | + python check.py --binaryen-bin=out/bin lit + python check.py --binaryen-bin=out/bin gtest + - name: upload coverage + uses: codecov/codecov-action@v3 + with: + gcov: true + # Duplicates build-asan. Please keep in sync + build-cxx20: + name: c++20 + # Make sure we can still build on older Ubuntu + runs-on: ubuntu-20.04 + env: + CC: "gcc" + CXX: "g++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 + - name: build + run: cmake --build out + - name: test + run: | + python check.py --binaryen-bin=out/bin lit + python check.py --binaryen-bin=out/bin gtest diff --git a/test/lit/lit.cfg.py b/test/lit/lit.cfg.py index f47ec3dc782..7ae6c943f17 100644 --- a/test/lit/lit.cfg.py +++ b/test/lit/lit.cfg.py @@ -55,7 +55,8 @@ def is_exe(fpath): if is_exe(exe_file + '.bat'): return exe_file + '.bat' -# v8 may be provided by jsvu, or it may be "d8". +# v8 may be provided by jsvu, or it may be "d8". It may also not exist at all, +# in which case the relevant lit tests should be skipped. V8 = os.environ.get('V8') or which('v8') or which('d8') -config.substitutions.append(('v8', V8)) - +if V8: + config.substitutions.append(('v8', V8)) From 48e93921e4fbb24ca9e8d3288072e65712738363 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 14:20:45 -0800 Subject: [PATCH 33/47] apply to release too --- .github/workflows/create_release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index a5d1f459e56..8cff451c779 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -126,12 +126,15 @@ jobs: echo 'docker exec alpine "$@";' > ./alpine.sh chmod +x ./alpine.sh - - name: install packages run: | ./alpine.sh apk update ./alpine.sh apk add build-base cmake git python3 clang ninja py3-pip + - name: avoid d8 tests (jsvu is not compatible with alpine) + run: | + ./alpine.sh rm -Rf test/lit/d8 + - name: install python dev dependencies run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt From 09badf253ddacad86642ef3aada4f80acf5f745b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 15:25:18 -0800 Subject: [PATCH 34/47] undo --- scripts/fuzz_opt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py index 4a40d267e85..037cfab63ae 100755 --- a/scripts/fuzz_opt.py +++ b/scripts/fuzz_opt.py @@ -235,7 +235,7 @@ def randomize_fuzz_settings(): # Test JSPI somewhat rarely, as it may be slower. global JSPI - JSPI = random.random() < 0.5 # XXX 0.25 + JSPI = random.random() < 0.25 print('randomized settings (NaNs, OOB, legalize, JSPI):', NANS, OOB, LEGALIZE, JSPI) From 13a4a4dc2990284e3b6db2525bc04ce907ea4d7c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 16:09:27 -0800 Subject: [PATCH 35/47] fix test --- test/lit/d8/fuzz_shell_jspi.wast | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index c69f44ee422..702f00d8a33 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -31,7 +31,7 @@ ;; Run that JS shell with our wasm. ;; RUN: wasm-opt %s -o %t.wasm -q -;; RUN: d8 --wasm-staging %t.js -- %t.wasm | filecheck %s +;; RUN: v8 --wasm-staging %t.js -- %t.wasm | filecheck %s ;; ;; The output here looks a little out of order, in particular because we do not ;; |await| the toplevel callExports() calls. That |await| is only valid if we From 3c246b93482a40d634f171faeedf82b4b29dd41b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 17 Jan 2025 16:39:59 -0800 Subject: [PATCH 36/47] try to fix windows --- test/lit/d8/fuzz_shell_jspi.wast | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index 702f00d8a33..499e0e326ac 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -24,7 +24,7 @@ ;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. ;; RUN: echo "JSPI = 1;" > %t.js -;; RUN: node -e "process.stdout.write(require('fs').readFileSync('%S/../../../scripts/fuzz_shell.js', 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js +;; RUN: node -e "process.stdout.write(require('fs').readFileSync(path.join('%S', '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js ;; Append another run with a random seed, so we reorder and delay execution. ;; RUN: echo "callExports(42);" >> %t.js From 663a667fea8c79271ceff6d9183fe78934c59eba Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2025 13:16:03 -0800 Subject: [PATCH 37/47] DEBUG.WINDOWS.1 --- .github/workflows/ci.yml | 340 +-------------------------------------- 1 file changed, 4 insertions(+), 336 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bb8aef00c3..08a93014c18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,43 +11,12 @@ on: jobs: - lint: - name: lint - if: ${{ github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - env: - # Keep this in sync with clang-format-diff.sh - LLVM_VERSION: 17 - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - fetch-depth: 0 - - name: install tools - run: | - pip3 install -r requirements-dev.txt - sudo apt install lsb-release wget software-properties-common gnupg - wget https://apt.llvm.org/llvm.sh - sudo chmod +x llvm.sh - sudo ./llvm.sh ${LLVM_VERSION} - sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} - - run: flake8 - - run: ./scripts/clang-format-diff.sh - - name: clang-tidy - run: | - # clang-tidy requires compile_commands.json generated by cmake - cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - ./scripts/clang-tidy-diff.sh - build: name: build runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [windows-latest] steps: - uses: actions/setup-python@v5 with: @@ -80,6 +49,9 @@ jobs: npm install jsvu -g jsvu --os=default --engines=v8 + - name: DEBUGDEBUGDEBUG + run: node -e "process.stdout.write(require('fs').readFileSync(path.join('D:\a\binaryen\binaryen\test\lit\d8', '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" + - name: mkdir run: mkdir -p out @@ -118,308 +90,4 @@ jobs: - name: test run: python check.py --binaryen-bin=out/bin - build-clang: - name: clang (LTO) - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBYN_ENABLE_LTO=ON - - name: build - run: cmake --build out -v - - name: test binaryen-lit - run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast - - name: test - run: python check.py --binaryen-bin=out/bin - - # TODO(sbc): Find a way to reduce the duplicate between these sanitizer jobs - build-asan: - name: asan - runs-on: ubuntu-latest - env: - ASAN_OPTIONS: "symbolize=1" - COMPILER_FLAGS: "-fsanitize=address" - CC: "clang-18" - CXX: "clang++-18" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install clang 18 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot). - # Note: Alpine uses musl libc. - # Keep in sync with build_release.yml - build-alpine: - name: alpine - runs-on: ubuntu-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: start docker - run: | - docker run -w /src -dit --name alpine -v $PWD:/src node:lts-alpine - echo 'docker exec alpine "$@";' > ./alpine.sh - chmod +x ./alpine.sh - - - name: install packages - run: | - ./alpine.sh apk update - ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja - - - name: avoid d8 tests (jsvu is not compatible with alpine) - run: | - ./alpine.sh rm -Rf test/lit/d8 - - - name: install python dev dependencies - run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt - - name: cmake - run: | - ./alpine.sh cmake . -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static" -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=install - - - name: build - run: | - ./alpine.sh ninja install - - - name: test - run: ./alpine.sh python3 ./check.py - - # Duplicates build-asan. Please keep in sync - build-ubsan: - name: ubsan - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fsanitize=undefined -fno-sanitize-recover=all" - CC: "clang" - CXX: "clang++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -fsanitize-blacklist=$PWD/ubsan.blacklist" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Duplicates build-asan. Please keep in sync - build-tsan: - name: tsan - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fsanitize=thread" - LINKER_FLAGS: "-fsanitize=thread" - CC: "clang-18" - CXX: "clang++-18" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install clang 18 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 18 - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" - - name: build - run: cmake --build out - - name: test - run: python check.py --binaryen-bin=out/bin - - # Build the .js outputs using emcc - build-emscripten: - name: emscripten - runs-on: ubuntu-latest - env: - # Set this environment variable to test a specific Emscripten branch. - # Format: https://github.com//emscripten/tree/ - EMSCRIPTEN_REPO: "" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: emsdk install - run: | - mkdir $HOME/emsdk - git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk - $HOME/emsdk/emsdk update-tags - $HOME/emsdk/emsdk install tot - $HOME/emsdk/emsdk activate tot - - name: override emscripten repository - if: ${{ env.EMSCRIPTEN_REPO != '' }} - run: | - $HOME/emsdk/emsdk install emscripten-main-64bit \ - --override-repository emscripten-main-64bit@$EMSCRIPTEN_REPO - $HOME/emsdk/emsdk activate emscripten-main-64bit - - name: update path - run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV - - name: emcc-tests - run: | - source $HOME/emsdk/emsdk_env.sh - ./scripts/emcc-tests.sh - - # Windows + gcc needs work before the tests will run, so just test the compile - build-mingw: - name: mingw - runs-on: windows-latest - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G "MSYS Makefiles" - - name: build - run: cmake --build out - - # Duplicates build-asan. Please keep in sync - build-gcov: - name: coverage - runs-on: ubuntu-latest - env: - COMPILER_FLAGS: "-fprofile-arcs -ftest-coverage" - CC: "gcc" - CXX: "g++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -DCMAKE_BUILD_TYPE=Debug" - - name: build - run: cmake --build out - - name: test - run: | - python check.py --binaryen-bin=out/bin lit - python check.py --binaryen-bin=out/bin gtest - - name: upload coverage - uses: codecov/codecov-action@v3 - with: - gcov: true - - # Duplicates build-asan. Please keep in sync - build-cxx20: - name: c++20 - # Make sure we can still build on older Ubuntu - runs-on: ubuntu-20.04 - env: - CC: "gcc" - CXX: "g++" - steps: - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/checkout@v4 - with: - submodules: true - - name: install ninja - run: sudo apt-get install ninja-build - - name: install v8 - run: | - npm install jsvu -g - jsvu --os=default --engines=v8 - - name: install Python dev dependencies - run: pip3 install -r requirements-dev.txt - - name: cmake - run: | - mkdir -p out - cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 - - name: build - run: cmake --build out - - name: test - run: | - python check.py --binaryen-bin=out/bin lit - python check.py --binaryen-bin=out/bin gtest From 110069b20bebd0ae4797eb8a88f1477a6ba06a21 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2025 13:21:10 -0800 Subject: [PATCH 38/47] DEBUG.WINDOWS.2 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08a93014c18..c555411992a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: jsvu --os=default --engines=v8 - name: DEBUGDEBUGDEBUG - run: node -e "process.stdout.write(require('fs').readFileSync(path.join('D:\a\binaryen\binaryen\test\lit\d8', '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" + run: node -e "process.stdout.write(require('fs').readFileSync(path.join('D:\a\binaryen\binaryen', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" - name: mkdir run: mkdir -p out From 3a57dad7b62b38a7aa22d8d042fae6610c06dce7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2025 13:27:46 -0800 Subject: [PATCH 39/47] DEBUG.WINDOWS.3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c555411992a..3caced67d51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: jsvu --os=default --engines=v8 - name: DEBUGDEBUGDEBUG - run: node -e "process.stdout.write(require('fs').readFileSync(path.join('D:\a\binaryen\binaryen', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" + run: node -e "process.stdout.write(require('fs').readFileSync(path.join('D:\\a\\binaryen\\binaryen', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" - name: mkdir run: mkdir -p out From d570dccf842e71c2aec016ea3796cab65dff36ce Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2025 13:36:28 -0800 Subject: [PATCH 40/47] DEBUG.WINDOWS.4 --- .github/workflows/ci.yml | 41 +------------------------------- test/lit/d8/fuzz_shell_jspi.wast | 6 ++++- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3caced67d51..18066b920a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,44 +50,5 @@ jobs: jsvu --os=default --engines=v8 - name: DEBUGDEBUGDEBUG - run: node -e "process.stdout.write(require('fs').readFileSync(path.join('D:\\a\\binaryen\\binaryen', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" - - - name: mkdir - run: mkdir -p out - - - name: cmake (linux) - run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install - if: matrix.os == 'ubuntu-latest' - - - name: cmake (macos) - run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' - if: matrix.os == 'macos-latest' - - - name: cmake (win) - # -G "Visual Studio 15 2017" - run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install - if: matrix.os == 'windows-latest' - - - name: build - run: cmake --build out --config Release -v - - - name: install - run: cmake --install out --config Release - - - name: strip - run: find out/install/ -type f -perm -u=x -exec strip -x {} + - if: matrix.os != 'windows-latest' - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: build-${{ matrix.os }} - path: out/install - - - name: test binaryen-lit - run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast - - - name: test - run: python check.py --binaryen-bin=out/bin - + run: echo D:\a\binaryen\binaryen | node -e "process.stdout.write(require('fs').readFileSync(path.join(require('fs').readFileSync(0, 'utf-8'), '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index 499e0e326ac..0d0f3304e3b 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -24,7 +24,11 @@ ;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. ;; RUN: echo "JSPI = 1;" > %t.js -;; RUN: node -e "process.stdout.write(require('fs').readFileSync(path.join('%S', '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js +;; Use |echo| here to avoid quoting issues on windows paths. +;; RUN: echo %S | node -e "process.stdout.write(require('fs').readFileSync(path.join(require('fs').readFileSync(0, 'utf-8'), '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js + +;; echo "foo" | node -e "console.log(require('fs').readFileSync(0, 'utf-8'))" + ;; Append another run with a random seed, so we reorder and delay execution. ;; RUN: echo "callExports(42);" >> %t.js From 639c964ffab50ea4b45a5b7ab47cc10cdd3fef28 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2025 13:43:28 -0800 Subject: [PATCH 41/47] UNDO --- .github/workflows/ci.yml | 377 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 374 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18066b920a7..5bb8aef00c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,12 +11,43 @@ on: jobs: + lint: + name: lint + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + env: + # Keep this in sync with clang-format-diff.sh + LLVM_VERSION: 17 + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + - name: install tools + run: | + pip3 install -r requirements-dev.txt + sudo apt install lsb-release wget software-properties-common gnupg + wget https://apt.llvm.org/llvm.sh + sudo chmod +x llvm.sh + sudo ./llvm.sh ${LLVM_VERSION} + sudo apt-get install clang-format clang-format-${LLVM_VERSION} clang-tidy-${LLVM_VERSION} + - run: flake8 + - run: ./scripts/clang-format-diff.sh + - name: clang-tidy + run: | + # clang-tidy requires compile_commands.json generated by cmake + cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + ./scripts/clang-tidy-diff.sh + build: name: build runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/setup-python@v5 with: @@ -49,6 +80,346 @@ jobs: npm install jsvu -g jsvu --os=default --engines=v8 - - name: DEBUGDEBUGDEBUG - run: echo D:\a\binaryen\binaryen | node -e "process.stdout.write(require('fs').readFileSync(path.join(require('fs').readFileSync(0, 'utf-8'), '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" + - name: mkdir + run: mkdir -p out + + - name: cmake (linux) + run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install + if: matrix.os == 'ubuntu-latest' + + - name: cmake (macos) + run: cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install '-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64' + if: matrix.os == 'macos-latest' + + - name: cmake (win) + # -G "Visual Studio 15 2017" + run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install + if: matrix.os == 'windows-latest' + + - name: build + run: cmake --build out --config Release -v + + - name: install + run: cmake --install out --config Release + + - name: strip + run: find out/install/ -type f -perm -u=x -exec strip -x {} + + if: matrix.os != 'windows-latest' + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: build-${{ matrix.os }} + path: out/install + + - name: test binaryen-lit + run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast + + - name: test + run: python check.py --binaryen-bin=out/bin + + build-clang: + name: clang (LTO) + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DBYN_ENABLE_LTO=ON + - name: build + run: cmake --build out -v + - name: test binaryen-lit + run: python out/bin/binaryen-lit -vv test/lit/parse-error.wast + - name: test + run: python check.py --binaryen-bin=out/bin + + # TODO(sbc): Find a way to reduce the duplicate between these sanitizer jobs + build-asan: + name: asan + runs-on: ubuntu-latest + env: + ASAN_OPTIONS: "symbolize=1" + COMPILER_FLAGS: "-fsanitize=address" + CC: "clang-18" + CXX: "clang++-18" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install clang 18 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot). + # Note: Alpine uses musl libc. + # Keep in sync with build_release.yml + build-alpine: + name: alpine + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: start docker + run: | + docker run -w /src -dit --name alpine -v $PWD:/src node:lts-alpine + echo 'docker exec alpine "$@";' > ./alpine.sh + chmod +x ./alpine.sh + + - name: install packages + run: | + ./alpine.sh apk update + ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja + + - name: avoid d8 tests (jsvu is not compatible with alpine) + run: | + ./alpine.sh rm -Rf test/lit/d8 + + - name: install python dev dependencies + run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt + + - name: cmake + run: | + ./alpine.sh cmake . -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static" -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC_LIB=ON -DCMAKE_INSTALL_PREFIX=install + - name: build + run: | + ./alpine.sh ninja install + + - name: test + run: ./alpine.sh python3 ./check.py + + # Duplicates build-asan. Please keep in sync + build-ubsan: + name: ubsan + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fsanitize=undefined -fno-sanitize-recover=all" + CC: "clang" + CXX: "clang++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -fsanitize-blacklist=$PWD/ubsan.blacklist" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Duplicates build-asan. Please keep in sync + build-tsan: + name: tsan + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fsanitize=thread" + LINKER_FLAGS: "-fsanitize=thread" + CC: "clang-18" + CXX: "clang++-18" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install clang 18 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LINKER_FLAGS" + - name: build + run: cmake --build out + - name: test + run: python check.py --binaryen-bin=out/bin + + # Build the .js outputs using emcc + build-emscripten: + name: emscripten + runs-on: ubuntu-latest + env: + # Set this environment variable to test a specific Emscripten branch. + # Format: https://github.com//emscripten/tree/ + EMSCRIPTEN_REPO: "" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: emsdk install + run: | + mkdir $HOME/emsdk + git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk + $HOME/emsdk/emsdk update-tags + $HOME/emsdk/emsdk install tot + $HOME/emsdk/emsdk activate tot + - name: override emscripten repository + if: ${{ env.EMSCRIPTEN_REPO != '' }} + run: | + $HOME/emsdk/emsdk install emscripten-main-64bit \ + --override-repository emscripten-main-64bit@$EMSCRIPTEN_REPO + $HOME/emsdk/emsdk activate emscripten-main-64bit + - name: update path + run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV + - name: emcc-tests + run: | + source $HOME/emsdk/emsdk_env.sh + ./scripts/emcc-tests.sh + + # Windows + gcc needs work before the tests will run, so just test the compile + build-mingw: + name: mingw + runs-on: windows-latest + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G "MSYS Makefiles" + - name: build + run: cmake --build out + + # Duplicates build-asan. Please keep in sync + build-gcov: + name: coverage + runs-on: ubuntu-latest + env: + COMPILER_FLAGS: "-fprofile-arcs -ftest-coverage" + CC: "gcc" + CXX: "g++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_C_FLAGS="$COMPILER_FLAGS" -DCMAKE_CXX_FLAGS="$COMPILER_FLAGS -DCMAKE_BUILD_TYPE=Debug" + - name: build + run: cmake --build out + - name: test + run: | + python check.py --binaryen-bin=out/bin lit + python check.py --binaryen-bin=out/bin gtest + - name: upload coverage + uses: codecov/codecov-action@v3 + with: + gcov: true + + # Duplicates build-asan. Please keep in sync + build-cxx20: + name: c++20 + # Make sure we can still build on older Ubuntu + runs-on: ubuntu-20.04 + env: + CC: "gcc" + CXX: "g++" + steps: + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + - uses: actions/checkout@v4 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: install v8 + run: | + npm install jsvu -g + jsvu --os=default --engines=v8 + - name: install Python dev dependencies + run: pip3 install -r requirements-dev.txt + - name: cmake + run: | + mkdir -p out + cmake -S . -B out -G Ninja -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 + - name: build + run: cmake --build out + - name: test + run: | + python check.py --binaryen-bin=out/bin lit + python check.py --binaryen-bin=out/bin gtest From f4d4311e416d4ac802a8dbb809e670f51a7ff9a4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Jan 2025 13:44:07 -0800 Subject: [PATCH 42/47] clean --- test/lit/d8/fuzz_shell_jspi.wast | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index 0d0f3304e3b..0e8b18bb5c1 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -23,13 +23,12 @@ ) ;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. + ;; RUN: echo "JSPI = 1;" > %t.js + ;; Use |echo| here to avoid quoting issues on windows paths. ;; RUN: echo %S | node -e "process.stdout.write(require('fs').readFileSync(path.join(require('fs').readFileSync(0, 'utf-8'), '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js -;; echo "foo" | node -e "console.log(require('fs').readFileSync(0, 'utf-8'))" - - ;; Append another run with a random seed, so we reorder and delay execution. ;; RUN: echo "callExports(42);" >> %t.js From 9cca44c4a4b288e44857604471e6589a2de28628 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Jan 2025 11:09:03 -0800 Subject: [PATCH 43/47] split --- test/lit/d8/fuzz_shell_jspi.wast | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index 0e8b18bb5c1..5eff1a96330 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -22,12 +22,16 @@ ) ) -;; Apply JSPI: prepend JSPI = 1 and remove comments around async and await. +;; Apply JSPI: first, prepend JSPI = 1 ;; RUN: echo "JSPI = 1;" > %t.js -;; Use |echo| here to avoid quoting issues on windows paths. -;; RUN: echo %S | node -e "process.stdout.write(require('fs').readFileSync(path.join(require('fs').readFileSync(0, 'utf-8'), '..', '..', '..', 'scripts', 'fuzz_shell.js'), 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js +;; Copy fuzz_shell to a temp file that we will modify. +;; RUN: cat %S/../../../scripts/fuzz_shell.js > %t.0.js + +;; Read that temp file and remove comments around async and await. (use |echo| +;; here to avoid quoting issues on windows paths) +;; RUN: cat %t.0.js | node -e "process.stdout.write(require('fs').readFileSync(0, 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js ;; Append another run with a random seed, so we reorder and delay execution. ;; RUN: echo "callExports(42);" >> %t.js From 3bfdbe59202018b3534006b81af1071406aa9fb1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Jan 2025 11:09:39 -0800 Subject: [PATCH 44/47] split --- test/lit/d8/fuzz_shell_jspi.wast | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index 5eff1a96330..00253232e86 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -27,11 +27,11 @@ ;; RUN: echo "JSPI = 1;" > %t.js ;; Copy fuzz_shell to a temp file that we will modify. -;; RUN: cat %S/../../../scripts/fuzz_shell.js > %t.0.js +;; RUN: cat > %t.0.js ;; Read that temp file and remove comments around async and await. (use |echo| ;; here to avoid quoting issues on windows paths) -;; RUN: cat %t.0.js | node -e "process.stdout.write(require('fs').readFileSync(0, 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js +;; RUN: cat %S/../../../scripts/fuzz_shell.js | node -e "process.stdout.write(require('fs').readFileSync(0, 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js ;; Append another run with a random seed, so we reorder and delay execution. ;; RUN: echo "callExports(42);" >> %t.js From 15fa8fe54a87a13bec15b9de8c48997795c31012 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Jan 2025 11:11:03 -0800 Subject: [PATCH 45/47] simpl --- test/lit/d8/fuzz_shell_jspi.wast | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/lit/d8/fuzz_shell_jspi.wast b/test/lit/d8/fuzz_shell_jspi.wast index 00253232e86..cc1e35f0274 100644 --- a/test/lit/d8/fuzz_shell_jspi.wast +++ b/test/lit/d8/fuzz_shell_jspi.wast @@ -22,15 +22,14 @@ ) ) -;; Apply JSPI: first, prepend JSPI = 1 +;; Apply JSPI: first, prepend JSPI = 1. ;; RUN: echo "JSPI = 1;" > %t.js -;; Copy fuzz_shell to a temp file that we will modify. -;; RUN: cat > %t.0.js +;; Second, remove comments around async and await: feed fuzz_shell.js into node +;; as stdin, so all node needs to do is read stdin, do the replacements, and +;; write to stdout. -;; Read that temp file and remove comments around async and await. (use |echo| -;; here to avoid quoting issues on windows paths) ;; RUN: cat %S/../../../scripts/fuzz_shell.js | node -e "process.stdout.write(require('fs').readFileSync(0, 'utf-8').replace(/[/][*] async [*][/]/g, 'async').replace(/[/][*] await [*][/]/g, 'await'))" >> %t.js ;; Append another run with a random seed, so we reorder and delay execution. From 2daccd229e1299b249fe5a6c16c42e0c6223a51d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Jan 2025 16:29:43 -0800 Subject: [PATCH 46/47] add chaining todo --- scripts/fuzz_shell.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 4f15bc18cfc..9193eb68014 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -443,8 +443,11 @@ function hashCombine(seed, value) { if (JSPI) { // When we are changing up the order, in JSPI we can also leave some // promises unresolved until later, which lets us interleave them. Note we - // never defer a task more than once (which would be pointless), and we - // also only defer a promise (which we check for using .then). + // never defer a task more than once, and we only defer a promise (which + // we check for using .then). + // TODO: Deferring more than once may make sense, by chaining promises in + // JS (that would not add wasm execution in the middle, but might + // find JS issues in principle). if (ordering !== undefined && !task.deferred && result && typeof result == 'object' && typeof result.then === 'function') { // Hash with -1 here, just to get something different than the hashing a From 1dd5febdb033b5141c0d11c8a7bf998c625270c5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 22 Jan 2025 16:30:49 -0800 Subject: [PATCH 47/47] add chaining todo --- scripts/fuzz_shell.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index 9193eb68014..1856c815b3e 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -447,7 +447,8 @@ function hashCombine(seed, value) { // we check for using .then). // TODO: Deferring more than once may make sense, by chaining promises in // JS (that would not add wasm execution in the middle, but might - // find JS issues in principle). + // find JS issues in principle). We could also link promises by + // depending on each other, ensuring certain orders of execution. if (ordering !== undefined && !task.deferred && result && typeof result == 'object' && typeof result.then === 'function') { // Hash with -1 here, just to get something different than the hashing a