Skip to content

Allow optional features in projects #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
awvwgk opened this issue Nov 14, 2021 · 4 comments
Open

Allow optional features in projects #609

awvwgk opened this issue Nov 14, 2021 · 4 comments
Labels
specification Issue regarding fpm manifest and model

Comments

@awvwgk
Copy link
Member

awvwgk commented Nov 14, 2021

Motivation

Not all parts of a project are always needed. Many Fortran projects can be build with and without MPI support for example. Currently there is no mechanism to express such features in the package manifest. An option is to rely on preprocessor and set reasonable default using constructs like shown below:

#ifndef WITH_FEATURE
#define WITH_FEATURE 0
#endif

Since preprocessor might be the easiest way to express project local optional features, we could include such mechanism in fpm.

Specification

A project could declare a features table and export this to the project via a preprocessor variable:

[features]
qp.preprocessor = "WITH_QP"

When used as a dependency the feature could be toggled using

[dependencies]
test-drive = {git="https://github.com/fortran-lang/test-drive", features=["qp"]}

Prior Art

Cargo has features: https://doc.rust-lang.org/cargo/reference/features.html

Additional Information

A use case would be fortran-lang/test-drive#7
The mechanism required in fpm is similar to the one described in #577 (comment)

@plevold
Copy link

plevold commented Nov 19, 2021

Features would be a great to have in fpm! In my opinion there's two crucial features in Cargo's feature functionality that would be great to see in fpm too:

Optional dependencies:
When a dependency is marked as optional in Cargo this creates an implicit feature with the same name. In an ecosystem with lot's of packages available eliminating the need to build unused dependencies are just as important as conditionally building parts of the project source code itself.

Feature dependencies:
For a project with many optional features it might be necessary to specify that one feature requires other features to be enabled.

@rouson
Copy link
Contributor

rouson commented May 24, 2024

@awvwgk @plevold @ivan-pi @LKedward is anyone still interested in and/or working on supporting optional features or specifically making MPI optional? @ktras and I are looking into adding this. Does anyone have suggestions on how and where to start in the fpm source tree? I have only made very minor contributions to fpm and this will be @ktras's first time contributing to fpm if we pursue this. Any pointers are welcome.

@rouson
Copy link
Contributor

rouson commented May 24, 2024

@everythingfunctional suggested that we take a look at how Rust cargo does handles similar behaviors.

@ivan-pi
Copy link
Member

ivan-pi commented May 24, 2024

A preprocessor mechanism is supported already AFAIK. I think @perazz may be able to provide the most accurate comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
specification Issue regarding fpm manifest and model
Projects
None yet
Development

No branches or pull requests

4 participants