StrawberryPerl / Perl-Dist-Strawberry

Tooling to build and package releases for Perl on Windows.
https://strawberryperl.com
Other
278 stars 48 forks source link

Create an alien module for Image::Magick #142

Open hakonhagland opened 11 months ago

hakonhagland commented 11 months ago

Continuing the discussion from here: https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1756279918, https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1756620667 and https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1758472269

The list of DLL dependencies can be obtained using App::PP::AutoLink. Use that to pack a perl file that uses Image::Magick. The list of detected DLLs is printed to the console and can then be edited to copy the needed files to a new location.

The advantage of the Alien approach is that it saves the files under .../site/lib/auto/share. The Alien package then adds itself to the path when it is used on the right OS and build type, and is a no-op otherwise (at least that's how I've implemented Alien::GtkStack::Windows). One could also probably use File::ShareDir directly but the Alien infrastructure makes installation and use easier.

Alien::ImageMagick uses an older style approach that also does not work on Windows since it uses Unix syntax. It should be possible to update it to use Alien::Build but there would still be the need to get all the dependencies in place. That is perhaps best done using a second Alien, or it could be done as a build step on Windows.

@shawnlaffan Looks like a good idea, I am creating an issue here so we can track it. I will investigate App::PP::AutoLink and come back here when I know more.

hakonhagland commented 11 months ago

I used the installation of Image::Magick in https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1753689994

Then, I created a test script:

use feature qw(say);
use strict;
use warnings;
use Image::Magick;

my $img=Image::Magick->new();
$img->Read('logo:');
$img->Write("logo.png");
say "Done.";

and ran pp_autolink on that file:

> pp_autolink.bat p.pl
DLL check iter: 1
DLL check iter: 2
DLL check iter: 3
DLL check iter: 4
No alien system dlls detected

Detected link list: c:/strawberry/c/bin/libmagickcore-7.q16hdri-10.dll c:/strawberry/c/bin/libdl.dll c:/strawberry/c/bin/libbz2-1__.dll c:/strawberry/c/bin/libgomp-1.dll c:/strawberry/c/bin/libjpeg-9__.dll

Detected aliens:

CMD: pp --link c:/strawberry/c/bin/libmagickcore-7.q16hdri-10.dll --link c:/strawberry/c/bin/libdl.dll --link c:/strawberry/c/bin/libbz2-1__.dll --link c:/strawberry/c/bin/libgomp-1.dll --link c:/strawberry/c/bin/libjpeg-9__.dll p.pl

Does this mean that we only need to pack the following 5 libraries?

shawnlaffan commented 11 months ago

Does this mean that we only need to pack the following 5 libraries?

It should only need those not ending in "__.dll" as those are part of Strawberry Perl (32 bit appends one underscore, 64 bit does two).

Although libdl and libgomp-1 are both part of the strawberry perl distribution so they too are not needed. (They are originally from winlibs and we decided to leave them in).

So that means it should only need libmagickcore-7.q16hdri-10.dll.

Edit - I think that is also consistent with what @sisyphus reported in https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/140#issuecomment-1756627785

hakonhagland commented 11 months ago

Refer to https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1756620667 :

The limitation is that each calling script needs a use Alien::XYZ statement at the top, or the PERL5OPT variable needs to be updated.

@shawnlaffan Interesting. Is it also correct that a third option (and maybe the best?) would be to have Gtk2 (in the form of an accepted PR) use Alien::GtkStack::Windows ? Then, when installing Gtk2 with for example cpanm Gtk2, Alien::GtkStack::Windows would also be installed automatically if missing..

shawnlaffan commented 11 months ago

In principle yes, but there are always complexities.

The builds need manual intervention at the moment, per the method @sisyphus worked out in https://www.perlmonks.org/?node_id=11153992 but this is a step forward.

In one scenario such an Alien would compile from source rather than munging MSYS2 files. The number of extra dependencies is high, though, which leads to more Aliens.

There's also the possibility of compiling the various dependencies using the approach we use for the Strawberry Perl deps (see https://github.com/StrawberryPerl/build-extlibs).