Using CRAFT_ARCH_TRIPLET in apps.$app.environment.LD_LIBRARY_PATH

Hello.

I’m working on a snap that tries to be totally useful, yet extremely compact. The snap uses adapter: none to avoid using the shell on startup. I would like to bake the right value, at snap build time, into the environment section of each application.

I use this naive approach:

apps:
  hare:
    command: usr/bin/hare
    adapter: none
    environment:
      HARECACHE: $SNAP_USER_COMMON/cache
      PATH: "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH"
      LD_LIBRARY_PATH: "$SNAP_LIBRARY_PATH:$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET"

This results in the following meta/snap.yaml fragment:

apps:
  hare:
    command: usr/bin/hare
    environment:
      HARECACHE: $SNAP_USER_COMMON/cache
      PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
      LD_LIBRARY_PATH: $SNAP_LIBRARY_PATH:$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET
    adapter: none
    command-chain:
    - snap/command-chain/snapcraft-runner

As you can see LD_LIBRARY_PATH contains un-expanded $CRAFT_ARCH_TRIPLET. I could work around this by manually putting the right variable but that defeats the purpose of the variable, IMO.

There’s also a minor issue with the command chain. Snapcraft generates unneeded snap/command-chain/snapcraft-runner executable although nothing is referencing it.

All of this is on snapcraft 7.x/candidate.

Am I holding it wrong? What is the right way to achieve what I want (LD_LIBRARY_PATH set, no command chain)?

CC @mr_cal

1 Like

Thanks for the feedback on core22, @zyga . Your yaml looks correct. I believe those are both regressions in core22 for meta/snap.yaml:

  1. The arch triplet variable is not resolving.
  2. Command chain is defaulting to [snap/command-chain/snapcraft-runner]

I’ll look into both of these and follow up.

1 Like

Isn’t it $SNAPCRAFT_ARCH_TRIPLET?

1 Like

I think this changed in snapcraft 7 with the introduction of craftctl and friends. For the record the variable doesn’t work either.

1 Like

Erf just ran into $CRAFT_ARCH_TRIPLET not being set as well.

Could it be that $SNAP_USER_DATA isn’t set as well?

For snapcraft 7 and core22, $CRAFT_ARCH_TRIPLET and other $CRAFT_ variables are now properly evaluating in meta/snap.yaml. You can also continue to use $SNAPCRAFT_ variables.

Even if you’re using snapcraft 7, core18 and core20 snaps will still use $SNAPCRAFT_ variables.

2 Likes

See https://snapcraft.io/docs/parts-environment-variables for more details.

1 Like