Skip to content

Commit 6c01a58

Browse files
committed
TST: verify that compilation uses MSVC when available
1 parent ddbcce4 commit 6c01a58

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-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: 14 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
@@ -215,3 +215,16 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
215215
assert meson.call_args_list[0].args[1][1] == 'setup'
216216
assert '--reconfigure' not in meson.call_args_list[0].args[1]
217217
project.build()
218+
219+
220+
@pytest.mark.skipif(not os.getenv('CI') or platform.system() != 'Windows', reason='Requires MSVC')
221+
def test_compiler(venv, package_detect_compiler, tmp_path):
222+
# Check that things are setup properly to use the MSVC compiler on
223+
# Windows. This effectively means running the compilation step
224+
# with 'meson compile' instead of 'ninja' on Windows. Run this
225+
# test only on CI where we know that MSVC is available.
226+
with mesonpy._project({'setup-args': ['--vsenv']}) as project:
227+
wheel = project.wheel(tmp_path)
228+
venv.pip('install', os.fspath(wheel))
229+
compiler = venv.python('-c', 'import detect_compiler; print(detect_compiler.compiler())').strip()
230+
assert compiler == 'msvc'

0 commit comments

Comments
 (0)