Skip to content

Commit d5dbbaf

Browse files
authored
Add meson build files (#42)
- use micromamba to install dependencies
1 parent 7734ed0 commit d5dbbaf

File tree

8 files changed

+208
-41
lines changed

8 files changed

+208
-41
lines changed

.github/workflows/CI.yml

+45-41
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10+
build: [fpm, meson]
1011
os: [ubuntu-latest, macos-latest, windows-latest]
1112
gcc: [10] # Version of GFortran we want to use.
12-
13+
defaults:
14+
run:
15+
shell: ${{ contains(matrix.os, 'windows') && 'powershell' || 'bash -l {0}' }}
16+
env:
17+
FC: gfortran
18+
CC: gcc
19+
FPM_FC: gfortran
20+
FPM_CC: gcc
1321
steps:
1422
- name: Checkout code
1523
uses: actions/checkout@v2
@@ -21,6 +29,7 @@ jobs:
2129
run: |
2230
brew install gcc@${{ matrix.gcc }}
2331
ln -s /usr/local/bin/gfortran-${{ matrix.gcc }} /usr/local/bin/gfortran
32+
ln -s /usr/local/bin/gcc-${{ matrix.gcc }} /usr/local/bin/gcc
2433
2534
- name: Install GFortran (Linux)
2635
if: ${{ contains(matrix.os, 'ubuntu') }}
@@ -36,35 +45,50 @@ jobs:
3645
Invoke-WebRequest -Uri ${{ env.DOWNLOAD }} -OutFile mingw-w64.zip
3746
Expand-Archive mingw-w64.zip
3847
echo "$pwd\mingw-w64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
48+
shell: pwsh
3949
env:
4050
DOWNLOAD: "https://github.com/brechtsanders/winlibs_mingw/releases/download/10.3.0-12.0.0-9.0.0-r2/winlibs-x86_64-posix-seh-gcc-10.3.0-mingw-w64-9.0.0-r2.zip"
4151

42-
- name: Setup Fortran Package Manager
43-
uses: fortran-lang/setup-fpm@v3
52+
- name: Install dependencies
53+
uses: mamba-org/provision-with-micromamba@main
4454
with:
45-
fpm-version: 'v0.3.0'
55+
environment-file: config/ci/${{ matrix.build }}-env.yaml
4656

47-
- name: Compile
57+
- name: Compile (fpm)
58+
if: ${{ matrix.build == 'fpm' }}
4859
run: fpm build --profile release
4960

50-
- name: Run test
61+
- name: Run test (fpm)
62+
if: ${{ matrix.build == 'fpm' }}
5163
run: fpm test
5264

53-
- name: Run examples
65+
- name: Run examples (fpm)
66+
if: ${{ matrix.build == 'fpm' }}
5467
run: fpm run --example --all
5568

56-
Docs:
57-
runs-on: ${{ matrix.os }}
58-
strategy:
59-
fail-fast: false
60-
matrix:
61-
os: [ubuntu-latest]
62-
gcc_v: [9] # Version of GFortran we want to use.
63-
python-version: [3.7]
64-
env:
65-
FC: gfortran-${{ matrix.gcc_v }}
66-
GCC_V: ${{ matrix.gcc_v }}
69+
- name: Setup build (meson)
70+
if: ${{ matrix.build == 'meson' }}
71+
run: >-
72+
meson setup _build
73+
--prefix=${{ contains(matrix.os, 'windows') && '$pwd\_dist' || '$PWD/_dist' }}
74+
75+
- name: Compile project (meson)
76+
if: ${{ matrix.build == 'meson' }}
77+
run: meson compile -C _build
6778

79+
- name: Run testsuite (meson)
80+
if: ${{ matrix.build == 'meson' }}
81+
run: meson test -C _build --no-rebuild --print-errorlogs
82+
83+
- name: Install project (meson)
84+
if: ${{ matrix.build == 'meson' }}
85+
run: meson install -C _build --no-rebuild
86+
87+
Docs:
88+
runs-on: ubuntu-latest
89+
defaults:
90+
run:
91+
shell: bash -l {0}
6892
steps:
6993
- id: deploy-on-push
7094
run:
@@ -77,30 +101,10 @@ jobs:
77101
with:
78102
submodules: recursive
79103

80-
- name: Set up Python 3.x
81-
uses: actions/setup-python@v1 # Use pip to install latest CMake, & FORD/Jin2For, etc.
104+
- name: Install dependencies
105+
uses: mamba-org/provision-with-micromamba@main
82106
with:
83-
python-version: ${{ matrix.python-version }}
84-
85-
- name: Setup Graphviz
86-
uses: ts-graphviz/setup-graphviz@v1
87-
88-
- name: Install Python dependencies
89-
if: ${{ contains( matrix.os, 'ubuntu') }}
90-
run: |
91-
python -m pip install --upgrade pip
92-
pip install numpy matplotlib ford
93-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
94-
95-
- name: Install GFortran Linux
96-
if: ${{ contains( matrix.os, 'ubuntu') }}
97-
run: |
98-
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
99-
sudo apt-get update
100-
sudo apt-get install -y gcc-${GCC_V} gfortran-${GCC_V}
101-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
102-
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
103-
--slave /usr/bingcov gcov /usr/bin/gcov-${GCC_V}
107+
environment-file: config/ci/docs-env.yaml
104108

105109
- name: Build documentation
106110
run: ford ./minpack.md

config/ci/docs-env.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: docs
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python
6+
- numpy
7+
- matplotlib-base
8+
- ford
9+
- graphviz
10+
- gfortran

config/ci/fpm-env.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: devel
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- fpm

config/ci/meson-env.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: devel
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- meson
6+
- ninja

config/install-mod.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
3+
from os import environ, listdir, makedirs
4+
from os.path import join, isdir, exists
5+
from sys import argv
6+
from shutil import copy
7+
8+
build_dir = environ["MESON_BUILD_ROOT"]
9+
if "MESON_INSTALL_DESTDIR_PREFIX" in environ:
10+
install_dir = environ["MESON_INSTALL_DESTDIR_PREFIX"]
11+
else:
12+
install_dir = environ["MESON_INSTALL_PREFIX"]
13+
14+
include_dir = argv[1] if len(argv) > 1 else "include"
15+
module_dir = join(install_dir, include_dir)
16+
17+
modules = []
18+
for d in listdir(build_dir):
19+
bd = join(build_dir, d)
20+
if isdir(bd):
21+
for f in listdir(bd):
22+
if f.endswith(".mod"):
23+
modules.append(join(bd, f))
24+
25+
if not exists(module_dir):
26+
makedirs(module_dir)
27+
28+
for mod in modules:
29+
print("Installing", mod, "to", module_dir)
30+
copy(mod, module_dir)

examples/meson.build

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
tests = [
2+
'hybrd',
3+
'hybrd1',
4+
'lmder1',
5+
'lmdif1',
6+
'primes',
7+
]
8+
9+
foreach t : tests
10+
test(
11+
t,
12+
executable(
13+
'example-@0@'.format(t),
14+
sources: files('example_@[email protected]'.format(t.underscorify())),
15+
dependencies: minpack_dep,
16+
),
17+
suite: 'example',
18+
)
19+
endforeach

meson.build

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
project(
2+
'minpack',
3+
'fortran',
4+
version: '2.0.0',
5+
meson_version: '>=0.55',
6+
default_options: [
7+
'default_library=both',
8+
'buildtype=debugoptimized',
9+
],
10+
)
11+
12+
minpack_lib = library(
13+
meson.project_name(),
14+
sources: files(
15+
'src/minpack.f90',
16+
'src/minpack_capi.f90',
17+
),
18+
install: true,
19+
)
20+
21+
minpack_inc = minpack_lib.private_dir_include()
22+
minpack_dep = declare_dependency(
23+
link_with: minpack_lib,
24+
include_directories: [minpack_inc, include_directories('include')],
25+
)
26+
27+
minpack_lic = files(
28+
'LICENSE.txt',
29+
)
30+
31+
minpack_header = files(
32+
'include/minpack.h',
33+
)
34+
35+
install_data(
36+
minpack_lic,
37+
install_dir: get_option('datadir')/'licenses'/meson.project_name()
38+
)
39+
40+
install_headers(
41+
minpack_header,
42+
)
43+
44+
module_id = meson.project_name()
45+
meson.add_install_script(
46+
find_program(files('config'/'install-mod.py')),
47+
get_option('includedir') / module_id,
48+
)
49+
50+
pkg = import('pkgconfig')
51+
pkg.generate(
52+
minpack_lib,
53+
description: 'Solver for nonlinear equations and least squares problems',
54+
subdirs: ['', module_id],
55+
)
56+
57+
# add examples
58+
subdir('examples')
59+
60+
# add the testsuite
61+
subdir('test')

test/meson.build

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
tests = [
2+
'chkder',
3+
'hybrd',
4+
'hybrj',
5+
'lmder',
6+
'lmdif',
7+
'lmstr',
8+
]
9+
10+
foreach t : tests
11+
test(
12+
t,
13+
executable(
14+
'test-@0@'.format(t),
15+
sources: files('test_@[email protected]'.format(t.underscorify())),
16+
dependencies: minpack_dep,
17+
),
18+
suite: 'unit',
19+
)
20+
endforeach
21+
22+
if add_languages('c', required: false, native: false)
23+
test(
24+
'c-api',
25+
executable(
26+
'c-tester',
27+
sources: files('api/tester.c'),
28+
dependencies: minpack_dep,
29+
),
30+
suite: 'api',
31+
)
32+
endif

0 commit comments

Comments
 (0)