Skip to content

Commit

Permalink
meson: Simplify the build system
Browse files Browse the repository at this point in the history
- Make full use of Meson's Python module.
- Drop python_incdir option. It's now possible to use a .pc file to
  specify the include path.
- Drop config.h, as we only needed it for HAVE_MACOS, which we can
  easily check for in the single location that we need it.
  • Loading branch information
oleavr committed Mar 21, 2024
1 parent a053489 commit 88330bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 106 deletions.
19 changes: 0 additions & 19 deletions config.h.in

This file was deleted.

2 changes: 1 addition & 1 deletion frida/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ frida_sources = [
'core.py',
]

install_data(frida_sources, install_dir: join_paths(python_site_packages, 'frida'))
python.install_sources(frida_sources, subdir: 'frida', pure: false)
74 changes: 4 additions & 70 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
project('frida-python', 'c', version: '1.0.0')

host_os = host_machine.system()
if host_os == 'android'
host_os_family = 'linux'
else
host_os_family = host_os
endif
python = import('python').find_installation()

cc = meson.get_compiler('c')

Expand All @@ -19,76 +14,15 @@ if ndebug == 'true' or (ndebug == 'if-release' and not get_option('debug'))
]
endif

target_conditionals_prefix = '#include <TargetConditionals.h>'

is_macos_src = target_conditionals_prefix + '''
#if !TARGET_OS_OSX
# error Not macOS
#endif
'''
if cc.compiles(is_macos_src, name: 'compiling for macOS')
host_os = 'macos'
endif

is_ios_src = target_conditionals_prefix + '''
#if !TARGET_OS_IOS
# error Not iOS
#endif
'''
if cc.compiles(is_ios_src, name: 'compiling for iOS')
host_os = 'ios'
endif

if cc.has_header('android/api-level.h')
host_os = 'android'
endif

python = import('python').find_installation()

python_incdir = get_option('python_incdir')
if python_incdir == ''
result = run_command(python, '-c',
'import sys; sys.stdout.write(f"{sys.version_info[0]}.{sys.version_info[1]}")',
check: true)
python_version = result.stdout()
python_name = 'python' + python_version

result = run_command(python, '-c',
'from distutils import sysconfig; import sys; sys.stdout.write(sysconfig.get_python_inc())',
check: true)
python_incdir = result.stdout()
else
py_major_v = cc.get_define('PY_MAJOR_VERSION',
prefix: '#include <patchlevel.h>',
args: ['-I' + python_incdir])

py_minor_v = cc.get_define('PY_MINOR_VERSION',
prefix: '#include <patchlevel.h>',
args: ['-I' + python_incdir])

python_version = py_major_v + '.' + py_minor_v
python_name = 'python' + python_version
endif

python_site_packages = join_paths(get_option('libdir'), python_name, 'site-packages')

cdata = configuration_data()

cdata.set('HAVE_' + host_os_family.to_upper(), 1)
if host_os != host_os_family
cdata.set('HAVE_' + host_os.to_upper(), 1)
endif

python_dep = python.dependency()
frida_core_dep = dependency('frida-core-1.0')

os_deps = []
host_os_family = host_machine.system()
if host_os_family != 'windows'
os_deps += dependency('gio-unix-2.0')
endif

configure_file(input: 'config.h.in',
output: 'config.h',
configuration: cdata)

subdir('src')
subdir('frida')

Expand Down
5 changes: 0 additions & 5 deletions meson.options

This file was deleted.

8 changes: 5 additions & 3 deletions src/_frida.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# undef _POSIX_C_SOURCE
#endif

#define Py_LIMITED_API 0x03070000
#define PY_SSIZE_T_CLEAN

/*
Expand All @@ -39,8 +38,11 @@
#ifdef _MSC_VER
# pragma warning (pop)
#endif
#ifdef HAVE_MACOS
# include <crt_externs.h>
#ifdef __APPLE__
# include <TargetConditionals.h>
# if TARGET_OS_OSX
# include <crt_externs.h>
# endif
#endif

#define PyUnicode_FromUTF8String(str) PyUnicode_DecodeUTF8 (str, strlen (str), "strict")
Expand Down
13 changes: 5 additions & 8 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
extra_link_args = []
if host_os_family == 'darwin'
extra_link_args += ['-Wl,-exported_symbol,_PyInit__frida']
extra_link_args += '-Wl,-exported_symbol,_PyInit__frida'
elif host_os_family != 'windows'
extra_link_args += ['-Wl,--version-script,' + join_paths(meson.current_source_dir(), '_frida.version')]
extra_link_args += '-Wl,--version-script,' + meson.current_source_dir() / '_frida.version'
endif

extension = shared_module('_frida', '_frida.c',
name_prefix: '',
name_suffix: 'so',
extension = python.extension_module('_frida', '_frida.c',
limited_api: '3.7',
c_args: frida_component_cflags,
include_directories: include_directories(python_incdir),
link_args: extra_link_args,
dependencies: [frida_core_dep] + os_deps,
dependencies: [python_dep, frida_core_dep, os_deps],
install: true,
install_dir: python_site_packages,
)

0 comments on commit 88330bf

Please sign in to comment.