liveBook · Manning

Goarch

As explained in Learn Go with Pocket-Sized Projects

GOARCH is the Go build setting that specifies the target processor architecture for compiled code.

GOARCH specifies the target processor architecture for compiled Go code. Setting GOARCH=wasm with GOOS=js builds a WebAssembly binary for browser execution. section 12.1.1

Build a small browser-targeted Go program with these steps:

  • Create a Go module and main.go containing a Hello, WASM! program. section 12.1.1
  • Run GOOS=js GOARCH=wasm go build -o main.wasm; Windows uses set commands before building. section 12.1.1
  • Use go tool dist list to view supported platform combinations. section 12.1.1
  • Load wasm_exec.js and main.wasm from an HTML page to run the binary in a browser. section 12.1.1
> GOOS=js GOARCH=wasm go build -o main.wasm

Shows the primary command for compiling Go code to a browser-targeted WebAssembly binary. section 12.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains environment-variable settings, platform defaults, supported-target discovery, and a complete WebAssembly build path.
Examples
Uses a Hello, WASM! program, main.wasm, HTML, wasm_exec.js, and browser console output.
What it assumes
Assumes basic Go program creation and command-line use while demonstrating module setup and browser integration.
What you can do after
Build it from scratch as a WebAssembly binary and run it through a browser-hosted JavaScript runtime.
How it connects
Connects GOARCH with GOOS, WebAssembly, JavaScript, browsers, and Go's wasm_exec.js support file.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.