Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. CLOSURE_DIR=closure-compiler
  2. CLOSURE=$(CLOSURE_DIR)/compiler.jar
  3. NASM_TEST_DIR=./tests/nasm
  4. INSTRUCTION_TABLES=src/rust/gen/jit.rs src/rust/gen/jit0f.rs \
  5. src/rust/gen/interpreter.rs src/rust/gen/interpreter0f.rs \
  6. src/rust/gen/analyzer.rs src/rust/gen/analyzer0f.rs \
  7. # Only the dependencies common to both generate_{jit,interpreter}.js
  8. GEN_DEPENDENCIES=$(filter-out gen/generate_interpreter.js gen/generate_jit.js gen/generate_analyzer.js, $(wildcard gen/*.js))
  9. JIT_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_jit.js
  10. INTERPRETER_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_interpreter.js
  11. ANALYZER_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_analyzer.js
  12. STRIP_DEBUG_FLAG=
  13. ifeq ($(STRIP_DEBUG),true)
  14. STRIP_DEBUG_FLAG=--v86-strip-debug
  15. endif
  16. WASM_OPT ?= false
  17. default: build/v86-debug.wasm
  18. all: build/v86_all.js build/libv86.js build/v86.wasm
  19. all-debug: build/libv86-debug.js build/v86-debug.wasm
  20. browser: build/v86_all.js
  21. # Used for nodejs builds and in order to profile code.
  22. # `debug` gives identifiers a readable name, make sure it doesn't have any side effects.
  23. CLOSURE_READABLE=--formatting PRETTY_PRINT --debug
  24. CLOSURE_SOURCE_MAP=\
  25. --source_map_format V3\
  26. --create_source_map '%outname%.map'
  27. CLOSURE_FLAGS=\
  28. --generate_exports\
  29. --externs src/externs.js\
  30. --warning_level VERBOSE\
  31. --jscomp_error accessControls\
  32. --jscomp_error checkRegExp\
  33. --jscomp_error checkTypes\
  34. --jscomp_error checkVars\
  35. --jscomp_error conformanceViolations\
  36. --jscomp_error const\
  37. --jscomp_error constantProperty\
  38. --jscomp_error deprecated\
  39. --jscomp_error deprecatedAnnotations\
  40. --jscomp_error duplicateMessage\
  41. --jscomp_error es5Strict\
  42. --jscomp_error externsValidation\
  43. --jscomp_error globalThis\
  44. --jscomp_error invalidCasts\
  45. --jscomp_error misplacedTypeAnnotation\
  46. --jscomp_error missingProperties\
  47. --jscomp_error missingReturn\
  48. --jscomp_error msgDescriptions\
  49. --jscomp_error nonStandardJsDocs\
  50. --jscomp_error suspiciousCode\
  51. --jscomp_error strictModuleDepCheck\
  52. --jscomp_error typeInvalidation\
  53. --jscomp_error undefinedVars\
  54. --jscomp_error unknownDefines\
  55. --jscomp_error visibility\
  56. --use_types_for_optimization\
  57. --assume_function_wrapper\
  58. --summary_detail_level 3\
  59. --language_in ECMASCRIPT_2020\
  60. --language_out ECMASCRIPT_2020
  61. CARGO_FLAGS_SAFE=\
  62. --target wasm32-unknown-unknown \
  63. -- \
  64. -C linker=tools/rust-lld-wrapper \
  65. -C link-args="--import-table --global-base=4096 $(STRIP_DEBUG_FLAG)" \
  66. -C link-args="build/softfloat.o" \
  67. -C link-args="build/zstddeclib.o" \
  68. --verbose
  69. CARGO_FLAGS=$(CARGO_FLAGS_SAFE) -C target-feature=+bulk-memory -C target-feature=+multivalue -C target-feature=+simd128
  70. CORE_FILES=const.js config.js io.js main.js lib.js buffer.js ide.js pci.js floppy.js \
  71. memory.js dma.js pit.js vga.js vga_text.js ps2.js rtc.js uart.js \
  72. acpi.js apic.js ioapic.js \
  73. state.js ne2k.js sb16.js virtio.js virtio_console.js virtio_net.js \
  74. bus.js log.js cpu.js debug.js \
  75. elf.js kernel.js
  76. LIB_FILES=9p.js filesystem.js jor1k.js marshall.js
  77. BROWSER_FILES=screen.js keyboard.js mouse.js speaker.js serial.js \
  78. network.js starter.js worker_bus.js dummy_screen.js \
  79. fake_network.js wisp_network.js fetch_network.js print_stats.js filestorage.js
  80. RUST_FILES=$(shell find src/rust/ -name '*.rs') \
  81. src/rust/gen/interpreter.rs src/rust/gen/interpreter0f.rs \
  82. src/rust/gen/jit.rs src/rust/gen/jit0f.rs \
  83. src/rust/gen/analyzer.rs src/rust/gen/analyzer0f.rs
  84. CORE_FILES:=$(addprefix src/,$(CORE_FILES))
  85. LIB_FILES:=$(addprefix lib/,$(LIB_FILES))
  86. BROWSER_FILES:=$(addprefix src/browser/,$(BROWSER_FILES))
  87. build/v86_all.js: $(CLOSURE) src/*.js src/browser/*.js lib/*.js
  88. mkdir -p build
  89. -ls -lh build/v86_all.js
  90. java -jar $(CLOSURE) \
  91. --js_output_file build/v86_all.js\
  92. --define=DEBUG=false\
  93. $(CLOSURE_SOURCE_MAP)\
  94. $(CLOSURE_FLAGS)\
  95. --compilation_level ADVANCED\
  96. --js $(CORE_FILES)\
  97. --js $(LIB_FILES)\
  98. --js $(BROWSER_FILES)\
  99. --js src/browser/main.js
  100. ls -lh build/v86_all.js
  101. build/v86_all_debug.js: $(CLOSURE) src/*.js src/browser/*.js lib/*.js
  102. mkdir -p build
  103. java -jar $(CLOSURE) \
  104. --js_output_file build/v86_all_debug.js\
  105. --define=DEBUG=true\
  106. $(CLOSURE_SOURCE_MAP)\
  107. $(CLOSURE_FLAGS)\
  108. --compilation_level ADVANCED\
  109. --js $(CORE_FILES)\
  110. --js $(LIB_FILES)\
  111. --js $(BROWSER_FILES)\
  112. --js src/browser/main.js
  113. build/libv86.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  114. mkdir -p build
  115. -ls -lh build/libv86.js
  116. java -jar $(CLOSURE) \
  117. --js_output_file build/libv86.js\
  118. --define=DEBUG=false\
  119. $(CLOSURE_FLAGS)\
  120. --compilation_level SIMPLE\
  121. --jscomp_off=missingProperties\
  122. --output_wrapper ';(function(){%output%}).call(this);'\
  123. --js $(CORE_FILES)\
  124. --js $(BROWSER_FILES)\
  125. --js $(LIB_FILES)
  126. ls -lh build/libv86.js
  127. build/libv86-debug.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  128. mkdir -p build
  129. java -jar $(CLOSURE) \
  130. --js_output_file build/libv86-debug.js\
  131. --define=DEBUG=true\
  132. $(CLOSURE_FLAGS)\
  133. $(CLOSURE_READABLE)\
  134. --compilation_level SIMPLE\
  135. --jscomp_off=missingProperties\
  136. --output_wrapper ';(function(){%output%}).call(this);'\
  137. --js $(CORE_FILES)\
  138. --js $(BROWSER_FILES)\
  139. --js $(LIB_FILES)
  140. src/rust/gen/jit.rs: $(JIT_DEPENDENCIES)
  141. ./gen/generate_jit.js --output-dir build/ --table jit
  142. src/rust/gen/jit0f.rs: $(JIT_DEPENDENCIES)
  143. ./gen/generate_jit.js --output-dir build/ --table jit0f
  144. src/rust/gen/interpreter.rs: $(INTERPRETER_DEPENDENCIES)
  145. ./gen/generate_interpreter.js --output-dir build/ --table interpreter
  146. src/rust/gen/interpreter0f.rs: $(INTERPRETER_DEPENDENCIES)
  147. ./gen/generate_interpreter.js --output-dir build/ --table interpreter0f
  148. src/rust/gen/analyzer.rs: $(ANALYZER_DEPENDENCIES)
  149. ./gen/generate_analyzer.js --output-dir build/ --table analyzer
  150. src/rust/gen/analyzer0f.rs: $(ANALYZER_DEPENDENCIES)
  151. ./gen/generate_analyzer.js --output-dir build/ --table analyzer0f
  152. build/v86.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  153. mkdir -p build/
  154. -BLOCK_SIZE=K ls -l build/v86.wasm
  155. cargo rustc --release $(CARGO_FLAGS)
  156. cp build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm
  157. -$(WASM_OPT) && wasm-opt -O2 --strip-debug build/v86.wasm -o build/v86.wasm
  158. BLOCK_SIZE=K ls -l build/v86.wasm
  159. build/v86-debug.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  160. mkdir -p build/
  161. -BLOCK_SIZE=K ls -l build/v86-debug.wasm
  162. cargo rustc $(CARGO_FLAGS)
  163. cp build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm
  164. BLOCK_SIZE=K ls -l build/v86-debug.wasm
  165. build/v86-fallback.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  166. mkdir -p build/
  167. cargo rustc --release $(CARGO_FLAGS_SAFE)
  168. cp build/wasm32-unknown-unknown/release/v86.wasm build/v86-fallback.wasm || true
  169. debug-with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  170. mkdir -p build/
  171. cargo rustc --features profiler $(CARGO_FLAGS)
  172. cp build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm || true
  173. with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  174. mkdir -p build/
  175. cargo rustc --release --features profiler $(CARGO_FLAGS)
  176. cp build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm || true
  177. watch:
  178. cargo watch -x 'rustc $(CARGO_FLAGS)' -s 'cp build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm'
  179. build/softfloat.o: lib/softfloat/softfloat.c
  180. mkdir -p build
  181. clang -c -Wall \
  182. --target=wasm32 -O3 -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  183. -DSOFTFLOAT_FAST_INT64 -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32 \
  184. -o build/softfloat.o \
  185. lib/softfloat/softfloat.c
  186. build/zstddeclib.o: lib/zstd/zstddeclib.c
  187. mkdir -p build
  188. clang -c -Wall \
  189. --target=wasm32 -O3 -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  190. -DZSTDLIB_VISIBILITY="" \
  191. -o build/zstddeclib.o \
  192. lib/zstd/zstddeclib.c
  193. clean:
  194. -rm build/libv86.js
  195. -rm build/libv86-debug.js
  196. -rm build/v86_all.js
  197. -rm build/v86.wasm
  198. -rm build/v86-debug.wasm
  199. -rm $(INSTRUCTION_TABLES)
  200. -rm build/*.map
  201. -rm build/*.wast
  202. -rm build/*.o
  203. $(MAKE) -C $(NASM_TEST_DIR) clean
  204. run:
  205. python3 -m http.server 2> /dev/null
  206. update_version:
  207. set -e ;\
  208. COMMIT=`git log --format="%h" -n 1` ;\
  209. DATE=`git log --date="format:%b %e, %Y %H:%m" --format="%cd" -n 1` ;\
  210. SEARCH='<code>Version: <a href="https://github.com/copy/v86/commits/[a-f0-9]\+">[a-f0-9]\+</a> ([^(]\+)</code>' ;\
  211. REPLACE='<code>Version: <a href="https://github.com/copy/v86/commits/'$$COMMIT'">'$$COMMIT'</a> ('$$DATE')</code>' ;\
  212. sed -i "s@$$SEARCH@$$REPLACE@g" index.html ;\
  213. grep $$COMMIT index.html
  214. $(CLOSURE):
  215. mkdir -p $(CLOSURE_DIR)
  216. # don't upgrade until https://github.com/google/closure-compiler/issues/3972 is fixed
  217. wget -nv -O $(CLOSURE) https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20210601/closure-compiler-v20210601.jar
  218. build/integration-test-fs/fs.json: images/buildroot-bzimage68.bin
  219. mkdir -p build/integration-test-fs/flat
  220. cp images/buildroot-bzimage68.bin build/integration-test-fs/bzImage
  221. touch build/integration-test-fs/initrd
  222. cd build/integration-test-fs && tar cfv fs.tar bzImage initrd
  223. ./tools/fs2json.py build/integration-test-fs/fs.tar --out build/integration-test-fs/fs.json
  224. ./tools/copy-to-sha256.py build/integration-test-fs/fs.tar build/integration-test-fs/flat
  225. rm build/integration-test-fs/fs.tar build/integration-test-fs/bzImage build/integration-test-fs/initrd
  226. tests: all-debug build/integration-test-fs/fs.json
  227. ./tests/full/run.js
  228. tests-release: build/libv86.js build/v86.wasm build/integration-test-fs/fs.json
  229. TEST_RELEASE_BUILD=1 ./tests/full/run.js
  230. nasmtests: all-debug
  231. $(NASM_TEST_DIR)/create_tests.js
  232. $(NASM_TEST_DIR)/gen_fixtures.js
  233. $(NASM_TEST_DIR)/run.js
  234. nasmtests-force-jit: all-debug
  235. $(NASM_TEST_DIR)/create_tests.js
  236. $(NASM_TEST_DIR)/gen_fixtures.js
  237. $(NASM_TEST_DIR)/run.js --force-jit
  238. jitpagingtests: all-debug
  239. $(MAKE) -C tests/jit-paging test-jit
  240. ./tests/jit-paging/run.js
  241. qemutests: all-debug
  242. $(MAKE) -C tests/qemu test-i386
  243. ./tests/qemu/run.js > build/qemu-test-result
  244. ./tests/qemu/run-qemu.js > build/qemu-test-reference
  245. diff build/qemu-test-result build/qemu-test-reference
  246. qemutests-release: build/libv86.js build/v86.wasm
  247. $(MAKE) -C tests/qemu test-i386
  248. TEST_RELEASE_BUILD=1 time ./tests/qemu/run.js > build/qemu-test-result
  249. ./tests/qemu/run-qemu.js > build/qemu-test-reference
  250. diff build/qemu-test-result build/qemu-test-reference
  251. kvm-unit-test: all-debug
  252. (cd tests/kvm-unit-tests && ./configure && make x86/realmode.flat)
  253. tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  254. kvm-unit-test-release: build/libv86.js build/v86.wasm
  255. (cd tests/kvm-unit-tests && ./configure && make x86/realmode.flat)
  256. TEST_RELEASE_BUILD=1 tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  257. expect-tests: all-debug build/libwabt.js
  258. make -C tests/expect/tests
  259. ./tests/expect/run.js
  260. devices-test: all-debug
  261. ./tests/devices/virtio_9p.js
  262. ./tests/devices/virtio_console.js
  263. ./tests/devices/fetch_network.js
  264. USE_VIRTIO=1 ./tests/devices/fetch_network.js
  265. ./tests/devices/wisp_network.js
  266. rust-test: $(RUST_FILES)
  267. env RUSTFLAGS="-D warnings" RUST_BACKTRACE=full RUST_TEST_THREADS=1 cargo test -- --nocapture
  268. ./tests/rust/verify-wasmgen-dummy-output.js
  269. rust-test-intensive:
  270. QUICKCHECK_TESTS=100000000 make rust-test
  271. api-tests: all-debug
  272. ./tests/api/clean-shutdown.js
  273. ./tests/api/state.js
  274. ./tests/api/reset.js
  275. ./tests/api/floppy-insert-eject.js
  276. ./tests/api/serial.js
  277. ./tests/api/reboot.js
  278. all-tests: eslint kvm-unit-test qemutests qemutests-release jitpagingtests api-tests nasmtests nasmtests-force-jit tests expect-tests
  279. # Skipping:
  280. # - devices-test (hangs)
  281. eslint:
  282. eslint src tests gen lib examples tools
  283. rustfmt: $(RUST_FILES)
  284. cargo fmt --all -- --check --config fn_single_line=true,control_brace_style=ClosingNextLine
  285. build/capstone-x86.min.js:
  286. mkdir -p build
  287. wget -nv -P build https://github.com/AlexAltea/capstone.js/releases/download/v3.0.5-rc1/capstone-x86.min.js
  288. build/libwabt.js:
  289. mkdir -p build
  290. wget -nv -P build https://github.com/WebAssembly/wabt/archive/1.0.6.zip
  291. unzip -j -d build/ build/1.0.6.zip wabt-1.0.6/demo/libwabt.js
  292. rm build/1.0.6.zip
  293. build/xterm.js:
  294. curl https://cdn.jsdelivr.net/npm/xterm@5.2.1/lib/xterm.min.js > build/xterm.js
  295. curl https://cdn.jsdelivr.net/npm/xterm@5.2.1/lib/xterm.js.map > build/xterm.js.map
  296. curl https://cdn.jsdelivr.net/npm/xterm@5.2.1/css/xterm.css > build/xterm.css