Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to cross-compile #5

Open
alexlarsson opened this issue May 19, 2016 · 20 comments
Open

Document how to cross-compile #5

alexlarsson opened this issue May 19, 2016 · 20 comments

Comments

@alexlarsson
Copy link
Member

From @hadess on May 5, 2016 17:25

When we have, in the near future, support for ARM in the Freedesktop and GNOME SDK, it would be good to document how to cross compile for one to the other, if only x86-64 to i686 to start with, and x86-64 to ARM afterwards.

Copied from original issue: alexlarsson/xdg-app#155

@hadess
Copy link
Contributor

hadess commented Jun 29, 2016

@aleixpol
Copy link
Contributor

aleixpol commented Apr 4, 2017

What kind of documentation do you want? Currently it's just about passing --arch and hoping binfmt is properly configured, correct?

@hadess
Copy link
Contributor

hadess commented Apr 4, 2017

I'd expect instructions to include:

  • Installing the target runtime and SDK
  • Verifying that binfmt is correctly configured (launching a flatpak with --arch, and expecting bash to run properly)
  • Passing --arch to flatpak-builder, or setting it in the json file if the binaries are targeted only at this specific architecture (eg. not compiling from source)

@aleixpol
Copy link
Contributor

aleixpol commented Apr 6, 2017

If you tell me where you want this documentation and an example, I can write something.

@bochecha
Copy link
Contributor

Having just gone through that, here's what I ended up doing:

  1. install the qemu support
$ sudo dnf install qemu-system-arm qemu-user-static
$ sudo systemctl restart systemd-binfmt.service
  1. install the runtime/sdk for the target architecture:
$ flatpak install --user gnome org.freedesktop.Sdk/${ARCH}/1.6 org.freedesktop.Platform/${ARCH}/1.6
  1. build:
$ flatpak-builder --arch=${ARCH} [OPTIONS] DIRECTORY MANIFEST

The thing which caused me problems is that I had installed the qemu-user-binfmt package instead of the qemu-user-static one, and that only led to "No such file or directory" errors.

Of course, the packages might be named differently depending on the distribution.

@fedelibre
Copy link

There's a nice guide about cross-compilation here:
https://developer.puri.sm/Librem5/Apps/Packaging_Apps/Building_Flatpaks/Cross-Building.html

I've followed it and I'm now trying to use it to build an aarch64 flatpak using an x86_64 laptop. But I get a weird error when building the first module in the manifest:

⬢[fede@toolbox org.frescobaldi.Frescobaldi]$ flatpak-builder --force-clean --arch=aarch64 --repo=myrepo _aarch64 org.frescobaldi.Frescobaldi.yaml
Emptying app dir '_aarch64'
Downloading sources
Starting build of org.frescobaldi.Frescobaldi
Cache miss, checking out last cache hit
========================================================================
Building module guile in /var/home/fede/src/flathub.org/org.frescobaldi.Frescobaldi/.flatpak-builder/build/guile-2
========================================================================
Applying patch guile-1.8.8-deplibs.patch
patching file guile-1.8.pc.in
patching file guile-config/guile-config.in
patching file libguile/Makefile.in
Hunk #2 succeeded at 2126 (offset -5 lines).
Hunk #3 succeeded at 2148 (offset -5 lines).
Applying patch guile-1.8.8-cve-2016-8605.patch
patching file libguile/filesys.c
Hunk #1 succeeded at 791 (offset -464 lines).
Applying patch guile-1.8.8-configure.patch
patching file configure.in
patching file configure
bwrap: execvp /bin/sh: Exec format error
Error: module guile: Child process exited with code 1

Is this something related to binfmt? (as @aleixpol mentioned above)

I'm on Fedora 34 Silverblue and I'm running flatpak-builder within a fedora 34 container, where I installed qemu-user-static.

@fedelibre
Copy link

I've just tried building Lollypop and I get an error while building the first module:

$ flatpak-builder --arch=aarch64 --repo=myrepo _aarch64 org.gnome.Lollypop.json 
[...]
Starting build of org.gnome.Lollypop
========================================================================
Building module python3-beautifulsoup4 in /var/home/fede/src/flathub.org/org.gnome.Lollypop/.flatpak-builder/build/python3-beautifulsoup4-1
========================================================================
Running: pip3 install --exists-action=i --no-index --find-links="file:https://${PWD}" --prefix=${FLATPAK_DEST} "beautifulsoup4"
bwrap: execvp /bin/sh: Exec format error
Error: module python3-beautifulsoup4: Child process exited with code 1

What I'm doing wrong?

@hadess
Copy link
Contributor

hadess commented Jun 2, 2021

bwrap: execvp /bin/sh: Exec format error

Your system can't execute aarch64 executables, from the likes of it. Note that this issue is about documenting cross-compilation, not helping folks out with their own problems. You might want to reach out to your distribution's help forums instead.

@nanonyme
Copy link
Contributor

This has become relevant again now that i386 is EOL and you need to use cross-compile Sdk extensions to build 32bit binaries.

@gasinvein
Copy link
Member

@nanonyme This issue was about using qemu-user-static to build native compiler targets on machines with foreign arch CPU (e.g. do aarch64 build with aarch64 SDK on a x86_64 machine). This approach doesn't involve cross-compilers, but emulation. So, to use this approach to build i386 apps, one would need actual i386 SDK.

@tinywrkb
Copy link

tinywrkb commented Jan 16, 2022

Here's another idea how to handle this.

Create an SDK extension org.freedesktop.Sdk.Extension.runner-aarch64

build.sh

#!/bin/bash

_WRKDIR="$PWD"
_BUILDDIR="$_WRKDIR"/build
_APPNAME=org.freedesktop.Sdk.Extension.runner-aarch64
_SDK=org.freedesktop.Sdk
_RUNTIME=org.freedesktop.Sdk
_BRANCH=21.08
_REPO="$_WRKDIR"/flatpak-repo
_QEMU_DOWNLOAD="https://github.com/multiarch/qemu-user-static/releases/download/v6.1.0-8/qemu-aarch64-static.tar.gz"

flatpak build-init --arch=aarch64 --type=extension --extension-tag=org.freedesktop.Sdk.Extension "$_BUILDDIR" $_APPNAME $_SDK $_RUNTIME $_BRANCH

curl -L "$_QEMU_DOWNLOAD" | bsdtar -Oxf - | install -Dm755 /dev/stdin "$_BUILDDIR"/files/bin/qemu-aarch64-static

flatpak build-finish --arch=aarch64 --type=extension --extension-tag=org.freedesktop.Sdk.Extension "$_BUILDDIR"

flatpak build-export $_REPO "$_BUILDDIR" $_BRANCH

Install the extension.

$ flatpak install --user --arch=aarch64 flatpak-repo org.freedesktop.Sdk.Extension.runner-aarch64//21.08

Update binfmt_misc.

$ sudo install -dm755 /run/binfmt.d
$ echo ':qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/lib/sdk/runner-aarch64/bin/qemu-aarch64-static:OC' | sudo tee /run/binfmt.d/qemu-user.conf
$ sudo systemctl restart systemd-binfmt.service

Build your app with Flatpak Builder's --arch=aarch64 option.

@talregev
Copy link

talregev commented Sep 4, 2022

Having just gone through that, here's what I ended up doing:

  1. install the qemu support
$ sudo dnf install qemu-system-arm qemu-user-static
$ sudo systemctl restart systemd-binfmt.service
  1. install the runtime/sdk for the target architecture:
$ flatpak install --user gnome org.freedesktop.Sdk/${ARCH}/1.6 org.freedesktop.Platform/${ARCH}/1.6
  1. build:
$ flatpak-builder --arch=${ARCH} [OPTIONS] DIRECTORY MANIFEST

The thing which caused me problems is that I had installed the qemu-user-binfmt package instead of the qemu-user-static one, and that only led to "No such file or directory" errors.

Of course, the packages might be named differently depending on the distribution.

@bochecha Thank you for writing this! Take me long time to understand how to build flatpak for arm.
This is what I really needed.
@aleixpol Why this is not documented? For arch / arm explain in the official docs?
Please add this to the docs:
https://docs.flatpak.org/

@mbridon
Copy link

mbridon commented Sep 4, 2022

Hi, I used to be called @bochecha but due to $reasons I had to create this new account and abandon that old one because the Github support couldn't just give me back my old account...

You're welcome, I'm glad that documentation I wrote a long time ago could still be useful after all these years 😄

I welcome the idea of moving it to the Flatpak docs 👍

@talregev
Copy link

talregev commented Sep 4, 2022

@mbridon Thank you again!
I have an issue, but I think it more global, if you can confirm.
I am no longer able can install these flatpack from arm / aarch64:

  • org.gnome.Sdk
  • org.gnome.Platform
  • org.freedesktop.Platform
  • org.freedesktop.Sdk

Yesterday I was able to download and install using flatpak, but today no. Can you verify it from your side?

@mbridon
Copy link

mbridon commented Sep 5, 2022

I just installed runtime/org.gnome.Sdk/arm/3.36 on my x86_64 machine 🤷

it only complained about this:

Info: org.gnome.Sdk//3.36 is end-of-life, with reason:
   The GNOME 3.36 runtime is no longer supported as of February 13, 2021. Please ask your application developer to migrate to a supported platform.
Info: org.freedesktop.Platform.GL.default//19.08 is end-of-life, with reason:
   The Freedesktop SDK 19.08 runtime is no longer supported as of September 1, 2021. Please ask your application developer to migrate to a supported version

@talregev
Copy link

talregev commented Sep 5, 2022

I try to do the same on my local and the gitgub action (CI), both work for me on Saturday, but yesterday and today not:

sudo apt update 
sudo apt install -y flatpak flatpak-builder qemu-system-arm qemu-user-static
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak install -y flathub org.gnome.Sdk/${{ matrix.arch }}/42 flathub org.gnome.Platform/${{ matrix.arch }}/42

The matrix.arch are:

      matrix:
        include:
        - type: x64
          arch: x86_64
        - type: arm64
          arch: aarch64

It not found the aarch64.

Looking for matches…
error: Nothing matches org.gnome.Sdk in remote flathub
Error: Process completed with exit code 1.

It it succeeded on Saturday in both (local computer and github action), I think it not a problem on my side. and If it is, I am not sure what I am doing wrong. Thank you for your response.

@talregev
Copy link

talregev commented Sep 5, 2022

Can you try with aarch64?

@mbridon
Copy link

mbridon commented Sep 5, 2022

Same result as arm 🤷

@talregev
Copy link

talregev commented Sep 5, 2022

Same result as arm shrug

Thank you for trying!

@talregev
Copy link

talregev commented Sep 5, 2022

@mbridon
I understand the issue!
#5080

pwithnall added a commit to pwithnall/flatpak that referenced this issue Mar 1, 2023
The checksum here can leak if `flatpak_dir_remote_load_cached_summary()`
returns false at least once.

Spotted by asan while running gnome-software:
```
Direct leak of 2925 byte(s) in 45 object(s) allocated from:
    #0 0x7f44774ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
    flatpak#1 0x7f44764c941a in g_malloc ../../source/glib/glib/gmem.c:130
    flatpak#2 0x7f445bc860e7 in ostree_checksum_from_bytes src/libostree/ostree-core.c:1599
    flatpak#3 0x7f445bdbea82 in flatpak_dir_remote_fetch_indexed_summary /opt/gnome/source/flatpak/common/flatpak-dir.c:12563
    flatpak#4 0x7f445bd9932e in flatpak_remote_state_ensure_subsummary /opt/gnome/source/flatpak/common/flatpak-dir.c:577
    flatpak#5 0x7f445bdbfd42 in _flatpak_dir_get_remote_state /opt/gnome/source/flatpak/common/flatpak-dir.c:12872
    flatpak#6 0x7f445bdc006c in flatpak_dir_get_remote_state_optional /opt/gnome/source/flatpak/common/flatpak-dir.c:12953
    flatpak#7 0x7f445be07886 in flatpak_transaction_ensure_remote_state /opt/gnome/source/flatpak/common/flatpak-transaction.c:2057
    flatpak#8 0x7f445be095c7 in flatpak_transaction_add_ref /opt/gnome/source/flatpak/common/flatpak-transaction.c:2732
    flatpak#9 0x7f445be09c37 in flatpak_transaction_add_update /opt/gnome/source/flatpak/common/flatpak-transaction.c:2940
    flatpak#10 0x7f445bdd202c in flatpak_installation_list_installed_refs_for_update /opt/gnome/source/flatpak/common/flatpak-installation.c:1103
    flatpak#11 0x7f445bf07824 in gs_flatpak_add_updates ../../source/gnome-software/plugins/flatpak/gs-flatpak.c:2082
    flatpak#12 0x7f445bf2e2b9 in gs_plugin_add_updates ../../source/gnome-software/plugins/flatpak/gs-plugin-flatpak.c:484
    flatpak#13 0x7f44770533b2 in gs_plugin_loader_call_vfunc ../../source/gnome-software/lib/gs-plugin-loader.c:620
    flatpak#14 0x7f447705430f in gs_plugin_loader_run_results ../../source/gnome-software/lib/gs-plugin-loader.c:748
    flatpak#15 0x7f447706cb03 in gs_plugin_loader_process_thread_cb ../../source/gnome-software/lib/gs-plugin-loader.c:3110
    #16 0x7f44769967ed in g_task_thread_pool_thread ../../source/glib/gio/gtask.c:1531
    flatpak#17 0x7f447650e760 in g_thread_pool_thread_proxy ../../source/glib/glib/gthreadpool.c:350
    flatpak#18 0x7f447650dd02 in g_thread_proxy ../../source/glib/glib/gthread.c:831
```

Signed-off-by: Philip Withnall <[email protected]>
smcv pushed a commit to pwithnall/flatpak that referenced this issue Mar 20, 2023
The checksum here can leak if `flatpak_dir_remote_load_cached_summary()`
returns false at least once.

Spotted by asan while running gnome-software:
```
Direct leak of 2925 byte(s) in 45 object(s) allocated from:
    #0 0x7f44774ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
    flatpak#1 0x7f44764c941a in g_malloc ../../source/glib/glib/gmem.c:130
    flatpak#2 0x7f445bc860e7 in ostree_checksum_from_bytes src/libostree/ostree-core.c:1599
    flatpak#3 0x7f445bdbea82 in flatpak_dir_remote_fetch_indexed_summary /opt/gnome/source/flatpak/common/flatpak-dir.c:12563
    flatpak#4 0x7f445bd9932e in flatpak_remote_state_ensure_subsummary /opt/gnome/source/flatpak/common/flatpak-dir.c:577
    flatpak#5 0x7f445bdbfd42 in _flatpak_dir_get_remote_state /opt/gnome/source/flatpak/common/flatpak-dir.c:12872
    flatpak#6 0x7f445bdc006c in flatpak_dir_get_remote_state_optional /opt/gnome/source/flatpak/common/flatpak-dir.c:12953
    flatpak#7 0x7f445be07886 in flatpak_transaction_ensure_remote_state /opt/gnome/source/flatpak/common/flatpak-transaction.c:2057
    flatpak#8 0x7f445be095c7 in flatpak_transaction_add_ref /opt/gnome/source/flatpak/common/flatpak-transaction.c:2732
    flatpak#9 0x7f445be09c37 in flatpak_transaction_add_update /opt/gnome/source/flatpak/common/flatpak-transaction.c:2940
    flatpak#10 0x7f445bdd202c in flatpak_installation_list_installed_refs_for_update /opt/gnome/source/flatpak/common/flatpak-installation.c:1103
    flatpak#11 0x7f445bf07824 in gs_flatpak_add_updates ../../source/gnome-software/plugins/flatpak/gs-flatpak.c:2082
    flatpak#12 0x7f445bf2e2b9 in gs_plugin_add_updates ../../source/gnome-software/plugins/flatpak/gs-plugin-flatpak.c:484
    flatpak#13 0x7f44770533b2 in gs_plugin_loader_call_vfunc ../../source/gnome-software/lib/gs-plugin-loader.c:620
    flatpak#14 0x7f447705430f in gs_plugin_loader_run_results ../../source/gnome-software/lib/gs-plugin-loader.c:748
    flatpak#15 0x7f447706cb03 in gs_plugin_loader_process_thread_cb ../../source/gnome-software/lib/gs-plugin-loader.c:3110
    #16 0x7f44769967ed in g_task_thread_pool_thread ../../source/glib/gio/gtask.c:1531
    flatpak#17 0x7f447650e760 in g_thread_pool_thread_proxy ../../source/glib/glib/gthreadpool.c:350
    flatpak#18 0x7f447650dd02 in g_thread_proxy ../../source/glib/glib/gthread.c:831
```

Signed-off-by: Philip Withnall <[email protected]>
smcv pushed a commit that referenced this issue Mar 20, 2023
The checksum here can leak if `flatpak_dir_remote_load_cached_summary()`
returns false at least once.

Spotted by asan while running gnome-software:
```
Direct leak of 2925 byte(s) in 45 object(s) allocated from:
    #0 0x7f44774ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
    #1 0x7f44764c941a in g_malloc ../../source/glib/glib/gmem.c:130
    #2 0x7f445bc860e7 in ostree_checksum_from_bytes src/libostree/ostree-core.c:1599
    #3 0x7f445bdbea82 in flatpak_dir_remote_fetch_indexed_summary /opt/gnome/source/flatpak/common/flatpak-dir.c:12563
    #4 0x7f445bd9932e in flatpak_remote_state_ensure_subsummary /opt/gnome/source/flatpak/common/flatpak-dir.c:577
    #5 0x7f445bdbfd42 in _flatpak_dir_get_remote_state /opt/gnome/source/flatpak/common/flatpak-dir.c:12872
    #6 0x7f445bdc006c in flatpak_dir_get_remote_state_optional /opt/gnome/source/flatpak/common/flatpak-dir.c:12953
    #7 0x7f445be07886 in flatpak_transaction_ensure_remote_state /opt/gnome/source/flatpak/common/flatpak-transaction.c:2057
    #8 0x7f445be095c7 in flatpak_transaction_add_ref /opt/gnome/source/flatpak/common/flatpak-transaction.c:2732
    #9 0x7f445be09c37 in flatpak_transaction_add_update /opt/gnome/source/flatpak/common/flatpak-transaction.c:2940
    #10 0x7f445bdd202c in flatpak_installation_list_installed_refs_for_update /opt/gnome/source/flatpak/common/flatpak-installation.c:1103
    #11 0x7f445bf07824 in gs_flatpak_add_updates ../../source/gnome-software/plugins/flatpak/gs-flatpak.c:2082
    #12 0x7f445bf2e2b9 in gs_plugin_add_updates ../../source/gnome-software/plugins/flatpak/gs-plugin-flatpak.c:484
    #13 0x7f44770533b2 in gs_plugin_loader_call_vfunc ../../source/gnome-software/lib/gs-plugin-loader.c:620
    #14 0x7f447705430f in gs_plugin_loader_run_results ../../source/gnome-software/lib/gs-plugin-loader.c:748
    #15 0x7f447706cb03 in gs_plugin_loader_process_thread_cb ../../source/gnome-software/lib/gs-plugin-loader.c:3110
    #16 0x7f44769967ed in g_task_thread_pool_thread ../../source/glib/gio/gtask.c:1531
    #17 0x7f447650e760 in g_thread_pool_thread_proxy ../../source/glib/glib/gthreadpool.c:350
    #18 0x7f447650dd02 in g_thread_proxy ../../source/glib/glib/gthread.c:831
```

Signed-off-by: Philip Withnall <[email protected]>
smcv pushed a commit to smcv/flatpak that referenced this issue Nov 14, 2023
The checksum here can leak if `flatpak_dir_remote_load_cached_summary()`
returns false at least once.

Spotted by asan while running gnome-software:
```
Direct leak of 2925 byte(s) in 45 object(s) allocated from:
    #0 0x7f44774ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
    #1 0x7f44764c941a in g_malloc ../../source/glib/glib/gmem.c:130
    flatpak#2 0x7f445bc860e7 in ostree_checksum_from_bytes src/libostree/ostree-core.c:1599
    flatpak#3 0x7f445bdbea82 in flatpak_dir_remote_fetch_indexed_summary /opt/gnome/source/flatpak/common/flatpak-dir.c:12563
    flatpak#4 0x7f445bd9932e in flatpak_remote_state_ensure_subsummary /opt/gnome/source/flatpak/common/flatpak-dir.c:577
    flatpak#5 0x7f445bdbfd42 in _flatpak_dir_get_remote_state /opt/gnome/source/flatpak/common/flatpak-dir.c:12872
    flatpak#6 0x7f445bdc006c in flatpak_dir_get_remote_state_optional /opt/gnome/source/flatpak/common/flatpak-dir.c:12953
    flatpak#7 0x7f445be07886 in flatpak_transaction_ensure_remote_state /opt/gnome/source/flatpak/common/flatpak-transaction.c:2057
    flatpak#8 0x7f445be095c7 in flatpak_transaction_add_ref /opt/gnome/source/flatpak/common/flatpak-transaction.c:2732
    flatpak#9 0x7f445be09c37 in flatpak_transaction_add_update /opt/gnome/source/flatpak/common/flatpak-transaction.c:2940
    flatpak#10 0x7f445bdd202c in flatpak_installation_list_installed_refs_for_update /opt/gnome/source/flatpak/common/flatpak-installation.c:1103
    flatpak#11 0x7f445bf07824 in gs_flatpak_add_updates ../../source/gnome-software/plugins/flatpak/gs-flatpak.c:2082
    flatpak#12 0x7f445bf2e2b9 in gs_plugin_add_updates ../../source/gnome-software/plugins/flatpak/gs-plugin-flatpak.c:484
    flatpak#13 0x7f44770533b2 in gs_plugin_loader_call_vfunc ../../source/gnome-software/lib/gs-plugin-loader.c:620
    flatpak#14 0x7f447705430f in gs_plugin_loader_run_results ../../source/gnome-software/lib/gs-plugin-loader.c:748
    flatpak#15 0x7f447706cb03 in gs_plugin_loader_process_thread_cb ../../source/gnome-software/lib/gs-plugin-loader.c:3110
    #16 0x7f44769967ed in g_task_thread_pool_thread ../../source/glib/gio/gtask.c:1531
    flatpak#17 0x7f447650e760 in g_thread_pool_thread_proxy ../../source/glib/glib/gthreadpool.c:350
    flatpak#18 0x7f447650dd02 in g_thread_proxy ../../source/glib/glib/gthread.c:831
```

Signed-off-by: Philip Withnall <[email protected]>
(cherry picked from commit ce4bb3d)
smcv pushed a commit to smcv/flatpak that referenced this issue May 6, 2024
smcv pushed a commit to smcv/flatpak that referenced this issue May 6, 2024
Add MIT license to code and generated code

Closes flatpak#5

See merge request alexl/variant-schema-compiler!12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests