Search code examples
cross-platformsnapcraftsnap

building snaps for different architectures


I'm currently working on creating a snap for Apache IoTDB, that should build for both arm64 and amd64 architectures.

Now I know this should be possible, but the problem I'm having is, that if I use "stage-packages" one of the packages is "openjdk-11-jre-headless", when listing the content of the snap in both cases I can only see "squashfs-root/usr/lib/jvm/java-11-openjdk-arm64"

I'm building a "core22" image and defined this for the architectures:

architectures:
 - build-on: [arm64, amd64]
   build-for: [arm64]
 - build-on: [arm64, amd64]
   build-for: [amd64]

I should mention I'm building on an Ubuntu 22.04 VM on an M2 Mac.


Solution

  • Regarding the issue of creating a snap for Apache IoTDB, you can try the following: 1、You can specify architecture-specific stage-packages using a syntax like this in your snapcraft.yaml:

    architectures:
      - build-on: [amd64]
        build-for: [amd64]
      - build-on: [arm64]
        build-for: [arm64]
    
    parts:
      mypart:
        plugin: nil
        stage-packages:
          - on amd64: [openjdk-11-jre-headless:amd64]
          - on arm64: [openjdk-11-jre-headless:arm64]
    

    2、Review and Validate the Snap Contents: After building the snap, you can inspect the contents using the unsquashfs tool to list out the files and check if the correct Java version is present for each architecture:

    unsquashfs -l <your-snap-name>.snap
    

    3、Building Separately on Native Architectures: If feasible, consider building the snap separately on native architecture environments (i.e., use an AMD64 environment for AMD64 builds and an ARM64 environment for ARM64 builds). This can sometimes help avoid cross-compilation issues and is a good way to ensure that each architecture is handled correctly.