canonical / charmcraft

Collaborate, build and publish charmed operators for Kubernetes, Linux and Windows.
Apache License 2.0
64 stars 66 forks source link

build-for architecture 'all' for arch-independent charms not supported #1698

Open lengau opened 3 weeks ago

lengau commented 3 weeks ago

Bug Description

The following should be a valid platform description for a charm:

platforms:
  all:
    build-on: [amd64]
    build-for: [all]

When included, the user should receive a warning from charmcraft that it does not validate that charms are architecture independent but allow the charm to build anyway.

To Reproduce

charmcraft pack

Environment

n/a

charmcraft.yaml

type: charm

base: ubuntu@24.04
platforms:
  all:
    build-on:
      - amd64
    build-for: all

parts:
  charm:
    plugin: dump
    source: .

Relevant log output

2024-06-10 14:22:40.681 Starting charmcraft, version 3.0.0.post46+ga44c03e
2024-06-10 14:22:40.681 Log verbosity level set to BRIEF
2024-06-10 14:22:40.681 Configuring application...
2024-06-10 14:22:40.681 Preparing application...
2024-06-10 14:22:40.682 Build plan: platform=None, build_for=None
2024-06-10 14:22:40.683 Loading project file '/home/lengau/Work/Code/charm-nova-compute/charmcraft.yaml'
2024-06-10 14:22:40.684 Warning: use of 'prime' in a charm part is deprecated and no longer works, see https://juju.is/docs/sdk/include-extra-files-in-a-charm
2024-06-10 14:22:40.715 Architecture 'all' is not supported.
2024-06-10 14:22:40.716 Traceback (most recent call last):
2024-06-10 14:22:40.716   File "/snap/charmcraft/3838/lib/python3.10/site-packages/craft_application/application.py", line 508, in run
2024-06-10 14:22:40.716     self.services.project = self.get_project(
2024-06-10 14:22:40.716   File "/snap/charmcraft/3838/lib/python3.10/site-packages/craft_application/application.py", line 303, in get_project
2024-06-10 14:22:40.716     yaml_data = self._transform_project_yaml(yaml_data, build_on, build_for)
2024-06-10 14:22:40.716   File "/snap/charmcraft/3838/lib/python3.10/site-packages/craft_application/application.py", line 601, in _transform_project_yaml
2024-06-10 14:22:40.716     self._expand_environment(yaml_data=yaml_data, build_for=build_for)
2024-06-10 14:22:40.716   File "/snap/charmcraft/3838/lib/python3.10/site-packages/craft_application/application.py", line 629, in _expand_environment
2024-06-10 14:22:40.716     info = craft_parts.ProjectInfo(
2024-06-10 14:22:40.716   File "/snap/charmcraft/3838/lib/python3.10/site-packages/craft_parts/infos.py", line 99, in __init__
2024-06-10 14:22:40.716     self._set_machine(arch)
2024-06-10 14:22:40.716   File "/snap/charmcraft/3838/lib/python3.10/site-packages/craft_parts/infos.py", line 333, in _set_machine
2024-06-10 14:22:40.716     raise errors.InvalidArchitecture(arch)
2024-06-10 14:22:40.716 craft_parts.errors.InvalidArchitecture: Architecture 'all' is not supported.
2024-06-10 14:22:40.716 Make sure the architecture name is correct.
2024-06-10 14:22:40.716 Recommended resolution: Make sure the architecture name is correct.
2024-06-10 14:22:40.716 Full execution log: '/home/lengau/.local/state/charmcraft/log/charmcraft-20240610-142240.681125.log'
mr-cal commented 3 weeks ago

Snapcraft is also missing build-for: [all] in core24: https://forum.snapcraft.io/t/architectures/4972/25

I wonder if this is worth upstreaming to craft-applicaiton

lengau commented 3 weeks ago

@mr-cal Or perhaps to craft-platforms as a valid destination architecture?