Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

9 migrate wasm code from golang to rust#10

Open
bbgott wants to merge 7 commits into
mainfrom
9-migrate-wasm-code-from-golang-to-rust
Open

9 migrate wasm code from golang to rust#10
bbgott wants to merge 7 commits into
mainfrom
9-migrate-wasm-code-from-golang-to-rust

Conversation

@bbgott
Copy link
Copy Markdown
Owner

@bbgott bbgott commented Jan 8, 2026

This pull request is a major refactor that transitions the emulator core from Go to Rust, introduces a modular Rust workspace for CPU emulation, and updates the frontend to interact with the new Rust/WASM backend. The Go WASM code and build system are removed, and a new Rust-based WASM interface is integrated with the React frontend. Documentation and configuration files are updated to reflect these architectural changes.

Core architecture migration to Rust/WASM:

  • Added a Rust workspace (rustwasm/Cargo.toml) with modular crates for the emulator core (emucore), i8080 CPU (cpu_i8080), z80 CPU (cpu_z80), and WASM export interface (wasm_export). Each crate includes initial structure and basic register/memory handling. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Removed all Go-related files and build configuration, including Makefile, go.mod, and Go WASM runtime references in index.html. [1] [2] [3]

Frontend integration with Rust/WASM:

  • Updated the React frontend (src/App.jsx) to load and interact with the Rust WASM module via wasm-pack, replacing the previous Go WASM message-passing logic. Added a new message-passing layer for communication with the Rust Emulator instance. [1] [2] [3]
  • Improved terminal component to buffer output until ready, ensuring reliable display of emulator output. [1] [2]

Build and development environment updates:

  • Updated .devcontainer/devcontainer.json to include Rust and install wasm-pack for WASM builds.
  • Modified package.json scripts and dependencies to use wasm-pack for Rust builds, removed Go build steps, and added vite-plugin-wasm-pack for easier WASM integration. [1] [2]

Documentation and project overview:

  • Overhauled README.md to describe the new Rust-based architecture, build steps, and future plans for embedded support. Removed references to Go and updated instructions for building and running the webapp with Rust/WASM.

Encoded references:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21]

bbgott added 7 commits January 8, 2026 18:24
- Updated devcontainer configuration to install wasm-pack.
- Modified .gitignore to exclude Rust target directory.
- Removed Makefile and Go module files as they are no longer needed.
- Updated index.html to remove reference to wasm_exec.js.
- Added vite-plugin-wasm-pack to package.json and package-lock.json.
- Created new Rust project structure with Cargo.toml and Cargo.lock files.
- Implemented Rust CPU emulators (i8080 and z80) and their respective logic.
- Updated WASM export functions to communicate with JavaScript.
- Refactored App.jsx to integrate Rust WASM and handle message passing.
- Cleaned up Terminal component to improve logging and message handling.
- Removed obsolete Go files related to CPU emulation and main logic.
@bbgott bbgott requested a review from Copilot January 8, 2026 22:21
@bbgott bbgott self-assigned this Jan 8, 2026
@bbgott bbgott linked an issue Jan 8, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the emulator core from Go to Rust, establishing a modular Rust workspace architecture for CPU emulation and integrating it with the React frontend via WASM. The Go WASM implementation is completely removed, and the build system is updated to use wasm-pack for Rust/WASM compilation.

Key changes:

  • Introduced a Rust workspace with modular crates for emulator core, i8080/z80 CPU implementations, and WASM exports
  • Replaced Go WASM with Rust WASM bindings using wasm-bindgen
  • Updated frontend to communicate with Rust emulator instance via new message-passing layer

Reviewed changes

Copilot reviewed 21 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wasm/main.go Removed Go WASM implementation including emulator config, CPU interface, and JS message passing
wasm/cpu/z80.go Removed Go z80 CPU implementation
wasm/cpu/i8080.go Removed Go i8080 CPU implementation
rustwasm/Cargo.toml Added Rust workspace manifest defining modular crate structure
rustwasm/emucore/ Added placeholder emulator core crate
rustwasm/cpu_i8080/ Added Rust i8080 CPU implementation with register/memory handling
rustwasm/cpu_z80/ Added Rust z80 CPU implementation with register/memory handling
rustwasm/wasm_export/ Added WASM bindings crate exposing Emulator API to JavaScript
src/App.jsx Replaced Go WASM integration with Rust WASM, updated message passing to use Emulator instance
src/components/Terminal.jsx Added output buffering to handle writes before terminal initialization
package.json Updated build scripts for Rust/WASM, added wasm-pack dependency
vite.config.js Removed Go WASM static copy plugin configuration
index.html Removed Go WASM runtime script reference
.devcontainer/devcontainer.json Replaced Go with Rust toolchain and added wasm-pack installation
README.md Updated documentation to reflect Rust architecture and new build process
Makefile Removed Go build configuration
go.mod Removed Go module definition

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,128 @@

Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the leading blank line at the start of the file for consistency with other Rust files in the project.

Suggested change

Copilot uses AI. Check for mistakes.
pub struct Emulator {
config: EmulatorConfig,
cpu: CpuType,
debug_enabled: bool,
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The debug_enabled field is private but accessed in JavaScript code (line 70 of App.jsx checks emulatorInstance.debug_enabled). This field should be made public or a getter method should be provided to avoid potential issues with WASM bindings.

Copilot uses AI. Check for mistakes.
Comment thread src/App.jsx
case 'memoryWrite': {
const req = JSON.parse(payload);
emulatorInstance.memory_write(req.addr, req.value);
if (emulatorInstance.debug_enabled) {
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing debug_enabled directly on the Rust WASM instance may fail because the field is private in the Rust struct. The Rust implementation should either make this field public with #[wasm_bindgen] annotation or provide a getter method.

Copilot uses AI. Check for mistakes.
Comment thread README.md
### 3. Clean the build output (optional)

```bash
npm run clean
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'clean' script is referenced here but was removed from package.json in this PR. Either restore the clean script or remove this section from the documentation.

Copilot uses AI. Check for mistakes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate WASM code from Golang to Rust with future modular architecture

2 participants