Distributing Fortran projects for Windows / MacOS

Reliable software distribution is one of the major issues I faced when starting my open source projects. Especially proprietary operating systems like Windows and OSX have always been hard to support, because I don’t have those available in my local development environment. Yet I get plenty of requests for Windows and OSX versions.

I’m currently relying mostly on conda-forge to distribute Fortran programs, which does a great job to reliably create packages for Linux (x86_64, ppc64le and aarch64) and OSX (x86_64) based on GFortran 9 (there is also aarch64 for OSX available now, but I haven’t tried this toolchain yet).

I also explored homebrew for OSX a while ago, which always has been a dead-end for modern Fortran because of their GFortran 4.9 version requirement to build the bottled packages. Packaging for OSX is particular difficult because you cannot statically link binaries like on Linux, distribution outside of a package manager therefore always seemed unfeasible for me.

Distribution for Windows has been an issue so far, conda-forge offers either classic flang 5 with LLVM or GFortran 5 with MinGW, which left me stuck with a similar issue I faced with homebrew: modern Fortran projects don’t compile with this setup.

What is your experience with packaging Fortran projects? Have you found a good solution for creating distributions for Windows?


There are two distinctions:

  • Cross-platform binary package manager: I also use Conda . To fix Windows, cannot you simply compile your Conda packages at conda-forge using a more modern compiler?

  • Cross-platform source package manager: we are hoping fpm will fill this role for Fortran. There are other source package managers such as Spack, which is planning to add Windows support.

I’m looking for a binary package manager, having users compile on their system opens a whole new can of worms :wink:. Providing source code distributions for developers works perfectly fine with fpm or meson so far.

I don’t think they have newer compilers packaged. You can check the Fortran compilers available here:

I see. We should package the latest GFortran for Windows.

Btw, one of the goals of LFortran is to have a first class support on Windows and good interoperation with MSVC. But we are not there yet for production codes.

1 Like

It seems like we are not yet there for reliably distributing Fortran software for Windows, are we? From my limited knowledge on Windows there seem to exist at least several other packaging ecosystems beside conda as well:

But maybe my assumption that one is using a package manager on Windows is a naive one.

Let’s rephrase the question and concentrate on a concrete example:
How would one package fpm for MacOS or Windows to reach a large amount of users?

I think the answer for MacOS is simple; Homebrew.

I did try using Linuxbrew for a while, I guess a Formula like this might be able to build fpm:

class Fpm < Formula
  desc "Fortran Package Manager (fpm)"
  homepage "https://fpm.fortran-lang.org"
  url "https://github.com/fortran-lang/fpm/releases/download/v0.1.4/fpm-0.1.4.f90"
  sha256 "06c139b16cf871e06cd3ea3be93c1ddbb5a94e4546a0c64822d10dc87333ac0c"
  license "MIT"

  depends_on "gcc" # for gfortran
  fails_with :gcc => "4"
  fails_with :gcc => "5"
  fails_with :gcc => "6"
  fails_with :clang

  def install
    # ENV.fc is not defined and setting it up with ENV.fortran will yield default gfortran
    ENV["FC"] = ENV.cc.gsub /gcc/, "gfortran"
    system ENV["FC"], "fpm-0.1.4.f90", "-o", "fpm"
    bin.install "fpm"

  test do
    system "#{bin}/fpm", "--version"

Selecting a Fortran compiler other than GCC 4 required me a bit of hacking… not sure if this is still an issue in brew.

1 Like

Is the intel fortran compiler a possible option for windows?

As far as I know the answer is not yet. There has been discussions on the conda-forge gitter channel regarding the oneAPI compilers with no clear outcome yet.

Anaconda seems to be using Intel Parallel Studio to build most of their Windows stack and I know of many communities that use Intel oneAPI already to build their packages for Windows, MacOS and Linux, but this doesn’t mean it is automatically working for open source community at conda-forge as well.

Related gitter thread: conda-forge/conda-forge-compilers - Gitter

1 Like

For Windows distributing a MinGW packages might be the way to go.

The PKGBUILD would look somewhat like this:

pkgdesc="Fortran package manager (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran")

build() {
  cd "${srcdir}"
  local _build="build_${CARCH}"
  local _fc="${MINGW_PREFIX}/bin/gfortran"
  # Compiler flags need some tweaking
  local _fflags="-J ${_build}"

  mkdir -p "${_build}"
  ${_fc} ${_fflags} "fpm-${pkgver}.f90" -o "${_build}/fpm"

package() {
  cd "${srcdir}/build_${CARCH}"
  install -Dm755 fpm "${pkgdir}"${MINGW_PREFIX}/bin/fpm

One can build and install fpm using the following commands (PKGBUILD file is in the working directory):

MINGW_INSTALLS=mingw64 makepkg-mingw
pacman -U mingw-w64-x86_64-fpm-0.1.4-1-any.pkg.tar.zst