Different sources for different archs

Hi All,

I’m trying to repackage a deb as a snap and I’m targeting both x86 and aarch64, so I need 2 different debs to be used as sources.

I declared that this snap will only build on x86 but should target both platforms with

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

So far so good. But now I’m hitting a wall when I try to set 2 different debs as sources

parts:
  my-app:
    source:
      - on amd64: http://redacted/x86.deb
      - on arm64:  http://redacted/arm64.deb
    source-type: deb
    plugin: dump

I thought that was what I needed, but my arm64 snap contains the x86 files. So I think my yaml selecting the source deb based on the host arch, i.e. it will use the arm64 deb if I build the snap on an arm64 system.

How can I select different sources for different target platforms?

Thanks,

Eric.

Hi ! @eriff

Try to separate the two scope to see .

Like this .

parts:
  my-app-1:
    source:
      - on amd64: http://redacted/x86.deb
    source-type: deb
    plugin: dump

 my-app-2:
    source:
      - on arm64:  http://redacted/arm64.deb
    source-type: deb
    plugin: dump

That produces the same behavior. Since I’m building the snaps on x86, snapcraft is just repackaging x86.deb.

I think your suggestion produces a my-app-1 with x86.deb and my-app-2 has no sources at all. Which is the same problem I have on my approach.

I think I would need to be able to set for <arch> instead of on arch on the sources, which would be in line with the build-on / build-for keywords. E.g.

parts:
  my-app:
    source:
      - for amd64: http://redacted/x86.deb
      - for arm64: http://redacted/arm64.deb
    source-type: deb
    plugin: dump

Did you have the compiler gcc-aarch64-linux-gnu on the arm64 machine ?

No, I don’t. And I don’t think I need it? I’m not building anything, just repackaging pre built artifacts.

Anyways, I happened to find another similar thread Specialize parts based on architecture , and there I got a hint about Advanced Grammar. Turns out what I needed was the to keyword. Now I have this, which works as expected:

parts:
  my-app:
    source:
      - on amd64 to amd64: http://redacted/x86.deb
      - on amd64 to arm64: http://redacted/arm64.deb
    source-type: deb
    plugin: dump

You meant ?

parts:
  my-app:
    source:
      - on amd64 to amd64: http://redacted/x86.deb
      - on amd64 to arm64: http://redacted/arm64.deb
    source-type: deb
    plugin: dump

I’d do something like this and manually unpack based on detection of arch at build time. Not tested, just to give you an idea, but we have done this in the past. It’s a bit manky but works.

parts:
  myapp:
    source: .
    plugin: nil
    override-build: |
      case $CRAFT_ARCH_BUILD_FOR in
        amd64)
          url=http://redacted/x86.deb
          ;;
        arm64)
          url=http://redacted/arm64.deb
          ;;
      esac
      wget -O foo.deb $url
      dpkg-deb -x foo.deb $CRAFT_PART_INSTALL/

Yes, sorry. I edited it.

Yep @eriff . This is indeed correct grammar .

1 Like