|
| 1 | +project('vmprof', 'c', |
| 2 | + version: '0.5.0', |
| 3 | + license: 'MIT', |
| 4 | + meson_version: '>=1.1.0', |
| 5 | +) |
| 6 | + |
| 7 | +py = import('python').find_installation(pure: false) |
| 8 | +py_dep = py.dependency() |
| 9 | +cc = meson.get_compiler('c') |
| 10 | + |
| 11 | +# PyPy ships _vmprof as a built-in module, so the PyPy wheel is pure python. |
| 12 | +is_pypy = run_command(py, '-c', |
| 13 | + 'import sys; print("__pypy__" in sys.builtin_module_names)', |
| 14 | + check: true, |
| 15 | +).stdout().strip() == 'True' |
| 16 | + |
| 17 | +# The pure python packages. The test packages are not installed. |
| 18 | +python_dir = py.get_install_dir(pure: is_pypy) |
| 19 | +install_subdir('vmprof', |
| 20 | + install_dir: python_dir, |
| 21 | + exclude_directories: ['test', '__pycache__'], |
| 22 | +) |
| 23 | +install_subdir('jitlog', |
| 24 | + install_dir: python_dir, |
| 25 | + exclude_directories: ['test', '__pycache__'], |
| 26 | +) |
| 27 | +install_subdir('vmshare', |
| 28 | + install_dir: python_dir, |
| 29 | + exclude_directories: ['__pycache__'], |
| 30 | +) |
| 31 | + |
| 32 | +if not is_pypy |
| 33 | + system = host_machine.system() |
| 34 | + |
| 35 | + sources = files( |
| 36 | + 'src/_vmprof.c', |
| 37 | + 'src/machine.c', |
| 38 | + 'src/compat.c', |
| 39 | + 'src/vmp_stack.c', |
| 40 | + 'src/vmprof_common.c', |
| 41 | + 'src/vmprof_memory.c', |
| 42 | + ) |
| 43 | + c_args = [] |
| 44 | + deps = [py_dep] |
| 45 | + # libbacktrace ships a pre-generated config.h, so it is built as plain |
| 46 | + # sources without running its configure script. |
| 47 | + inc = include_directories('src', 'src/libbacktrace') |
| 48 | + |
| 49 | + if system == 'windows' |
| 50 | + sources += files('src/vmprof_win.c') |
| 51 | + c_args += ['-DVMPROF_WINDOWS=1'] |
| 52 | + elif system == 'darwin' |
| 53 | + sources += files( |
| 54 | + 'src/symboltable.c', |
| 55 | + 'src/vmprof_unix.c', |
| 56 | + 'src/vmprof_mt.c', |
| 57 | + ) |
| 58 | + c_args += ['-DVMPROF_APPLE=1', '-DVMPROF_UNIX=1'] |
| 59 | + elif system == 'linux' or system == 'freebsd' |
| 60 | + sources += files( |
| 61 | + 'src/symboltable.c', |
| 62 | + 'src/vmprof_unix.c', |
| 63 | + 'src/vmprof_mt.c', |
| 64 | + 'src/libbacktrace/backtrace.c', |
| 65 | + 'src/libbacktrace/state.c', |
| 66 | + 'src/libbacktrace/elf.c', |
| 67 | + 'src/libbacktrace/dwarf.c', |
| 68 | + 'src/libbacktrace/fileline.c', |
| 69 | + 'src/libbacktrace/mmap.c', |
| 70 | + 'src/libbacktrace/mmapio.c', |
| 71 | + 'src/libbacktrace/posix.c', |
| 72 | + 'src/libbacktrace/sort.c', |
| 73 | + ) |
| 74 | + c_args += ['-DVMPROF_UNIX=1'] |
| 75 | + unwind_dep = dependency('libunwind', required: false) |
| 76 | + if not unwind_dep.found() |
| 77 | + unwind_dep = cc.find_library('unwind') |
| 78 | + endif |
| 79 | + deps += unwind_dep |
| 80 | + if system == 'linux' |
| 81 | + c_args += ['-DVMPROF_LINUX=1'] |
| 82 | + deps += cc.find_library('dl', required: false) |
| 83 | + else |
| 84 | + c_args += ['-DVMPROF_BSD=1'] |
| 85 | + inc = [inc, include_directories('/usr/local/include')] |
| 86 | + endif |
| 87 | + else |
| 88 | + error('platform "' + system + '" is not supported') |
| 89 | + endif |
| 90 | + |
| 91 | + if system != 'windows' |
| 92 | + c_args += cc.get_supported_arguments('-Wno-unused') |
| 93 | + endif |
| 94 | + |
| 95 | + if py.language_version().version_compare('>=3.11') |
| 96 | + sources += files('src/populate_frames.c') |
| 97 | + endif |
| 98 | + |
| 99 | + py.extension_module('_vmprof', |
| 100 | + sources, |
| 101 | + c_args: c_args, |
| 102 | + include_directories: inc, |
| 103 | + dependencies: deps, |
| 104 | + install: true, |
| 105 | + ) |
| 106 | +endif |
0 commit comments