pythondistutils

Can Python's distutils compile .S (assembly)?


I wrote a small Python extension that bundles, compiles and statically links with a small C library with one optional .S (assembler) file. Distutils's Extension() doesn't recognize the .S by default. Is there a good way to compile that file, or should I just shell out to make? Right now I compile the C code only for a slightly slower library.


Solution

  • I don't know how new it is, but the Extension class has an extra_objects argument, which I found can specify assembly files. So for example, my setup.py looks something like this:

    example_module = Extension('_example',
        extra_compile_args = ['-Wall', '-g', '-std=c++11'],
        sources=['something.cpp'],
        extra_objects=['asm_amd64.s'])
    

    I double checked, and if you inspect the generated library with nm -D example.so, the assembly functions are properly assembled and linked if you include it in the extra_objects, but they are not linked if you don't include it in that argument. So it seems to work.