Skip to content

feat: shared and static library targets #1138

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
wants to merge 60 commits into
base: main
Choose a base branch
from

Conversation

perazz
Copy link
Member

@perazz perazz commented May 12, 2025

🔧 Add support for building shared libraries via [library] type option

This PR introduces a new manifest option to control how libraries are built:

[library]
type = "shared"      # Build shared libraries (.so, .dylib, .dll + .lib/.def on Windows)
type = "static"      # Build a static archive (.a or .lib)
type = "monolithic"  # Default: build a single static archive for the root package and all dependencies

Key features for type = "shared":

  • Each package in the dependency graph is compiled into its own shared library (lib<package>.{so|dll|dylib}).
  • Properly resolves and links dynamic library dependencies via a topologically sorted package dependency graph.
  • Cross-platform support: .so on Linux, .dylib on macOS, .dll + .lib + .def on Windows.
  • Install integration: when install.library = true, shared libraries are installed to the lib/ directory.
  • fpm run automatically updates LD_LIBRARY_PATH (or platform equivalent) to find runtime libraries.
  • Naming convention is future-proof for later versioning extensions.

📚 documentation available at fortran-lang/fpm-docs#164

Address #681 #655, Supersede #1050.

cc: @certik @urbanjost @arteevraina @henilp105

@perazz perazz changed the title feat: shared library targets feat: shared and static library targets May 15, 2025
@perazz
Copy link
Member Author

perazz commented May 15, 2025

  • Replaced shared = true with a unified type = "monolithic" | "static" | "shared" string-based key
    → keep the manifest similar to meson.buildtype or cargo’s crate-type, we can later extend it to simultaneous configs.
  • Added tests for complex configurations
    • Empty libraries
    • Dependency graphs with circular/shared library references
  • On Windows (MinGW/Cygwin), generate import libraries (.lib / .dll.a) and definition files (.def)

cc: @zoziha

Copy link
Contributor

@zoziha zoziha left a comment

Choose a reason for hiding this comment

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

This looks really complex. Thank you for your work, @perazz . Since all the tests have passed, I think this PR can be merged after waiting for potential review comments from others.

Additionally, I've left some comments.

@perazz perazz force-pushed the dynamic_library branch from 2a47835 to c45ed06 Compare May 15, 2025 17:37
@perazz perazz force-pushed the dynamic_library branch from c45ed06 to 523c670 Compare May 15, 2025 17:43
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.

2 participants