Skip to content

Commit 0d620e2

Browse files
committed
oh boy, what has to come next is gonna be painful.
1 parent ded6aea commit 0d620e2

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

src/main.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ pub fn should_run(dir_entry: &DirEntry) -> bool {
6363
true
6464
}
6565

66-
pub fn ensure_version(cmd: &str, expected: &str) {
66+
pub fn ensure_version(cmd: &str, arg: &str, expected: &str) {
6767
let output = Command::new(cmd)
68-
.arg("--version")
68+
.arg(arg)
6969
.output()
7070
.unwrap_or_else(|_| panic!("failed to execute version command for {}", &cmd));
7171
let actual = std::str::from_utf8(&output.stdout).unwrap_or_else(|_| panic!("Error decoding stdout"));
@@ -79,7 +79,7 @@ pub fn generate_wat_from_wasm(dir_entry: &DirEntry) {
7979
// println!("generating wat from wasm: {:?}", &wasm_input);
8080

8181
let cmd = "wasm2wat";
82-
ensure_version(cmd, "1.0.32");
82+
ensure_version(cmd, "--version", "1.0.34");
8383

8484
// convert the .wat file to a .wasm file (also validates the .wat)
8585
let output = Command::new(cmd)
@@ -165,7 +165,7 @@ pub fn generate_wasm_from_wat(wat_input: &DirEntry) {
165165
// println!("generating wasm from wat: {:?}", &wat_input.path());
166166

167167
let cmd = "wat2wasm";
168-
ensure_version(cmd, "1.0.32");
168+
ensure_version(cmd, "--version", "1.0.34");
169169

170170
// convert the .wat file to a .wasm file (also validates the .wat)
171171
let output = Command::new(cmd)
@@ -201,7 +201,9 @@ pub fn generate_wasm_from_c(c_input: &DirEntry) {
201201
// println!("generating wasm from c: {:?}", &c_input.path());
202202

203203
let cmd = "emcc";
204-
ensure_version(cmd, "3.1.6");
204+
ensure_version(cmd, "-v", "3.1.6");
205+
// ensure_version(cmd, "-v", "clang version 14.0.6-1");
206+
ensure_version(cmd, "-v", "Target: wasm-unknown-emscripten");
205207

206208
// convert the .wat file to a .wasm file (also validates the .wat)
207209
let output = Command::new(cmd)
@@ -249,30 +251,37 @@ fn main() {
249251
mod tests {
250252
use super::*;
251253

254+
/// Here's how this works.
255+
///
256+
/// We can take two inputs:
257+
/// - one is a .wat file from the `test/from-wat` directory
258+
/// - the other is a .c file from the `test/from-c` directory.
259+
///
260+
/// If it starts as a C file, we generate a .wat from that.
261+
///
262+
/// In both cases we generate `.wasm` files.
263+
///
264+
/// The `.dump` file is a debug representation of the `.wat` file's parsed contents.
265+
///
266+
/// We then generate a `.ts` file from our program.
267+
///
268+
/// #### from-wat
269+
/// 1. read .wat
270+
/// 2. generate and write .wasm from .wat with `wat2wasm`
271+
///
272+
/// #### from-c
273+
/// 1. read .c files
274+
/// 2. generate and write .wasm from the .c files with `emcc` (which uses `clang`)
275+
/// 3. generate and write .wat with `wasm2wat`
276+
///
277+
/// #### point of convergence
278+
/// 1. parse .wat and write .dump
279+
/// 2. generate and write .ts file
280+
///
281+
/// #### runtime tests
282+
/// runtime tests are done from JavaScript, so they need to be run with `pnpm test` in a separate step
252283
#[test]
253284
fn run_conformance_tests() {
254-
/*
255-
256-
Here's how this works. We can take two inputs. One is a .wat file from the `test/from-wat` directory, and the other is a .c file from the `test/from-c` directory. If it starts as a C file, we generate a .wat from that. In both cases we generate `.wasm` files. The `.dump` file is a debug representation of the `.wat` file's parsed contents. We then generate a `.ts` file from our program.
257-
258-
## from-wat
259-
1. read .wat
260-
2. generate and write .wasm from .wat with wat2wasm
261-
262-
## from-c
263-
1. read .c
264-
2. generate and write .wasm from the .c with emcc
265-
3. generate and write .wat with wasm2wat
266-
267-
## point of convergence
268-
- parse .wat and write .dump
269-
- generate and write .ts file
270-
271-
## runtime tests
272-
runtime tests are done from javascript, so they need to be run with `pnpm test` in a separate step
273-
274-
*/
275-
276285
let from_wat = get_wat_files();
277286
from_wat.iter().for_each(generate_wasm_from_wat);
278287

0 commit comments

Comments
 (0)