Skip to content

feat(fbuild): first-class data/ asset pipeline for UIAudio and future UI assets (with .lnk URL links) #2284

Closed

Description

@zackees

Summary

Promote data/ to a first-class asset folder that fbuild wires into sketches automatically, starting with fl::UIAudio. Today UIAudio already accepts a fl::url(...) (see examples/AudioUrl/AudioUrl.ino, src/fl/ui.h:432), but the URL is hardcoded in the sketch. This proposal moves the asset reference into the project's data/ directory so it becomes a build-time artifact the platform layer can resolve — WASM today, ESP32 LittleFS tomorrow — without changing sketch source.

Motivation

  • Current state: fl::UIAudio audio(\"Audio\", fl::url(\"https://...\")) bakes the URL into the sketch. Swapping assets means recompiling.
  • Desired state: fl::UIAudio audio(\"Audio\", fl::asset(\"data/track.mp3\")) — fbuild resolves the asset at build time based on what's in data/ and the target platform's asset capabilities.
  • Precedent: examples/Fx/FxSdCard/data/ already carries runtime assets. We want the same ergonomics but with transparent URL-or-local resolution and a path to LittleFS on ESP32.

Proposed Asset Model

1. The data/ folder is first-class

  • fbuild scans <sketch>/data/ at build time.
  • Each platform backend declares how it serves assets:
    • WASM: assets become fetchable URLs (virtual filesystem or emitted <script> blob). Existing url JSON field on the audio UI element is reused.
    • ESP32 (future): when CONFIG_LITTLEFS_ENABLE is selected, fbuild packs data/ into a LittleFS partition image and flashes alongside the sketch. The runtime opens /data/track.mp3.
    • Native/stub/host tests: resolved via filesystem relative to the sketch.
  • Sketch code is platform-agnostic: fl::asset(\"data/track.mp3\") returns an opaque handle that UIAudio (and future UIImage, UIVideo, etc.) consume.

2. URL link files — design choice

The user raised two options for "this asset lives at a URL, not on disk":

Option Example Pros Cons
A. Bare file contains URL data/track.mp3 whose contents are literally https://.../song.mp3\n zero-config; drop-in; no new extension magic sniffing required; breaks any tool that opens the file as real MP3 bytes; confuses editors/preview; can't survive a binary byte that happens to match http
B. Suffix marker data/track.mp3.lnk containing the URL explicit; unambiguous to tools and humans; preserves the underlying mime (.mp3) for type detection; easy to grep/list; extensible to multi-line (primary + fallback URLs, checksum, cache hint) one more filename convention to learn
C. Windows .url / .desktop data/track.url (INI-style) established format drops mime info; parser overhead; Windows Explorer auto-resolves and can hide the file

Recommendation: Option B (*.lnk) as the primary mechanism, with Option A reserved as a future opt-in shortcut.

Rationale:

  • .lnk preserves the real extension (track.mp3.lnk) so the asset pipeline still knows it's audio without sniffing content.
  • A build-time scan is trivial: for f in data/**; if f.endswith('.lnk'): read_url(f).
  • Multi-line format leaves room for metadata without breaking v1:
    https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3
    # optional:
    sha256=abc123...
    fallback=https://mirror.example.com/song.mp3
    
  • Tooling (editors, git diff, cat) handles it correctly with no surprises.
  • Forward-compatible: if we later want Option A ("bare file whose content is a URL"), we can add it as a detection pass without invalidating .lnk files.

3. Sketch-side API (proposed)

// URL-backed asset (resolves .lnk at build time, or points to local file on LittleFS-capable platforms)
fl::UIAudio audio(\"Audio\", fl::asset(\"data/track.mp3\"));

// Equivalent explicit forms still work:
fl::UIAudio audio(\"Audio\", fl::url(\"https://...\"));          // existing
fl::UIAudio audio(\"Audio\", fl::asset::local(\"data/track.mp3\")); // forces local/LittleFS
fl::UIAudio audio(\"Audio\", fl::asset::remote(\"data/track.mp3\")); // forces URL (must resolve to .lnk)

fl::asset(path) is a compile-time-friendly handle. At runtime it yields either a fl::url or a filesystem path depending on the platform backend fbuild selected.

Scope of this Issue

In scope (v1):

  • .lnk file format spec (one URL per line, # comments, trailing metadata keys TBD)
  • fl::asset(path) handle type in src/fl/asset.h with compile-time path validation
  • fbuild scan of <sketch>/data/ to build an asset manifest
  • WASM backend: resolve .lnk → fl::url, emit existing url JSON field so UIAudio keeps working with zero changes to the JS side (src/platforms/wasm/compiler/modules/audio/audio_manager.ts)
  • Host/stub backend: resolve local files via filesystem; .lnk falls back to URL via fl::url for tests
  • Migration: examples/AudioUrl/ gets a data/track.mp3.lnk variant alongside the existing inline-URL version

Out of scope (tracked for future issues):

  • ESP32 LittleFS partition generation and flashing from data/
  • ESP32 runtime asset open (/data/track.mp3)
  • Option A (bare-file-with-URL auto-detection)
  • Asset checksums / integrity verification
  • UIImage, UIVideo asset support (same pipeline, different UI element)

Risks / Open Questions

  • Checksum / cache: should v1 of .lnk support sha256= so WASM can cache across reloads? Lean toward yes for the format, no for enforcement.
  • Path security: fl::asset(\"data/../../../etc/passwd\") must be rejected at compile time.
  • Offline WASM: today the browser fetches the URL live. Do we also want fbuild to optionally pre-fetch and inline via data: URL? Defer.
  • ESP32 partition layout: LittleFS requires partition table changes — needs coordination with existing partition presets.

References

  • src/fl/ui.h:428 — class UIAudio (existing URL ctor)
  • examples/AudioUrl/AudioUrl.ino — current URL usage
  • tests/fl/audio_url.cpp — serialization tests for url JSON field
  • src/platforms/shared/ui/json/audio.h — JSON schema for audio UI element
  • examples/Fx/FxSdCard/data/ — existing data/ folder convention

Activity

  1. zackees commented on Apr 19, 2026

    @zackees
    MemberAuthor

    Closing — shipped in ec35801a feat(fbuild): first-class data/ asset pipeline (#2284) via PR #2335.

    Landed:

    • src/fl/asset.h + src/fl/asset.cpp.hpp — runtime asset resolution layer.
    • ci/compiler/asset_scanner.py — build-time asset discovery that wires data/ into sketches.
    • src/fl/stl/url.h with parse_lnk() helper (feat(fl::url): add parse_lnk() for .lnk asset link files (slice 1 of #2284) #2286, merged earlier as bd197af5) — resolves .lnk URL link files from the asset pipeline.
    • examples/AudioUrl/AudioUrl.ino updated to demonstrate the new flow; src/fl/ui.cpp.hpp / src/fl/ui.h integrate UIAudio with the pipeline.

    Reopen if there's a regression or the follow-up work (ESP32 LittleFS backend for the same pipeline) deserves its own tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions