cross-language-cpp / djinni-support-lib

C++ support library that is required as a foundation for the generated djinni gluecode
https://djinni.xlcpp.dev/djinni-support-lib/install
Apache License 2.0
28 stars 10 forks source link

Python CFFI build problem on Windows #42

Open a4z opened 3 years ago

a4z commented 3 years ago

On Windows, the current CMake build ends with a Python CFFI problem. This is unfortunately unsolved so far, and help for fixing this problem is welcome

...
...
  Building CFFI lib
  PyCFFIlib_cffi.c
CUSTOMBUILD : warning : I don't know what to do with 'runtime_library_dirs': ['.'] [C:\Users\a4z\work\djinni\support-lib\build\py2\test-suite\PyCFFIlib_cffi.vcxproj]
  Traceback (most recent call last):
    File "C:\Users\a4z\work\djinni\support-lib\build\py2\test-suite\generated-src\cffi\pycffi_lib_build.py", line 25, in <module>
      ffi.compile()
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\cffi\api.py", line 725, in compile
      return recompile(self, module_name, source, tmpdir=tmpdir,
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\cffi\recompiler.py", line 1564, in recompile
      outputfilename = ffiplatform.compile('.', ext,
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\cffi\ffiplatform.py", line 22, in compile
      outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\cffi\ffiplatform.py", line 51, in _build
      dist.run_command('build_ext')
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\setuptools\command\build_ext.py", line 79, in run
      _build_ext.run(self)
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\command\build_ext.py", line 340, in run
      self.build_extensions()
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\command\build_ext.py", line 449, in build_extensions
      self._build_extensions_serial()
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial
      self.build_extension(ext)
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\setuptools\command\build_ext.py", line 196, in build_extension
      _build_ext.build_extension(self, ext)
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\command\build_ext.py", line 551, in build_extension
      self.compiler.link_shared_object(
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\ccompiler.py", line 713, in link_shared_object
      self.link(CCompiler.SHARED_OBJECT, objects,
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\_msvccompiler.py", line 460, in link
      lib_opts = gen_lib_options(self,
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\site-packages\setuptools\msvc.py", line 329, in msvc14_gen_lib_options
      return get_unpatched(msvc14_gen_lib_options)(*args, **kwargs)
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\ccompiler.py", line 1093, in gen_lib_options
      opt = compiler.runtime_library_dir_option(dir)
    File "C:\Users\a4z\AppData\Local\Programs\Python\Python39\lib\distutils\_msvccompiler.py", line 519, in runtime_library_dir_option
      raise DistutilsPlatformError(
  distutils.errors.DistutilsPlatformError: don't know how to set runtime library search path for MSVC
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(241,5): error MSB8066: Custom build for 'C:\Users\a4z\work\djinni\support-lib\build\py2\CMakeFiles 
\aadf18d4fcbdff197304b4b5d83cea85\pycffi_lib_build.py.rule;C:\Users\a4z\work\djinni\support-lib\build\py2\CMakeFiles\5ce445708c0c39eeaefe4c3c138abd3a\Foo_Record.py.rule;C:\Users\a4z\work\djinni\support-lib\build\py 
2\CMakeFiles\0723da9f51c0e0e7e15825be3e6cbffb\PyCFFIlib_cffi.rule' exited with code 1. [C:\Users\a4z\work\djinni\support-lib\build\py2\test-suite\PyCFFIlib_cffi.vcxproj]
~\work\djinni\support-lib [private/moreWindowsTweaks +4 ~1 -0 !] (18:36:58)
paulocoutinhox commented 3 years ago

Hi,

The module distutils is deprecated: https://bugs.python.org/issue2437

https://www.python.org/dev/peps/pep-0632/

Need use setuptools instead.

a4z commented 3 years ago

that gets pulled in from cffi, so this is not our dependency

a4z commented 3 years ago

a little bit of progress, maybe

runtime lib dir setup

https://github.com/cross-language-cpp/djinni-generator/blob/4854a164b1aa737b4e09c36b1b403b3048346bd7/src/main/scala/djinni/CffiGenerator.scala#L56

needs kind of such a logic

if sys.platform=='win32':
   runtime_lib_dirs = []
else:
   runtime_lib_dirs = ['.']

Missing symbols

Additionally, our generated libraries do not export any symbols on Windows This is a problem since there is nothing to link against (when creating the test mylib.dll, we do not get the mylib.lib file so the Windows linker can find mylib from the python test)