Skip to content

Commit

Permalink
Switch to github-actions
Browse files Browse the repository at this point in the history
Advantages:

- unified configuration format for linux/windows/mac
- simplified usage of artifacts (compared to travis): no more external
  manually managed artifact repository
- artifacts should work on pull requests even without secrets (wasn't
  the case previously which meant that all PR builds always failed)
- unified access to all artifacts on github actions tab
- cache control with explicit cache key
- better integration into github UI
- pipeline can include jobs on different OSes
- easier configuration of parallel workflows
- ...?
  • Loading branch information
coldfix committed Sep 4, 2020
1 parent ad6f0e4 commit 6a614a6
Show file tree
Hide file tree
Showing 20 changed files with 463 additions and 577 deletions.
76 changes: 0 additions & 76 deletions .appveyor.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/build/manylinux1/cpymad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#! /usr/bin/env bash
set -ex

# Build cpymad from checked out sources.
# Expects a built madx distribution in '../MAD-X/dist'.
# Builds in './build' and places wheels in './dist'.

: ${PY:=/opt/python/cp36-cp36m/bin}

# Build variables:
export MADXDIR=$(readlink -nf ../MAD-X/dist)
export X11=0 BLAS=0 LAPACK=0
export CFLAGS="-flto"
export LDFLAGS="-flto"

# Copy the cpymad source files to a build folder in order to avoid permission
# issues with the host filesystem (on both sides):
mkdir -p build
$PY/python setup.py egg_info
tar -c $(cat src/cpymad.egg-info/SOURCES.txt) |
tar -x -C build --no-same-owner

# We create the wheels from the source distribution to verify that the
# source distribution can be used as installation medium. We will later
# upload this exact source distribution to PyPI:
pushd build
$PY/pip install cython
$PY/python setup.py sdist
$PY/pip uninstall cython -y

for PYBIN in /opt/python/*/bin; do
"${PYBIN}/pip" install -U setuptools
"${PYBIN}/pip" wheel dist/*.tar.gz --no-deps -w dist/
done
popd

# Bundle external shared libraries into the wheels
mkdir -p dist
for whl in build/dist/*.whl; do
auditwheel repair "$whl" -w dist/
done
cp build/dist/*.tar.gz dist/
27 changes: 27 additions & 0 deletions .github/build/manylinux1/madx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env bash
set -ex

# Build MAD-X static library from prepared sources.
# Must be run from the root the directory of the MAD-X sources.
# Builds in './build' and installs to './dist'.

rm -rf build
mkdir build
cd build

: ${PY:=/opt/python/cp36-cp36m/bin}

$PY/pip install --upgrade cmake
$PY/cmake .. \
-DBUILD_SHARED_LIBS=OFF \
-DMADX_STATIC=ON \
-DCMAKE_INSTALL_PREFIX=../dist \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS="-fvisibility=hidden -flto" \
-DCMAKE_CXX_FLAGS="-fvisibility=hidden -flto" \
-DCMAKE_Fortran_FLAGS="-fvisibility=hidden -flto" \
-DMADX_INSTALL_DOC=OFF \
-DMADX_ONLINE=OFF \
-DMADX_FORCE_32=OFF \
-DMADX_X11=OFF
$PY/cmake --build . --target install
112 changes: 112 additions & 0 deletions .github/build/msys2/cpymad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#! /usr/bin/env bash
set -ex

# Build cpymad from checked out sources.
# Expects a built madx distribution in '../MAD-X/dist'.
# Builds in './build' and places wheels in './dist'.

main()
{
ARCH=$1
MADXDIR=${2:-$MADXDIR}

# Create python environments:
conda_ create -qyf -n py27 python=2.7 wheel cython -c anaconda
conda_ create -qyf -n py35 python=3.5 wheel cython -c anaconda
conda_ create -qyf -n py36 python=3.6 wheel cython -c anaconda
conda_ create -qyf -n py37 python=3.7 wheel cython -c anaconda
conda_ create -qyf -n py38 python=3.8 wheel cython -c anaconda

# Build cpymad wheels:
if [[ $ARCH == i686 ]]; then
CFLAGS=
build py27 27 win32-2.7 ''
build py35 35 win32-3.5 .cp35-win32
build py36 36 win32-3.6 .cp36-win32
build py37 37 win32-3.7 .cp37-win32
build py38 38 win32-3.8 .cp38-win32
else
CFLAGS=-DMS_WIN64
build py27 27 win-amd64-2.7 ''
build py35 35 win-amd64-3.5 .cp35-win_amd64
build py36 36 win-amd64-3.6 .cp36-win_amd64
build py37 37 win-amd64-3.7 .cp37-win_amd64
build py38 38 win-amd64-3.8 .cp38-win_amd64
fi
}

# We manually build the C extension using our msys gcc because setuptools is
# not smart enough to figure out how to build it. The downside is that
# we link a different C runtime than is natively used by python. This will
# result in horrible evil should we ever mix C objects/memory between python
# and cpymad!
build()
{
py_env=$1
py_ver=$2
dir_tag=$3
file_tag=$4

# Ensure that cython code and extension module will be rebuilt since the
# cython code is partially incompatible between python versions:
rm -f src/cpymad/libmadx.c \
src/cpymad/libmadx.pyd

# We use a two stage build with the exact filenames as `python setup.py
# build_ext` would do (compile `.c` to `.obj` in $tempdir, then link to
# `.pyd` in $libdir) to prevent the final `python setup.py bdist_wheel`
# command from trying trying to perform either of these steps with MSVC.

conda_ activate $py_env
tempdir=build/temp.$dir_tag/Release/src/cpymad
libdir=build/lib.$dir_tag/cpymad
mkdir -p $tempdir
mkdir -p $libdir

pythondir="$(python -c 'import sys; print(sys.prefix)')"

# This will cythonize `.pyx` to `.c`:
pip install -U setuptools
python setup.py build_py

# We turn back on the base environment for building in order to set the
# the path to the runtime DLLs required for running gcc. Without this
# the command errors with a windows error that is visible only via the
# remote desktop but doesn't get logged as console output.
conda_ deactivate

gcc -mdll -O -Wall -flto $CFLAGS \
-I$MADXDIR/include \
-I$pythondir/include \
-c src/cpymad/libmadx.c \
-o $tempdir/libmadx.obj \
-std=gnu99

# Linking directly against the `pythonXX.dll` is the only way I found to
# satisfy the linker in a conda python environment. The conventional
# command line `-L$pythondir/libs -lpython$py_ver` used to work fine on
# WinPython, but fails on conda with large number of complaints about
# about undefined references, such as `__imp__Py_NoneStruct`,
gcc -shared -s -flto \
$tempdir/libmadx.obj \
-L$MADXDIR/lib \
-static \
-lmadx -lDISTlib -lptc -lgc-lib \
-lstdc++ -lgfortran -lquadmath \
$pythondir/python$py_ver.dll \
-o $libdir/libmadx$file_tag.pyd

# Turn target python environment back on, see above:
conda_ activate $py_env
python setup.py bdist_wheel
conda_ deactivate
}

conda_() {
# Conda with disabled trace (really noisy otherwise):
{ set +x; } 2>/dev/null
conda "$@"
{ set -x; } 2>/dev/null
}

main "$@"
24 changes: 24 additions & 0 deletions .github/build/msys2/madx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env bash
set -ex

# Build MAD-X static library from prepared sources.
# Must be run from the root the directory of the MAD-X sources.
# Builds in './build' and installs to './dist'.

rm -rf build
mkdir build
cd build

# Build MAD-X as library:
pip install --upgrade cmake
cmake .. \
-G "MinGW Makefiles" \
-DBUILD_SHARED_LIBS=OFF \
-DMADX_STATIC=ON \
-DCMAKE_INSTALL_PREFIX=../dist \
-DCMAKE_BUILD_TYPE=Release \
-DMADX_INSTALL_DOC=OFF \
-DMADX_ONLINE=OFF \
-DMADX_FORCE_32=OFF \
-DMADX_X11=OFF
cmake --build . --target install
14 changes: 14 additions & 0 deletions .github/checkout-madx/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Download and prepare MAD-X sources
inputs:
madx_version:
description: 'MAD-X version'
required: true

runs:
using: composite
steps:
- run: git clone https://github.com/MethodicalAcceleratorDesign/MAD-X
../MAD-X -b "${{ inputs.madx_version }}" --depth 1
shell: bash
- run: patch -d ../MAD-X -p1 < .github/patch/fix-cmake-Fortran_FLAGS.patch
shell: bash
File renamed without changes.

0 comments on commit 6a614a6

Please sign in to comment.