Skip to content

Commit a541dbd

Browse files
authored
Merge pull request numpy#24174 from charris/backport-24162
ENH: Improve clang-cl compliance
2 parents f9e8543 + d8fa9a1 commit a541dbd

File tree

7 files changed

+138
-10
lines changed

7 files changed

+138
-10
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Test Clang-CL Build (Windows)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- maintenance/**
8+
9+
env:
10+
PYTHON_VERSION: 3.11
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read # to fetch code (actions/checkout)
18+
19+
jobs:
20+
meson:
21+
name: Meson windows build/test
22+
runs-on: windows-2019
23+
# if: "github.repository == 'numpy/numpy'"
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
27+
with:
28+
submodules: recursive
29+
fetch-depth: 0
30+
- name: Setup Python
31+
uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
32+
with:
33+
python-version: ${{ env.PYTHON_VERSION }}
34+
35+
- name: Install dependencies
36+
run: |
37+
pip install -r build_requirements.txt
38+
- name: openblas-libs
39+
run: |
40+
# Download and install pre-built OpenBLAS library
41+
# with 32-bit interfaces
42+
# Unpack it in the pkg-config hardcoded path
43+
choco install unzip -y
44+
choco install wget -y
45+
# Install llvm, which contains clang-cl
46+
choco install llvm -y --version=16.0.6
47+
choco install -y --checksum 6004DF17818F5A6DBF19CB335CC92702 pkgconfiglite
48+
wget https://anaconda.org/multibuild-wheels-staging/openblas-libs/v0.3.21/download/openblas-v0.3.21-win_amd64-gcc_10_3_0.zip
49+
unzip -d c:\opt openblas-v0.3.21-win_amd64-gcc_10_3_0.zip
50+
echo "PKG_CONFIG_PATH=c:\opt\64\lib\pkgconfig;" >> $env:GITHUB_ENV
51+
- name: meson-configure
52+
run: |
53+
"[binaries]","c = 'clang-cl'","cpp = 'clang-cl'","ar = 'llvm-lib'","c_ld = 'lld-link'","cpp_ld = 'lld-link'" | Out-File $PWD/clang-cl-build.ini -Encoding ascii
54+
meson setup build --prefix=$PWD\build-install --native-file=$PWD/clang-cl-build.ini -Ddebug=false --optimization 2 --vsenv
55+
- name: meson-build
56+
run: |
57+
meson compile -C build -v
58+
59+
- name: meson-install
60+
run: |
61+
cd build
62+
meson install --no-rebuild
63+
- name: build-path
64+
run: |
65+
echo "installed_path=$PWD\build-install\Lib\site-packages" >> $env:GITHUB_ENV
66+
- name: post-install
67+
run: |
68+
$numpy_path = "${env:installed_path}\numpy"
69+
$libs_path = "${numpy_path}\.libs"
70+
mkdir ${libs_path}
71+
$ob_path = "C:/opt/64/bin/"
72+
cp $ob_path/*.dll $libs_path
73+
# Write _distributor_init.py to load .libs DLLs.
74+
python -c "from tools import openblas_support; openblas_support.make_init(r'${numpy_path}')"
75+
76+
- name: prep-test
77+
run: |
78+
echo "PYTHONPATH=${env:installed_path}" >> $env:GITHUB_ENV
79+
python -m pip install -r test_requirements.txt
80+
python -m pip install threadpoolctl
81+
82+
- name: test
83+
run: |
84+
mkdir tmp
85+
cd tmp
86+
echo "============================================"
87+
python -c "import numpy; print(numpy.show_runtime())"
88+
echo "============================================"
89+
echo "LASTEXITCODE is '$LASTEXITCODE'"
90+
python -c "import numpy, sys; sys.exit(numpy.test(verbose=3) is False)"
91+
echo "LASTEXITCODE is '$LASTEXITCODE'"

build_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ meson-python>=0.10.0
22
Cython>=0.29.34,<3.0
33
wheel==0.38.1
44
ninja
5-
spin==0.3
5+
spin==0.4

doc_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ breathe>4.33.0
1111

1212
# needed to build release notes
1313
towncrier
14+
toml

numpy/core/src/multiarray/_multiarray_tests.c.src

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,13 +2054,13 @@ get_fpu_mode(PyObject *NPY_UNUSED(self), PyObject *args)
20542054
return NULL;
20552055
}
20562056

2057-
#if defined(_MSC_VER)
2057+
#if defined(_MSC_VER) && !defined(__clang__)
20582058
{
20592059
unsigned int result = 0;
20602060
result = _controlfp(0, 0);
20612061
return PyLong_FromLongLong(result);
20622062
}
2063-
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
2063+
#elif (defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))) || (defined(_MSC_VER) && defined(__clang__))
20642064
{
20652065
unsigned short cw = 0;
20662066
__asm__("fstcw %w0" : "=m" (cw));

numpy/core/tests/test_einsum.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import itertools
2+
import sys
3+
import platform
24

35
import pytest
46

@@ -8,6 +10,12 @@
810
assert_raises, suppress_warnings, assert_raises_regex, assert_allclose
911
)
1012

13+
try:
14+
COMPILERS = np.show_config(mode="dicts")["Compilers"]
15+
USING_CLANG_CL = COMPILERS["c"]["name"] == "clang-cl"
16+
except TypeError:
17+
USING_CLANG_CL = False
18+
1119
# Setup for optimize einsum
1220
chars = 'abcdefghij'
1321
sizes = np.array([2, 3, 4, 5, 4, 3, 2, 6, 5, 4, 3])
@@ -102,7 +110,7 @@ def test_einsum_errors(self):
102110

103111
def test_einsum_object_errors(self):
104112
# Exceptions created by object arithmetic should
105-
# successfully propogate
113+
# successfully propagate
106114

107115
class CustomException(Exception):
108116
pass
@@ -609,9 +617,23 @@ def check_einsum_sums(self, dtype, do_opt=False):
609617
[2.]) # contig_stride0_outstride0_two
610618

611619
def test_einsum_sums_int8(self):
620+
if (
621+
(sys.platform == 'darwin' and platform.machine() == 'x86_64')
622+
or
623+
USING_CLANG_CL
624+
):
625+
pytest.xfail('Fails on macOS x86-64 and when using clang-cl '
626+
'with Meson, see gh-23838')
612627
self.check_einsum_sums('i1')
613628

614629
def test_einsum_sums_uint8(self):
630+
if (
631+
(sys.platform == 'darwin' and platform.machine() == 'x86_64')
632+
or
633+
USING_CLANG_CL
634+
):
635+
pytest.xfail('Fails on macOS x86-64 and when using clang-cl '
636+
'with Meson, see gh-23838')
615637
self.check_einsum_sums('u1')
616638

617639
def test_einsum_sums_int16(self):

numpy/core/tests/test_scalarmath.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
assert_warns, _SUPPORTS_SVE,
1818
)
1919

20+
try:
21+
COMPILERS = np.show_config(mode="dicts")["Compilers"]
22+
USING_CLANG_CL = COMPILERS["c"]["name"] == "clang-cl"
23+
except TypeError:
24+
USING_CLANG_CL = False
25+
2026
types = [np.bool_, np.byte, np.ubyte, np.short, np.ushort, np.intc, np.uintc,
2127
np.int_, np.uint, np.longlong, np.ulonglong,
2228
np.single, np.double, np.longdouble, np.csingle,
@@ -798,7 +804,13 @@ class TestBitShifts:
798804
@pytest.mark.parametrize('op',
799805
[operator.rshift, operator.lshift], ids=['>>', '<<'])
800806
def test_shift_all_bits(self, type_code, op):
801-
""" Shifts where the shift amount is the width of the type or wider """
807+
"""Shifts where the shift amount is the width of the type or wider """
808+
if (
809+
USING_CLANG_CL and
810+
type_code in ("l", "L") and
811+
op is operator.lshift
812+
):
813+
pytest.xfail("Failing on clang-cl builds")
802814
# gh-2449
803815
dt = np.dtype(type_code)
804816
nbits = dt.itemsize * 8

test_requirements.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
cython>=0.29.34,<3.0
22
wheel==0.38.1
3-
setuptools==59.2.0
4-
hypothesis==6.24.1
5-
pytest==6.2.5
6-
pytz==2021.3
7-
pytest-cov==3.0.0
3+
setuptools==59.2.0 ; python_version < '3.12'
4+
setuptools ; python_version >= '3.12'
5+
hypothesis==6.81.1
6+
pytest==7.4.0
7+
pytz==2023.3
8+
pytest-cov==4.1.0
9+
pytest-xdist
810
# for numpy.random.test.test_extending
911
cffi; python_version < '3.10'
1012
# For testing types. Notes on the restrictions:

0 commit comments

Comments
 (0)