1
0

Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 missingProperties\
  46. --jscomp_error missingReturn\
  47. --jscomp_error msgDescriptions\
  48. --jscomp_error nonStandardJsDocs\
  49. --jscomp_error suspiciousCode\
  50. --jscomp_error strictModuleDepCheck\
  51. --jscomp_error typeInvalidation\
  52. --jscomp_error undefinedNames\
  53. --jscomp_error undefinedVars\
  54. --jscomp_error unknownDefines\
  55. --jscomp_error visibility\
  56. --use_types_for_optimization\
  57. --summary_detail_level 3\
  58. --language_in ECMASCRIPT_2017\
  59. --language_out ECMASCRIPT_2017
  60. CARGO_FLAGS_SAFE=\
  61. --target wasm32-unknown-unknown \
  62. -- \
  63. -C linker=tools/rust-lld-wrapper \
  64. -C link-args="--import-table --global-base=262144 $(STRIP_DEBUG_FLAG)" \
  65. -C link-args="build/softfloat.o" \
  66. -C link-args="build/zstddeclib.o" \
  67. --verbose
  68. CARGO_FLAGS=$(CARGO_FLAGS_SAFE) -C target-feature=+bulk-memory
  69. CORE_FILES=const.js config.js io.js main.js lib.js ide.js pci.js floppy.js \
  70. memory.js dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js hpet.js \
  71. acpi.js apic.js ioapic.js \
  72. state.js ne2k.js sb16.js virtio.js bus.js log.js \
  73. cpu.js debug.js \
  74. elf.js kernel.js
  75. LIB_FILES=9p.js filesystem.js jor1k.js marshall.js utf8.js
  76. BROWSER_FILES=screen.js keyboard.js mouse.js speaker.js serial.js \
  77. network.js lib.js starter.js worker_bus.js dummy_screen.js \
  78. print_stats.js filestorage.js
  79. RUST_FILES=$(shell find src/rust/ -name '*.rs') \
  80. src/rust/gen/interpreter.rs src/rust/gen/interpreter0f.rs \
  81. src/rust/gen/jit.rs src/rust/gen/jit0f.rs \
  82. src/rust/gen/analyzer.rs src/rust/gen/analyzer0f.rs
  83. CORE_FILES:=$(addprefix src/,$(CORE_FILES))
  84. LIB_FILES:=$(addprefix lib/,$(LIB_FILES))
  85. BROWSER_FILES:=$(addprefix src/browser/,$(BROWSER_FILES))
  86. build/v86_all.js: $(CLOSURE) src/*.js src/browser/*.js lib/*.js
  87. mkdir -p build
  88. -ls -lh build/v86_all.js
  89. java -jar $(CLOSURE) \
  90. --js_output_file build/v86_all.js\
  91. --define=DEBUG=false\
  92. $(CLOSURE_SOURCE_MAP)\
  93. $(CLOSURE_FLAGS)\
  94. --compilation_level ADVANCED\
  95. --js $(CORE_FILES)\
  96. --js $(LIB_FILES)\
  97. --js $(BROWSER_FILES)\
  98. --js src/browser/main.js
  99. ls -lh build/v86_all.js
  100. build/v86_all_debug.js: $(CLOSURE) src/*.js src/browser/*.js lib/*.js
  101. mkdir -p build
  102. java -jar $(CLOSURE) \
  103. --js_output_file build/v86_all_debug.js\
  104. --define=DEBUG=true\
  105. $(CLOSURE_SOURCE_MAP)\
  106. $(CLOSURE_FLAGS)\
  107. --compilation_level ADVANCED\
  108. --js $(CORE_FILES)\
  109. --js $(LIB_FILES)\
  110. --js $(BROWSER_FILES)\
  111. --js src/browser/main.js
  112. build/libv86.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  113. mkdir -p build
  114. -ls -lh build/libv86.js
  115. java -jar $(CLOSURE) \
  116. --js_output_file build/libv86.js\
  117. --define=DEBUG=false\
  118. $(CLOSURE_FLAGS)\
  119. --compilation_level SIMPLE\
  120. --output_wrapper ';(function(){%output%}).call(this);'\
  121. --js $(CORE_FILES)\
  122. --js $(BROWSER_FILES)\
  123. --js $(LIB_FILES)
  124. ls -lh build/libv86.js
  125. build/libv86-debug.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  126. mkdir -p build
  127. java -jar $(CLOSURE) \
  128. --js_output_file build/libv86-debug.js\
  129. --define=DEBUG=true\
  130. $(CLOSURE_FLAGS)\
  131. $(CLOSURE_READABLE)\
  132. --compilation_level SIMPLE\
  133. --output_wrapper ';(function(){%output%}).call(this);'\
  134. --js $(CORE_FILES)\
  135. --js $(BROWSER_FILES)\
  136. --js $(LIB_FILES)
  137. src/rust/gen/jit.rs: $(JIT_DEPENDENCIES)
  138. ./gen/generate_jit.js --output-dir build/ --table jit
  139. src/rust/gen/jit0f.rs: $(JIT_DEPENDENCIES)
  140. ./gen/generate_jit.js --output-dir build/ --table jit0f
  141. src/rust/gen/interpreter.rs: $(INTERPRETER_DEPENDENCIES)
  142. ./gen/generate_interpreter.js --output-dir build/ --table interpreter
  143. src/rust/gen/interpreter0f.rs: $(INTERPRETER_DEPENDENCIES)
  144. ./gen/generate_interpreter.js --output-dir build/ --table interpreter0f
  145. src/rust/gen/analyzer.rs: $(ANALYZER_DEPENDENCIES)
  146. ./gen/generate_analyzer.js --output-dir build/ --table analyzer
  147. src/rust/gen/analyzer0f.rs: $(ANALYZER_DEPENDENCIES)
  148. ./gen/generate_analyzer.js --output-dir build/ --table analyzer0f
  149. build/v86.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  150. mkdir -p build/
  151. -ls -lh build/v86.wasm
  152. cargo rustc --release $(CARGO_FLAGS)
  153. mv build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm
  154. ls -lh build/v86.wasm
  155. build/v86-debug.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  156. mkdir -p build/
  157. -ls -lh build/v86-debug.wasm
  158. cargo rustc $(CARGO_FLAGS)
  159. mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm
  160. ls -lh build/v86-debug.wasm
  161. build/v86-fallback.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  162. mkdir -p build/
  163. cargo rustc --release $(CARGO_FLAGS_SAFE)
  164. mv build/wasm32-unknown-unknown/release/v86.wasm build/v86-fallback.wasm || true
  165. debug-with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  166. mkdir -p build/
  167. cargo rustc --features profiler $(CARGO_FLAGS)
  168. mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm || true
  169. with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml
  170. mkdir -p build/
  171. cargo rustc --release --features profiler $(CARGO_FLAGS)
  172. mv build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm || true
  173. build/softfloat.o: lib/softfloat/softfloat.c
  174. mkdir -p build
  175. clang -c -Wall \
  176. --target=wasm32 -O3 -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  177. -DSOFTFLOAT_FAST_INT64 -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32 \
  178. -o build/softfloat.o \
  179. lib/softfloat/softfloat.c
  180. build/zstddeclib.o: lib/zstd/zstddeclib.c
  181. mkdir -p build
  182. clang -c -Wall \
  183. --target=wasm32 -O3 -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
  184. -o build/zstddeclib.o \
  185. lib/zstd/zstddeclib.c
  186. clean:
  187. -rm build/libv86.js
  188. -rm build/libv86-debug.js
  189. -rm build/v86_all.js
  190. -rm build/v86.wasm
  191. -rm build/v86-debug.wasm
  192. -rm $(INSTRUCTION_TABLES)
  193. -rm build/*.map
  194. -rm build/*.wast
  195. -rm build/*.o
  196. $(MAKE) -C $(NASM_TEST_DIR) clean
  197. run:
  198. python3 -m http.server 2> /dev/null
  199. update_version:
  200. set -e ;\
  201. COMMIT=`git log --format="%h" -n 1` ;\
  202. DATE=`git log --date="format:%b %e, %Y %H:%m" --format="%cd" -n 1` ;\
  203. SEARCH='<code>Version: <a href="https://github.com/copy/v86/commits/[a-f0-9]\+">[a-f0-9]\+</a> ([^(]\+)</code>' ;\
  204. REPLACE='<code>Version: <a href="https://github.com/copy/v86/commits/'$$COMMIT'">'$$COMMIT'</a> ('$$DATE')</code>' ;\
  205. sed -i "s@$$SEARCH@$$REPLACE@g" index.html ;\
  206. grep $$COMMIT index.html
  207. $(CLOSURE):
  208. mkdir -p $(CLOSURE_DIR)
  209. wget -nv -O $(CLOSURE) https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/v20201207/closure-compiler-v20201207.jar
  210. build/integration-test-fs/fs.json:
  211. mkdir -p build/integration-test-fs/flat
  212. cp images/buildroot-bzimage.bin build/integration-test-fs/bzImage
  213. touch build/integration-test-fs/initrd
  214. cd build/integration-test-fs && tar cfv fs.tar bzImage initrd
  215. ./tools/fs2json.py build/integration-test-fs/fs.tar --out build/integration-test-fs/fs.json
  216. ./tools/copy-to-sha256.py build/integration-test-fs/fs.tar build/integration-test-fs/flat
  217. rm build/integration-test-fs/fs.tar build/integration-test-fs/bzImage build/integration-test-fs/initrd
  218. tests: all-debug build/integration-test-fs/fs.json
  219. ./tests/full/run.js
  220. tests-release: all build/integration-test-fs/fs.json
  221. TEST_RELEASE_BUILD=1 ./tests/full/run.js
  222. nasmtests: all-debug
  223. $(MAKE) -C $(NASM_TEST_DIR) all
  224. $(NASM_TEST_DIR)/gen_fixtures.js
  225. $(NASM_TEST_DIR)/run.js
  226. nasmtests-force-jit: all-debug
  227. $(MAKE) -C $(NASM_TEST_DIR) all
  228. $(NASM_TEST_DIR)/gen_fixtures.js
  229. $(NASM_TEST_DIR)/run.js --force-jit
  230. jitpagingtests: all-debug
  231. $(MAKE) -C tests/jit-paging test-jit
  232. ./tests/jit-paging/run.js
  233. qemutests: all-debug
  234. $(MAKE) -C tests/qemu test-i386
  235. ./tests/qemu/run.js > build/qemu-test-result
  236. ./tests/qemu/run-qemu.js > build/qemu-test-reference
  237. diff build/qemu-test-result build/qemu-test-reference
  238. qemutests-release: all
  239. $(MAKE) -C tests/qemu test-i386
  240. TEST_RELEASE_BUILD=1 time ./tests/qemu/run.js > build/qemu-test-result
  241. ./tests/qemu/run-qemu.js > build/qemu-test-reference
  242. diff build/qemu-test-result build/qemu-test-reference
  243. kvm-unit-test: all-debug
  244. (cd tests/kvm-unit-tests && ./configure && make)
  245. tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  246. kvm-unit-test-release: all
  247. (cd tests/kvm-unit-tests && ./configure && make)
  248. TEST_RELEASE_BUILD=1 tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  249. expect-tests: all-debug build/libwabt.js
  250. make -C tests/expect/tests
  251. ./tests/expect/run.js
  252. devices-test: all-debug
  253. ./tests/devices/virtio_9p.js
  254. rust-test: $(RUST_FILES)
  255. env RUSTFLAGS="-D warnings" RUST_BACKTRACE=full RUST_TEST_THREADS=1 cargo test -- --nocapture
  256. ./tests/rust/verify-wasmgen-dummy-output.js
  257. rust-test-intensive:
  258. QUICKCHECK_TESTS=100000000 make rust-test
  259. api-tests: all-debug
  260. ./tests/api/clean-shutdown.js
  261. ./tests/api/state.js
  262. ./tests/api/reset.js
  263. all-tests: jshint kvm-unit-test qemutests qemutests-release jitpagingtests api-tests nasmtests nasmtests-force-jit tests expect-tests
  264. # Skipping:
  265. # - devices-test (hangs)
  266. jshint:
  267. jshint --config=./.jshint.json src tests gen lib
  268. rustfmt: $(RUST_FILES)
  269. cargo fmt --all -- --check
  270. build/capstone-x86.min.js:
  271. mkdir -p build
  272. wget -nv -P build https://github.com/AlexAltea/capstone.js/releases/download/v3.0.5-rc1/capstone-x86.min.js
  273. build/libwabt.js:
  274. mkdir -p build
  275. wget -nv -P build https://github.com/WebAssembly/wabt/archive/1.0.6.zip
  276. unzip -j -d build/ build/1.0.6.zip wabt-1.0.6/demo/libwabt.js
  277. rm build/1.0.6.zip
  278. build/xterm.js:
  279. curl https://cdn.jsdelivr.net/npm/xterm@4.9.0/lib/xterm.js > build/xterm.js
  280. curl https://cdn.jsdelivr.net/npm/xterm@4.9.0/lib/xterm.js.map > build/xterm.js.map
  281. curl https://cdn.jsdelivr.net/npm/xterm@4.9.0/css/xterm.css > build/xterm.css