Strategies for finding binary dependencies
at main 34 lines 1.0 kB view raw
1# © NONE 2# SPDX-License-Identifier: CC0-1.0 3 4from cffi import FFI 5ffibuilder = FFI() 6 7ffibuilder.set_source("_example", 8 r""" // passed to the real C compiler, 9 // contains implementation of things declared in cdef() 10 #include <sys/types.h> 11 #include <pwd.h> 12 13 // We can also define custom wrappers or other functions 14 // here (this is an example only): 15 static struct passwd *get_pw_for_root(void) { 16 return getpwuid(0); 17 } 18 """, 19 libraries=[]) # or a list of libraries to link with 20 # (more arguments like setup.py's Extension class: 21 # include_dirs=[..], extra_objects=[..], and so on) 22 23ffibuilder.cdef(""" 24 // declarations that are shared between Python and C 25 struct passwd { 26 char *pw_name; 27 ...; // literally dot-dot-dot 28 }; 29 struct passwd *getpwuid(int uid); // defined in <pwd.h> 30 struct passwd *get_pw_for_root(void); // defined in set_source() 31""") 32 33if __name__ == "__main__": 34 ffibuilder.compile(verbose=True)