2017-02-28 56 views
1

我維護一個Cython綁定到一些OCaml代碼(通過他們各自的C接口)。對於以前的版本,我設法通過交叉編譯爲Windows分發輪盤文件。現在,我最終管理一個乾淨的本地方式來生成Windows 64位庫。如何更改setuptools構建過程(msvc)中的鏈接命令?

對於32位交叉編譯版本,我在我的setup.py中有一個特定的目標,並帶有正確的命令來執行。返回在Windows上,我想堅持做的setuptoolsic方式,但事情是我需要用不同的工具來取代常規的鏈接命令link.exe(RESP。flexlink.exe,與OCaml的附帶在Windows上)

不要驚慌:flexlink.exe只是在編譯和連接正常的link.exe之前編譯一些彙編程序狗屎。這是在Windows下鏈接OCaml可執行文件和共享庫的正確方式。

爲MacOS和Linux,傳統Extension圖案就像一個魅力如下(mlobject由OCaml的一些時間戳檢查後產生的文件中前面一點,asmrunlib是的python36.dll爲OCaml的等效的完整路徑):

extensions = [ 
    Extension("foo", 
       ["foo.pyx", "interface_c.c"], 
       language="c", 
       include_dirs=INCLUDE, 
       extra_compile_args=compileargs, 
       extra_link_args=[mlobject, asmrunlib, ] 
      ) 
] 

比方說,我限制自己的Python> = 3.5,我想(通過與像NumPy這樣過大的項目比較),我需要通過擴展distutils._msvccompiler.MSVCCompiler啓動和基於flexlink.exe東西代替self.linker = _find_exe("link.exe", paths)

問題是,我不知道他們如何管理接下來的管道工作(連接此擴展編譯器,並使其看起來像正常的msvc到安裝過程)。我認爲它在任何地方都沒有完整的記錄,如果他們能夠做的比NumPy更多,我應該能夠以某種方式達到我的目標。

我的setup.py仍然是合理的基礎,並且將整個建築/包裝過程保存在一個單一文件中的解決方案將非常棒!

+1

萬一你沒有得到回答在這裏,也嘗試setuptools的郵件列表:https://mail.python.org/pipermail/distutils-sig/ –

+0

發現這個答案有點相關,提到MSVC distutils編譯器:http://stackoverflow.com/questions/36212494/get-the-commands-distutils-passes-to-the-compiler/36710903#36710903 –

+0

問題也可以在郵件列表上找到:https://mail.python.org/pipermail/distutils-sig/2017-March/030211.html – xoolive

回答

-1

的代碼沒有進行測試,但你可以嘗試:

from setuptools import setup 
from Cython.Distutils import build_ext as _build_ext 
# To modify regular setuptools extension: 
# from setuptools.command.build_ext import build_ext as _build_ext 

class build_ext(_build_ext): 
    def build_extension(self, ext): 
     self.compiler.linker = "mylinker.exe" 
     return super(build_ext, self).build_extension(ext) 

setup(
    cmdclass={'build_ext': build_ext}, 
    ... 
)