Our buildsystem outputs distro-independent tarballs which are then used as input for a packaging build that create distro-specific packages (deb, rpm, etc.). Our tarballs (apart from libc6) are self-contained, i.e. all SOs are shipped and RPATHs are set correctly. We are adding snap creation to this setup but I’m running into problems while creating the armhf and arm64 packages.
We are running snapcraft in a 16.04-based docker container and building the x86 and amd64 snaps works fine. However, during both armhf and arm64 building we get the following error:
Could not find a required package in 'build-packages': libc6-dev-armhf-cross
Then I try to add it:
parts:
mypart:
stage-packages: [libc6]
build-packages:
- to armhf: [libc6-dev-armhf-cross]
Now the error becomes:
Could not find a required package in 'build-packages': libc6-dev-armhf-cross:armhf
We are calling snapcraft as snapcraft --target-arch=armhf. I was under the impression that this package would be automatically added to build-packages, but even adding it explicitly fails in a weird way. What’s the solution here? Can we avoid dev packages completely? We don’t use snapcraft to “build” the application (nor want to), we are just using the dump plugin, so we shouldn’t need these (unless I’m missing something). Thanks for any input.
The error now becomes gcc-aarch64-linux-gnu. I tried things like this, always staging what it complained about but eventually ran into the first error again. But all around it’s weird that it requires a compiler.
Thanks. I tried that again but I’m getting the same error (Could not find a required package in 'build-packages': gcc-aarch64-linux-gnu). I verified that I’m building the right commit, just to be sure. There is no stage-packages section.
I wonder if the clue here is Could not find a required package in 'build-packages': libc6-dev-armhf-cross:armhf the fact that it’s mentioning :armhf which is probably not a supported architecture inside your docker image. So it can’t find armhf packages in the container .
Thanks for the suggestion, I’m trying it right now (though I find it weird that when I remove all the stage-packages, gcc becomes required as a build-package).
OK, interesting. We are mirroring archive.ubuntu.com and we’re using our mirror in the source.list. I’ve added the armhf and arm64 architectures as you suggested, but now I’m getting this:
E: Failed to fetch https://<our server>/cache-ubuntu-archive/dists/xenial/main/binary-armhf/Packages 404 Not Found
E: Failed to fetch https://<our server>/cache-ubuntu-archive/dists/xenial-updates/main/binary-armhf/Packages 404 Not Found
E: Failed to fetch https://<our server>/cache-ubuntu-archive/dists/xenial-backports/main/binary-armhf/Packages 404 Not Found
E: Failed to fetch https://<our server>/cache-ubuntu-security/dists/xenial-security/main/binary-armhf/Packages 404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
Still fails with: Could not find a required package in 'build-packages': libc6-dev-arm64-cross (again, nothing staged nor added to build-packages explicitly).
I also tried the commit where we added to & on statements failed the same way:
- stage-packages: [libc6]
- # build-packages:
- # - to armhf: [libc6-dev-armhf-cross, gcc-arm-linux-gnueabihf]
- # - to amd64: [libc6-dev-amd64-cross]
+ stage-packages:
+ - on amd64:
+ - to armhf: ["libc6:armhf"]
+ - to arm64: ["libc6:arm64"]
+ - else: ["libc6"]
For my cross compiling setup there were two things I found necessary for it to work.
Make sure you add the repository where the libs for your architecture. For me I do this in my CI script (not in my snapcraft file, although maybe you can find a way to do that).
In core22 the target arch is available in step override scriptlets as $CRAFT_TARGET_ARCH ($SNAPCRAFT_TARGET_ARCH also works for backwards compatibility). The current version can be recovered by invoking craftctl get version (or using $SNAPCRAFT_PROJECT_VERSION).
Not that I’m aware of. $CRAFT_TARGET_ARCH is the variable that craft-parts understands, and Snapcraft also sets $SNAPCRAFT_TARGET_ARCH on top of that, but mostly for compatibility reasons. For new projects, $CRAFT_TARGET_ARCH is the preferred variable to use.