Create and package a starter app§

Install the Roc nightly for 0.1.0 as roc. Use the windows-VERSION-HASH.tar.zst CLI bundle URL from a platform release. Set $env:WINDOWS_TOOL_URL to that URL in PowerShell.

roc $env:WINDOWS_TOOL_URL -- init my-app
Set-Location my-app
roc windows.roc -- package --target x64mingw

The command writes dist/my-app-x64mingw.msi. On Windows x64, open the MSI to install the app. Launch it from the Start menu. Enter a title, select Add, mark the title read, and remove it. During development on Windows, use roc windows.roc -- dev to rebuild and relaunch from the app.

The starter keeps the Roc Signals view in src/, pure decisions in a separate logic/ package, and its image, icon and font in assets/. Edit the view in src/main.roc or change the reading-list rules in logic/ReadingList.roc. Use init --simple my-app for a single-file counter. From a checkout, run roc cli/windows.roc -- init my-app at the repository root to use the local platform.

Choose a Windows build target§

ArgumentApp architecture
--target x64mingwWindows x64
--target arm64mingwWindows ARM64

On macOS and Linux the default target is x64. On Windows it follows the architecture running Roc. Build writes the executable and its assets to build/<target>/. Package writes a Windows MSI or ZIP to dist/. The release includes the Win32 host and its linker inputs, so the consumer build needs Roc. Use ROC_WINDOWS_ROC to select a particular compiler executable if needed.

An MSI packager’s filename identifies the machine running that tool. For example, roc-windows-msi-0.1.0-linux-x64 runs on an x64 Linux machine and can produce either Windows target. The CLI selects the packager automatically and checks its SHA-256 before running it. For a custom platform, use init --platform <platform/main.roc-or-bundle-URL>.

Choose a build profile§

build and package accept --profile dev, --profile size and --profile speed. speed is the default and passes --opt=speed to Roc. size passes --opt=size, and dev uses the Roc dev backend, which builds in about a second but makes a larger, slower executable. test builds its scenario executable with dev unless you pass --profile. With the tested nightly, speed can miscompile List.map over a list of UI elements or signals (roc-lang/roc#13391), so an app that crashes while mounting under speed but not under size has probably hit it. Use --profile size, or build the list with a fold. Every profile strips the linked debug metadata and writes the selected target to build/<target>/. package uses the selected executable in the MSI or ZIP.

roc windows.roc -- build --target arm64mingw
roc windows.roc -- package --profile size

Reload during development§

From the app directory on Windows, start a development session.

roc windows.roc -- dev

The launcher builds with Roc’s --opt=dev backend. Each session has its own temporary directory under build/dev/. It stages the executable, packaged assets, catalog, and manifest settings together, as in a normal build. The target defaults to the architecture running Roc. Use --target to select another Windows architecture when your machine can launch it.

Save your changes and press Ctrl+R in an app window. The launcher closes the app, rebuilds it from disk, and starts a new process. If the build fails, the terminal reports the errors and the launcher restarts the last successful build. The new process opens fresh windows and starts with fresh in-memory signals, session storage, and effects. Local app storage on disk survives. Close the app normally to end the development session.

Reload uses a rebuilt executable so the current assets and manifest settings travel with the new code. To preview a shipping build, run build and launch build/<target>/<app>.exe.

Select native features§

Export native alongside main in the app header. Keep the configuration pure by passing the registration functions themselves to Win.Features.use. For an app that fetches HTTP responses and displays packaged images, use the following configuration.

native = Win.Features.use([Win.Features.http!, Win.Features.image_codecs!])

The platform runs the selected registrations before mounting the UI. Use Win.Features.use([]) for an app that only needs the core Win32 controls. The core includes native accessibility, keyboard input, signals, and app settings. The linker can discard optional implementations when the app omits their registration. Every configuration uses the same platform package and build commands.

RegistrationUse it for
Win.Features.clipboard!Copy buttons that write plain text.
Win.Features.direct3d!Shader views and their image textures. Includes image codecs.
Win.Features.files!Native file and folder pickers, drops, file operations, and folder listings.
Win.Features.grid!Editable data grids with their accessibility provider.
Win.Features.http!Native HTTP requests. Declare allowed origins in windows.json.
Win.Features.image_codecs!PNG, JPEG, and BMP assets and selected file decoding.
Win.Features.taskbar!Progress on the Windows taskbar button.
Win.Features.workers!Background Roc workers declared through with_workers.

To move a project to this platform version, add native to app [main, native] and select the registrations used by the project. Both init templates supply the configuration for their own features.

Check an app§

Run these commands from the directory containing src/main.roc or main.roc.

roc windows.roc -- test --check
roc windows.roc -- fuzz --check

Use test on Windows to execute the app’s behaviour specs. The portable check runs Roc expects and validates spec syntax. The starter has a separate roc-fuzz target in tests/fuzz/main.roc. On Apple Silicon macOS or x64 Linux, fuzz runs a short generated-input campaign, and fuzz --check runs the declared cases once.

See Write behaviour specs for native control actions, effect simulation, and recording.

Open packaged assets§

Images, shaders, command icons, and packaged fonts open their files beneath the installed assets directory. Use a relative name such as images/preview.png. Each directory component resolves through an open parent handle, and the loader uses the resulting file or its bytes. The Windows loader rejects traversal, alternate streams, reserved device names, and reparse points. Use a drive-letter installation path with regular files and directories.

Persist app settings§

Local storage uses the current user’s Windows Local App Data Known Folder and keeps the existing roc-native-windows/<executable-stem>/storage directory and key names. Renaming the executable changes this namespace. Storage opens directories relative to held handles, refuses reparse points and multiply linked entries, and stages replacements in the same directory.

Copy text from an app action§

Use Win.Ui.copy_button(title, { text, on_result }) for a custom Copy command. The native button copies its current text once when the user activates it. The host checks plain text, including Windows line endings, against a 64 KiB UTF-16 limit before touching the clipboard. The result is Copied, Unavailable for a busy clipboard, InvalidText for embedded NUL, or TooLarge. Retrying takes another activation. Native edit Copy, Cut, and Paste continue to follow focus.

Files uses this button for Copy SHA-256. HTTP uses it for Copy request details. An app-authored Clipboard.text request returns NotAllowed. Move its text signal and response handling to the button.

Read time and regional settings§

boot.now_ms and Engine.timer(0) provide signed Unix milliseconds. Engine.interval(milliseconds) uses a monotonic schedule and samples the Windows wall clock on each tick. For elapsed time, request System.monotonic({}) at both ends and call later.elapsed_ms_since(earlier). Marks are meaningful only during the current app process. Equal millisecond marks are valid, and reversing the order returns OutOfOrder.

boot.languages contains the user’s ordered Windows display languages. Use System.regional_settings({}) for the separate formatting locale and optional Windows time-zone key. For local offsets, use boot.zone.offset_at(unix_ms) and handle OutsideZone by requesting a fresh Engine.environment({}) snapshot. The zone table uses minutes east of UTC and has inclusive bounds. Windows zone keys are provided in regional settings. At boot, Windows may supply coverage for only the sample instant when extended rules are unavailable. If that offset cannot be read, boot logs a diagnostic and uses UTC. A failed refresh returns Refused. Use Engine.utc when the app wants an explicit UTC policy.

System.format_timestamps(instants, {}) formats up to 64 timestamps using the local time zone and the Windows short date format by default. Pass { zone: Utc, date: LongDate } to choose both options explicitly. The returned date and time are presentation strings. Keep the original timestamps for storage and comparison. The formatting call returns OutsideRange for an unsupported calendar date, TooLarge for an oversized batch, and Unavailable or Refused if it cannot provide a result. Regional settings and monotonic requests report Unavailable or Refused.

System.secure_random(count) draws up to 65,536 bytes from Windows CNG. Zero returns an empty list. Handle TooLarge, Unavailable, and Refused explicitly. The HTTP example asks for 16 bytes for each request and still offers Copy request details when the reference is unavailable.

These services read the clock, language and format preferences, and OS entropy for the current app. They need no external-resource grant and give the app no ability to change settings or query machine or account identity. Bound checks precede native allocation and are repeated in the host for raw requests. Region and time-zone refreshes run on a worker and only the current effect can deliver a response. Regional facts, timestamps, and bytes stay in the app until it chooses to share them. Clipboard export is a separate user action.

Declare packaged assets§

Keep packaged files under assets/. Put an optional assets.json next to windows.json to give the files your app relies on stable names. Paths are relative to assets/.

{
  "logo": "images/logo.png",
  "title-font": "fonts/CrimsonText-Bold.ttf"
}

Import pf.Win and pass Win.asset("logo") to a control that accepts an asset path. For an image’s signal parameter, use Engine.const(Win.asset("logo")) when the image is fixed. Use the same lookup for a command icon, shader, texture, or font. Existing literal paths still work and remain useful for computed paths.

windows.roc test --check and the build validate the asset tree and every declared path. The build checks the staged files before running Roc and replaces the previous executable only after staging succeeds. The checks cover regular files, Windows-safe path components and supported media headers and size limits. Windows still verifies decoding and font or shader compatibility when loading the asset.

The launcher embeds the name-to-path catalog in the executable. The app opens requested files directly and uses no directory scan at startup. An unknown name or an asset unavailable after installation uses the consuming control’s normal fallback. A name computed by Roc is resolved when the app uses it.

Package an app for distribution§

Set app and MSI metadata in windows.json at the app root, beside windows.roc. The optional display_name supplies the initial window title, the MSI product name and the Start shortcut label. Use a Windows-safe ASCII name of up to 64 bytes. The name defaults to the executable’s basename. The ZIP retains the title through the executable resource. Set icon to a catalog name or an .ico path relative to assets/ to brand the executable on both Windows architectures. A multi-size icon serves the window, Start shortcut and Explorer. The launcher embeds it in the staged executable and uses that executable for both MSI and ZIP. The Reading List scaffold includes an icon you can replace with your own. The starter sets an example ID from the project name. Choose your own stable reverse-DNS ID before publishing, and keep it for upgrades. The version is a three-part MSI product version. The ID, publisher, and asset filenames use ASCII.

{
  "id": "com.example.reading-list",
  "version": "1.0.0",
  "publisher": "Example",
  "display_name": "Reading List",
  "icon": "reading-list.ico"
}
roc windows.roc -- package --target x64mingw
roc windows.roc -- package --target arm64mingw --format zip

Use --id, --app-version, or --publisher to override a field for one build. Projects can omit windows.json for local development defaults. See the embedded Win32 manifest for process settings such as DPI awareness.

The MSI uses roc-<id> for its folder under Program Files and its Start menu group. It adds the app’s named shortcut inside that group. The ZIP contains an executable that can run after extraction. Both carry the executable, assets/, and any top-level LICENSE or THIRD_PARTY_LICENSES.md supplied by the app author.

Grant an HTTP origin§

The app can use HTTP only for exact origins declared in windows.json. Declare the scheme, ASCII DNS name or IPv4 address, and port. An omitted port uses the scheme’s default. An origin grants all paths at that scheme, host and port. Apps without a grant can still use native pickers, clipboard commands, assets and local settings.

{
  "capabilities": {
    "version": 1,
    "http": { "origins": ["https://api.example.com"] }
  }
}

The launcher validates the declaration and embeds it in the app EXE. The host checks requests before starting network work or supplying a scenario response. It follows same-origin redirects with a bounded deadline. A redirect to another granted origin returns the 3xx response so the app can issue a fresh request. An undeclared destination returns the existing Network failure. A Signals proposal describes a distinct policy result.

Choose an example§

ExampleWhat it demonstrates
Reading ListA pure logic package, specs, and fuzz cases
CounterLocal state and a label updated by button actions
TodosTasks, due dates, and notes in a modal dialog
WorkersA stock-count grid with validation and snapshot reconciliation on a Roc worker
FilesFile selection, text and raster previews, contrast adjustment, image comparison and SHA-256
HTTPWinHTTP requests and bounded response previews
AppearanceLight, dark and themed appearances derived from app state, with toggle switches