Flatpack example for shipping a binary package

Signed-off-by: Mitja Horvat <pinkfluid@gmail.com>
This commit is contained in:
2026-02-04 10:19:00 +01:00
committed by Mitja Horvat
commit ad975fd826
3 changed files with 111 additions and 0 deletions

87
README.md Normal file
View File

@ -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

View File

@ -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

6
hello.c Normal file
View File

@ -0,0 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello from Flatpak binary package!\n");
return 0;
}