Building my first flatpak

As a test, I am trying to build a flatpak for a small wxWidgets test program built with C++ under Codelite - under Mint 21.1 Cinnamon
The app is called wxmt.

Being very new to this, I am totally in the dark as to what my manifest ought to contain and what, if anything in the way of existing support libraries from my build system, I can use.
Or whether I need to rebuild all support libraries from scratch.

FWIW, my wxWidgets app is built with the current 3.2.2 release code, with all libraries linked statically.

My dir tree
…appBase\menutest\build-debug\bin\wxmt ---- compiled app
\flatpak\ wxmt <--------+ copied manually for testing
| org.flatpak.wxmt.yml

My basic manifest at this point looks like

---
app-id: org.flatpak.wxmt
runtime: org.freedesktop.Platform
runtime-version: '22.08'
sdk: org.freedesktop.Sdk
command: wxmt
modules:
  - name: wxmt
    buildsystem: simple
    build-commands:
      - install -D wxmt /app/bin/wxmt
    sources:
      - type: file
        path: wxmt

Running
flatpak-builder --user --install --force-clean build-dir org.flatpak.wxmt.yml
produces no errors and completes, but running
flatpak run org.flatpak.wxmt
produces, not unexpectedly:

flatpak run org.flatpak.wxmt
wxmt: error while loading shared libraries: libwx_gtk3u_unofficial_xrc-3.2.so.0: cannot open shared object file: No such file or directory

The library which it cannot find is present on my system because when I run the app on its own, it runs and displays the expected GUI.
My questions are:

  • How can I specify the necessary dependencies in my manifest?
  • Can I use existing libraries and use copies ?
  • If I can’t use the existing libraries, what step do I need to execute and how can I describe these in the manifest.

I have searched the flatpak documentation, but have not found anything to get me going in the right direction.
TIA

2 Likes

A Flatpak application is isolated from the host system, you can’t use libraries from your system. You should build them with your manifest to bundle them with your application.

Check out the documentation for more information: Dependencies & Manifests.

My apologies, I was not clear enough in my question.
I understand that I cannot use files & libraries from my build system.
My intent was to copy those existing libraries so that the flatpak builder could use them, rather than to recreate them just for the builder.

If possible, you should still build the dependencies & the application in your manifest. Your build host & the Flatpak runtime are not necessary compatible.

You can try to find existing modules in the Flathub organization, but should try to build the latest version of the dependencies. I don’t know which package would provide the library so I couldn’t look for it.

@George, I just build my first flatpak package and I may help you out. But I need access to wxmt program source code. Is source code publicly published? If yes, please provide web link to it.

Though I thought I had responded to this message earlier, I don’t seem to see my posting here.
So I will carry on from where I am right now.

In the meanwhile, I have used the link to your first flatpak build and built a paralell copy on my system to get the practice and to understand the process better.
As a part of that, I now have a couple of questions, before I can carry on.

  1. my current build system is based on Codelite and its own proprietary make system, which is not supported by Flatpak builder. While Codelite lists CMake as an available alternative, I have not been able to switch to that and I have left a question on the Codelite forum.
    That issue is the main reason that making any source code available right now is useless, unless & until I can come up with a usable build system
  2. another question that was on my mind all along is, why I would need to download and install anything from the 'net, when I have just built my app locally and presumably have all it needs ‘right here’?
    After poking through the documentation, it would seem I ought to be able to install everything using the ‘file’ or ‘dir’ build type along with ‘simple’ build system.

That is my current state and if anyone has some useful pointers or comments, I would very much appreciate any help.

Like I understand this is Flathub requirement (check the “reproducible builds” paragraph) if application is built from open source software, to be reproducible. I assume because of a trust, there is program’s open source and I build it in reproducible way, that means I haven’t injected any “my special” code into the product.

But… on Flathub I see there are also flatpak with proprietary license, that for sure do not have source code available for reproducibility. In Flathub on left site there is “License” and you can filter by “Proprietary”.

I don’t know if I am of any use now, because your case is pretty different them my. Hope this helps.

At one time I thought much the same, but I see no reason why someone could not download from a malicious site, or even download & modify the code before installing it.

As far as I can see, using an app packaged in a flatpak is no guarantee of freedom from malware.

Then there is the flatpak example using a plain shell script, which I intend to follow up on.

But my current efforts at making this example work have run into a dead end.
When I create all the files (hello.sh & org.flatpak.Hello.yml) in a test directory and then run the given command, I get an error back which says it cannot find hello.sh

But before that it gives me several flatpak-builder:5575 warnings about ‘unknown property build-commands’
and that from instructions from the current PDF document - a bit discouraging.

And I cannot find anything on-line which even comes close to being helpful :frowning:

As far as I know: You should build your application & dependencies in the manifest to ensure compatibility. You take libwx from your distribution, build against one release GTK 3, and use it in the runtime which probably provides a different GTK 3 release. I think this can lead to crashes (Changes in GTK 3).

It’s always easier to provide assistance if you simply post your manifest. Currently we can only guess what could be wrong.

But I tried the current example and can confirm that it still works. The whitespaces seem to get lost when copied from the PDF, but indentation is part of the syntax & therefore required. Just copy the examples from the browser.

Thank you for helping me resolve this issue :slight_smile:
Your comment regarding the indentation was all I needed.
Being new to all this, I was unaware of this ‘restriction’ and somewhat surprised that this was not pointed out in any error message.
For this simple trial, I assumed that the documents I was following would be sufficient. My apology.

As for your other recommendations, I understand them - I think.

My wxWidgets apps are always built with all libraries kinked statically and I will now try and see what I need to do to actually install one on my local PC.

Undoubtedly, I will be back asking for help.
With the necessary files etc.

To expand a bit more on my hope to be able to use the existing build.
My current build environment is based on the Codelite IDE and up to now I have been using the default build environment which uses a proprietary make system which is not supported by Flatpak.
There seems to be support for CMake from within the IDE, but I have not been able to simply switch the make process to generate CMake files for a command line build.
Learning to actually build my apps using CMake is just another steep leaning curve and the time to climb that mountain may just scare me off.

Only time will tell

This restriction is called YAML.

If you don’t want whitespace to be semantic, use JSON.

Yes, I am finding out :slight_smile: don’t really mind once I was made aware of it.

I’m sure there will be a few more similar ‘obvious’ bumps in the road

You are not limited to the build systems directly supported by flatpak. You can always use buildsystem: simple & run what’s necessary as build-commands:. If this actually works with your buildsystem (it must work outside the IDE in an offline environment) I can’t say.

That will be my next trial - using CMake - I expect.

That buildsystem is supported directly and you don’t need simple for that Flatpak Builder Command Reference — Flatpak documentation

Yes, I have seen the reference to CMake & CMake-ninja,
But just saying that it it supported is helpful only to folks who are familiar with both CMake & Flatpak. :frowning:
My search to find examples has not been very successful, I’m afraid.
Still at this time, I have just barely made the test project compile & run under Windows using CMake to build *.sln file for MSVC and my next step will be to port that code to Mint.

It would seem that building & debugging will still need also a good IDE/Debugger alongside the CMake code

If you can point me to any more specific examples, I’ll be very grateful

I usually recommend searching through the flathub sources here
https://github.com/search?q=org%3Aflathub+"buildsystem"%3A+"cmake&type=code

But YMMV and it depends how your app is setup quiet a bit.

Will check it out; thank you

My progress has been slow, but I have now gotten part of the way.
My current test project is based on the latest wxWidgets demo ‘life’.
I have uploaded the basic code to Github and the package is available at:

It consists of the source code from the wxWidgets demos/life and includes a the CMake build script adapted from the blog wxWidgets + CMake: Multiplatform Superbuild | justdevtutorials.com for this code and for CMake-Ninja.
FWIW, the base CMake project still has a way to go and I am working on that in parallel. I evidently need more platform specific code fixes. Right now, I don’t see those issues getting in the way of my flatpak packaging.

The script to create the flatpak YML file and start the build process: flmakelife.sh

#!/bin/bash

# Install flatpak-builder - already installed on Mint
#sudo apt -y install flatpak-builder


# Create Manifest file
cat > org.cmlife.cmlife.yml  <<EOL
app-id: org.cmlife.cmlife
runtime: org.freedesktop.Platform
runtime-version: '22.08'
sdk: org.freedesktop.Sdk
command: life
#rename-icon: life
#rename-desktop-file: life.desktop
#finish-args:
#  - --socket=fallback-x11
#  - --socket=wayland
#  - --share=ipc
#  - --filesystem=xdg-documents
#  - --env=PWS_HELPDIR=/app/share/passwordsafe/help/

modules:
	# Note: the order of modules is important as the builder works its way
	# in a linear fashion - any dependencies need to be satisfied when 
	# the process tries to build a module

  - name: wxwidgets
    cleanup:
      - /bin
      - /include
      - /lib/cmake
      - /lib/wx
      - /share
    sources:
      - type: archive
        url: https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.2.1/wxWidgets-3.2.2.1.tar.bz2
        sha256: dffcb6be71296fff4b7f8840eb1b510178f57aa2eb236b20da41182009242c02
        x-checker-data:
          type: anitya
          project-id: 5150
          stable-only: true
          url-template: https://github.com/wxWidgets/wxWidgets/releases/download/v/wxWidgets-.tar.bz2

  - name: life
    buildsystem: cmake-ninja
    
    sources:
      - type: git
        url: https://github.com/tester0077/flcmlife.git
        branch: master
        
EOL

I run the script - under Mint 21.2 from a directory
~/Public/flatpak/flcmlife/flatpak/

While I can run this script with more success in my local build directory, but not all the way,
for this test case with the project code available from Github, I get stuck at a much earlier spot.

/Public/flatpak/flcmlife/flatpak$ ./flmakelife.sh 
Downloading sources
Fetching full git repo https://github.com/tester0077/flcmlife.git
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Failed to download sources: module life: Child process exited with code 128

Obviously, I still have a lot to learn about most of this process. :wink:
Any help will be much appreciated.