From 15cb6802dc2ddedbefc24a6859dfcd4d8bdc5960 Mon Sep 17 00:00:00 2001 From: Mitja Horvat Date: Wed, 4 Feb 2026 10:19:00 +0100 Subject: [PATCH] Flatpack example for shipping a binary package Signed-off-by: Mitja Horvat --- README.md | 87 ++++++++++++++++++++++++++++++++++++++ com.example.HelloWorld.yml | 18 ++++++++ hello.c | 6 +++ 3 files changed, 111 insertions(+) create mode 100644 README.md create mode 100644 com.example.HelloWorld.yml create mode 100644 hello.c diff --git a/README.md b/README.md new file mode 100644 index 0000000..2bb7e85 --- /dev/null +++ b/README.md @@ -0,0 +1,87 @@ +# Binary-Only Flatpak Package Example + +This demonstrates how to create a Flatpak package that distributes only a compiled binary without source code. + +## Project Structure + +- **hello.c** - Source code (kept only for development, not distributed) +- **hello** - Compiled binary (this is what gets distributed) +- **com.example.HelloWorld.yml** - Flatpak manifest + +## Key Points + +The Flatpak manifest uses a pre-compiled binary instead of building from source: + +```yaml +modules: + - name: hello + buildsystem: simple + build-commands: + - install -D hello /app/bin/hello + sources: + - type: file + path: hello # Pre-compiled binary +``` + +This approach: +- Distributes only the compiled binary +- Does not include source code in the package +- Source file (hello.c) is excluded from distribution + +## Build Instructions + +### Option 1: Pre-compiled Binary (com.example.HelloWorld.yml) + +1. Compile the binary locally: + ```bash + gcc -o hello hello.c + ``` + +2. Build and install the Flatpak: + ```bash + flatpak-builder --user --install --force-clean build-dir com.example.HelloWorld.yml + ``` + +### Option 2: Build Inside Flatpak (com.example.HelloWorld-build-inside.yml) + +Build the binary inside the Flatpak sandbox using the SDK: + +```bash +flatpak-builder --user --install --force-clean build-dir com.example.HelloWorld-build-inside.yml +``` + +This compiles `hello.c` using gcc inside the Flatpak environment, then installs only the resulting binary. + +### Run the Application + +```bash +flatpak run com.example.HelloWorld +``` + +## Package for Distribution + +After building, create a single-file bundle for distribution: + +```bash +# Create bundle from user installation +flatpak build-bundle ~/.local/share/flatpak/repo com.example.HelloWorld.flatpak com.example.HelloWorld + +# Or create a custom repo and bundle +flatpak-builder --repo=repo build-dir com.example.HelloWorld.yml +flatpak build-bundle repo com.example.HelloWorld.flatpak com.example.HelloWorld +``` + +The resulting `.flatpak` file contains only the compiled binary and can be distributed to users. + +### Install from Bundle + +Users can install your package: +```bash +flatpak install com.example.HelloWorld.flatpak +``` + +## Notes + +- The source file (hello.c) is never included in the Flatpak package +- Only the compiled binary is distributed +- You can delete hello.c after building if desired diff --git a/com.example.HelloWorld.yml b/com.example.HelloWorld.yml new file mode 100644 index 0000000..f60b80a --- /dev/null +++ b/com.example.HelloWorld.yml @@ -0,0 +1,18 @@ +app-id: com.example.HelloWorld +runtime: org.freedesktop.Platform +runtime-version: '23.08' +sdk: org.freedesktop.Sdk +command: hello +finish-args: + - --share=ipc + - --socket=fallback-x11 + - --socket=wayland +modules: + - name: hello + buildsystem: simple + build-commands: + - gcc -o hello hello.c + - install -D hello /app/bin/hello + sources: + - type: file + path: hello.c diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..ae5bcd9 --- /dev/null +++ b/hello.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello from Flatpak binary package!\n"); + return 0; +}