Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 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 bus.js log.js \
  74. cpu.js debug.js \
  75. elf.js kernel.js
  76. LIB_FILES=9p.js filesystem.js jor1k.js marshall.js utf8.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. 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. build/softfloat.o: lib/softfloat/softfloat.c
  178. mkdir -p build
  179. clang -c -Wall \
  180. --target=wasm32 -O3 -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  181. -DSOFTFLOAT_FAST_INT64 -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32 \
  182. -o build/softfloat.o \
  183. lib/softfloat/softfloat.c
  184. build/zstddeclib.o: lib/zstd/zstddeclib.c
  185. mkdir -p build
  186. clang -c -Wall \
  187. --target=wasm32 -O3 -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  188. -DZSTDLIB_VISIBILITY="" \
  189. -o build/zstddeclib.o \
  190. lib/zstd/zstddeclib.c
  191. clean:
  192. -rm build/libv86.js
  193. -rm build/libv86-debug.js
  194. -rm build/v86_all.js
  195. -rm build/v86.wasm
  196. -rm build/v86-debug.wasm
  197. -rm $(INSTRUCTION_TABLES)
  198. -rm build/*.map
  199. -rm build/*.wast
  200. -rm build/*.o
  201. $(MAKE) -C $(NASM_TEST_DIR) clean
  202. run:
  203. python3 -m http.server 2> /dev/null
  204. update_version:
  205. set -e ;\
  206. COMMIT=`git log --format="%h" -n 1` ;\
  207. DATE=`git log --date="format:%b %e, %Y %H:%m" --format="%cd" -n 1` ;\
  208. SEARCH='<code>Version: <a href="https://github.com/copy/v86/commits/[a-f0-9]\+">[a-f0-9]\+</a> ([^(]\+)</code>' ;\
  209. REPLACE='<code>Version: <a href="https://github.com/copy/v86/commits/'$$COMMIT'">'$$COMMIT'</a> ('$$DATE')</code>' ;\
  210. sed -i "s@$$SEARCH@$$REPLACE@g" index.html ;\
  211. grep $$COMMIT index.html
  212. $(CLOSURE):
  213. mkdir -p $(CLOSURE_DIR)
  214. # don't upgrade until https://github.com/google/closure-compiler/issues/3972 is fixed
  215. wget -nv -O $(CLOSURE) https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20210601/closure-compiler-v20210601.jar
  216. build/integration-test-fs/fs.json:
  217. mkdir -p build/integration-test-fs/flat
  218. cp images/buildroot-bzimage.bin build/integration-test-fs/bzImage
  219. touch build/integration-test-fs/initrd
  220. cd build/integration-test-fs && tar cfv fs.tar bzImage initrd
  221. ./tools/fs2json.py build/integration-test-fs/fs.tar --out build/integration-test-fs/fs.json
  222. ./tools/copy-to-sha256.py build/integration-test-fs/fs.tar build/integration-test-fs/flat
  223. rm build/integration-test-fs/fs.tar build/integration-test-fs/bzImage build/integration-test-fs/initrd
  224. tests: all-debug build/integration-test-fs/fs.json
  225. ./tests/full/run.js
  226. tests-release: build/libv86.js build/v86.wasm build/integration-test-fs/fs.json
  227. TEST_RELEASE_BUILD=1 ./tests/full/run.js
  228. nasmtests: all-debug
  229. $(NASM_TEST_DIR)/create_tests.js
  230. $(NASM_TEST_DIR)/gen_fixtures.js
  231. $(NASM_TEST_DIR)/run.js
  232. nasmtests-force-jit: all-debug
  233. $(NASM_TEST_DIR)/create_tests.js
  234. $(NASM_TEST_DIR)/gen_fixtures.js
  235. $(NASM_TEST_DIR)/run.js --force-jit
  236. jitpagingtests: all-debug
  237. $(MAKE) -C tests/jit-paging test-jit
  238. ./tests/jit-paging/run.js
  239. qemutests: all-debug
  240. $(MAKE) -C tests/qemu test-i386
  241. ./tests/qemu/run.js > build/qemu-test-result
  242. ./tests/qemu/run-qemu.js > build/qemu-test-reference
  243. diff build/qemu-test-result build/qemu-test-reference
  244. qemutests-release: build/libv86.js build/v86.wasm
  245. $(MAKE) -C tests/qemu test-i386
  246. TEST_RELEASE_BUILD=1 time ./tests/qemu/run.js > build/qemu-test-result
  247. ./tests/qemu/run-qemu.js > build/qemu-test-reference
  248. diff build/qemu-test-result build/qemu-test-reference
  249. kvm-unit-test: all-debug
  250. (cd tests/kvm-unit-tests && ./configure && make x86/realmode.flat)
  251. tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  252. kvm-unit-test-release: build/libv86.js build/v86.wasm
  253. (cd tests/kvm-unit-tests && ./configure && make x86/realmode.flat)
  254. TEST_RELEASE_BUILD=1 tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  255. expect-tests: all-debug build/libwabt.js
  256. make -C tests/expect/tests
  257. ./tests/expect/run.js
  258. devices-test: all-debug
  259. ./tests/devices/virtio_9p.js
  260. rust-test: $(RUST_FILES)
  261. env RUSTFLAGS="-D warnings" RUST_BACKTRACE=full RUST_TEST_THREADS=1 cargo test -- --nocapture
  262. ./tests/rust/verify-wasmgen-dummy-output.js
  263. rust-test-intensive:
  264. QUICKCHECK_TESTS=100000000 make rust-test
  265. api-tests: all-debug
  266. ./tests/api/clean-shutdown.js
  267. ./tests/api/state.js
  268. ./tests/api/reset.js
  269. ./tests/api/floppy-insert-eject.js
  270. ./tests/api/serial.js
  271. all-tests: jshint kvm-unit-test qemutests qemutests-release jitpagingtests api-tests nasmtests nasmtests-force-jit tests expect-tests
  272. # Skipping:
  273. # - devices-test (hangs)
  274. jshint:
  275. jshint --config=./.jshint.json src tests gen lib
  276. rustfmt: $(RUST_FILES)
  277. cargo +nightly fmt --all -- --check
  278. build/capstone-x86.min.js:
  279. mkdir -p build
  280. wget -nv -P build https://github.com/AlexAltea/capstone.js/releases/download/v3.0.5-rc1/capstone-x86.min.js
  281. build/libwabt.js:
  282. mkdir -p build
  283. wget -nv -P build https://github.com/WebAssembly/wabt/archive/1.0.6.zip
  284. unzip -j -d build/ build/1.0.6.zip wabt-1.0.6/demo/libwabt.js
  285. rm build/1.0.6.zip
  286. build/xterm.js:
  287. curl https://cdn.jsdelivr.net/npm/xterm@5.2.1/lib/xterm.min.js > build/xterm.js
  288. curl https://cdn.jsdelivr.net/npm/xterm@5.2.1/lib/xterm.js.map > build/xterm.js.map
  289. curl https://cdn.jsdelivr.net/npm/xterm@5.2.1/css/xterm.css > build/xterm.css