multipass icon indicating copy to clipboard operation
multipass copied to clipboard

No Snapcraft support on Apple Silicon

Open moughxyz opened this issue 2 years ago • 25 comments

multipass find lists the following:

Image                       Aliases           Version          Description
18.04                       bionic            20220104         Ubuntu 18.04 LTS
20.04                       focal,lts         20220118         Ubuntu 20.04 LTS
21.04                       hirsute           20220118         Ubuntu 21.04
21.10                       impish            20220118         Ubuntu 21.10
anbox-cloud-appliance                         latest           Anbox Cloud Appliance
charm-dev                                     latest           A development and testing environment for charmers
minikube                                      latest           minikube is local Kubernetes

But I can't use any of them with snapcraft:

snap/snapcraft.yml: base: core18

$ snapcraft
Launching a VM.
Build environment is in unknown state, cleaning first.
info failed: The following errors occurred:
instance "snapcraft-my-snap-name" does not exist
launch failed: Unable to find an image matching "core18". Please use `multipass find` for supported remotes and images.
An error occurred with the instance when trying to launch with 'multipass': returned exit code 2.
Ensure that 'multipass' is setup correctly and try again.

Same result if I change base to bionic, '18.04', or anything else. What am I missing? How do I get snapcraft:core18 image?


macOS 12.0.1, arm64 multipass 1.8.1+mac multipassd 1.8.1+mac snapcraft, version 5.0

moughxyz avatar Jan 20 '22 19:01 moughxyz

Hi @moughxyz, we currently don't have images to support Snapcraft natively on the M1.

A workaround is to use remote-build or launching a "builder" (multipass launch -c8 -m8G -d40G -nbuilder), set up LXD (multipass exec builder -- sudo lxd init --auto), mount your code (multipass mount …) and and use snapcraft --use-lxd inside.

Sorry for the hoops, we'll be working on streamlining this in the future.

Saviq avatar Jan 20 '22 19:01 Saviq

Ah gotcha, thanks.

moughxyz avatar Jan 20 '22 20:01 moughxyz

Btw, I had this all running fine on my M1 before I upgraded snapcraft and multipass. If I want to go back to a workable configuration where I can get back core18, would I downgrade snapcraft, multipass, or both?

moughxyz avatar Jan 20 '22 20:01 moughxyz

@moughxyz not really possible… Those images just don't exist for ARM64…

Saviq avatar Jan 20 '22 20:01 Saviq

Right I was using the x64 images I believe. Would I just require the x64 version of snapcraft/multipass?

moughxyz avatar Jan 20 '22 20:01 moughxyz

@moughxyz you'd require the x64 version of your MacBook, too :D

We don't currently support cross-architecture instances (and Rosetta can't help here).

Saviq avatar Jan 20 '22 20:01 Saviq

Lol I'm not following—I had this working just fine a few hours ago. But my M1 was bootstrapped from a backup of my x64 MacBook. But even on my M1 I had no issues building an x64 snap.

moughxyz avatar Jan 20 '22 20:01 moughxyz

@moughxyz o.O… I just can't see how… The CPU can't virtualize (different to emulation) a x86_64 machine… Just for the fun of it, I tried installing 1.7.2 which had no arm64 support, was all x86_64, and it expectedly failed starting the VM:

[2022-01-20T22:08:31.087] [error] [prompt-dolphin] hv_vm_create HV_ERROR (unspecified error)

Similarly, with 1.8.1, ran under arch -x86_64, both the hyperkit and qemu backends failed:

[2022-01-20T22:15:47.473] [error] [stirred-ostrich] hv_vm_create HV_ERROR (unspecified error)
[2022-01-20T22:16:38.034] [warning] [radiant-groundhog] qemu-system-x86_64: -accel hvf: Error: HV_ERROR

We would love to know how you achieved building x86 snaps on the M1…

Saviq avatar Jan 20 '22 21:01 Saviq

Sorry, I meant amd64, not x64. I'm mixed up because our Windows builds were suffixed x64 and our Snap builds were suffixed amd64. So, to clarify, I've been building amd64 snap builds on my M1 Mac for a few months now.

Although I'm reading that amd64, x64, and x86_64 are pretty much the same thing? If that's the case then you can see here that I've definitely been building amd64 snaps on M1 since version 3.9.12 when arm64 mac builds were first introduced.

moughxyz avatar Jan 20 '22 21:01 moughxyz

@moughxyz yes, the same architecture is often referred to by any of these strings… It doesn't help

If you have any logs from a build that worked, we'd love to see it. So far we've not had any evidence that this could work, and we have a lot to show that it doesn't…

Saviq avatar Jan 21 '22 08:01 Saviq

@moughxyz all in all, the only thing that comes to mind was that you used snapcraft remote-build, which builds on Launchpad servers.

Saviq avatar Jan 21 '22 13:01 Saviq

I'm honestly not sure how electron-builder goes about packaging snaps, but I tested electron-builder --linux --x64 -c.linux.target=snap just now and it builds the snap just fine, using all the latest versions of snapcraft/multipass.

However looking at the logs it doesn't appear to be spawning anything snapcraft/multipass related. It also builds fine with networking disabled on my device, so I don't think it's remote-build.

This appears to be the build script: https://github.com/electron-userland/electron-builder/blob/master/packages/app-builder-lib/src/targets/snap.ts

The Snapcraft docs say

This will work even if you are running Mac or Windows. electron-builder is capable of building Linux snaps from any operating system.

So I'm not sure what the source of the magic is.

moughxyz avatar Jan 21 '22 18:01 moughxyz

@moughxyz Ah! electron-builder just packages things together. It has a static runtime that it downloads (and caches) and bundles into a snap package. No Snapcraft or Multipass involved.

Mystery solved!

Saviq avatar Jan 21 '22 18:01 Saviq

Ahhh 😅 So with that said, could I then build arm64 builds via this same mechanism?

moughxyz avatar Jan 21 '22 18:01 moughxyz

@moughxyz arm64 you can build natively, since the M1 is a arm64 CPU… and yes, electron-builder will work cross architecture because it doesn't actually execute any code in the target architecture.

Saviq avatar Jan 21 '22 18:01 Saviq

Hmm, well I suppose this is what brought us here in the first place. When running electron-builder --linux --arm64 -c.linux.target=snap, it starts to use Snapcraft, and brings up the original error "Unable to find an image matching "core18"

Perhaps a missing runtime? I'll probably have to take that up with them.

moughxyz avatar Jan 21 '22 18:01 moughxyz

Ah yes, they may be falling back to building through Snapcraft in this case.

Saviq avatar Jan 21 '22 19:01 Saviq

Hi 👋 I have still the error that the snapcraft:core18/20 images are not available on M1 Mac. For building snaps remote-build works fine, but for debugging it is not enough.

What would be needed to build those images?

0xE282B0 avatar Mar 15 '22 15:03 0xE282B0

Hi @0xE282B0 for now you can launch a beefy instance, mount your code and use snapcraft --use-lxd inside it. We're working on getting those images up for native experience.

Saviq avatar Mar 15 '22 15:03 Saviq

last comment was basically three months ago. How is this going? Is there any release date scheduled for releasing the images?

matheushent avatar Jun 10 '22 13:06 matheushent

Hi @matheushent,

This depends on a different team at Canonical and a fix has to be SRU'd to other series for this to be enabled. See https://bugs.launchpad.net/ubuntu/+source/livecd-rootfs/+bug/1966636 for more detail. I have asked what the status of the SRU is though.

townsend2010 avatar Jun 10 '22 13:06 townsend2010

@townsend2010 thank you for the quick response mate.

matheushent avatar Jun 10 '22 14:06 matheushent

Would you have any idea how to use remote-build with electron-builder? I'm currently having a hard time putting together arm64 snaps on x64 machines in GitHub CI environments for an Electron app.

I get snapcraft does not currently support building arm64 on amd64, which is fair enough, but electron-builder as mentioned above uses static assets and doesn't need to actually "build", so not sure what the source of this error is.

moughxyz avatar Jun 13 '22 15:06 moughxyz

@townsend2010 The issue you mention seems to have been fixed already. Is there any news on this issue? Thank you!

anpep avatar Jul 05 '22 12:07 anpep

Hi @anpep,

The issue I mentioned is fixed for Jammy, but it needs to be SRU'd to Bionic and Focal in order to support building core18 and core20 based snaps respectively. Until the SRU's are complete and these arm64-based images are built and released, we can't support it.

townsend2010 avatar Jul 06 '22 12:07 townsend2010

any updates on this? trying to build a linux arm64 on apple silicon and it still fails today

DaveFlashNL avatar Nov 17 '22 16:11 DaveFlashNL

Hey @DaveFlashNL,

The SRU's I mentioned before for Bionic and Focal have been accepted and released, but still waiting on the CPC Team to publish these artifacts for those series. I will follow up with them for when they may have an ETA on when this will happen.

townsend2010 avatar Nov 17 '22 16:11 townsend2010

ah ok. @townsend2010 because we have a deadline on a project, and I currently can't even test the amd64 linux binaries (which i can build through node with the electron builder on apple silicon), as linux, or at least ubuntu (in a vm), has no emulation support for x86_64/amd64 as far as i can see, unlike windows on arm or macos on apple silicon.

DaveFlashNL avatar Nov 17 '22 16:11 DaveFlashNL

oh i actually could test, that is if snap images run on asahi linux, but asahi linux is currently broken on my machine because apple OS upgrades mess with the bootloader, but from their github, that should be fixable, tho I haven't had time yet to do so.

DaveFlashNL avatar Nov 17 '22 16:11 DaveFlashNL

Hey @DaveFlashNL,

I'm a little confused. Are you trying to build an arm64-based Snap or are you just trying to test if an arm64-based snap works on arm64-based Ubuntu?

townsend2010 avatar Nov 17 '22 16:11 townsend2010