Update information about need to use modern standards in c++

add test for c++ standards for all platform change macos platform tag on more generic.
This commit is contained in:
Grzegorz Bokota
2020-01-16 16:10:05 +01:00
parent d17517902e
commit 758f158bbd
5 changed files with 149 additions and 6 deletions
@@ -0,0 +1,55 @@
import os
import sys
import pytest
import utils
def test_cpp11(tmp_path):
add_env = {"CIBW_SKIP": "cp27-win*", "CIBW_ENVIRONMENT": "STANDARD=11"}
# VC for python 2.7 do not support modern standards
if utils.platform == "macos":
add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.9"
project_dir = os.path.dirname(__file__)
# this test checks if c++11 standard is supported.
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env)
expected_wheels = [x for x in utils.expected_wheels('spam', '0.1.0', "10.9") if "cp27-cp27m-win" not in x]
assert set(actual_wheels) == set(expected_wheels)
def test_cpp14():
add_env = {"CIBW_SKIP": "cp27-win* cp35-win*", "CIBW_ENVIRONMENT": "STANDARD=14"}
# VC for python 2.7 do not support modern standards
# manylinux1 docker image do not support compilers with standards newer than c++11
# python 3.4 and 3.5 are compiled with MSVC 10. which not support c++14
if utils.platform == "macos":
add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.9"
project_dir = os.path.dirname(__file__)
# this test checks if c++14 standard is supported.
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env)
expected_wheels = [x for x in utils.expected_wheels('spam', '0.1.0', "10.9")
if "cp27-cp27m-win" not in x and "cp35-cp35m-win" not in x]
assert set(actual_wheels) == set(expected_wheels)
def test_cpp17():
# python 2.7 use `register` keyword which is forbidden in c++17 standard
# manylinux1 docker image do not support compilers with standards newer than c++11
# python 3.4 and 3.5 are compiled with MSVC 10. which not support c++17
if os.environ.get("APPVEYOR_BUILD_WORKER_IMAGE", "") == "Visual Studio 2015":
pytest.skip("Visual Studio 2015 does not support c++17")
add_env = {"CIBW_SKIP": "cp27-win* cp35-win*", "CIBW_ENVIRONMENT": "STANDARD=17"}
if utils.platform == "macos":
add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.13"
project_dir = os.path.dirname(__file__)
# this test checks if c++17 standard is supported.
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env)
expected_wheels = [x for x in utils.expected_wheels('spam', '0.1.0', "10.13")
if "cp27-cp27m-win" not in x and "cp35-cp35m-win" not in x]
assert set(actual_wheels) == set(expected_wheels)
+21
View File
@@ -0,0 +1,21 @@
import os, sys
from setuptools import setup, Extension
import platform
standard = os.environ["STANDARD"]
language_standard = "/std:c++" + standard if platform.system() == "Windows" else "-std=c++" + standard
extra_compile_args=[language_standard, "-DSTANDARD=" + standard]
if standard == "17":
if platform.system() == "Windows":
extra_compile_args.append("/wd5033")
else:
extra_compile_args.append("-Wno-register")
setup(
name="spam",
ext_modules=[Extension('spam', sources=['spam.cpp'], language="c++", extra_compile_args=extra_compile_args)],
version="0.1.0",
)
+62
View File
@@ -0,0 +1,62 @@
#include <Python.h>
#include <string>
#if STANDARD == 11
#include <array>
#elif STANDARD == 14
int a = 100'000;
#elif STANDARD == 17
#include <utility>
auto a = std::pair(5.0, false);
#else
#error Standard needed
#endif
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
static PyObject *
spam_system(PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return PyLong_FromLong(sts);
}
/* Module initialization */
#if PY_MAJOR_VERSION >= 3
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
#define MOD_DEF(m, name, doc, methods, module_state_size) \
static struct PyModuleDef moduledef = { \
PyModuleDef_HEAD_INIT, name, doc, module_state_size, methods, }; \
m = PyModule_Create(&moduledef);
#define MOD_RETURN(m) return m;
#else
#define MOD_INIT(name) PyMODINIT_FUNC init##name(void)
#define MOD_DEF(m, name, doc, methods, module_state_size) \
m = Py_InitModule3(name, methods, doc);
#define MOD_RETURN(m) return;
#endif
static PyMethodDef module_methods[] = {
{"system", (PyCFunction)spam_system, METH_VARARGS,
"Execute a shell command."},
{NULL} /* Sentinel */
};
MOD_INIT(spam)
{
PyObject* m;
MOD_DEF(m,
"spam",
"Example module",
module_methods,
-1)
MOD_RETURN(m)
}