Skip to content

Commit

Permalink
ENH: support shared libraries inside packages
Browse files Browse the repository at this point in the history
This drops the use of staged installs with `--destdir` in favor
of using `--prefix` for the install location. The problem is that
RPATHs in extension modules end up pointing to what Meson thinks is
the final install location (i.e., inside the prefix) rather than
to the staging directory.

`--destdir` seems meant for packaging, as an actual staging area,
while for `spin` the final install directory is `build-install`
(by default), there is no intent to later put this package into
`/usr` or `C:\`. Hence using `--prefix` seems like the correct
thing to do.

The one test change here is to a test that was incorrect.
`meson setup --prefix` expects an absolute path, and `/foobar`
isn't a path that exists or can be created.

Addresses the issue discussed in PR 238 - the `spin build` behavior
before this change cannot be made to work for SciPy, because the
internal shared library in `scipy.special` keeps breaking.

It should also address the problem discussed in issue spin#176.
  • Loading branch information
rgommers committed Dec 5, 2024
1 parent 794cabf commit 81d56af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
16 changes: 5 additions & 11 deletions spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat, build_dir
)


if sys.platform.startswith("win"):
DEFAULT_PREFIX = "C:/"
else:
DEFAULT_PREFIX = "/usr"

build_dir_option = click.option(
"-C",
"--build-dir",
Expand Down Expand Up @@ -266,10 +261,10 @@ def _check_coverage_tool_installation(coverage_type: GcovReportFormat, build_dir
)
@click.option(
"--prefix",
help="The build prefix, passed directly to meson.",
help="The build prefix as an absolute path, passed directly to meson.",
type=str,
metavar="PREFIX",
default=DEFAULT_PREFIX,
default='',
)
@click.argument("meson_args", nargs=-1)
@build_dir_option
Expand Down Expand Up @@ -320,6 +315,9 @@ def build(
install_dir = _get_install_dir(build_dir)
abs_install_dir = os.path.abspath(install_dir)

if not prefix:
prefix = abs_install_dir

cfg = get_config()
distname = cfg.get("project.name", None)
if distname and _is_editable_install_of_same_source(distname):
Expand Down Expand Up @@ -385,10 +383,6 @@ def build(
"--only-changed",
"-C",
build_dir,
"--destdir",
install_dir
if os.path.isabs(install_dir)
else os.path.relpath(abs_install_dir, abs_build_dir),
]
+ list(meson_install_args),
output=(not quiet) and verbose,
Expand Down
3 changes: 2 additions & 1 deletion spin/tests/test_build_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_debug_builds(example_pkg):

def test_prefix_builds(example_pkg):
"""does spin build --prefix create a build-install directory with the correct structure?"""
spin("build", "--prefix=/foobar/")
prefix = Path('.').resolve() / 'build-install' / 'foobar'
spin("build", f"--prefix={prefix}")
assert (Path("build-install") / Path("foobar")).exists()


Expand Down

0 comments on commit 81d56af

Please sign in to comment.