| 1 | #!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp |
| 2 | |
| 3 | import os |
| 4 | import net.http |
| 5 | |
| 6 | fn main() { |
| 7 | os.chdir(@VEXEROOT)! // make sure that the workfolder is stable |
| 8 | tloc := os.join_path(@VEXEROOT, 'thirdparty') |
| 9 | loc := os.join_path(tloc, 'wabt') |
| 10 | if os.exists(loc) { |
| 11 | eprintln('thirdparty/wabt exists, will not overwrite') |
| 12 | eprintln('delete the folder, and execute again') |
| 13 | exit(1) |
| 14 | } |
| 15 | tag := '1.0.32' |
| 16 | fname := 'wabt-${tag}' |
| 17 | mut platform := '' |
| 18 | $if windows { |
| 19 | platform = 'windows' |
| 20 | } $else $if macos { |
| 21 | platform = 'macos-14' |
| 22 | } $else $if linux { |
| 23 | platform = 'ubuntu' |
| 24 | } $else { |
| 25 | eprintln('A premade binary library is not available for your system.') |
| 26 | eprintln('Build it from source, following the documentation here: https://github.com/WebAssembly/wabt/') |
| 27 | exit(1) |
| 28 | } |
| 29 | url := 'https://github.com/WebAssembly/wabt/releases/download/${tag}/${fname}-${platform}.tar.gz' |
| 30 | saveloc := os.join_path(tloc, '${fname}.tar.gz') |
| 31 | println('>> Url: ${url}') |
| 32 | println('>> Archive: ${saveloc}') |
| 33 | if !os.exists(saveloc) { |
| 34 | println('Downloading archive: ${saveloc}, from url: ${url} ...') |
| 35 | http.download_file(url, saveloc)! |
| 36 | // defer { os.rm(saveloc) or {}! } |
| 37 | } |
| 38 | println('Extracting `${tloc}/${fname}` to `${tloc}/wabt` ...') |
| 39 | cmd := 'tar -xvf ${saveloc} --directory ${tloc}' |
| 40 | if os.system(cmd) != 0 { |
| 41 | eprintln('`${cmd}` exited with a non zero exit code') |
| 42 | exit(1) |
| 43 | } |
| 44 | println(cmd) |
| 45 | println('Moving `${tloc}/${fname}` to `${tloc}/wabt` ...') |
| 46 | os.rename_dir('${tloc}/${fname}', loc)! |
| 47 | println('Done. You can now use `v test vlib/wasm` .') |
| 48 | } |
| 49 | |