-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
build_python_wheels.sh
73 lines (65 loc) · 2.82 KB
/
build_python_wheels.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
set -e
set -x
if [[ $# -ne 2 ]]; then
echo "Usage: $0 [platform_id] [commit ID]"
exit 1
fi
platform_id=$1
commit_id=$2
# Bundle libomp 11.1.0 when targeting MacOS.
# This is a workaround in order to prevent segfaults when running inside a Conda environment.
# See https://github.com/dmlc/xgboost/issues/7039#issuecomment-1025125003 for more context.
# The workaround is also used by the scikit-learn project.
if [[ "$platform_id" == macosx_* ]]; then
# Make sure to use a libomp version binary compatible with the oldest
# supported version of the macos SDK as libomp will be vendored into the
# XGBoost wheels for MacOS.
if [[ "$platform_id" == macosx_arm64 ]]; then
# MacOS, Apple Silicon
# arm64 builds must cross compile because CI is on x64
# cibuildwheel will take care of cross-compilation.
wheel_tag=macosx_12_0_arm64
cpython_ver=39
cibw_archs=arm64
export MACOSX_DEPLOYMENT_TARGET=12.0
#OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2"
OPENMP_URL="https://xgboost-ci-jenkins-artifacts.s3.us-west-2.amazonaws.com/llvm-openmp-11.1.0-hf3c4609_1-osx-arm64.tar.bz2"
elif [[ "$platform_id" == macosx_x86_64 ]]; then
# MacOS, Intel
wheel_tag=macosx_10_15_x86_64.macosx_11_0_x86_64.macosx_12_0_x86_64
cpython_ver=39
cibw_archs=x86_64
export MACOSX_DEPLOYMENT_TARGET=10.15
#OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2"
OPENMP_URL="https://xgboost-ci-jenkins-artifacts.s3.us-west-2.amazonaws.com/llvm-openmp-11.1.0-hda6cdc1_1-osx-64.tar.bz2"
else
echo "Platform not supported: $platform_id"
exit 3
fi
# Set up environment variables to configure cibuildwheel
export CIBW_BUILD=cp${cpython_ver}-${platform_id}
export CIBW_ARCHS=${cibw_archs}
export CIBW_ENVIRONMENT=${setup_env_var}
export CIBW_TEST_SKIP='*-macosx_arm64'
export CIBW_BUILD_VERBOSITY=3
mamba create -n build $OPENMP_URL
PREFIX="$HOME/miniconda3/envs/build"
# Set up build flags for cibuildwheel
# This is needed to bundle libomp lib we downloaded earlier
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I$PREFIX/include"
export CXXFLAGS="$CXXFLAGS -I$PREFIX/include"
export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib -L$PREFIX/lib -lomp"
else
echo "Platform not supported: $platform_id"
exit 2
fi
python -m pip install cibuildwheel
python -m cibuildwheel python-package --output-dir wheelhouse
python tests/ci_build/rename_whl.py \
--wheel-path wheelhouse/*.whl \
--commit-hash ${commit_id} \
--platform-tag ${wheel_tag}