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

Merged
merged 60 commits into from
May 16, 2025

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
@perazz
Copy link
Member Author

perazz commented May 16, 2025

Thank you for the review @zoziha. I will merge this one so we can release it with a new fpm version soon, to allow for battletesting this feature on the ground.

@perazz perazz merged commit fd1b1f8 into fortran-lang:main May 16, 2025
27 checks passed
@perazz perazz deleted the dynamic_library branch May 16, 2025 20:22
@perazz perazz mentioned this pull request May 16, 2025
2 tasks
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