Verified Commit 9b28fa80 authored by nagayama15's avatar nagayama15

rewrite embedding script with Ruby

parent d36d0038
......@@ -16,3 +16,7 @@ trim_trailing_whitespace = false
[{Makefile,*.mk}]
indent_style = tab
indent_size = 4
[*.rb]
indent_style = space
indent_size = 2
#!/usr/bin/env ruby
require 'fileutils'
require 'pathname'
SNPI="./build/bin/snpi"
PISN="./build/bin/pisn"
WASM_BINARIES = {
:ammo => "./node_modules/ammo.js/builds/ammo.wasm.wasm",
:jq => "./node_modules/jq-web/jq.wasm.wasm",
:source_map => "./node_modules/source-map/lib/mappings.wasm",
:wasm_flate => "./node_modules/wasm-flate/wasm_flate_bg.wasm",
:vim => "./node_modules/vim-wasm/vim.wasm",
:vim_small => "./node_modules/vim-wasm/small/vim.wasm",
}
OUTPUT_DIRS = {
:ammo => "./out/ammo.js",
:jq => "./out/jq-web",
:source_map => "./out/source-map",
:wasm_flate => "./out/wasm-flate",
:vim => "./out/vim-wasm",
:vim_small => "./out/vim-wasm/small",
}
METHODS = [
{:name => "function-reorder", :abbr => "fn"},
{:name => "export-reorder", :abbr => "ex"},
{:name => "operand-swap", :abbr => "op"},
]
def copy(file, out)
FileUtils.copy(file, out, {:verbose => true})
end
def embed(file, out, method, watermark, chunk_size = 20)
output = IO.popen([SNPI, "-o", out.to_s, "-m", method, "-w", watermark, "-c", chunk_size.to_s, file.to_s]).read
puts "#{file}, #{out}, #{method}, #{watermark}, #{output}"
end
WASM_BINARIES.each do |id, file|
dir = Pathname(OUTPUT_DIRS[id])
FileUtils.mkdir_p(dir)
copy(file, dir + Pathname(file).basename)
end
METHODS.each do |method|
WASM_BINARIES.each do |id, file|
watermark = "TEST"
dir = Pathname(OUTPUT_DIRS[id])
out = dir + Pathname(file).basename.sub(".wasm", "-#{method[:abbr]}-#{watermark}.wasm")
embed(file, out, method[:name], watermark)
end
end
#!/bin/sh
SNPI="./build/bin/snpi"
PISN="./build/bin/pisn"
OUT_DIR="./out"
WASM_AMMO_JS="./node_modules/ammo.js/builds/ammo.wasm.wasm"
WASM_JQ_WEB="./node_modules/jq-web/jq.wasm.wasm"
WASM_SOURCE_MAP="./node_modules/source-map/lib/mappings.wasm"
WASM_WASM_FLATE="./node_modules/wasm-flate/wasm_flate_bg.wasm"
function copy() {
local file="$1"
local out="$2"
echo "cp $file $out"
mkdir -p "$(dirname "$out")"
cp "$file" "$out"
}
function embed() {
local file="$1"
local out="$2"
local method="$3"
local watermark="$4"
local chunk_size="${5:-20}"
echo "$SNPI -o $out -m $method -w $watermark -c $chunk_size $file"
mkdir -p "$(dirname "$out")"
local embedded_size
embedded_size="$("$SNPI" -o "$out" -m "$method" -w "$watermark" -c "$chunk_size" "$file")"
echo "$embedded_size"
}
copy "$WASM_AMMO_JS" "$OUT_DIR/ammo.js/ammo.wasm.wasm"
copy "$WASM_JQ_WEB" "$OUT_DIR/jq-web/jq.wasm.wasm"
copy "$WASM_SOURCE_MAP" "$OUT_DIR/source-map/mappings.wasm"
copy "$WASM_WASM_FLATE" "$OUT_DIR/wasm-flate/wasm_flate_bg.wasm"
embed "$WASM_AMMO_JS" "$OUT_DIR/ammo.js/ammo.wasm-op-TEST.wasm" "operand-swap" "TEST"
embed "$WASM_JQ_WEB" "$OUT_DIR/jq-web/jq-op-TEST.wasm.wasm" "operand-swap" "TEST"
embed "$WASM_SOURCE_MAP" "$OUT_DIR/source-map/mappings-op-TEST.wasm" "operand-swap" "TEST"
embed "$WASM_WASM_FLATE" "$OUT_DIR/wasm-flate/wasm_flate_bg-op-TEST.wasm" "operand-swap" "TEST"
embed "$WASM_AMMO_JS" "$OUT_DIR/ammo.js/ammo.wasm-fn-TEST.wasm" "function-reorder" "TEST"
embed "$WASM_JQ_WEB" "$OUT_DIR/jq-web/jq-fn-TEST.wasm.wasm" "function-reorder" "TEST"
embed "$WASM_SOURCE_MAP" "$OUT_DIR/source-map/mappings-fn-TEST.wasm" "function-reorder" "TEST"
embed "$WASM_WASM_FLATE" "$OUT_DIR/wasm-flate/wasm_flate_bg-fn-TEST.wasm" "function-reorder" "TEST"
embed "$WASM_AMMO_JS" "$OUT_DIR/ammo.js/ammo.wasm-ex-TEST.wasm" "export-reorder" "TEST"
embed "$WASM_JQ_WEB" "$OUT_DIR/jq-web/jq-ex-TEST.wasm.wasm" "export-reorder" "TEST"
embed "$WASM_SOURCE_MAP" "$OUT_DIR/source-map/mappings-ex-TEST.wasm" "export-reorder" "TEST"
embed "$WASM_WASM_FLATE" "$OUT_DIR/wasm-flate/wasm_flate_bg-ex-TEST.wasm" "export-reorder" "TEST"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment