File tree Expand file tree Collapse file tree 1 file changed +29
-3
lines changed
Expand file tree Collapse file tree 1 file changed +29
-3
lines changed Original file line number Diff line number Diff line change 1+ from functools import partial
12from typing import Any
23
34from Cython .Build import cythonize
910 "demo.core" ,
1011 sources = ["lib/core.pyx" , "lib/libcore.cpp" ],
1112 language = "c++" ,
12- extra_compile_args = ["-std=c++17" ],
13- extra_link_args = ["-std=c++17" ],
1413 ),
1514]
1615
1716
17+ class BuildExt (build_ext ):
18+
19+ compiler_flags = {
20+ "msvc" : "/std:{std}" ,
21+ "unix" : "-std={std}" ,
22+ }
23+
24+ def __init__ (self , * args : Any , std : str = "" , ** kwargs : Any ):
25+ self .std = std
26+ super ().__init__ (* args , ** kwargs )
27+
28+ def build_extensions (self ):
29+ if self .std :
30+ std_options = [self .compiler_flags [self .compiler .compiler_type ].format (std = self .std )]
31+ else :
32+ std_options = []
33+
34+ for ext in self .extensions :
35+ ext .extra_compile_args += std_options
36+ ext .extra_link_args += std_options
37+
38+ super ().build_extensions ()
39+
40+
41+ Cpp20BuildExt = partial (BuildExt , std = "c++20" )
42+
43+
1844def build (setup_kwargs : dict [str , Any ]):
1945 setup_kwargs .update (
2046 {
2147 "ext_modules" : cythonize (ext_modules ),
22- "cmdclass" : {"build_ext" : build_ext },
48+ "cmdclass" : {"build_ext" : Cpp20BuildExt },
2349 }
2450 )
You can’t perform that action at this time.
0 commit comments