Skip to content

Commit

Permalink
TST: verify that compilation uses MSVC when available
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Apr 10, 2023
1 parent d87fcbb commit e742188
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
38 changes: 38 additions & 0 deletions tests/packages/detect-compiler/detect_compiler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: 2023 The meson-python developers
//
// SPDX-License-Identifier: MIT

#include <Python.h>

#if defined _MSC_VER
# define _COMPILER "msvc"
#elif defined __clang__
# define _COMPILER "clang"
#elif defined __GNUC__
# define _COMPILER "gcc"
#else
# define _COMPILER "unknown"
#endif

static PyObject* compiler(PyObject* self)
{
return PyUnicode_FromString(_COMPILER);
}

static PyMethodDef methods[] = {
{"compiler", (PyCFunction)compiler, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL},
};

static struct PyModuleDef module = {
PyModuleDef_HEAD_INIT,
"detect_compiler",
NULL,
-1,
methods,
};

PyMODINIT_FUNC PyInit_detect_compiler(void)
{
return PyModule_Create(&module);
}
13 changes: 13 additions & 0 deletions tests/packages/detect-compiler/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2023 The meson-python developers
#
# SPDX-License-Identifier: MIT

project(
'detect-compiler',
'c',
version: '1.0',
)

py = import('python').find_installation()

py.extension_module('detect_compiler', 'detect_compiler.c', install: true)
7 changes: 7 additions & 0 deletions tests/packages/detect-compiler/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2023 The meson-python developers
#
# SPDX-License-Identifier: MIT

[build-system]
build-backend = 'mesonpy'
requires = ['meson-python']
14 changes: 13 additions & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

import ast
import os.path
import os
import platform
import shutil
import sys
Expand Down Expand Up @@ -219,3 +219,15 @@ def test_invalid_build_dir(package_pure, tmp_path, mocker):
assert meson.call_args_list[0].args[1][1] == 'setup'
assert '--reconfigure' not in meson.call_args_list[0].args[1]
project.build()


@pytest.mark.skipif(not os.getenv('CI') or platform.system() != 'Windows', reason='Requires MSVC')
def test_compiler(venv, package_detect_compiler, tmp_path):
# Check that things are setup properly to use the MSVC compiler on
# Windows. This effectively means running the compilation step
# with 'meson compile' instead of 'ninja' on Windows. Run this
# test only on CI where we know that MSVC is available.
wheel = mesonpy.build_wheel(tmp_path, {'setup-args': ['--vsenv']})
venv.pip('install', os.fspath(tmp_path / wheel))
compiler = venv.python('-c', 'import detect_compiler; print(detect_compiler.compiler())').strip()
assert compiler == 'msvc'

0 comments on commit e742188

Please sign in to comment.