Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: awvwgk/setup-fortran@main
- uses: fortran-lang/setup-fortran@v1
id: setup-fortran
if: runner.os != 'Windows'
# We aren't using this yet, and takes 4 mins to setup on Windows
# On macOS this causes a bug to be hit on macos-13+ and CMake, gcc14 may fix
with:
compiler: gcc
version: 12
# setup-fortran installs MinGW via choco, which only edits the machine PATH
# registry; GitHub Actions doesn't reload that into the running job. Put the
# bin dir on PATH so CMake can find gcc/gfortran (see pi-fortran override).
- name: Add MinGW to PATH (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$bin = Split-Path (Get-ChildItem C:\ProgramData\chocolatey\lib\mingw -Recurse -Filter gfortran.exe | Select-Object -First 1).FullName
"$bin" | Out-File -FilePath $env:GITHUB_PATH -Append -Encoding utf8
- uses: astral-sh/setup-uv@v8.0.0
- run: uvx nox -s ${{ matrix.session }}

Expand Down
3 changes: 1 addition & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"hello-pybind11",
"hello-cython",
"hello-cmake-package",
"pi-fortran",
]
if not sys.platform.startswith("win"):
hello_list.append("pi-fortran")
long_hello_list = [
*hello_list,
"pen2-cython",
Expand Down
8 changes: 8 additions & 0 deletions projects/pi-fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ execute_process(
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# On Windows the path comes back with backslashes, which CMake reads as escapes.
file(TO_CMAKE_PATH "${F2PY_INCLUDE_DIR}" F2PY_INCLUDE_DIR)

set(f2py_module_name "pi")
set(fortran_src_file "${CMAKE_SOURCE_DIR}/pi/_pi.f")
Expand All @@ -41,4 +43,10 @@ target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC

target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Python::NumPy)

# With the MinGW toolchain (Windows), statically link the GNU runtime so the
# module has no external libgfortran/libgcc/libwinpthread DLL dependencies.
if(WIN32 AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -static)
endif()

install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION pi)
9 changes: 9 additions & 0 deletions projects/pi-fortran/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ dependencies = ["numpy>=1.21"]
[tool.scikit-build]
ninja.version = ">=1.10"
cmake.version = ">=3.17.2"

# Windows defaults to the Visual Studio generator, which has no Fortran support
# and ignores compiler overrides. Use Ninja with the MinGW toolchain instead
# (gcc and gfortran must be on PATH).
[[tool.scikit-build.overrides]]
if.platform-system = "win32"
cmake.args = ["-GNinja"]
cmake.define.CMAKE_C_COMPILER = "gcc"
cmake.define.CMAKE_Fortran_COMPILER = "gfortran"
Loading