Skip to content

Commit 755fddd

Browse files
authored
Merge pull request #82 from matthew-brett/refactor-build-script
MRG: Refactor build_openblas script
2 parents 087c6e4 + df2b693 commit 755fddd

File tree

5 files changed

+119
-104
lines changed

5 files changed

+119
-104
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: Windows build
42

5-
defaults:
6-
run:
7-
shell: bash
8-
93
on:
104
push:
115
branches: [ master ]
@@ -15,13 +9,16 @@ on:
159
env:
1610
OPENBLAS_COMMIT: "bfd9c1b58cd3"
1711
OPENBLAS_ROOT: "c:\\opt"
12+
# Preserve working directory for calls into bash
13+
CHERE_INVOKING: "yes"
14+
BASH_PATH: "c:\\rtools40\\usr\\bin\\bash"
1815

1916
jobs:
2017
build:
2118
strategy:
2219
matrix:
2320
BUILD_BITS: [64, 32]
24-
INTERFACE64: ['1', '']
21+
INTERFACE64: ['1', '0']
2522
os: [windows-latest]
2623
exclude:
2724
- BUILD_BITS: 32
@@ -31,65 +28,46 @@ jobs:
3128

3229
steps:
3330
- uses: actions/checkout@v2
34-
- uses: ilammy/msvc-dev-cmd@v1
35-
36-
- name: Setup
31+
- name: install-rtools
3732
run: |
38-
BITS=${{ matrix.BUILD_BITS }}
39-
echo "BUILD_BITS=$BITS" >> $GITHUB_ENV;
40-
if [ "$BITS" == "32" ]; then
41-
echo "PLAT=i686" >> $GITHUB_ENV;
42-
else
43-
echo "PLAT=x86_64" >> $GITHUB_ENV;
44-
fi
45-
echo "START_DIR=$PWD" >> $GITHUB_ENV;
46-
choco install -y zip
47-
48-
- run: |
49-
choco install -y mingw --forcex86 --force --version=8.1.0
50-
choco install -y make
51-
name: Install 32-bit mingw
52-
shell: powershell
53-
if: ${{ matrix.BUILD_BITS == '32' }}
33+
choco install rtools --no-progress
5434
55-
- run: |
56-
# see https://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg586184.html
57-
if [ "${{ matrix.BUILD_BITS }}" == "64" ]; then
58-
include=/c/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/avx512fintrin.h
59-
else
60-
include=/c/ProgramData/Chocolatey/lib/mingw/tools/install/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/avx512fintrin.h
61-
fi
62-
sed -i -e"s/_mm512_abs_pd (__m512 __A)/_mm512_abs_pd (__m512d __A)/" $include
63-
name: Fix gcc bug
35+
- name: Set env variables
36+
run: |
37+
echo "START_DIR=$PWD" >> $env:GITHUB_ENV
38+
$BITS = ${{ matrix.BUILD_BITS }}
39+
echo "BUILD_BITS=$BITS" >> $env:GITHUB_ENV
40+
# For interpretation of MSYSTEM, see:
41+
# https://sourceforge.net/p/msys2/discussion/general/thread/b7dfdac8/#3939
42+
if ($BITS -eq 32) {
43+
echo "PLAT=i686" >> $env:GITHUB_ENV
44+
echo "MSYSTEM=MINGW32" >> $env:GITHUB_ENV
45+
echo "LDFLAGS=-static -static-libgcc" >> $env:GITHUB_ENV
46+
} else {
47+
echo "PLAT=x86_64" >> $env:GITHUB_ENV
48+
echo "MSYSTEM=UCRT64" >> $env:GITHUB_ENV
49+
echo "LDFLAGS=-lucrt -static -static-libgcc" >> $env:GITHUB_ENV
50+
}
51+
if ( ${{ matrix.INTERFACE64 }} -eq 1 ) {
52+
echo "INTERFACE64=1" >> $env:GITHUB_ENV
53+
}
6454
6555
- name: Build
6656
run: |
67-
BITS=${{ matrix.BUILD_BITS }}
68-
if [ "${{ matrix.INTERFACE64 }}" == "1" ]; then
69-
export INTERFACE64=1
70-
fi
71-
if [ "$BITS" == "32" ]; then
72-
export PATH=/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw32/bin:$PATH
73-
fi
74-
echo $PATH
7557
git submodule update --init --recursive
76-
tools/build_openblas.sh
58+
& $env:BASH_PATH -lc tools/build_openblas.sh
7759
7860
- name: Test
7961
run: |
80-
BITS=${{ matrix.BUILD_BITS }}
81-
if [ "$BITS" == "32" ]; then
82-
export PATH=/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw32/bin:$PATH
83-
fi
84-
if [ "${{ matrix.INTERFACE64 }}" == "1" ]; then
85-
export INTERFACE64=1
86-
fi
87-
tools/build_gfortran.sh
88-
cp test.exe builds
89-
cp test_dyn.exe builds
90-
./test.exe
91-
cp $(cygpath $OPENBLAS_ROOT)/$BITS/bin/*.dll .
92-
./test_dyn.exe
62+
& $env:BASH_PATH -lc tools/build_gfortran.sh
63+
echo "Static test"
64+
.\for_test\test.exe
65+
echo "Dynamic test"
66+
.\for_test\test_dyn.exe
67+
68+
- name: Copy
69+
run: |
70+
cp for_test\test*.exe builds
9371
9472
- uses: actions/upload-artifact@v3
9573
with:
@@ -100,4 +78,4 @@ jobs:
10078
OPENBLAS_LIBS_STAGING_UPLOAD_TOKEN: ${{ secrets.MULTIBUILD_WHEELS_STAGING_ACCESS }}
10179
run: |
10280
pip install -q git+https://github.com/Anaconda-Platform/anaconda-client@1.8.0
103-
tools/upload_to_anaconda_staging.sh
81+
& $env:BASH_PATH -lc tools/upload_to_anaconda_staging.sh

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ builds/
33
*~
44
*.pyc
55
*.swp
6-
test.exe
6+
for_test/

OpenBLAS

tools/build_gfortran.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
set -e
44

5-
cd $(cygpath "$START_DIR")
5+
rm -rf for_test
6+
mkdir for_test
7+
cd for_test
8+
9+
repo_path=$(cygpath "$START_DIR")
610
OBP=$(cygpath $OPENBLAS_ROOT\\$BUILD_BITS)
711

812
static_libname=$(find $OBP/lib -maxdepth 1 -type f -name '*.a' \! -name '*.dll.a' | tail -1)
913
dynamic_libname=$(find $OBP/lib -maxdepth 1 -type f -name '*.dll.a' | tail -1)
14+
dll_name=$(echo $dynamic_libname | sed 's#/lib/#/bin/#' | sed 's/.a$//')
15+
16+
cp $dll_name .
1017

1118
if [ "$INTERFACE64" == "1" ]; then
12-
gfortran -I $OBP/include -fdefault-integer-8 -o test.exe test64_.f90 $static_libname
13-
gfortran -I $OBP/include -fdefault-integer-8 -o test_dyn.exe test64_.f90 $dynamic_libname
19+
gfortran -I $OBP/include -fdefault-integer-8 -o test.exe ${repo_path}/test64_.f90 $static_libname
20+
gfortran -I $OBP/include -fdefault-integer-8 -o test_dyn.exe ${repo_path}/test64_.f90 $dynamic_libname
1421
else
15-
gfortran -I $OBP/include -o test.exe test.f90 $static_libname
16-
gfortran -I $OBP/include -o test_dyn.exe test.f90 $dynamic_libname
22+
gfortran -I $OBP/include -o test.exe ${repo_path}/test.f90 $static_libname
23+
gfortran -I $OBP/include -o test_dyn.exe ${repo_path}/test.f90 $dynamic_libname
1724
fi

tools/build_openblas.sh

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,62 @@
11
#!/bin/bash
22
# Build script for OpenBLAS on Windows
3-
# Expects environment variables:
4-
# OPENBLAS_ROOT
5-
# OPENBLAS_COMMIT
6-
# BUILD_BITS
7-
# START_DIR
8-
# Expects "lib.exe" and "gcc" to be on the path
3+
#
4+
# Usage: build_openblas.sh [openblas_root [build_bits [if_bits]]]
5+
#
6+
# e.g build_openblas.sh c:\\opt 64 32
7+
#
8+
# Uses the optional environment variables. We always prefer command line argument
9+
# values above to environment variable values:
10+
#
11+
# OPENBLAS_ROOT (default directory root for binaries, unspecified -> c:\opt).
12+
# BUILD_BITS (default binary architecture, 32 or 64, unspec -> 64).
13+
# INTERFACE64 (1 for 64-bit interface, anything else or undefined for 32,
14+
# This gives the default value if if_bits not specified above).
15+
# START_DIR (directory containing OpenBLAS source, unspec -> .. from here)
16+
# OPENBLAS_COMMIT (unspec -> current submodule commit)
17+
# LDFLAGS (example: "-lucrt -static -static-libgcc")
18+
#
19+
# Expects at leasts these binaries on the PATH:
20+
# realpath, cygpath, zip, gcc, make, ar, dlltool
21+
# usually as part of an msys installation.
922

10-
set -ex
23+
# Convert to Unix-style path
24+
openblas_root="$(cygpath ${1:-${OPENBLAS_ROOT:-c:\\opt}})"
25+
build_bits="${2:-${BUILD_BITS:-64}}"
26+
if [ "$INTERFACE64" == "1" ]; then if_default=64; else if_default=32; fi
27+
if_bits=${3:-${if_default}}
28+
# Our directory for later copying
29+
if [ -z "$START_DIR" ]; then
30+
our_wd="$(realpath $(dirname "${BASH_SOURCE[0]}")/..)"
31+
else
32+
our_wd=$(cygpath "$START_DIR")
33+
fi
1134

12-
# Paths in Unix format
13-
OPENBLAS_ROOT=$(cygpath "$OPENBLAS_ROOT")
35+
echo "Building from $our_wd, to $openblas_root"
36+
echo "Binaries are $build_bits bit, interface is $if_bits bit"
37+
echo "Using gcc at $(which gcc), --version:"
38+
gcc --version
1439

15-
# Our directory for later copying
16-
our_wd=$(cygpath "$START_DIR")
17-
cd $our_wd
1840
# Make output directory for build artifacts
19-
rm -rf builds
20-
mkdir builds
41+
builds_dir="$our_wd/builds"
42+
rm -rf $builds_dir
43+
mkdir $builds_dir
2144

22-
cd OpenBLAS
45+
cd "${our_wd}/OpenBLAS"
2346
git submodule update --init --recursive
2447

25-
# Check which gcc we're using
26-
which gcc
27-
gcc --version
2848

2949
# Get / clean code
3050
git fetch origin
31-
git checkout $OPENBLAS_COMMIT
51+
if [ -n "$OPENBLAS_COMMIT" ]; then
52+
git checkout $OPENBLAS_COMMIT
53+
fi
3254
git clean -fxd
3355
git reset --hard
34-
rm -rf $OPENBLAS_ROOT/$BUILD_BITS
56+
rm -rf $openblas_root/$build_bits
3557

3658
# Set architecture flags
37-
if [ "$BUILD_BITS" == 64 ]; then
59+
if [ "$build_bits" == 64 ]; then
3860
march="x86-64"
3961
# https://csharp.wekeepcoding.com/article/10463345/invalid+register+for+.seh_savexmm+in+Cygwin
4062
extra="-fno-asynchronous-unwind-tables"
@@ -51,9 +73,9 @@ cflags="-O2 -march=$march -mtune=generic $extra"
5173
fflags="$fextra $cflags -frecursive -ffpe-summary=invalid,zero"
5274

5375
# Set suffixed-ILP64 flags
54-
if [ "$INTERFACE64" == "1" ]; then
55-
interface64_flags="INTERFACE64=1 SYMBOLSUFFIX=64_"
56-
SYMBOLSUFFIX=64_
76+
if [ "$if_bits" == "64" ]; then
77+
SYMBOLSUFFIX="64_"
78+
interface64_flags="INTERFACE64=1 SYMBOLSUFFIX=${SYMBOLSUFFIX}"
5779
# We override FCOMMON_OPT, so we need to set default integer manually
5880
fflags="$fflags -fdefault-integer-8"
5981
else
@@ -66,42 +88,50 @@ OPENBLAS_VERSION=$(git describe --tags)
6688
# Build OpenBLAS
6789
# Variable used in creating output libraries
6890
export LIBNAMESUFFIX=${OPENBLAS_VERSION}-${GCC_TAG}
69-
make BINARY=$BUILD_BITS DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \
91+
make BINARY=$build_bits DYNAMIC_ARCH=1 USE_THREAD=1 USE_OPENMP=0 \
7092
NUM_THREADS=24 NO_WARMUP=1 NO_AFFINITY=1 CONSISTENT_FPCSR=1 \
7193
BUILD_LAPACK_DEPRECATED=1 TARGET=PRESCOTT BUFFERSIZE=20\
94+
LDFLAGS="$LDFLAGS" \
7295
COMMON_OPT="$cflags" \
7396
FCOMMON_OPT="$fflags" \
7497
MAX_STACK_ALLOC=2048 \
7598
$interface64_flags
76-
make PREFIX=$OPENBLAS_ROOT/$BUILD_BITS $interface64_flags install
99+
make PREFIX=$openblas_root/$build_bits $interface64_flags install
77100
DLL_BASENAME=libopenblas${SYMBOLSUFFIX}_${LIBNAMESUFFIX}
78-
if [ "$INTERFACE64" == "1" ]; then
101+
if [ "$if_bits" == "64" ]; then
79102
# OpenBLAS does not build a symbol-suffixed static library on Windows:
80103
# do it ourselves
81104
set -x # echo commands
82105
static_libname=$(find . -maxdepth 1 -type f -name '*.a' \! -name '*.dll.a' | tail -1)
83106
make -C exports $interface64_flags objcopy.def
84107
objcopy --redefine-syms exports/objcopy.def "${static_libname}" "${static_libname}.renamed"
85-
cp -f "${static_libname}.renamed" "$OPENBLAS_ROOT/$BUILD_BITS/lib/${static_libname}"
86-
cp -f "${static_libname}.renamed" "$OPENBLAS_ROOT/$BUILD_BITS/lib/${DLL_BASENAME}.a"
108+
cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${static_libname}"
109+
cp -f "${static_libname}.renamed" "$openblas_root/$build_bits/lib/${DLL_BASENAME}.a"
87110
set +x
88111
fi
89-
cd $OPENBLAS_ROOT
112+
cd $openblas_root
90113
# Copy library link file for custom name
91-
cd $BUILD_BITS/lib
114+
cd $build_bits/lib
115+
cp ${our_wd}/OpenBLAS/exports/${DLL_BASENAME}.def ${DLL_BASENAME}.def
92116
# At least for the mingwpy wheel, we have to use the VC tools to build the
93117
# export library. Maybe fixed in later binutils by patch referred to in
94118
# https://sourceware.org/ml/binutils/2016-02/msg00002.html
95-
cp ${our_wd}/OpenBLAS/exports/${DLL_BASENAME}.def ${DLL_BASENAME}.def
96-
"lib.exe" /machine:${vc_arch} /def:${DLL_BASENAME}.def
119+
# "lib.exe" /machine:${vc_arch} /def:${DLL_BASENAME}.def
120+
# Maybe this will now work (after 2016 patch above).
121+
dlltool --input-def ${DLL_BASENAME}.def \
122+
--output-exp ${DLL_BASENAME}.exp \
123+
--dllname ${DLL_BASENAME}.dll \
124+
--output-lib ${DLL_BASENAME}.lib
125+
# Replace the DLL name with the generated name.
126+
sed -i "s/ -lopenblas$/ -l${DLL_BASENAME:3}/g" pkgconfig/openblas.pc
97127
cd ../..
98128
# Build template site.cfg for using this build
99-
cat > ${BUILD_BITS}/site.cfg.template << EOF
129+
cat > ${build_bits}/site.cfg.template << EOF
100130
[openblas${SYMBOLSUFFIX}]
101131
libraries = $DLL_BASENAME
102-
library_dirs = {openblas_root}\\${BUILD_BITS}\\lib
103-
include_dirs = {openblas_root}\\${BUILD_BITS}\\include
132+
library_dirs = {openblas_root}\\${build_bits}\\lib
133+
include_dirs = {openblas_root}\\${build_bits}\\include
104134
EOF
105-
ZIP_NAME="openblas${SYMBOLSUFFIX}-${OPENBLAS_VERSION}-${plat_tag}-${GCC_TAG}.zip"
106-
zip -r $ZIP_NAME $BUILD_BITS
107-
cp $ZIP_NAME $our_wd/builds
135+
zip_name="openblas${SYMBOLSUFFIX}-${OPENBLAS_VERSION}-${plat_tag}-${GCC_TAG}.zip"
136+
zip -r $zip_name $build_bits
137+
cp $zip_name ${builds_dir}

0 commit comments

Comments
 (0)