Skip to content

Commit 5f96c46

Browse files
committed
TST: verify that compilation uses MSVC when available
1 parent f4206b3 commit 5f96c46

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-FileCopyrightText: 2023 The meson-python developers
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Python.h>
6+
7+
#if defined _MSC_VER
8+
# define _COMPILER "msvc"
9+
#elif defined __clang__
10+
# define _COMPILER "clang"
11+
#elif defined __GNUC__
12+
# define _COMPILER "gcc"
13+
#else
14+
# define _COMPILER "unknow"
15+
#endif
16+
17+
static PyObject* compiler(PyObject* self)
18+
{
19+
return PyUnicode_FromString(_COMPILER);
20+
}
21+
22+
static PyMethodDef methods[] = {
23+
{"compiler", (PyCFunction)compiler, METH_NOARGS, NULL},
24+
{NULL, NULL, 0, NULL},
25+
};
26+
27+
static struct PyModuleDef module = {
28+
PyModuleDef_HEAD_INIT,
29+
"detect_compiler",
30+
NULL,
31+
-1,
32+
methods,
33+
};
34+
35+
PyMODINIT_FUNC PyInit_detect_compiler(void)
36+
{
37+
return PyModule_Create(&module);
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2023 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
project(
6+
'detect-compiler',
7+
'c',
8+
version: '1.0',
9+
)
10+
11+
py = import('python').find_installation()
12+
13+
py.extension_module('detect_compiler', 'detect_compiler.c', install: true)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: 2023 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
[build-system]
6+
build-backend = 'mesonpy'
7+
requires = ['meson-python']

tests/test_project.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
import ast
6-
import os.path
6+
import os
77
import platform
88
import shutil
99
import sys
@@ -219,3 +219,15 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
219219
assert meson.call_args_list[0].args[1][1] == 'setup'
220220
assert '--reconfigure' not in meson.call_args_list[0].args[1]
221221
project.build()
222+
223+
224+
@pytest.mark.skipif(not os.getenv('CI') or platform.system() != 'Windows', reason='Requires MSVC')
225+
def test_compiler(venv, package_detect_compiler, tmp_path):
226+
# Check that things are setup properly to use the MSVC compiler on
227+
# Windows. This effectively means running the compilation step
228+
# with 'meson compile' instead of 'ninja' on Windows. Run this
229+
# test only on CI where we know that MSVC is available.
230+
wheel = mesonpy.build_wheel(tmp_path, {'setup-args': ['--vsenv']})
231+
venv.pip('install', os.fspath(tmp_path / wheel))
232+
compiler = venv.python('-c', 'import detect_compiler; print(detect_compiler.compiler())').strip()
233+
assert compiler == 'msvc'

0 commit comments

Comments
 (0)