Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 259
joeforker Avatar asked Nov 03 '09 02:11

joeforker


2 Answers

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.

like image 152
Steve Avatar answered Oct 30 '22 01:10

Steve


As distributed, distutils don't know about assembly code, and I don't know of extensions to it that let it deal automatically with it. In a similar situation I've always built the library separately (with C and assembly as needed and feasible) and only used the resulting .a with setup.py.

like image 30
Alex Martelli Avatar answered Oct 30 '22 03:10

Alex Martelli