Packaging i386 32bit binary in AMD64 snap

Welcome to the community, @ixubuntu. I think snaps are great to preserve old software.

I think this snap will be very similar to what you want. This is also a 32-bit desktop app: s4a/snapcraft.yaml at master · snapcrafters/s4a · GitHub

Snaps run in a sandbox, they do not have access to the host system. This has the advantage for 32-bit apps that the i386 architecture does not have to be enabled on the computer of the user. The only thing you need to do is add all the i386 libraries that your app needs to the snap at build time.

In this example

  • the i386 part enables the architecture in the snap
  • the s4a part installs the deb (inside of the snap) and includes all the 32-bit dependencies of the application (using stage-packages).
parts:
  i386:
    plugin: nil
    override-build: |
      sudo dpkg --add-architecture i386
      sudo apt-get update  
  s4a:
    after: 
      - i386
      - glib-only
    plugin: dump
    source: http://s4a.cat/downloads/S4A16.deb
    source-type: deb
    stage-packages:
      - libsm6:i386
      - libatk1.0-0:i386
      - libbsd0:i386
      - libc6:i386
      - libcairo2:i386
      - libgcc1:i386
      - libgdk-pixbuf2.0-0:i386
      - libglib2.0-0:i386
      - libglu1-mesa:i386
      - libgtk2.0-0:i386
      - libpango-1.0-0:i386
      - libpulse0:i386
      - libx11-6:i386
      - libxau6:i386
      - libxcb1:i386
      - libxdmcp6:i386
      - libxml2:i386
      - libxrandr2:i386
      - libv4l-0:i386
    override-build: |
      snapcraftctl build
      sed -i 's|Icon=s4a|Icon=${SNAP}/usr/share/icons/hicolor/128x128/apps/s4a.png|' ${SNAPCRAFT_PART_INSTALL}/usr/share/applications/s4a.desktop
      echo "Keywords=Arduino" >> ${SNAPCRAFT_PART_INSTALL}/usr/share/applications/s4a.desktop
      rm -rf $SNAPCRAFT_PART_INSTALL/lib/x86_64-linux-gnu
      rm -rf $SNAPCRAFT_PART_INSTALL/usr/lib/x86_64-linux-gnu
      rm -rf $SNAPCRAFT_PART_INSTALL/usr/share/bug
      rm -rf $SNAPCRAFT_PART_INSTALL/usr/share/doc
      rm -rf $SNAPCRAFT_PART_INSTALL/usr/share/doc-base
      rm -rf $SNAPCRAFT_PART_INSTALL/usr/share/lintian
      rm -rf $SNAPCRAFT_PART_INSTALL/usr/share/man
    stage:
      - -usr/bin/update-mime-database

So for your snap, you will probably need to add all the dependencies of your application in stage-packages of your opensonic part. The installation instructions for opensonic will probably tell you what its dependencies are.

You will also need the glib-only part in order to enable desktop features

  glib-only:
    after: [i386]
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: glib-only
    plugin: make
    build-packages:
      - libglib2.0-dev
    stage-packages:
      - libglib2.0-bin:i386
      - shared-mime-info:i386

I think you’ll also need the launcher part (also copy the script folder into your snap) and add bin/launcher and bin/desktop-launch to the command chain, so all the desktop stuff gets initialized correctly.

1 Like