diff --git a/.gitignore b/.gitignore index 0f4570f3..075ec3ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/* +build-install/* dist/* src/flint/**/*.c src/flint/*.html diff --git a/.spin/cmds.py b/.spin/cmds.py new file mode 100644 index 00000000..dbabf542 --- /dev/null +++ b/.spin/cmds.py @@ -0,0 +1,53 @@ +import os.path +import click +from spin.cmds import meson + +# +# Wrap spin's build command to add the --local-flint argument +# + +@click.command() +@click.argument("meson_args", nargs=-1) +@click.option("-j", "--jobs", help="Number of parallel tasks to launch", type=int) +@click.option("--clean", is_flag=True, help="Clean build directory before build") +@click.option( + "-v", "--verbose", is_flag=True, help="Print all build output, even installation" +) + +@click.option("--local-flint", + help="Path to pkgconfig directory for a local build of flint and other directories") + +@click.pass_context +def build(ctx, *args, local_flint=None, **kwargs): + """🔧 Build package with Meson/ninja and install + + To link against a local build of flint use e.g. + + spin build --local-flint=.local/lib/pkgconfig + + MESON_ARGS are passed through e.g.: + + spin build -- -Dpkg_config_path=/lib64/pkgconfig + + The package is installed to build-install + + By default meson-python does release builds. To be able to use a debugger, + tell meson to build in debug mode: + + spin build -- -Dbuildtype=debug + + or set CFLAGS appropriately: + + CFLAGS="-O0 -g" spin build + """ + if local_flint is not None: + pkg_config_path = os.path.abspath(local_flint) + ctx.params["meson_args"] += ( + f'-Dpkg_config_path={pkg_config_path}', + f'-Dadd_flint_rpath=true', + ) + + del ctx.params["local_flint"] + + # Call spin's build function + ctx.forward(meson.build) diff --git a/meson.build b/meson.build index b4fe7f83..7e941dbb 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,16 @@ gmp_dep = dependency('gmp') mpfr_dep = dependency('mpfr') flint_dep = dependency('flint') +# Add rpaths for a local build of flint found via pkgconfig +# https://github.com/mesonbuild/meson/issues/13046 +if get_option('add_flint_rpath') + flint_lib_dir = flint_dep.get_pkgconfig_variable('libdir') + add_project_link_arguments( + '-Wl,-rpath=' + flint_lib_dir, + language: 'c', + ) +endif + # flint.pc was missing -lflint until Flint 3.1.0 if flint_dep.version().version_compare('<3.1') flint_dep = cc.find_library('flint') diff --git a/meson.options b/meson.options new file mode 100644 index 00000000..21079382 --- /dev/null +++ b/meson.options @@ -0,0 +1 @@ +option('add_flint_rpath', type : 'boolean', value : false) diff --git a/pyproject.toml b/pyproject.toml index e29f7ccf..7c6d6704 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ package = "flint" [tool.spin.commands] "Build" = [ - "spin.cmds.meson.build", + ".spin/cmds.py:build", "spin.cmds.meson.test", "spin.cmds.build.sdist", "spin.cmds.pip.install", diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..536a010f --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,7 @@ +cython +spin +meson +meson-python +pytest +coverage +pytest-cov