Cross-compiling a flatpak

Alexander Larsson alexl at redhat.com
Fri Mar 23 07:35:51 UTC 2018


Cross building is very tricky and needs a lot of custom code.
Supporting that in a generic way is going to be a massive pain. I
mean, just look at yocto (warning, might go blind).

The nice thing with flatpak is that it ships an entire build
environment that you can run in all arches which means emulation is
very easy. So, say you have org.my.App.json on an x86-64 fedora
machine and want to build a aarch64 build. Here is how you do this:

dnf install qemu-user-static
flatpak-builder --arch=aarch64 --install-deps-from=flathub dir org.my.App.json

This will use the userspace qemu emulation to just run the aarch64
binaries. This works surprisingly well, but obviously it is a bit slow
to run the compiler emulated. Christian recently proposed a minor
extension of this model where we keep the aarch64 basic runtime, but
replace/add a few strategic binaries with x86-64 versions. For
example, we could make bash, sed, make, etc native which would not
really affect anything at runtime other than performance, and we could
have a crosscompile toolchain that looks like a regular build
(generate aarch64, looks for includes in /usr/include, etc) but built
as a x86-64 binary. This would speed up builds a lot, while
essentially letting us cross-compile *anything*  without having to
change any code.





On Thu, Mar 22, 2018 at 5:17 PM, Corentin Noël
<corentin.noel at collabora.com> wrote:
> Hi everyone,
>
> I'm playing a little bit with flatpak and wanted to experiment cross-
> compilation with it.
> I haven't seen anything regarding cross-compilation right now, but I'm
> wanting to further investigate this issue.
>
> I wanted to know if you had some thoughts about it, or if there was
> some plans documented somewhere (or in someone's mind)
>
> Here are my thoughts when I look at this issue:
>
> Let's imagine that I'm using a x86_64 system and want to build a
> `bar.foo.HelloWorld` application targetting the aarch64 architecture.
>  * my application will target the `org.freedesktop.Platform//1.6`
> runtime and require the `org.freedesktop.Sdk//1.6` sdk
>  * I start a build with `flatpak build` using a new --target=aarch64
> flag showing my intention to cross-build
>    * `org.freedesktop.Sdk/x86_64/1.6` and
> `org.freedesktop.Platform/x86_64/1.6` are mounted as usual to start the
> compilation.
>    * the target flag makes flatpak mount a
> `org.freedesktop.Sdk.Extension.Cross-aarch64/x86_64/1.6` SDK extension
> (mounted under /usr/lib/sdk/Cross-aarch64), this extension contains all
> the toolchain for building to the aarch64 architecture. (and it might
> also contain some useful things for cross-compilation like a meson
> crossfile definition)
>    * the target flag makes flatpak mount
> `org.freedesktop.Platform/aarch64/1.6` and
> `org.freedesktop.Sdk/aarch64/1.6` (and their dependencies) under
> /sysroots/aarch64/ as it is doing for the native architecture in /
>    * the build happens targetting the sysroot in /sysroots/aarch64/
>    * the resulting flatpak is define to be aarch64
>
> So with the current flatpak implementation I'm mostly missing two
> parts:
>  * Be able to mount at build time a Sdk & Runtime of a foreign
> architecture in a well-defined location
>  * Define the resulting flatpak as being of another architecture
>
> Do you think that it's the right way to do it and that it's something
> that might be implemented in flatpak?
> _______________________________________________
> Flatpak mailing list
> Flatpak at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/flatpak



-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                Red Hat, Inc
       alexl at redhat.com         alexander.larsson at gmail.com


More information about the Flatpak mailing list