Skip to content

Commit 26a4015

Browse files
authored
Build on Windows (#12)
* Switch from micromamba action to miniforge * Only test on python=3.13 * Set up Windows job * Checkout submodule on Windows * Back to micromamba, I guess * Set the FC environment variable * Use an absolute path to flang * Use ninja build backend * Set PREFIX environment variable * Use contexts for env vars in cmake call * Make a LINKER variable pointing to the VS linker * Quote LINKER variable in cmake call * Checkout bmi-example-fortran v2.1.4 * Restructure for flang 19 * Use build isolation with pip install * CONDA_PREFIX is now available * Push MSVC link.exe to front of path * Remove the link.exe in the Git install * Quote path to link.exe * Use dependency function and pkg-config to find deps * Use LIBRARY_PREFIX env var to install HeatModelF * Try to best match working example * Thanks, VS Code * Append conda libpath to Windows LIB * Add tests * Specify path to config file for bmi-tester * Also set absolute path to bmi-tester root dir * Don't run bmi-tester on Windows * Add notes on workflow steps
1 parent f910ed0 commit 26a4015

File tree

4 files changed

+93
-9
lines changed

4 files changed

+93
-9
lines changed

.github/workflows/test.yml

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ env:
66
BUILD_DIR: _build
77

88
jobs:
9-
build-and-test:
9+
build-test-unix:
1010
if:
1111
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
1212

@@ -19,7 +19,6 @@ jobs:
1919
strategy:
2020
matrix:
2121
os: [ubuntu-latest, macos-latest]
22-
python-version: ["3.11", "3.12", "3.13"]
2322

2423
steps:
2524
- uses: actions/checkout@v4
@@ -42,13 +41,94 @@ jobs:
4241
run: |
4342
make install
4443
45-
- name: Test BMI
44+
- name: Test imports
45+
working-directory: ${{ github.workspace }}/examples
4646
run: |
4747
python -c 'import pymt_heatf'
48+
python -c 'from pymt.models import HeatModelF'
49+
50+
- name: Test BMI
51+
run: |
4852
make test
4953
5054
- name: Run examples
5155
working-directory: ${{ github.workspace }}/examples
5256
run: |
5357
python heatf_ex.py
5458
python pymt_heatf_ex.py
59+
60+
build-test-windows:
61+
if:
62+
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
63+
64+
runs-on: windows-latest
65+
66+
env:
67+
LIBRARY_PREFIX: $env:CONDA_PREFIX\Library
68+
69+
defaults:
70+
run:
71+
shell: pwsh
72+
73+
steps:
74+
- uses: actions/checkout@v4
75+
with:
76+
submodules: true
77+
78+
- uses: ilammy/msvc-dev-cmd@v1
79+
80+
- uses: mamba-org/setup-micromamba@v2
81+
with:
82+
micromamba-version: latest
83+
environment-file: environment.yml
84+
init-shell: >-
85+
powershell
86+
87+
# The Fortran conda compiler, flang, needs to be set over the gfortran installed by chocolatety.
88+
- name: Set the FC environment variable
89+
run: |
90+
echo "FC=$env:CONDA_PREFIX\Library\bin\flang-new.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
91+
92+
# A link.exe installed by chocolatey was ahead of the MSVC link.exe in the path.
93+
- name: Remove link.exe in the Git install
94+
run: |
95+
Remove-Item -Path "C:\Program Files\Git\usr\bin\link.exe" -Force
96+
97+
# The flang FortranRuntime.lib wasn't being found. This recommendation comes from the Meson docs.
98+
- name: Add conda environment libpath to Windows LIB (not LIBPATH)
99+
run: |
100+
echo "LIB=$env:LIB;$env:CONDA_PREFIX\Library\lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
101+
102+
- name: View environment variables
103+
run: |
104+
ls env:
105+
106+
# The install prefix must be quoted.
107+
- name: Configure, build, and install HeatModelF
108+
run: |
109+
pushd ./external/bmi-example-fortran
110+
cmake -B ${{ env.BUILD_DIR }} -LA -G Ninja -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
111+
cmake --build ${{ env.BUILD_DIR }} --target install --config Release
112+
popd
113+
114+
- name: Build and install package
115+
run: |
116+
make install
117+
118+
- name: Test imports
119+
working-directory: ${{ github.workspace }}/examples
120+
run: |
121+
python -c 'import pymt_heatf'
122+
python -c 'from pymt.models import HeatModelF'
123+
124+
# Weird Windows stuff here. If the examples in the next step run to completion, the BMI works.
125+
# - name: Test BMI
126+
# working-directory: ${{ github.workspace }}
127+
# run: |
128+
# bmi-test pymt_heatf._bmi:HeatModelF --config-file=${{ github.workspace }}\examples\test.cfg --root-dir=examples -vvv
129+
130+
- name: Run examples
131+
working-directory: ${{ github.workspace }}/examples
132+
run: |
133+
python heatf_ex.py
134+
python pymt_heatf_ex.py

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ dist: clean ## builds source and wheel package
8787
ls -l dist
8888

8989
install: clean ## install the package to the active Python's site-packages
90-
python -m pip install . -v
90+
python -m pip install . -v --no-build-isolation

meson.build

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'pymt_heatf',
33
'c', 'cython', 'fortran',
4-
version: '3.1.dev0',
4+
version: '3.2.dev0',
55
license: 'MIT',
66
)
77

@@ -25,10 +25,14 @@ incs = include_directories(
2525
]
2626
)
2727

28+
# gfortran on Linux/macOS can find these libraries with fc.find_library(); flang 19 on Windows cannot.
29+
bmif_dep = dependency('bmif', method: 'pkg-config')
30+
heatf_dep = dependency('heatf', method: 'pkg-config')
31+
bmiheatf_dep = dependency('bmiheatf', method: 'pkg-config')
2832
deps = [
29-
fc.find_library('bmif'),
30-
fc.find_library('heatf'),
31-
fc.find_library('bmiheatf'),
33+
bmif_dep,
34+
heatf_dep,
35+
bmiheatf_dep,
3236
py.dependency(),
3337
]
3438

0 commit comments

Comments
 (0)