Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Support yarn Plug'n'Play #3888

Closed
lovell opened this issue Dec 10, 2023 · 3 comments
Closed

Enhancement: Support yarn Plug'n'Play #3888

lovell opened this issue Dec 10, 2023 · 3 comments

Comments

@lovell
Copy link
Owner

lovell commented Dec 10, 2023

The default linker in yarn 3+ is Plug'n'Play, which wraps the Node.js require mechanics so it can control filesystem layout.

Most of the time this is a virtual filesystem built on zip files, but we know this won't work with sharp so the prebuilt binaries are already configured to be "unplugged".

"preferUnplugged": true,

https://github.com/lovell/sharp-libvips/blob/9835b9e1326f38ebdd8b26554aa5e936b8485865/npm/linux-x64/package.json#L16

However yarn unplugs to a directory name that contains a hash.

.yarn/unplugged/@img-sharp-libvips-linux-x64-npm-1.0.0-7dae7d64d5/...

I had assumed this was a content-based hash and therefore we wouldn't know it up-front. However it looks like it's a sha512 hash of the package scope, name and version.

$ echo -n "imgsharp-libvips-linux-x64" | sha512sum
66eeeaa2992db3c78bc9680eed56bf22325281230b955df181e137a0835f3849749df49a58b589b1d3aa3be61944322752da5426e05688eb8a64132ce3bd6531

$ echo -n "66eeeaa2992db3c78bc9680eed56bf22325281230b955df181e137a0835f3849749df49a58b589b1d3aa3be61944322752da5426e05688eb8a64132ce3bd6531npm:1.0.0" | sha512sum | head -c10
7dae7d64d5

This means we should be able to add an rpath to satisfy yarn's Plug'n'Play filesystem layout.

sharp/src/binding.gyp

Lines 176 to 179 in 004fff9

'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@img/sharp-libvips-<(platform_and_arch)/lib\''

This will result in something like (untested):

$ORIGIN/../../../../../@img-sharp-libvips-linux-x64-npm-1.0.0-7dae7d64d5/node_modules/@img/sharp-libvips-linux-x64/lib/

See 004fff9 for some discussion about this.

@lovell
Copy link
Owner Author

lovell commented Dec 13, 2023

A release candidate is available should anyone wish to help test this:

yarn add sharp@v0.33.1-rc.0

@lovell
Copy link
Owner Author

lovell commented Dec 17, 2023

v0.33.1 now available with support for Yarn v3+ Plug'n'Play

https://github.com/lovell/sharp/actions/runs/7240743852

@lovell lovell closed this as completed Dec 17, 2023
@cjroebuck
Copy link

Excellent. Thank you for the quick turnaround. Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants