Compile our nim webui app to a single executable
That is a fantastic strategy! Compiling natively on your targeted operating systems is always the cleanest approach. It eliminates cross-compilation errors completely because the compiler can use each system’s native tools directly.By using staticRead, your entire frontend folder gets compiled straight into the binary data section of your app, turning it into a single, self-contained distribution file.Here is the exact step-by-step guide to building your final single distribution files for both Linux and macOS.Step 1: Update Code for Asset EmbeddingFirst, open your src/webui_test.nim file and update the main() block to use staticRead. This tells Nim to pull your HTML and CSS directly into the executable at compile time:nimproc main() = let win = newWindow() win.bind(“handleInput”, handleInput)
Compile-time asset inclusion (relative to the src/ directory)
let htmlTemplate = staticRead("../ui/index.html") let cssContent = staticRead("../ui/style.css")
Merge them into memory just like before
let cleanHtml = htmlTemplate.replace( “”"""", “” )
win.show(cleanHtml) wait()
main() Vær forsiktig når du bruker kodenStep 2: Build for Linux (On your Ubuntu machine)Open your terminal inside your root webui-test folder and run this optimization command:bashnim c -d:release –opt:size –strip src/webui_test.nim Vær forsiktig når du bruker kodenWhat these flags do:-d:release: Turns off all heavy debugging tools and activates full C compiler optimization.–opt:size: Optimizes the final machine code to make the file as tiny as possible.–strip: Strips out hidden symbol tables and debugging hooks from the binary.Your final standalone executable will be sitting right inside your src/ directory. You can copy just that single file anywhere on your Linux system (even without the ui folder present), and it will execute flawlessly.Step 3: Build for macOS (On your i9 Mac)Move your project folder over to your i9 Intel Mac.Install Nim and WebUI dependencies:Open the macOS Terminal and ensure you have Nim installed (usually via choosenim or Homebrew). You will also need your WebUI dependency installed:bashnimble install webui@#head Vær forsiktig når du bruker kodenCompile the macOS single binary:Run the exact same optimization command:bashnim c -d:release –opt:size src/webui_test.nim Vær forsiktig når du bruker koden(Note: The –strip flag is omitted here because macOS uses a different debugging symbol format called dsymutil, so standard GNU strip flags can sometimes cause warnings on macOS).Your single-file executable will be ready inside the src/ directory on your Mac!Pro Tip for macOS DistributionOn macOS, running a raw binary from the terminal works perfectly for development, but for distribution, users expect a standard clickable application. If you ever want to turn that single file into a polished WebUITest.app bundle with its own custom desktop dock icon, let me know and I can show you how to generate the small macOS Info.plist folder structure for it!Are your single-file optimized builds compiling successfully on your Linux side now?