Product Basket

Rust & FLTK

A (mostly) fictional project

The plot

In a nearby an office

How do you convert product IDs to hyperlinks?

In Microsoft Excel, try

=CONCAT("https://example.com/products?id=", A1)

That’s programming! I could never program!

Maybe we could vibe code an app.

Requirements

  • Runs on Microsoft Windows
  • Single file executable
  • Windowed GUI
  • Cut and Paste

Proposed Solution

  • Nix: simple* build environment.
  • Rust: easy LLM coding. (better error messages make for fewer bugs when “vibe” coding.)
  • FLTK: small cross platform GUI library. Statically linkable.

Project Setup

nix flake init

# flake.nix
{
    description = "Product Basket";
    inputs = {
        nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.zst";
    }
    outputs = inputs: {
        packages =
        {
            # Minimalist GNU for Windows (MinGW) configuration
            # to build 
        };

        devShells =
        {
            # local Linux build, for development
        };
    }
}

cargo new basket

basket/
    Cargo.toml
    src/
        main.rs

What about an icon?

Where does an icon live?

  • MS Windows embeds icons into the executable. Great!
  • Linux: a desktop file points to program and icon files.
  • MacOS: the icon is part of the package. (?)

Have Rust embed the icon

crate winresource

A build.rs file runs at compile time.

fn main() {
    // Embed the application icon into the Windows executable.
    if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
        winresource::WindowsResource::new()
            .set_icon("assets/basket.ico")
            .compile()
            .expect("failed to embed Windows icon");
    }
}

Got questions? I do!

Where should icon embedding belong?

MinGW provides a winres utility to embed icons. Why use Rust build time?

Was Nix even needed?

You do need to get MinGW from somewhere. Nix was a convenient spot.

But does Cargo include something to target windows anyways? (Yes and no.)

The ABI rabbit hole

Operating systems expect a certain format for executables.

Linux: Executable and Linking Format (ELF)

Microsoft Windows: Portable Executable (PE)

Application Binary Interface (ABI) actually refers to… the whole set of operating system interfaces? (It seems to in Linux, at least.)

What’s the word on rust build scripts?

Thanks!