Ejemplo n.º 1
0
def build():
    ffi = FFI()

    for file in ["libnek5000.h"]:
        with open(file) as header:
            func_prototypes = header.read()
            ffi.cdef(func_prototypes)

    MPI = False

    # os.environ["LD_LIBRARY_PATH"] = os.getcwd()

    source = """
#include "libnek5000.h"
"""
    if MPI:
        #  source = '#include "mpi.h"' + source
        ffi.cdef("#define MPI_COMM_WORLD ...")

    # import subprocess
    # ompi_ldflags = subprocess.getoutput("pkg-config --libs ompi").split()
    #  extra_link_args=ompi_ldflags
    # ['-Wl,-rpath=.', '-L$PWD']
    if MPI:
        ffi.set_source_pkgconfig(
            "nek5000_ffi",
            pkgconfig_libs=["ompi"],
            source=source,
            libraries=["nek5000"],
        )
    else:
        ffi.set_source(
            "nek5000_ffi",
            source=source,
            libraries=["nek5000"],
        )

    lib = ffi.compile(verbose=True)

    return lib, ffi
Ejemplo n.º 2
0
    libpcap_pcap_h_all_cdef,
    libpcap_pcap_h_nowin_cdef,
)

libpcap_ffi = FFI()

libpcap_ffi.cdef(libc_typedefs_h_cdef)
libpcap_ffi.cdef(libpcap_bpf_h_cdef)
libpcap_ffi.cdef(libpcap_dlt_h_cdef)

libpcap_ffi.cdef(libpcap_pcap_h_all_cdef)
libpcap_ffi.cdef(libpcap_pcap_h_nowin_cdef)

_pkg_name = 'wishpy.libpcap.lib.libpcap_ext'
_pkgconfig_libs = ['libpcap']

_sources = '''
    #include <pcap/pcap.h>
    '''

_extra_compile_args = ['-I/usr/local/include']
_extra_link_args = ['-L/usr/local/lib', '-lpcap']

try:
    libpcap_ffi.set_source_pkgconfig(_pkg_name, _pkgconfig_libs, _sources)
except PkgConfigError:
    libpcap_ffi.set_source(_pkg_name,
                           _sources,
                           extra_compile_args=_extra_compile_args,
                           extra_link_args=_extra_link_args)
Ejemplo n.º 3
0
    # FIXME: Remove the hardcoding below. Change following paths to match
    # Those on your machine.
    _extra_compile_args = [
            "-IC:\\Program Files (x86)\\Wireshark\\include\\Wireshark",
            "-IC:\\wireshark-dev\\wireshark-win64-libs-3.2\\vcpkg-export-20190318-win64ws\\installed\\x64-windows\\include"
            ]
    _extra_link_args = [
            "/LIBPATH:C:\\wireshark-dev\\wireshark-win64-libs-3.2\\vcpkg-export-20190318-win64ws\\installed\\x64-windows\\lib",
            "/LIBPATH:C:\\Program Files (x86)\\Wireshark"
        ]
else:
    _extra_compile_args = [
        '-I/usr/local/include/wireshark',
        '-I/usr/include/wireshark',
        '-I/usr/include/glib-2.0',
        '-I/usr/lib/x86_64-linux-gnu/glib-2.0/include',
        ]

    _extra_link_args = [
            '-L/usr/local/lib',
        ]

try:
    epan_ffi.set_source_pkgconfig(_pkg_name, _pkgconfig_libs, _sources,
            extra_link_args=_extra_link_args)
except PkgConfigError:
    epan_ffi.set_source(_pkg_name, _sources,
            extra_compile_args=_extra_compile_args,
            libraries=_libraries,
            extra_link_args=_extra_link_args)
Ejemplo n.º 4
0
ffibuilder.set_source_pkgconfig(
    "rsyscall._raw", ["rsyscall"], """
#include <asm/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <linux/capability.h>
#include <linux/if_tun.h>
#include <linux/netlink.h>
#include <linux/futex.h>
#include <linux/fuse.h>
#include <linux/memfd.h>
#include <net/if.h>
#include <netinet/ip.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <rsyscall.h>
#include <sched.h>
#include <setjmp.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/timerfd.h>
#include <sys/inotify.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/signal.h>
#include <sys/signalfd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/uio.h>
#include <syscall.h>
#include <unistd.h>
#include <limits.h>

struct linux_dirent64 {
    ino64_t        d_ino;    /* 64-bit inode number */
    off64_t        d_off;    /* 64-bit offset to next structure */
    unsigned short d_reclen; /* Size of this dirent */
    unsigned char  d_type;   /* File type */
    char           d_name[]; /* Filename (null-terminated) */
};

// the double underscores are hard to use from Python,
// since they will be replaced with the class name
#define _WNOTHREAD __WNOTHREAD
#define _WCLONE __WCLONE
#define _WALL __WALL
#define _ss_padding __ss_padding

// glibc hides the real O_LARGEFILE from us - it lies to us! evil!
#undef O_LARGEFILE
#define O_LARGEFILE 0100000

#define SA_RESTORER 0x04000000
typedef void (*sighandler_t)(int);
typedef void (*sigrestore_t)(void);
// we assume NSIGNALS == 64, so we don't need any more than this
struct kernel_sigset {
    unsigned long int val;
};
struct kernel_sigaction {
	sighandler_t ksa_handler;
	unsigned long ksa_flags;
	sigrestore_t ksa_restorer;
	struct kernel_sigset ksa_mask;
};
struct fdpair {
    int first;
    int second;
};
struct futex_node {
  struct robust_list list;
  uint32_t futex;
};

// there are some buggy headers on older systems which have a negative value for EPOLLET :(
#undef EPOLLET
#define EPOLLET 0x80000000
""")
Ejemplo n.º 5
0
_pkgconfig_libs = ['wireshark']

_sources = '''
            #include <config.h>
            #include <epan/address.h>
            #include <epan/proto.h>
            #include <epan/epan_dissect.h>
            #include <epan/epan.h>
            #include <epan/packet.h>
            #include <epan/ftypes/ftypes.h>
            #include <epan/dfilter/dfilter.h>
            #include <wsutil/privileges.h>

            struct packet_provider_data {
                const frame_data *ref;
                const frame_data *prev;
            };
'''
_libraries = ['glib-2.0', 'wireshark', 'wsutil']
_extra_compile_args = ['-I/usr/include/wireshark',
            '-I/usr/include/glib-2.0',
            '-I/usr/lib/x86_64-linux-gnu/glib-2.0/include',
            ]

try:
    epan_ffi.set_source_pkgconfig(_pkg_name, _pkgconfig_libs, _sources)
except PkgConfigError:
    epan_ffi.set_source(_pkg_name, _sources,
            libraries=_libraries,
            extra_compile_args=_extra_compile_args)