Scons builder for cython extensions (#2485)
	
		
	
				
					
				
			* complie boardd without python * not good, but don't want to lose the file, because it works * clean a bit * update dbc * should build on CI * not good, but don't want to lose the file, because it works * clean a bit * should build on CI * remove unneeded path * reorder paths * reduce diff * and now it works?! * ... should work in CI * add kj, 30% chance to fix macos * pydebug * new way to find path * fix :) * tested * sanity check * repl. MacOS flags * hope it works * need more logs * need more logs2 * test if it works * should work on CI * correct python file * should not work * cleanup * real cleanup * more removals * 50% of file * transformations * fixed a hardcoded variable * more logs * simpl. * kalman * all donw if it passes tests * cleanup * reduce code by 20 lines if this works * fix bugs * cleanup * SharedLibrary * cleanup * ... * remove unused * CI fix maybe? * add more valid path * more logs * ...: * fix webcam CI * remove WError flag * deprecated is not an error * more Wno things * reduce diff, add Wno to env * don't import nonexistent stuff * SharedLibrary v2 * less custom env * renaming, remove SharedLibs * pack libs in envCython * experiment * better docker caching * whitespace * more docker caching * improvement * improvements Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>pull/2527/head
							parent
							
								
									8896b7a791
								
							
						
					
					
						commit
						9529764549
					
				
				 20 changed files with 104 additions and 158 deletions
			
			
		| @ -1,14 +1,4 @@ | |||||||
| Import('env', 'cython_dependencies') | Import('envCython') | ||||||
| 
 | 
 | ||||||
| # Build cython clock module | envCython.Program('clock.so', 'clock.pyx') | ||||||
| env.Command(['common_pyx.so', 'clock.cpp'], | envCython.Program('params_pyx.so', 'params_pyx.pyx') | ||||||
|             cython_dependencies + ['common_pyx_setup.py', 'clock.pyx'], |  | ||||||
|             "cd common && python3 common_pyx_setup.py build_ext --inplace") |  | ||||||
| 
 |  | ||||||
| # Build cython params module |  | ||||||
| env.Command(['params_pyx.so', 'params_pyx.cpp'], |  | ||||||
|             cython_dependencies + [ |  | ||||||
|                 'params_pyx_setup.py', 'params_pyx.pyx', 'params_pxd.pxd', |  | ||||||
|                 '#selfdrive/common/params.cc', '#selfdrive/common/params.h', |  | ||||||
|                 '#selfdrive/common/util.c', '#selfdrive/common/util.h'], |  | ||||||
|             "cd common && python3 params_pyx_setup.py build_ext --inplace") |  | ||||||
|  | |||||||
| @ -1,20 +0,0 @@ | |||||||
| from distutils.core import Extension, setup  # pylint: disable=import-error,no-name-in-module |  | ||||||
| from Cython.Build import cythonize |  | ||||||
| 
 |  | ||||||
| from common.cython_hacks import BuildExtWithoutPlatformSuffix |  | ||||||
| 
 |  | ||||||
| sourcefiles = ['clock.pyx'] |  | ||||||
| extra_compile_args = ["-std=c++1z"] |  | ||||||
| 
 |  | ||||||
| setup(name='common', |  | ||||||
|       cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, |  | ||||||
|       ext_modules=cythonize( |  | ||||||
|         Extension( |  | ||||||
|           "common_pyx", |  | ||||||
|           language="c++", |  | ||||||
|           sources=sourcefiles, |  | ||||||
|           extra_compile_args=extra_compile_args, |  | ||||||
|         ), |  | ||||||
|         nthreads=4, |  | ||||||
|       ), |  | ||||||
| ) |  | ||||||
| @ -1,6 +1,3 @@ | |||||||
| Import('env', 'cython_dependencies') | Import('envCython') | ||||||
| 
 |  | ||||||
| env.Command(['simple_kalman_impl.so'], |  | ||||||
|             cython_dependencies + ['simple_kalman_impl.pyx', 'simple_kalman_impl.pxd', 'simple_kalman_setup.py'], |  | ||||||
|             "cd common/kalman && python3 simple_kalman_setup.py build_ext --inplace") |  | ||||||
| 
 | 
 | ||||||
|  | envCython.Program('simple_kalman_impl.so', 'simple_kalman_impl.pyx') | ||||||
|  | |||||||
| @ -1,10 +0,0 @@ | |||||||
| from distutils.core import Extension, setup |  | ||||||
| 
 |  | ||||||
| from Cython.Build import cythonize |  | ||||||
| 
 |  | ||||||
| from common.cython_hacks import BuildExtWithoutPlatformSuffix |  | ||||||
| 
 |  | ||||||
| setup(name='Simple Kalman Implementation', |  | ||||||
|       cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, |  | ||||||
|       ext_modules=cythonize(Extension("simple_kalman_impl", |  | ||||||
|                                       ["simple_kalman_impl.pyx"]))) |  | ||||||
| @ -1,33 +0,0 @@ | |||||||
| import os |  | ||||||
| import subprocess |  | ||||||
| from distutils.core import Extension, setup |  | ||||||
| from Cython.Build import cythonize |  | ||||||
| 
 |  | ||||||
| from common.cython_hacks import BuildExtWithoutPlatformSuffix |  | ||||||
| from common.basedir import BASEDIR |  | ||||||
| from common.hardware import TICI |  | ||||||
| 
 |  | ||||||
| ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()  # pylint: disable=unexpected-keyword-arg |  | ||||||
| 
 |  | ||||||
| sourcefiles = ['params_pyx.pyx'] |  | ||||||
| extra_compile_args = ["-std=c++1z"] |  | ||||||
| 
 |  | ||||||
| if ARCH == "aarch64": |  | ||||||
|   if TICI: |  | ||||||
|     extra_compile_args += ["-DQCOM2"] |  | ||||||
|   else: |  | ||||||
|     extra_compile_args += ["-DQCOM"] |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| setup(name='common', |  | ||||||
|       cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, |  | ||||||
|       ext_modules=cythonize( |  | ||||||
|         Extension( |  | ||||||
|           "params_pyx", |  | ||||||
|           language="c++", |  | ||||||
|           sources=sourcefiles, |  | ||||||
|           include_dirs=[BASEDIR, os.path.join(BASEDIR, 'selfdrive')], |  | ||||||
|           extra_compile_args=extra_compile_args |  | ||||||
|         ) |  | ||||||
|       ) |  | ||||||
| ) |  | ||||||
| @ -1,8 +1,3 @@ | |||||||
| Import('env', 'cython_dependencies') | Import('envCython') | ||||||
| 
 | 
 | ||||||
| d = Dir('.') | envCython.Program('transformations.so', 'transformations.pyx') | ||||||
| 
 |  | ||||||
| env.Command(['transformations.so'], |  | ||||||
|             cython_dependencies + ['transformations.pxd', 'transformations.pyx', |  | ||||||
|              'coordinates.cc', 'orientation.cc', 'coordinates.hpp', 'orientation.hpp'], |  | ||||||
|             'cd ' + d.path + ' && python3 setup.py build_ext --inplace') |  | ||||||
|  | |||||||
| @ -1,20 +0,0 @@ | |||||||
| import numpy |  | ||||||
| 
 |  | ||||||
| from Cython.Build import cythonize |  | ||||||
| from distutils.core import Extension, setup  # pylint: disable=import-error,no-name-in-module |  | ||||||
| from common.cython_hacks import BuildExtWithoutPlatformSuffix |  | ||||||
| 
 |  | ||||||
| setup( |  | ||||||
|   name='Cython transformations wrapper', |  | ||||||
|   cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, |  | ||||||
|   ext_modules=cythonize( |  | ||||||
|     Extension( |  | ||||||
|       "transformations", |  | ||||||
|       sources=["transformations.pyx"], |  | ||||||
|       language="c++", |  | ||||||
|       extra_compile_args=["-std=c++1z", "-Wno-cpp"], |  | ||||||
|       include_dirs=[numpy.get_include()], |  | ||||||
|     ), |  | ||||||
|     nthreads=4, |  | ||||||
|   ) |  | ||||||
| ) |  | ||||||
| @ -1,8 +1,6 @@ | |||||||
| Import('env', 'common', 'cereal', 'messaging', 'cython_dependencies') | Import('env', 'envCython', 'common', 'cereal', 'messaging') | ||||||
| 
 | 
 | ||||||
| env.Program('boardd', ['boardd.cc', 'panda.cc', 'pigeon.cc'], LIBS=['usb-1.0', common, cereal, messaging, 'pthread', 'zmq', 'capnp', 'kj']) | env.Program('boardd', ['boardd.cc', 'panda.cc', 'pigeon.cc'], LIBS=['usb-1.0', common, cereal, messaging, 'pthread', 'zmq', 'capnp', 'kj']) | ||||||
| env.Library('libcan_list_to_can_capnp', ['can_list_to_can_capnp.cc']) | env.Library('libcan_list_to_can_capnp', ['can_list_to_can_capnp.cc']) | ||||||
| 
 | 
 | ||||||
| env.Command(['boardd_api_impl.so', 'boardd_api_impl.cpp'], | envCython.Program('boardd_api_impl.so', 'boardd_api_impl.pyx', LIBS=["can_list_to_can_capnp", 'capnp', 'kj'] + envCython["LIBS"]) | ||||||
|             cython_dependencies + ['libcan_list_to_can_capnp.a', 'boardd_api_impl.pyx', 'boardd_setup.py'], |  | ||||||
|             "cd selfdrive/boardd && python3 boardd_setup.py build_ext --inplace") |  | ||||||
|  | |||||||
| @ -1,22 +0,0 @@ | |||||||
| from distutils.core import Extension, setup |  | ||||||
| from Cython.Build import cythonize |  | ||||||
| 
 |  | ||||||
| from common.cython_hacks import BuildExtWithoutPlatformSuffix |  | ||||||
| 
 |  | ||||||
| libraries = ['can_list_to_can_capnp', 'capnp', 'kj'] |  | ||||||
| 
 |  | ||||||
| setup(name='Boardd API Implementation', |  | ||||||
|       cmdclass={'build_ext': BuildExtWithoutPlatformSuffix}, |  | ||||||
|       ext_modules=cythonize( |  | ||||||
|         Extension( |  | ||||||
|           "boardd_api_impl", |  | ||||||
|           libraries=libraries, |  | ||||||
|           library_dirs=[ |  | ||||||
|             './', |  | ||||||
|           ], |  | ||||||
|           sources=['boardd_api_impl.pyx'], |  | ||||||
|           language="c++", |  | ||||||
|           extra_compile_args=["-std=c++1z", "-Wno-nullability-completeness"], |  | ||||||
|         ) |  | ||||||
|       ) |  | ||||||
| ) |  | ||||||
| @ -0,0 +1,37 @@ | |||||||
|  | import SCons | ||||||
|  | from SCons.Action import Action | ||||||
|  | 
 | ||||||
|  | cythonAction = Action("$CYTHONCOM") | ||||||
|  | 
 | ||||||
|  | def create_builder(env): | ||||||
|  |     try: | ||||||
|  |         cython = env['BUILDERS']['Cython'] | ||||||
|  |     except KeyError: | ||||||
|  |         cython = SCons.Builder.Builder( | ||||||
|  |                   action = cythonAction, | ||||||
|  |                   emitter = {}, | ||||||
|  |                   suffix = cython_suffix_emitter, | ||||||
|  |                   single_source = 1) | ||||||
|  |         env['BUILDERS']['Cython'] = cython | ||||||
|  |     return cython | ||||||
|  | 
 | ||||||
|  | def cython_suffix_emitter(env, source): | ||||||
|  |     return "$CYTHONCFILESUFFIX" | ||||||
|  | 
 | ||||||
|  | def generate(env): | ||||||
|  |     env["CYTHON"] = "cythonize" | ||||||
|  |     env["CYTHONCOM"] = "$CYTHON $CYTHONFLAGS $SOURCE" | ||||||
|  |     env["CYTHONCFILESUFFIX"] = ".cpp" | ||||||
|  | 
 | ||||||
|  |     c_file, _ = SCons.Tool.createCFileBuilders(env) | ||||||
|  | 
 | ||||||
|  |     c_file.suffix['.pyx'] = cython_suffix_emitter | ||||||
|  |     c_file.add_action('.pyx', cythonAction) | ||||||
|  | 
 | ||||||
|  |     c_file.suffix['.py'] = cython_suffix_emitter | ||||||
|  |     c_file.add_action('.py', cythonAction) | ||||||
|  | 
 | ||||||
|  |     create_builder(env) | ||||||
|  | 
 | ||||||
|  | def exists(env): | ||||||
|  |   return True | ||||||
					Loading…
					
					
				
		Reference in new issue