Skip to content

Commit

Permalink
Rebuild with flang 19 (#22)
Browse files Browse the repository at this point in the history
* Set a build directory for cmake

* Build on Windows with bmi-fortran from conda

* Explicitly request flang >=19

* Remove space between package name and version

* Revert to conda fortran compiler

* Set the FC environment variable

* Use status messages

* Use object libraries for test fixtures and example helpers

* Remove fixtures.mod artifact

* Use library names from flang, not gfortran

* Run ctest from source directory

* Simplify build/install instructions with CMake
  • Loading branch information
mdpiper authored Dec 19, 2024
1 parent 98b4e33 commit f964dfe
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 73 deletions.
71 changes: 28 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: Build/Test

on: [push, pull_request]

env:
BUILD_DIR: _build

jobs:
build-test-unix:
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: ${{ matrix.os }}

Expand All @@ -25,7 +27,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: mamba-org/setup-micromamba@v1
- uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: latest
environment-name: testing
Expand All @@ -35,19 +37,14 @@ jobs:
fortran-compiler
bmi-fortran
- name: Make CMake build directory
run: cmake -E make_directory build

- name: Configure CMake
working-directory: ${{ github.workspace }}/build
- name: Configure project
run: |
cmake $GITHUB_WORKSPACE \
cmake $GITHUB_WORKSPACE -B ${{ env.BUILD_DIR }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
- name: Build
working-directory: ${{ github.workspace }}/build
run: cmake --build . --target install --config ${{ matrix.build-type }}
- name: Build and install project
run: cmake --build ${{ env.BUILD_DIR }} --target install --config ${{ matrix.build-type }}

- name: Test for installed files
run: |
Expand All @@ -58,9 +55,8 @@ jobs:
test -f $CONDA_PREFIX/include/bmiheatf.mod
test -f $CONDA_PREFIX/lib/pkgconfig/bmiheatf.pc
- name: Run CTest
working-directory: ${{ github.workspace }}/build
run: ctest -C ${{ matrix.build-type }} --output-on-failure
- name: Run project tests
run: ctest --test-dir ${{ env.BUILD_DIR }} -C ${{ matrix.build-type }} --output-on-failure

- name: Memcheck
if: matrix.os == 'ubuntu-latest'
Expand All @@ -78,8 +74,7 @@ jobs:
build-test-windows:
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: windows-latest

Expand All @@ -89,52 +84,42 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: mamba-org/setup-micromamba@v1
- uses: mamba-org/setup-micromamba@v2
with:
micromamba-version: latest
environment-name: testing
create-args: >-
cmake
pkg-config
cxx-compiler
fortran-compiler
bmi-fortran
init-shell: >-
powershell
# The Fortran conda compiler doesn't seem to work on Windows in Actions.
# Instead, use the gfortran installed by chocolately. However, we then
# can't use the bmi-fortran package from conda-forge because it's not
# ABI-compatible. So, build bmi-fortran locally, This is a hack
# workaround.
- name: Build the bmi-fortran specification locally
- name: Set the FC environment variable to the Fortran conda compiler
run: |
echo "FC=$env:CONDA_PREFIX\Library\bin\flang-new.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: List current environment variables
run: |
curl -o bmi-fortran.zip -L https://github.com/csdms/bmi-fortran/archive/refs/heads/master.zip
unzip bmi-fortran.zip
cd bmi-fortran-master
mkdir build && cd build
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build . --target install --config Release
cd ${{ github.workspace }}
- name: Make cmake build directory
run: cmake -E make_directory build

- name: Configure, build, and install
working-directory: ${{ github.workspace }}/build
ls env:
- name: Configure, build, and install project
run: |
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build . --target install --config Release
cmake -B ${{ env.BUILD_DIR }} -LA -G Ninja -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build ${{ env.BUILD_DIR }} --target install --config Release
- name: Test for installed files
run: |
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libheatf.a ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\heatf.lib ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_heatf.exe ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\heatf.mod ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\heatf.pc ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_bmiheatf.exe ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmiheatf.a ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmiheatf.lib ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmiheatf.mod ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\bmiheatf.pc ) ){ exit 1 }
- name: Run CTest
working-directory: ${{ github.workspace }}/build
run: ctest -C Release -VV --output-on-failure
run: ctest --test-dir ${{ env.BUILD_DIR }} -C Release -VV --output-on-failure
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ set(bmi_name bmi${model_name})
find_package(PkgConfig REQUIRED)
pkg_check_modules(BMIF REQUIRED IMPORTED_TARGET bmif)
string(REPLACE "." "_" bmif_module_version ${BMIF_VERSION})
message("-- bmif module version - ${bmif_module_version}")
message("-- bmif library path - ${BMIF_LINK_LIBRARIES}")
message("-- bmif include dir - ${BMIF_INCLUDE_DIRS}")
message(STATUS " bmif module version - ${bmif_module_version}")
message(STATUS " bmif library path - ${BMIF_LINK_LIBRARIES}")
message(STATUS " bmif include dir - ${BMIF_INCLUDE_DIRS}")
include_directories(${BMIF_INCLUDE_DIRS})

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)
Expand Down
42 changes: 17 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

An example of implementing the
[Fortran bindings](https://github.com/csdms/bmi-fortran)
for the CSDMS
[Basic Model Interface](https://bmi-spec.readthedocs.io) (BMI).

for the CSDMS [Basic Model Interface](https://bmi.csdms.io) (BMI).

## Overview

Expand Down Expand Up @@ -50,22 +48,21 @@ This example can be built on Linux, macOS, and Windows.

### CMake - Linux and macOS

To build this example from source with CMake,
To configure and build this example from source with CMake,
using the current Fortran BMI version, run

mkdir _build && cd _build
cmake .. -DCMAKE_INSTALL_PREFIX=<path-to-installation>
make
cmake -B _build -DCMAKE_INSTALL_PREFIX=<path-to-installation>
cmake --build _build

where `<path-to-installation>` is the base directory
in which the Fortran BMI bindings have been installed
(`/usr/local` is the default).
When installing into a conda environment,
use the `$CONDA_PREFIX` environment variable.

Then, to install (on both Linux and macOS):
Then, to install:

make install
cmake --install _build

The installation will look like
(on macOS, using v2.0 of the Fortran BMI specification):
Expand All @@ -81,8 +78,8 @@ The installation will look like
| `-- heatf.mod
`-- lib
|-- libbmif.a
|-- libbmif.2.0.2.dylib
|-- libbmif.dylib -> libbmif.2.0.2.dylib
|-- libbmif.2.1.4.dylib
|-- libbmif.dylib -> libbmif.2.1.4.dylib
|-- libbmiheatf.dylib
|-- libheatf.dylib
`-- pkgconfig
Expand All @@ -91,41 +88,36 @@ The installation will look like
`-- heatf.pc
```

From the build directory,
run unit tests and examples of using the sample implementation with
Run unit tests and examples of using the sample implementation with

ctest
ctest --test-dir _build

### CMake - Windows

An additional prerequisite is needed for Windows:

* Microsoft Visual Studio 2017 or Microsoft Build Tools for Visual Studio 2017

To configure this example from source with cmake
To configure and build this example from source with CMake
using the current Fortran BMI version,
run the following in a [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)

mkdir _build && cd _build
cmake .. ^
-G "NMake Makefiles" ^
-DCMAKE_INSTALL_PREFIX=<path-to-installation> ^
-DCMAKE_BUILD_TYPE=Release
cmake -B _build -L -G Ninja -DCMAKE_INSTALL_PREFIX=<path-to-installation>
cmake --build _build

where `<path-to-installation>` is the base directory
in which the Fortran BMI bindings have been installed.
The default is `"C:\Program Files (x86)"`.
Note that quotes and an absolute path are needed.
When using a conda environment, use `"%CONDA_PREFIX%\Library"`.

Then, to build and install:
Then, to install:

cmake --build . --target install --config Release
cmake --install _build

From the build directory,
run unit tests and examples of using the sample implementation with
Run unit tests and examples of using the sample implementation with

ctest
ctest --test-dir _build


### Fortran Package Manager (fpm)
Expand Down
4 changes: 3 additions & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ include(CTest)

include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})

add_library(helpers OBJECT testing_helpers.f90)

function(make_example example_name)
add_test(NAME ${example_name} COMMAND ${example_name} ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(${example_name} ${example_name}.f90 testing_helpers.f90)
add_executable(${example_name} ${example_name}.f90 $<TARGET_OBJECTS:helpers>)
target_link_libraries(${example_name} ${bmi_name})
endfunction(make_example)

Expand Down
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ include(CTest)

include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})

add_library(fixtures OBJECT fixtures.f90)

function(make_test test_name)
add_test(NAME ${test_name} COMMAND ${test_name} "${CMAKE_CURRENT_SOURCE_DIR}/sample.cfg")
add_executable(${test_name} ${test_name}.f90 fixtures.f90)
add_executable(${test_name} ${test_name}.f90 $<TARGET_OBJECTS:fixtures>)
target_link_libraries(${test_name} ${bmi_name})
endfunction(make_test)

Expand Down
Binary file removed test/fixtures.mod
Binary file not shown.

0 comments on commit f964dfe

Please sign in to comment.