More advanced grammar support

Advanced grammar is great to help with ensuring that things are declarative instead of imperative, but a key missing support is on the plugin-provided keys, like cmake-parameters, autotools-configure-parameters, meson-parameters, etc. This post is a request for snapcraft plugins to grow support for advanced grammar on keys they add to the snapcraft.yaml schema. Specifically I want to be able to do something like this:

  libaom:
    after: [gegl]
    source: https://aomedia.googlesource.com/aom
    source-type: git
    plugin: cmake
    build-snaps: [cmake]
    build-environment:
      - CFLAGS: -Ofast -g -pipe -flto
      - CXXFLAGS: -Ofast -g -pipe -flto
      - LDFLAGS: -flto
    cmake-parameters:
    - -DCMAKE_BUILD_TYPE=Release
    - -DCMAKE_INSTALL_PREFIX=/usr
    - -DENABLE_DOCS=OFF
    - -DENABLE_EXAMPLES=OFF
    - -DENABLE_TESTDATA=OFF
    - -DENABLE_TESTS=OFF
    - -DCONFIG_PIC=1
    - -DCONFIG_AV1_ENCODER=1
    - -DCONFIG_AV1_DECODER=1
    - -DCONFIG_MULTITHREAD=1

    # Needs advanced grammar support from Snapcraft that isn't available here
    - to armhf:
      - -DAOM_NEON_INTRIN_FLAG=-mfpu=neon

Because this isn’t available I have to do everything the plugin would do for me in an override-build block, which is prone to error in implementation, and is duplicating work that has already been done in Snapcraft upstream.

2 Likes

This should be possible to do in Snapcraft 7.x for core22, while we did not hook it all up, the logic is now detanlged from how parts and plugins work (possible as we removed support for try).

So while not there today, this is now within reach.

2 Likes

In case anyone fancies contributing https://github.com/snapcore/snapcraft/blob/main/snapcraft/parts/grammar.py is where this lives and you can probably see that adding here is simple, validation would also need touching https://github.com/snapcore/snapcraft/blob/main/snapcraft/projects.py#L458; the hardest part would be the tests

1 Like