Skip to content

github-ci: add fpm support #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 16, 2021
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
51 changes: 51 additions & 0 deletions .github/workflows/fpm-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: fpm-deployment

on: [push, pull_request]
env:
GCC_V: "10"

jobs:
Build:
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/[email protected]

- name: Set up Python 3.x
uses: actions/setup-python@v1
with:
python-version: 3.x

- name: Install fypp
run: pip install --upgrade fypp

- name: Generate stdlib-fpm package 🔧
run: |
bash ./ci/fpm-deployment.sh

- name: Install GFortran
run: |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ env.GCC_V }} 100 \
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${{ env.GCC_V }} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${{ env.GCC_V }}

- name: Install fpm latest release
uses: fortran-lang/setup-fpm@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run fpm test ⚙
run: |
cp -r stdlib-fpm stdlib-fpm-test
cd stdlib-fpm-test
fpm test
fpm test --profile release

# Update and deploy the f90 files generated by github-ci to the `stdlib-fpm` branch.
- name: Deploy 🚀
uses: JamesIves/[email protected]
if: github.event_name != 'pull_request'
with:
BRANCH: stdlib-fpm
FOLDER: stdlib-fpm
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ API-doc/

# Build directory for out-of-tree builds
/build
/stdlib-fpm

# Emacs backup files
*~
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [Supported compilers](#supported-compilers)
- [Build with CMake](#build-with-cmake)
- [Build with make](#build-with-make)
- [Build with fortran-lang/fpm](#build-with-fortran-langfpm)
* [Using stdlib in your project](#using-stdlib-in-your-project)
* [Documentation](#documentation)
* [Contributing](#contributing)
Expand Down Expand Up @@ -176,7 +177,21 @@ You can limit the maximum rank by setting ``-DMAXRANK=<num>`` in the ``FYPPFLAGS
make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4
```

### Build with [fortran-lang/fpm](https://github.com/fortran-lang/fpm)

Fortran Package Manager (fpm) is a package manager and build system for Fortran.
You can build `stdlib` using provided `fpm.toml`:

```sh
git checkout stdlib-fpm
fpm build --profile release
```

To use `stdlib` within your `fpm` project, add the following lines to your `fpm.toml` file:
```toml
[dependencies]
stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" }
```

## Using stdlib in your project

Expand Down
50 changes: 50 additions & 0 deletions ci/fpm-deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -ex

# Target directory to deploy stdlib to
destdir="${DESTDIR:-stdlib-fpm}"

# Get fypp preprocessor
fypp="${FYPP:-$(which fypp)}"

# Arguments for the fypp preprocessor
fyflags="${FYFLAGS:--DMAXRANK=4}"

# Number of parallel jobs for preprocessing
njob="$(nproc)"

# Additional files to include
include=(
"ci/fpm.toml"
"LICENSE"
)

# Files to remove from collection
prune=(
"$destdir/test/test_always_fail.f90"
"$destdir/test/test_always_skip.f90"
"$destdir/test/test_mean_f03.f90"
"$destdir/src/common.f90"
"$destdir/src/f18estop.f90"
)

mkdir -p "$destdir/src" "$destdir/test"

# Preprocess stdlib sources
find src -maxdepth 1 -iname "*.fypp" \
| cut -f1 -d. | xargs -P "$njob" -I{} "$fypp" "{}.fypp" "$destdir/{}.f90" $fyflags

# Collect stdlib source files
find src -maxdepth 1 -iname "*.f90" -exec cp {} "$destdir/src/" \;
find src/tests -name "test_*.f90" -exec cp {} "$destdir/test/" \;
find src/tests -name "*.dat" -exec cp {} "$destdir/" \;

# Include additional files
cp "${include[@]}" "$destdir/"

# Source file workarounds for fpm
rm "${prune[@]}"

# List stdlib-fpm package contents
ls -R "$destdir"
5 changes: 5 additions & 0 deletions ci/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "stdlib"
version = "0.0.0"
license = "MIT"
author = "stdlib contributors"
copyright = "2019-2021 stdlib contributors"