#resource Region

Planned — design subject to change

This feature is designed but not yet implemented. The syntax and behavior described here represent the target specification.

PlannedThe #resource region is designed but not implemented yet: the region splitter recognizes the marker, but its contents are not processed. This page describes the design.

Purpose

The #resource region declares assets embedded directly into the binary. No runtime file loading needed.

tape
#resource
icon app_icon = "assets/icon.png";
image splash = "assets/splash.png" { max_size: 256; format: rgba; };
font main_font = "assets/Inter-Regular.ttf" { sizes: [12, 14, 16, 18, 24]; };
sound click = "assets/click.wav";
binary shader_data = "shaders/compiled.spv";

Each declaration is kind name = "path" [{ options }];. The path is relative to the .tape file and resolved at compile time: a missing file, a file that isn’t the declared kind, or a repeated name is a compile error.

Resource types

KeywordTypePurposeOptions
iconresource.IconApplication/toolbar iconsnone
imageresource.ImageRaster imagesmax_size, format
fontresource.FontFont filessizes (pre-rasterization)
soundresource.SoundAudio clipssample_rate
binary[]const u8Raw binary datanone

Accessing from #code

tape
#code
fn setup_window() {
    ui.set_icon(app_icon.images);   // its sizes, as gfx.Surfaces
    ui.show_splash(splash);
}

fn play_feedback() {
    audio.play(click);
}

Resources are module-level typed constants, available in #code, #view and #test by name. They don’t allocate at run time: the data lives in the binary’s read-only data.

Font pre-rasterization

tape
font ui_font = "assets/JetBrainsMono.ttf" { sizes: [12, 14, 16]; };

The sizes option pre-rasterizes the font at the specified pixel sizes during compilation. At runtime, rendering is instant — no font parsing needed.

@exeicon — Executable icon

tape
#resource
@exeicon("assets/app.ico")

Sets the application icon for the compiled executable. The path is resolved relative to the source file. This is a compile-time-only directive — it does not create a runtime-accessible resource.

  • Windows: embeds the icon into the PE resource section (.rsrc) with RT_ICON and RT_GROUP_ICON entries, visible in Explorer, taskbar, and Alt+Tab, and on the title bar of every window the program opens (ui, uwm, and gpu and gl, whose windows are uwm ones)
  • Uusi/ELF: stores the icon in a .note.icon ELF section for the desktop shell
  • Only one @exeicon per build target (multiple is a compile error)
  • Supported format: .ico
  • Only valid inside #resource
  • Only applies to tape build — ignored in tape run (VM mode)

This is different from icon resource declarations, which create runtime-accessible constants for UI use (toolbar icons, tray icons, etc.).

@windowed

tape
#resource
@exeicon("assets/sulle.ico")
@windowed(BUILD != Build.Dev)     // `@windowed` alone is `@windowed(true)`

Says the executable is a windowed (GUI) program: on Windows it is built for the GUI subsystem instead of the console one, so starting it opens no console window. The subsystem is a field of the executable’s header, read before any of its code runs, so it is said here with the rest of what the executable says about itself, not decided by a library at run time and not guessed from what the program imports (a headless tool that imports ui wants its console).

  • The argument is a compile-time bool: a literal, a const, a build setting, @target comparisons, and !, &&, ||, ==, != of these. A dev build keeps its console for logs and a release has none, decided in the source.
  • At most one @windowed, in the root file’s #resource region. One in a module the program imports (a library can’t decide how its program is packaged), or a second one, is a compile error.
  • Only tape build of an executable for win64 is windowed: tape run, tape test, tape check, --dll and --sto ignore it, and so do the other targets, which have no such field.
  • There is no command-line flag for it: tape build --windowed is an unknown flag whose message points here.

What a windowed program’s standard streams do, and what Windows’ shells make of one, is in tape build: Windowed programs.

Image format options

tape
image texture = "assets/tile.png" {
    max_size: 512;    // compile error if either dimension is larger
    format: rgba;     // convert to raw RGBA pixels (rgba, rgb or gray)
};

Last modified: