From f964dfe20cc7419db1a4b8336055bd023d4129cf Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Thu, 19 Dec 2024 12:49:42 -0700 Subject: [PATCH] Rebuild with flang 19 (#22) * 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 --- .github/workflows/test.yml | 71 +++++++++++++++---------------------- CMakeLists.txt | 6 ++-- README.md | 42 +++++++++------------- example/CMakeLists.txt | 4 ++- test/CMakeLists.txt | 4 ++- test/fixtures.mod | Bin 618 -> 0 bytes 6 files changed, 54 insertions(+), 73 deletions(-) delete mode 100644 test/fixtures.mod diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e2e0bb1..4bd9251 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} @@ -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 @@ -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: | @@ -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' @@ -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 @@ -89,7 +84,7 @@ 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 @@ -97,44 +92,34 @@ jobs: 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 394e5da..3978206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index 46731f0..35459a8 100644 --- a/README.md +++ b/README.md @@ -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 @@ -50,12 +48,11 @@ 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= - make + cmake -B _build -DCMAKE_INSTALL_PREFIX= + cmake --build _build where `` is the base directory in which the Fortran BMI bindings have been installed @@ -63,9 +60,9 @@ in which the Fortran BMI bindings have been installed 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): @@ -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 @@ -91,10 +88,9 @@ 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 @@ -102,15 +98,12 @@ 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= ^ - -DCMAKE_BUILD_TYPE=Release + cmake -B _build -L -G Ninja -DCMAKE_INSTALL_PREFIX= + cmake --build _build where `` is the base directory in which the Fortran BMI bindings have been installed. @@ -118,14 +111,13 @@ 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) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index c9fabb6..2ae0bc6 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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_link_libraries(${example_name} ${bmi_name}) endfunction(make_example) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 463b8e4..53daa32 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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_link_libraries(${test_name} ${bmi_name}) endfunction(make_test) diff --git a/test/fixtures.mod b/test/fixtures.mod deleted file mode 100644 index e741f488b854a1676248fc7422fed7f816980849..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 618 zcmV-w0+szAiwFP!000001GQDlj+-zP-TN!<&alYHdD3vGmr_t#tUJ#@xD*TTdRSgx1X2&xG93BsG@*c#=F2aB-7@~@S zopXI1xV}IUm~=^*Ntv-O5;w=mtBjG-sP7i%81P4$9I{}Orkg*VJ0`$T)8{v6iy8{B zCN=CUq$~fK3!E0CchTkaO(d!*%yNmf0nP!RvQ2jGr14GXmj3)8kv(FnG%@bfNRv0z zfVBXe9d}W>IfS35b53=;)@~jsonl3O12K6TYxBiuHvSn-H?x?084PcAipOM z5)3V+=BLH99LiRf%fR#7N1KCi~OpvHytBrP*Ef;Gegk!+LvW40~7*n{(j_E5ezCJDrkHtx4(gBbkv~qH3d) zmmEYbk$Xmp?s?V45wtdR`2)QE{Sg>8t%1O(<+eo7Q`;MXIck~;frX0x0*XEV*YXDd E06Lu`5&!@I