run.sh 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # This file is a simple shell script that runs the bundle split process manually without the CLI involved
  2. # it's not necessarily meant to work on your machine (sorry!)
  3. #
  4. # To hack on harness you need the `wasm-tools` CLI installed
  5. # `cargo binstall wasm-tools`
  6. #
  7. # This script is also sensitive to where it's run from, so you *need* to be in the harness folder (running as `./run.sh`)
  8. TARGET_DIR=../../../target
  9. # build the harness
  10. cargo rustc --package wasm-split-harness --target wasm32-unknown-unknown --profile wasm-split-release -- -Clink-args=--emit-relocs
  11. # for a much smaller compile, you can crank up the flags. However, dioxus relies heavily on location detail, so we can't disable that
  12. #
  13. # -Zlocation-detail=none - we could compile with location detail off but if breaks our signals...
  14. #
  15. # cargo +nightly rustc \
  16. # -Z build-std=std,panic_abort \
  17. # -Z build-std-features="optimize_for_size" \
  18. # -Z build-std-features=panic_immediate_abort \
  19. # --target wasm32-unknown-unknown \
  20. # --no-default-features \
  21. # --profile wasm-split-release \
  22. # -- -Clink-args=--emit-relocs
  23. # Build the wasm-split-cli. We are going to call it directly since it's so noisy to build it multiple times
  24. cargo build --package wasm-split-cli --bin wasm-split-cli
  25. CLI=$TARGET_DIR/debug/wasm-split-cli
  26. # clear the workdir and assemble the new structure
  27. rm -rf data/harness
  28. mkdir -p data/harness/split
  29. mkdir -p data/harness/split_not
  30. # copy the output wasm file to the harness dir
  31. cp $TARGET_DIR/wasm32-unknown-unknown/wasm-split-release/wasm-split-harness.wasm data/harness/input.wasm
  32. # Run wasm-bindgen on this module, without splitting it
  33. wasm-bindgen data/harness/input.wasm --out-dir data/harness/split_not --target web --out-name main --no-demangle --no-typescript --keep-lld-exports --keep-debug
  34. # Run the wasm-split-cli on the with_body.wasm file
  35. ${CLI} split data/harness/input.wasm data/harness/split_not/main_bg.wasm data/harness/chunks
  36. # copy over the chunks
  37. paths=$(ls data/harness/chunks/ | grep "\.wasm")
  38. for path in $paths
  39. do
  40. path_without_ext=${path%.*}
  41. wasm-opt -Oz data/harness/chunks/$path -o data/harness/split/$path --enable-reference-types --memory-packing --debuginfo
  42. # remove stuff like manganis, etc
  43. wasm-tools strip data/harness/split/$path -o data/harness/split/$path
  44. # if you don't want names (making it harder to debug the outputs) use `--all`
  45. # wasm-tools strip data/harness/split/$path -o data/harness/split/$path --all
  46. done
  47. # rename the main chunk
  48. mv data/harness/split/main.wasm data/harness/split/main_bg.wasm
  49. cp data/harness/split_not/main.js data/harness/split/main.js
  50. cp -r data/harness/split_not/snippets data/harness/split/snippets
  51. cp data/harness/chunks/__wasm_split.js data/harness/split/__wasm_split.js
  52. wasm-opt -Oz data/harness/split_not/main_bg.wasm -o data/harness/split_not/main_bg_opt.wasm --enable-reference-types --memory-packing --debuginfo
  53. # Run wasm-strip to strip out the debug symbols
  54. wasm-tools strip data/harness/split_not/main_bg_opt.wasm -o data/harness/split_not/main_bg_opt.wasm
  55. # if you don't want names (making it harder to debug the outputs) use `--all`
  56. # wasm-tools strip data/harness/split/$path -o strip data/harness/split_not/main_bg_opt.wasm --all
  57. echo "===========================================================================\n"
  58. ls -l data/harness/split_not/main_bg_opt.wasm | awk '{ printf("%07d -> ", $5);print $9}'
  59. echo ""
  60. ls -l data/harness/split | grep "\.wasm" | awk '{ printf("%07d -> ", $5);print $9}'
  61. echo "\n==========================================================================="
  62. # hope you have python3 installed :)
  63. python3 -m http.server 9876 --directory data