Skip to content

Commit

Permalink
Improved macOS support via autoconf; GitHub CI
Browse files Browse the repository at this point in the history
This patch modifies the autoconf configuration to provide better support
on Mac OS and other BSD-based systems.

Macros are included for the following operations:
* Detect if `sigsetjmp` (BSD) or `__sigsetjmp` (glibc; Linux) is
  available.
* Test the size of jmp_buf and sigjmp_buf

The "sensible" Linux defaults are still present, but autoconf should now
populate these variables when used.

A MacOS CI test for GitHub actions has also been included, but this
probably needs additional work.
  • Loading branch information
marshallward committed Jun 14, 2022
1 parent c886ae7 commit a53af30
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 8 deletions.
79 changes: 79 additions & 0 deletions .github/actions/macos-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: 'Build-.testing-prerequisites'
description: 'Build pre-requisites for .testing including FMS and a symmetric MOM6 executable'
inputs:
build_symmetric:
description: 'If true, will build the symmetric MOM6 executable'
required: false
default: 'true'
install_python:
description: 'If true, will install the local python env needed for .testing'
required: false
default: 'true'
runs:
using: 'composite'
steps:
- name: Git info
shell: bash
run: |
echo "::group::Git commit info"
echo "git log:"
git log | head -60
echo "::endgroup::"
- name: Env
shell: bash
run: |
echo "::group::Environment"
env
echo "::endgroup::"
- name: Install needed packages for compiling
shell: bash
run: |
echo "::group::Install packages"
brew update
brew install automake
brew install gfortran
brew install netcdf
brew install mpich
echo "::endgroup::"
- name: Compile FMS library
shell: bash
run: |
echo "::group::Compile FMS library"
cd .testing
make deps/lib/libFMS.a -s -j
echo "::endgroup::"
- name: Store compiler flags used in Makefile
shell: bash
run: |
echo "::group::config.mk"
cd .testing
echo "FCFLAGS_DEBUG=-g -O0 -Wextra -Wno-compare-reals -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds" >> config.mk
echo "FCFLAGS_REPRO=-g -O2 -fbacktrace" >> config.mk
echo "FCFLAGS_INIT=-finit-real=snan -finit-integer=2147483647 -finit-derived" >> config.mk
cat config.mk
echo "::endgroup::"
- name: Compile MOM6 in symmetric memory mode
shell: bash
run: |
echo "::group::Compile MOM6 in symmetric memory mode"
cd .testing
test ${{ inputs.build_symmetric }} == true && make build/symmetric/MOM6 -j
echo "::endgroup::"
- name: Install local python venv for generating input data
shell: bash
run: |
echo "::group::Create local python env for input data generation"
cd .testing
test ${{ inputs.install_python }} == true && make work/local-env
echo "::endgroup::"
- name: Set flags
shell: bash
run: |
echo "TIMEFORMAT=... completed in %lR (user: %lU, sys: %lS)" >> $GITHUB_ENV
33 changes: 33 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: MacOS Stencil related verification

on: [push, pull_request]

jobs:
test-macos-symmetric-layout-rotation:

runs-on: macOS-latest

# TODO: Move these to the macos config file?
env:
CC: gcc-11
FC: gfortran-11

defaults:
run:
working-directory: .testing

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: ./.github/actions/macos-setup

- name: Compile MOM6 in asymmetric memory mode
run: make build/asymmetric/MOM6 -j

- name: Create validation data
run: make run.symmetric -k -s

- name: Run tests
run: make test.grid test.layout test.rotate -k -s
27 changes: 25 additions & 2 deletions ac/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [
AC_PATH_PROG([NF_CONFIG], [nf-config])
AS_IF([test -n "$NF_CONFIG"], [
AC_SUBST([LDFLAGS],
["$LDFLAGS -L$($NF_CONFIG --prefix)/lib"]
["$LDFLAGS $($NF_CONFIG --flibs | cut -f1 -d" ")"]
)
], [AC_MSG_ERROR([Could not find nf-config.])]
], [AC_MSG_ERROR([Could not find nf_create.])]
)
AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [
AC_MSG_ERROR([Could not find libnetcdff.])
Expand Down Expand Up @@ -224,6 +224,29 @@ AC_COMPILE_IFELSE(
)


# setjmp verification
AC_LANG_PUSH([C])

# Verify that either sigsetjmp (POSIX) or __sigsetjmp (glibc) are available.
AC_CHECK_FUNC([sigsetjmp])
AS_IF([test "$ac_cv_func_sigsetjmp" == "yes"], [
SIGSETJMP_NAME="sigsetjmp"
], [
AC_CHECK_FUNC([__sigsetjmp], [
SIGSETJMP_NAME="__sigsetjmp"
], [
AC_MSG_ERROR([Could not find a symbol for sigsetjmp.])
])
])
AC_DEFINE_UNQUOTED([SIGSETJMP_NAME], ["$SIGSETJMP_NAME"])

# Determine the size of jmp_buf and sigjmp_buf
AC_CHECK_SIZEOF([jmp_buf], [], [#include <setjmp.h>])
AC_CHECK_SIZEOF([sigjmp_buf], [], [#include <setjmp.h>])

AC_LANG_POP([C])


# Search for mkmf build tools
AC_PATH_PROG([LIST_PATHS], [list_paths])
AS_IF([test -z "$LIST_PATHS"], [
Expand Down
4 changes: 2 additions & 2 deletions src/framework/posix.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module posix
!! and any information required to restore the process state.
type, bind(c) :: jmp_buf
private
character(kind=c_char) :: state(JMP_BUF_SIZE)
character(kind=c_char) :: state(SIZEOF_JMP_BUF)
!< Unstructured array of bytes used to store the process state
end type jmp_buf

Expand All @@ -28,7 +28,7 @@ module posix
!! In addition to the content stored by `jmp_buf`, it also stores signal state.
type, bind(c) :: sigjmp_buf
private
character(kind=c_char) :: state(SIGJMP_BUF_SIZE)
character(kind=c_char) :: state(SIZEOF_SIGJMP_BUF)
!< Unstructured array of bytes used to store the process state
end type sigjmp_buf

Expand Down
8 changes: 4 additions & 4 deletions src/framework/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

! JMP_BUF_SIZE should be set to sizeof(jmp_buf).
! If unset, then use a typical glibc value (25 long ints)
#ifndef JMP_BUF_SIZE
#define JMP_BUF_SIZE 200
#ifndef SIZEOF_JMP_BUF
#define SIZEOF_JMP_BUF 200
#endif

! If unset, assume jmp_buf and sigjmp_buf are equivalent (as in glibc).
#ifndef SIGJMP_BUF_SIZE
#define SIGJMP_BUF_SIZE JMP_BUF_SIZE
#ifndef SIZEOF_SIGJMP_BUF
#define SIZEOF_SIGJMP_BUF SIZEOF_JMP_BUF
#endif

! glibc defines sigsetjmp as __sigsetjmp via macro readable from <setjmp.h>.
Expand Down

0 comments on commit a53af30

Please sign in to comment.