From 8107f26f1056279286f37db2b6230ebf1bd634a0 Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 31 Dec 2020 19:14:34 -0600 Subject: [PATCH] xxx: Add fallback for safari --- Makefile | 10 ++++++++-- src/browser/starter.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index aac658bd..2ab95c04 100644 --- a/Makefile +++ b/Makefile @@ -65,16 +65,17 @@ CLOSURE_FLAGS=\ --language_in ECMASCRIPT_2017\ --language_out ECMASCRIPT_2017 -CARGO_FLAGS=\ +CARGO_FLAGS_SAFE=\ --target wasm32-unknown-unknown \ -- \ - -C target-feature=+bulk-memory \ -C linker=tools/rust-lld-wrapper \ -C link-args="--import-table --global-base=262144 $(STRIP_DEBUG_FLAG)" \ -C link-args="build/softfloat.o" \ -C link-args="build/zstddeclib.o" \ --verbose +CARGO_FLAGS=$(CARGO_FLAGS_SAFE) -C target-feature=+bulk-memory + CORE_FILES=const.js config.js io.js main.js lib.js ide.js pci.js floppy.js \ memory.js dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js hpet.js \ acpi.js apic.js ioapic.js \ @@ -179,6 +180,11 @@ build/v86-debug.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.t mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm ls -lh build/v86-debug.wasm +build/v86-fallback.wasm: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml + mkdir -p build/ + cargo +nightly rustc --release $(CARGO_FLAGS_SAFE) + mv build/wasm32-unknown-unknown/release/v86.wasm build/v86-fallback.wasm || true + debug-with-profiler: $(RUST_FILES) build/softfloat.o build/zstddeclib.o Cargo.toml mkdir -p build/ cargo +nightly rustc --features profiler $(CARGO_FLAGS) diff --git a/src/browser/starter.js b/src/browser/starter.js index 13dcf6f6..276756e6 100644 --- a/src/browser/starter.js +++ b/src/browser/starter.js @@ -164,6 +164,7 @@ function V86Starter(options) }; let v86_bin = DEBUG ? "v86-debug.wasm" : "v86.wasm"; + let v86_bin_fallback = "v86-fallback.wasm"; if(options["wasm_path"]) { @@ -172,10 +173,12 @@ function V86Starter(options) else if(typeof window === "undefined" && typeof __dirname === "string") { v86_bin = __dirname + "/" + v86_bin; + v86_bin_fallback = __dirname + "/" + v86_bin_fallback; } else { v86_bin = "build/" + v86_bin; + v86_bin_fallback = "build/" + v86_bin_fallback; } v86util.load_file(v86_bin, { @@ -193,6 +196,24 @@ function V86Starter(options) cpu = emulator.cpu; this.continue_init(emulator, options); + }, err => { + v86util.load_file(v86_bin_fallback, { + done: bytes => { + WebAssembly + .instantiate(bytes, { "env": wasm_shared_funcs }) + .then(({ instance }) => { + const imports = wasm_shared_funcs; + const exports = instance["exports"]; + wasm_memory = exports.memory; + exports["rust_init"](); + + const emulator = this.v86 = new v86(this.emulator_bus, { exports, wasm_table }); + cpu = emulator.cpu; + + this.continue_init(emulator, options); + }); + }, + }); }); }, progress: e =>