Snapcraft 7.1.0 fails to find stage package when cross-compiling

Bug #1983009 reported by Koen Vervloesem
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Fix Released
Undecided
Callahan Kovacs

Bug Description

I tried the architectures support to cross-compile a snap for arm64 and armhf. So I added the following lines to my snapcraft.yaml:

```yaml
architectures:
  - build-on: amd64
    build-for: amd64
  - build-on: [amd64, arm64]
    build-for: arm64
  - build-on: [amd64, armhf]
    build-for: armhf
```

After running `snapcraft` on my amd64 machine, the amd64 snap is built correctly, but the arm64 and armhf builds fail with the error **Stage package not found in part 'theengs-gateway': bluez.**

Previously (with Snapcraft 7.0) I built the arm64 snap on a jammy LXC container on an arm64 machine, and the armhf snap on an a jammy LXC container on an armhf machine, and this just worked: the stage package bluez was found and the resulting snaps installed and ran fine locally. Building the arm64 snap on arm64 with Snapcraft 7.1 also works. So it seems something is going wrong with stage packages when cross-compiling.

Here's the project:

https://github.com/theengs/gateway-snap

Here's the pull request where I try to use the architectures support:

https://github.com/theengs/gateway-snap/pull/7

Relevant part of the logs:

```
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:42.596 Requested stage-packages: ['bluez']
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.491 Marking bluez (and its dependencies) to be fetched
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.492 Stage package not found in part 'theengs-gateway': bluez.
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 Traceback (most recent call last):
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 846, in _fetch_stage_packages
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 fetched_packages = packages.Repository.fetch_stage_packages(
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/packages/deb.py", line 261, in wrapped
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 return method(*args, **kwargs)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/packages/deb.py", line 588, in fetch_stage_packages
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 apt_cache.mark_packages(set(package_names))
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/packages/apt_cache.py", line 302, in mark_packages
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 raise errors.PackageNotFound(name_arch)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 craft_parts.packages.errors.PackageNotFound: Package not found: bluez.
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 During handling of the above exception, another exception occurred:
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 Traceback (most recent call last):
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/snapcraft/parts/parts.py", line 170, in run
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 aex.execute(action, stdout=stream, stderr=stream)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 301, in execute
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 self._executor.execute(actions, stdout=stdout, stderr=stderr)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 126, in execute
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 self._run_action(act, stdout=stdout, stderr=stderr)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/executor.py", line 189, in _run_action
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 handler.run_action(action, stdout=stdout, stderr=stderr)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 161, in run_action
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 state = handler(step_info, stdout=stdout, stderr=stderr)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.496 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 182, in _run_pull
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.497 fetched_packages = self._fetch_stage_packages(step_info=step_info)
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.497 File "/snap/snapcraft/x1/lib/python3.8/site-packages/craft_parts/executor/part_handler.py", line 854, in _fetch_stage_packages
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.497 raise errors.StagePackageNotFound(
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.497 craft_parts.errors.StagePackageNotFound: Stage package not found in part 'theengs-gateway': bluez.
2022-07-27 20:05:43.822 :: 2022-07-27 20:05:43.497 Full execution log: '/tmp/snapcraft.log'
2022-07-27 20:05:45.095 Failed to execute pack in instance.
2022-07-27 20:05:45.099 Traceback (most recent call last):
2022-07-27 20:05:45.099 File "/snap/snapcraft/7986/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 452, in _run_in_provider
2022-07-27 20:05:45.099 instance.execute_run(cmd, check=True, cwd=output_dir)
2022-07-27 20:05:45.099 File "/snap/snapcraft/7986/lib/python3.8/site-packages/craft_providers/lxd/lxd_instance.py", line 221, in execute_run
2022-07-27 20:05:45.099 return self.lxc.exec(
2022-07-27 20:05:45.099 File "/snap/snapcraft/7986/lib/python3.8/site-packages/craft_providers/lxd/lxc.py", line 326, in exec
2022-07-27 20:05:45.099 return runner(final_cmd, **kwargs) # pylint: disable=subprocess-run-check
2022-07-27 20:05:45.099 File "/snap/snapcraft/7986/usr/lib/python3.8/subprocess.py", line 516, in run
2022-07-27 20:05:45.099 raise CalledProcessError(retcode, process.args,
2022-07-27 20:05:45.099 subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-theengs-gateway-on-amd64-for-arm64-519419', '--cwd', '/root/project', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'SNAPCRAFT_MANAGED_MODE=1', 'SNAPCRAFT_BUILD_INFO=1', 'SNAPCRAFT_IMAGE_INFO={"build_url":"https://github.com/theengs/gateway-snap/actions/runs/2749306160"}', 'snapcraft', 'pack', '--enable-manifest', '--build-for', 'arm64']' returned non-zero exit status 1.
```

I have attached the full logs.

Tags: craft-1216
Revision history for this message
Koen Vervloesem (koen-vervloesem) wrote :
Revision history for this message
Callahan Kovacs (mr-cal) wrote :

I’m seeing the same behavior:
- When building on amd64 with core20, snapcraft will download bluez from the amd64 repository.
- When building on amd64 with core22, snapcraft attempts to download bluez from the arm64 repository, then fails because the arm64 repository was not added.

I'll follow up @sergiusens to see if core22 should follow core20's behavior.

Minimal reproducers:
core20:
```
name: hello-world
version: "1.0"
summary: Test staging packages during cross-compilation.
description: test
grade: stable
confinement: strict

base: core20
architectures:
  - build-on: amd64
    run-on: arm64

parts:
  hello-world:
    plugin: dump
    source: src
    stage-packages:
      - bluez
```

core22:
```
name: hello-world
version: "1.0"
summary: Test staging packages during cross-compilation.
description: test
grade: stable
confinement: strict

base: core22
architectures:
  - build-on: amd64
    build-for: arm64

parts:
  hello-world:
    plugin: nil
    source: .
    stage-packages:
      - bluez
```

Callahan Kovacs (mr-cal)
tags: added: craft-1216
Revision history for this message
Callahan Kovacs (mr-cal) wrote :

For the short term, our plan is to keep the behavior in core22 the same as core20.
This means that staged packages will come from the build-on repository, not the build-for repository.
I'll create a PR to fix this regression.

Changed in snapcraft:
assignee: nobody → Callahan Kovacs (mr-cal)
status: New → Confirmed
Callahan Kovacs (mr-cal)
Changed in snapcraft:
status: Confirmed → In Progress
Changed in snapcraft:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.