Custom environment variables for parts


#1

uboot uses the KBuild build system in a slightly unusual way. To cross-compile for arm64, it’s necessary to set ARCH to arm even when the kernel architecture is arm64. For snapcraft this case is not automatically detectable.
I proposed a PR to handle this case by picking up the value from the environment - that’s the same approached already done for the CROSS_COMPILE variable for kbuild/ kernel parts. Unfortunately there’s a catch: this won’t work on Launchpad builds where custom environment variables can’t be set at all.

@ondra suggested in a discussion on IRC a generic mechanism for environment variables in parts might be useful. It could handle both of these cases. And there might be other plugins that would benefit from that.

The make plugin has make-parameters which effectively makes it possible to add environment variables and arbitrary options. An argument could be made that kbuild could do the same - or, conversely, a more generic option could be used for all plugins, including make.

More arguments welcome. Especially if we could find other cases that would potentially make use of such a feature.


#2

Ability to define in snapcraft.yaml parts env variables which would be then honoured by plugin would be nice way to alter otherwise sometimes hard set behaviour of build systems. So I definitely think this could be useful and if not used should not cause any alteration to existing behaviour.


#3

isnt that there already when using the “environment:” keyword as a global statement in your snapcraft.yaml ?


#4

That doesn’t affect the build environment.


#5

if you talk about what I think, this is for run time, and we should have exactly same for build time


#6

We do really need this for build time. I’m trying to build a package that uses meson and needs CFLAGS and LDFLAGS set. I can’t find a way to accomplish this outside of environment variables.


#7

I can’t see a reason not to support this. We’re already in talks (and implementation?) of supporting small scripts to facilitate customization on specific build steps for parts. Having an environment section to allow for custom environment variables seems aligned with that and pretty nice and straightforward.


#8

If this is going to be supported, I would like to request that it not be plugin-specific. For example, Autotools and Meson both benefit from it, so rather than implement it twice, for each of those, it makes sense to implement once on the next-layer-up for all plugins to inherit.


#9

When implemented it would be a core feature of snapcraft so all plugins would benefit from it.


#10

This should be called build-environment to not squat on a potentially useful generic name of environment.


#11

Curious if this was implemented as I’ve been searching all over for something like this. I need to add some parameters to the make section of my autotools build.


#12

It hasn’t been implemented yet. So far it’s just a proposal.


#13

@sergiusens How’s that in your roadmap? Feels like an easy bite.


#14

Bump…

This would be a great feature. I have a case where I want to compile with OpenMPI and gcc-6 instead of gcc, and therefore would like to set CC and OMPI_CC environment variables in the build environment.