Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. default: build/v86-debug.wasm
  17. all: build/v86_all.js build/libv86.js build/v86.wasm
  18. all-debug: build/libv86-debug.js build/v86-debug.wasm
  19. browser: build/v86_all.js
  20. # Used for nodejs builds and in order to profile code.
  21. # `debug` gives identifiers a readable name, make sure it doesn't have any side effects.
  22. CLOSURE_READABLE=--formatting PRETTY_PRINT --debug
  23. CLOSURE_SOURCE_MAP=\
  24. --source_map_format V3\
  25. --create_source_map '%outname%.map'
  26. CLOSURE_FLAGS=\
  27. --generate_exports\
  28. --externs src/externs.js\
  29. --warning_level VERBOSE\
  30. --jscomp_error accessControls\
  31. --jscomp_error checkRegExp\
  32. --jscomp_error checkTypes\
  33. --jscomp_error checkVars\
  34. --jscomp_error conformanceViolations\
  35. --jscomp_error const\
  36. --jscomp_error constantProperty\
  37. --jscomp_error deprecated\
  38. --jscomp_error deprecatedAnnotations\
  39. --jscomp_error duplicateMessage\
  40. --jscomp_error es5Strict\
  41. --jscomp_error externsValidation\
  42. --jscomp_error globalThis\
  43. --jscomp_error invalidCasts\
  44. --jscomp_error misplacedTypeAnnotation\
  45. --jscomp_error missingGetCssName\
  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 undefinedNames\
  54. --jscomp_error undefinedVars\
  55. --jscomp_error unknownDefines\
  56. --jscomp_error visibility\
  57. --use_types_for_optimization\
  58. --summary_detail_level 3\
  59. --language_in ECMASCRIPT_2017\
  60. --language_out ECMASCRIPT_2017
  61. CARGO_FLAGS=\
  62. --target wasm32-unknown-unknown \
  63. -- \
  64. -C target-feature=+bulk-memory \
  65. -C linker=tools/rust-lld-wrapper \
  66. -C link-args="--import-table --global-base=262144 $(STRIP_DEBUG_FLAG)" \
  67. -C link-args="build/softfloat.o" \
  68. -C link-args="build/zstddeclib.o" \
  69. --verbose
  70. CORE_FILES=const.js config.js io.js main.js lib.js ide.js pci.js floppy.js \
  71. memory.js dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js hpet.js \
  72. acpi.js apic.js ioapic.js \
  73. state.js ne2k.js virtio.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 serial.js \
  78. network.js lib.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. echo '//# sourceMappingURL=v86_all.js.map' >> build/v86_all.js
  101. ls -lh build/v86_all.js
  102. build/libv86.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  103. mkdir -p build
  104. -ls -lh build/libv86.js
  105. java -jar $(CLOSURE) \
  106. --js_output_file build/libv86.js\
  107. --define=DEBUG=false\
  108. $(CLOSURE_FLAGS)\
  109. --compilation_level SIMPLE\
  110. --output_wrapper ';(function(){%output%}).call(this);'\
  111. --js $(CORE_FILES)\
  112. --js $(BROWSER_FILES)\
  113. --js $(LIB_FILES)
  114. ls -lh build/libv86.js
  115. build/libv86-debug.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  116. mkdir -p build
  117. java -jar $(CLOSURE) \
  118. --js_output_file build/libv86-debug.js\
  119. --define=DEBUG=true\
  120. $(CLOSURE_FLAGS)\
  121. $(CLOSURE_READABLE)\
  122. --compilation_level SIMPLE\
  123. --output_wrapper ';(function(){%output%}).call(this);'\
  124. --js $(CORE_FILES)\
  125. --js $(BROWSER_FILES)\
  126. --js $(LIB_FILES)
  127. src/rust/gen/jit.rs: $(JIT_DEPENDENCIES)
  128. ./gen/generate_jit.js --output-dir build/ --table jit
  129. src/rust/gen/jit0f.rs: $(JIT_DEPENDENCIES)
  130. ./gen/generate_jit.js --output-dir build/ --table jit0f
  131. src/rust/gen/interpreter.rs: $(INTERPRETER_DEPENDENCIES)
  132. ./gen/generate_interpreter.js --output-dir build/ --table interpreter
  133. src/rust/gen/interpreter0f.rs: $(INTERPRETER_DEPENDENCIES)
  134. ./gen/generate_interpreter.js --output-dir build/ --table interpreter0f
  135. src/rust/gen/analyzer.rs: $(ANALYZER_DEPENDENCIES)
  136. ./gen/generate_analyzer.js --output-dir build/ --table analyzer
  137. src/rust/gen/analyzer0f.rs: $(ANALYZER_DEPENDENCIES)
  138. ./gen/generate_analyzer.js --output-dir build/ --table analyzer0f
  139. build/v86.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  140. mkdir -p build/
  141. -ls -lh build/v86.wasm
  142. cargo +nightly rustc --release $(CARGO_FLAGS)
  143. mv build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm
  144. ls -lh build/v86.wasm
  145. build/v86-debug.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  146. mkdir -p build/
  147. -ls -lh build/v86-debug.wasm
  148. cargo +nightly rustc $(CARGO_FLAGS)
  149. mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm
  150. ls -lh build/v86-debug.wasm
  151. debug-with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  152. mkdir -p build/
  153. cargo +nightly rustc --features profiler $(CARGO_FLAGS)
  154. mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm || true
  155. with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  156. mkdir -p build/
  157. cargo +nightly rustc --release --features profiler $(CARGO_FLAGS)
  158. mv build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm || true
  159. build/softfloat.o: lib/softfloat/softfloat.c
  160. clang -c -Wall \
  161. --target=wasm32 -Os -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  162. -DSOFTFLOAT_FAST_INT64 -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32 \
  163. -o build/softfloat.o \
  164. lib/softfloat/softfloat.c
  165. build/zstddeclib.o: lib/zstd/zstddeclib.c
  166. clang -c -Wall \
  167. --target=wasm32 -Os -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  168. -I /usr/include \
  169. -o build/zstddeclib.o \
  170. lib/zstd/zstddeclib.c
  171. clean:
  172. -rm build/libv86.js
  173. -rm build/libv86-debug.js
  174. -rm build/v86_all.js
  175. -rm build/v86.wasm
  176. -rm build/v86-debug.wasm
  177. -rm $(INSTRUCTION_TABLES)
  178. -rm build/*.map
  179. -rm build/*.wast
  180. -rm build/*.o
  181. $(MAKE) -C $(NASM_TEST_DIR) clean
  182. run:
  183. python3 -m http.server 2> /dev/null
  184. update_version:
  185. set -e ;\
  186. COMMIT=`git log --format="%h" -n 1` ;\
  187. DATE=`git log --date="format:%b %e, %Y %H:%m" --format="%cd" -n 1` ;\
  188. SEARCH='<code>Version: <a href="https://github.com/copy/v86/commits/[a-f0-9]\+">[a-f0-9]\+</a> ([^(]\+)</code>' ;\
  189. REPLACE='<code>Version: <a href="https://github.com/copy/v86/commits/'$$COMMIT'">'$$COMMIT'</a> ('$$DATE')</code>' ;\
  190. sed -i "s@$$SEARCH@$$REPLACE@g" index.html ;\
  191. grep $$COMMIT index.html
  192. $(CLOSURE):
  193. wget -nv -P $(CLOSURE_DIR) http://dl.google.com/closure-compiler/compiler-latest.zip
  194. unzip -d closure-compiler $(CLOSURE_DIR)/compiler-latest.zip \*.jar
  195. mv $(CLOSURE_DIR)/*.jar $(CLOSURE)
  196. rm $(CLOSURE_DIR)/compiler-latest.zip
  197. build/integration-test-fs/fs.json:
  198. mkdir -p build/integration-test-fs/flat
  199. cp images/bzImage build/integration-test-fs/
  200. touch build/integration-test-fs/initrd
  201. cd build/integration-test-fs && tar cfv fs.tar bzImage initrd
  202. ./tools/fs2json.py build/integration-test-fs/fs.tar --out build/integration-test-fs/fs.json
  203. ./tools/copy-to-sha256.py build/integration-test-fs/fs.tar build/integration-test-fs/flat
  204. rm build/integration-test-fs/fs.tar build/integration-test-fs/bzImage build/integration-test-fs/initrd
  205. tests: all-debug build/integration-test-fs/fs.json
  206. ./tests/full/run.js
  207. tests-release: all build/integration-test-fs/fs.json
  208. TEST_RELEASE_BUILD=1 ./tests/full/run.js
  209. nasmtests: all-debug
  210. $(MAKE) -C $(NASM_TEST_DIR) all
  211. $(NASM_TEST_DIR)/gen_fixtures.js
  212. $(NASM_TEST_DIR)/run.js
  213. nasmtests-force-jit: all-debug
  214. $(MAKE) -C $(NASM_TEST_DIR) all
  215. $(NASM_TEST_DIR)/gen_fixtures.js
  216. $(NASM_TEST_DIR)/run.js --force-jit
  217. jitpagingtests: all-debug
  218. $(MAKE) -C tests/jit-paging test-jit
  219. ./tests/jit-paging/run.js
  220. qemutests: all-debug
  221. $(MAKE) -C tests/qemu test-i386
  222. ./tests/qemu/run.js > /tmp/v86-test-result
  223. ./tests/qemu/run-qemu.js > /tmp/v86-test-reference
  224. diff /tmp/v86-test-result /tmp/v86-test-reference
  225. qemutests-release: all
  226. $(MAKE) -C tests/qemu test-i386
  227. time TEST_RELEASE_BUILD=1 ./tests/qemu/run.js > /tmp/v86-test-result
  228. ./tests/qemu/run-qemu.js > /tmp/v86-test-reference
  229. diff /tmp/v86-test-result /tmp/v86-test-reference
  230. kvm-unit-test: all-debug
  231. (cd tests/kvm-unit-tests && ./configure && make)
  232. tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  233. kvm-unit-test-release: all
  234. (cd tests/kvm-unit-tests && ./configure && make)
  235. TEST_RELEASE_BUILD=1 tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  236. expect-tests: all-debug build/libwabt.js
  237. make -C tests/expect/tests
  238. ./tests/expect/run.js
  239. devices-test: all-debug
  240. ./tests/devices/virtio_9p.js
  241. rust-test: $(RUST_FILES)
  242. # RUSTFLAGS="-D warnings"
  243. env RUST_BACKTRACE=full RUST_TEST_THREADS=1 cargo +nightly test -- --nocapture
  244. ./tests/rust/verify-wasmgen-dummy-output.js
  245. rust-no-warnings:
  246. RUSTFLAGS="-D warnings" make all all-debug
  247. rust-test-intensive:
  248. QUICKCHECK_TESTS=100000000 make rust-test
  249. api-tests: all-debug
  250. ./tests/api/clean-shutdown.js
  251. ./tests/api/state.js
  252. ./tests/api/reset.js
  253. all-tests: jshint kvm-unit-test qemutests qemutests-release jitpagingtests api-tests nasmtests nasmtests-force-jit tests expect-tests
  254. # Skipping:
  255. # - devices-test (hangs)
  256. jshint:
  257. jshint --config=./.jshint.json src tests gen lib --exclude lib/closure-base.js
  258. rustfmt: $(RUST_FILES)
  259. cargo +nightly fmt --all -- --check
  260. build/capstone-x86.min.js:
  261. mkdir -p build
  262. wget -P build https://github.com/AlexAltea/capstone.js/releases/download/v3.0.5-rc1/capstone-x86.min.js
  263. build/libwabt.js:
  264. mkdir -p build
  265. wget -P build https://github.com/WebAssembly/wabt/archive/1.0.6.zip
  266. unzip -j -d build/ build/1.0.6.zip wabt-1.0.6/demo/libwabt.js
  267. rm build/1.0.6.zip
  268. build/xterm.js:
  269. curl https://cdn.jsdelivr.net/npm/xterm@4.2.0-vscode1/lib/xterm.js > build/xterm.js
  270. curl https://cdn.jsdelivr.net/npm/xterm@4.2.0-vscode1/lib/xterm.js.map > build/xterm.js.map
  271. curl https://cdn.jsdelivr.net/npm/xterm@4.2.0-vscode1/css/xterm.css > build/xterm.css