You are not logged in.

#1 2019-02-07 20:43:50

MatlertheGreat
Member
Registered: 2019-02-07
Posts: 3

[Solved]Optional dependencies that change build process

I'm trying to make a package that optionally depends on another program(its mason script checks whether or not it is installed).
My question is: how to package it so that correct 'build path' is chosen? How do official packages deal with it (I can install optional dependency after and the program just knows to use it)?

Last edited by MatlertheGreat (2019-02-07 21:14:02)

Offline

#2 2019-02-07 20:48:15

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 2,813

Re: [Solved]Optional dependencies that change build process

If you add it as a makedepends=() then it is guaranteed to be installed during the build.

If you also add it as an optdepends, users can uninstall it (e.g. makepkg -sri) after building the package, and pacman will tell them they could choose to reinstall it.

Does the meson build check only package the optional feature when build-time support was detected?


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2019-02-07 20:52:25

MatlertheGreat
Member
Registered: 2019-02-07
Posts: 3

Re: [Solved]Optional dependencies that change build process

eschwartz wrote:

Does the meson build check only package the optional feature when build-time support was detected?

Yes, it adds additional source files to compile. So the resulting program is either with or without the specific feature.

On the other hand, building with the feature included and having later removed the optional dependency will cause errors.

Last edited by MatlertheGreat (2019-02-07 20:56:09)

Offline

#4 2019-02-07 21:04:53

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 2,813

Re: [Solved]Optional dependencies that change build process

MatlertheGreat wrote:

Yes, it adds additional source files to compile. So the resulting program is either with or without the specific feature.

On the other hand, building with the feature included and having later removed the optional dependency will cause errors.

Then that is not an optional feature. You need to add it to depends. so that it is both compiled and enforced at runtime. Some projects have a plugin-based system that only loads additional features if their dependencies are present, but apparently that is not the case here.

So typically official packages opt to compile with more features, while Gentoo would add USE flags that let users determine whether to enable the features (and then add dependencies as relevant, change meson flags, etc.) and Debian might compile two copies of the program, one with the feature and one without.

In comparison, take vim for example. It optionally depends on python, ruby, lua, perl, and tcl for scripting support, but does so by dlopen() and if the optdepends is not available, then vim will log an error and just tell you there is no support for that scripting language. This is how to do optional depends correctly, but it requires that the source code support it.

Similarly, python applications will often have try/except clauses that attempt to import an optdepends and if that is not available, it will disable the feature.

Each language is a bit different in how it does things, but that is the general way things work.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2019-02-07 21:09:32

MatlertheGreat
Member
Registered: 2019-02-07
Posts: 3

Re: [Solved]Optional dependencies that change build process

eschwartz wrote:

and Debian might compile two copies of the program, one with the feature and one without.

Ah, I thought there was something similar in ArchLinux that I was missing.

Thank you very much for the explanation!

Offline

Board footer

Powered by FluxBB