Skip to content

Conversation

perazz
Copy link
Member

@perazz perazz commented Sep 11, 2025

This PR implements comprehensive Features and Profiles support, enabling conditional compilation, platform-specific configurations, and dependency feature propagation.

Overview

This implementation adds two major capabilities to FPM:

  1. Features: Named sets of conditional build configurations that can be selectively enabled.
  2. Profiles: Predefined combinations of features for common build scenarios

Key Features

✅ Feature System

  • Complete control: Features are complete representations of an fpm manifest, allowing full customization
  • Platform/compiler targeting: Features can be scoped to specific platforms or compilers:
[features]
my_feat.flag = ["-O3"] # Always applied
my_feat.gfortran.flag = ["-123"] # gfortran only, all OSes
my_feat.windows.flag = ["-DWIN32"] # all compilers, Windows-only
my_feat.macos.ifx.flag = ["..."] #
my_feat.ifx.macos.flag = ["..."] # specific compiler/OS combinations
  • Conditional compilation: Enable/disable code paths with preprocessor macros.
  • Compiler flags: Add feature-specific compilation flags
  • Dependencies: Conditionally include dependencies based on active features
[features]
with_mpi.dependencies.mpi = ["*"]
with_mpi.preprocess.cpp.macros = ["HAVE_MPI"]
  • Dependency feature propagation: Pass features to dependencies
[dependencies]
# Request fortran-regex with optional `mpi` feature enabled
fortran-regex = { git="https://github.com/perazz/fortran-regex", tag="1.1.2", features = ["mpi"]}

✅ Profile System

  • Predefined configurations: Named combinations of features (e.g., development = ["debug","with_blas"])
  • Default profiles: Built-in debug and release profiles (backward compatible; can be overridden)
  • CLI integration: --profile <name> and --features <list> command line options
[features]
parallel_cpu.dependencies.mpi = "*"
parallel_cpu.dependencies.openmp = "*"
gpu_support.macos.flags = ["-framework OpenCL"]
gpu_support.unix.link = ["OpenCL"]
[profiles]
parallel = ["parallel_cpu", "gpu_support"]

✅ Advanced Capabilities

  • Nested targeting: feature.os or feature.compiler or feature.compiler.os or feature.os.compiler syntax for fine-grained control
  • Dependency features: Specify which features to enable in dependencies
  • Preprocessing integration: CPP macro definitions and conditional compilation
  • Validation: Comprehensive error checking for invalid feature/profile combinations

Usage Examples

Basic Feature Definition

[features]
debug.flags = "-g"
debug.preprocess.cpp.macros = "DEBUG"

release.flags = "-O3"
release.preprocess.cpp.macros = "RELEASE"

#  Platform/Compiler Specific Features

[features]
debug.gfortran.flags = "-Wall -fcheck=bounds"
debug.linux.preprocess.cpp.macros = "LINUX_BUILD"

#Dependency Features

[features]
mpi_support.dependencies.mpi_lib = { version = "*", features = ["parallel"] }

# Profiles

[profiles]
development = ["debug"]
production = ["release", "openmp"]

CLI Usage

Enable specific features

  fpm run --features debug,openmp

Use a profile

  fpm run --profile development

Build with dependency features

fpm build --features mpi_support

Backward Compatibility

  • ✅ Fully backward compatible: Existing fpm.toml files work unchanged
  • ✅ Default behavior preserved: No features => define default debug and release features and profiles
  • ✅ Optional sections: [features] and [profiles] sections are completely optional

Testing

  • Core implementation + comprehensive tests
  • Integration tests: Multi-platform CI testing via ci/test_features.sh
  • Unit tests: Feature parsing, validation, and merging
  • Example packages: Real-world usage demonstrations
  • CLI tests: Command-line interface validation

This implementation provides a solid foundation for conditional compilation and advanced build configurations in FPM while maintaining full backward compatibility with existing projects.

@perazz perazz marked this pull request as ready for review September 11, 2025 17:18
@perazz perazz requested a review from Copilot September 15, 2025 07:32
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements comprehensive features and profiles support for FPM, enabling conditional compilation, platform-specific configurations, and dependency feature propagation. The implementation adds two major capabilities: features (named sets of conditional build configurations) and profiles (predefined combinations of features).

Key changes include:

  • Complete feature system with platform/compiler targeting and conditional compilation
  • Profile system for predefined feature combinations
  • Dependency feature propagation and specification
  • Command-line integration with --features and --profile options

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/fpm_command_line.f90 Adds --features CLI option parsing and validation
src/fpm/manifest/profiles.f90 Implements new profile configuration system
src/fpm/manifest/feature_collection.f90 Adds feature merging, validation, and duplicate checking
test files Updates and adds comprehensive test coverage
example packages Demonstrates feature and profile functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant