dsully / perl-crypt-openssl-x509

Perl interface to OpenSSL's X509 module.
Other
25 stars 33 forks source link

Failed to build perl-crypt-openssl-x509 on M1 Mac #81

Closed skaji closed 3 years ago

skaji commented 3 years ago

Description

The default path of homebrew for M1 Mac has been changed from /usr/local to /opt/homebrew. As a result, we cannot build perl-crypt-openssl-x509 on M1 Mac.

I think we can follow https://github.com/radiator-software/p5-net-ssleay/pull/158 :

diff --git Makefile.PL Makefile.PL
index 91e367a..a5a4f38 100644
--- Makefile.PL
+++ Makefile.PL
@@ -1,6 +1,6 @@
 use lib '.';
 use inc::Module::Install;
-
+use File::Spec;
 use Config;

 name('Crypt-OpenSSL-X509');
@@ -14,8 +14,14 @@ bugtracker 'https://github.com/dsully/perl-crypt-openssl-x509/issues';

 requires_external_cc();

-inc '-I/usr/local/opt/openssl/include -I/usr/local/include/openssl -I/usr/include/openssl -I/usr/local/include/ssl -I/usr/local/ssl/include';
-libs '-L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/lib -L/usr/local/ssl/lib -lcrypto -lssl';
+if ($^O ne 'MSWin32' and my $prefix = `brew --prefix openssl 2>@{[File::Spec->devnull]}`) {
+  chomp $prefix;
+  inc "-I$prefix/include";
+  libs "-L$prefix/lib -lcrypto -lssl";
+} else {
+  inc '-I/usr/local/opt/openssl/include -I/usr/local/include/openssl -I/usr/include/openssl -I/usr/local/include/ssl -I/usr/local/ssl/include';
+  libs '-L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/lib -L/usr/local/ssl/lib -lcrypto -lssl';
+}

 if ($Config::Config{myuname} =~ /darwin/i) {
   cc_optimize_flags('-O2 -g -Wall -Werror -Wno-deprecated-declarations');

Expected behaviour

Successfully build perl-crypt-openssl-x509 on M1 Mac

Actual behaviour

Failed to build perl-crypt-openssl-x509 on M1 Mac

Operating system and version

M1 Mac

❯ sw_vers
ProductName:    macOS
ProductVersion: 11.2.3
BuildVersion:   20D91

❯ uname -s -m
Darwin arm64

Crypt::OpenSSL::X509 version

1.902

Perl version

5.32.1

❯ ~/env/plenv/versions/5.32.1/bin/perl -v
This is perl 5, version 32, subversion 1 (v5.32.1) built for darwin-2level

❯ file ~/env/plenv/versions/5.32.1/bin/perl
/Users/skaji/env/plenv/versions/5.32.1/bin/perl: Mach-O 64-bit executable arm64

OpenSSL version

1.1.1k

❯ brew info openssl
openssl@1.1: stable 1.1.1k (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@1.1/1.1.1k (8,071 files, 18MB)
  Poured from bottle on 2021-04-06 at 13:51:08
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL

Output, if available

❯ ~/env/plenv/versions/5.32.1/bin/perl Makefile.PL
Checking if your kit is complete...
Looks good
WARNING: /Users/skaji/env/plenv/versions/5.32.1/bin/perl is loading libcrypto in an unsafe way
zsh: abort      ~/env/plenv/versions/5.32.1/bin/perl Makefile.PL

❯ echo $?
134

Step by step guide to reproducing the issue

❯ wget https://cpan.metacpan.org/authors/id/J/JO/JONASBN/Crypt-OpenSSL-X509-1.902.tar.gz

❯ tar xf Crypt-OpenSSL-X509-1.902.tar.gz

❯ cd Crypt-OpenSSL-X509-1.902

❯ perl Makefile.PL
Checking if your kit is complete...
Looks good
WARNING: /Users/skaji/env/plenv/versions/5.32.1/bin/perl is loading libcrypto in an unsafe way
zsh: abort      perl Makefile.PL

❯ echo $?
134
jonasbn commented 3 years ago

Hi @skaji

I have just uploaded a release (1.903 / 1.9.3) with your proposed patch. I do not have access to a Apple M1 or a newer brew install, could you please test it when possible and report any issues.

Thanks for your issue report and patch.

skaji commented 3 years ago

I was able to install Crypt-OpenSSL-X509-1.903. @jonasbn Thank you!

❯ wget https://cpan.metacpan.org/authors/id/J/JO/JONASBN/Crypt-OpenSSL-X509-1.903.tar.gz

❯ tar xf Crypt-OpenSSL-X509-1.903.tar.gz

❯ cd Crypt-OpenSSL-X509-1.903

❯ perl Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Crypt::OpenSSL::X509
Writing MYMETA.yml and MYMETA.json

❯ make
cp X509.pm blib/lib/Crypt/OpenSSL/X509.pm
Running Mkbootstrap for X509 ()
chmod 644 "X509.bs"
"/Users/skaji/env/plenv/versions/5.32.1/bin/perl" "-Iinc" -MExtUtils::Command::MM -e 'cp_nonempty' -- X509.bs blib/arch/auto/Crypt/OpenSSL/X509/X509.bs 644
"/Users/skaji/env/plenv/versions/5.32.1/bin/perl" "-Iinc" "/Users/skaji/env/plenv/versions/5.32.1/lib/perl5/5.32.1/ExtUtils/xsubpp"  -typemap '/Users/skaji/env/plenv/versions/5.32.1/lib/perl5/5.32.1/ExtUtils/typemap' -typemap '/Users/skaji/try/20210404/Crypt-OpenSSL-X509-1.903/typemap'  X509.xs > X509.xsc
Warning: Aliases 'subject_hash' and 'hash' have identical values in X509.xs, line 422
mv X509.xsc X509.c
cc -c  -I/opt/homebrew/opt/openssl@1.1/include -fno-common -DPERL_DARWIN -mmacosx-version-min=11.2 -fno-strict-aliasing -pipe -fstack-protector-strong -DPERL_USE_SAFE_PUTENV -Wno-error=implicit-function-declaration -O2 -g -Wall -Werror -Wno-deprecated-declarations   -DVERSION=\"1.903\" -DXS_VERSION=\"1.903\"  "-I/Users/skaji/env/plenv/versions/5.32.1/lib/perl5/5.32.1/darwin-2level/CORE"   X509.c
rm -f blib/arch/auto/Crypt/OpenSSL/X509/X509.bundle
LD_RUN_PATH="/opt/homebrew/opt/openssl@1.1/lib" cc  -mmacosx-version-min=11.2 -bundle -undefined dynamic_lookup -fstack-protector-strong  X509.o  -o blib/arch/auto/Crypt/OpenSSL/X509/X509.bundle  \
       -L/opt/homebrew/opt/openssl@1.1/lib -lcrypto -lssl   \

chmod 755 blib/arch/auto/Crypt/OpenSSL/X509/X509.bundle

❯ make test
"/Users/skaji/env/plenv/versions/5.32.1/bin/perl" "-Iinc" -MExtUtils::Command::MM -e 'cp_nonempty' -- X509.bs blib/arch/auto/Crypt/OpenSSL/X509/X509.bs 644
PERL_DL_NONLAZY=1 "/Users/skaji/env/plenv/versions/5.32.1/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'inc', 'blib/lib', 'blib/arch')" t/00-version.t t/pod.t t/utf8.t t/x509-ec.t t/x509.t
t/00-version.t .. # Running Crypt::OpenSSL::X509 test suite against LibreSSL 2.8.3
t/00-version.t .. ok
t/pod.t ......... ok
t/utf8.t ........ ok
t/x509-ec.t ..... ok
t/x509.t ........ ok
All tests successful.
Files=5, Tests=76,  2 wallclock secs ( 0.03 usr  0.01 sys +  0.24 cusr  0.09 csys =  0.37 CPU)
Result: PASS

❯ make install
"/Users/skaji/env/plenv/versions/5.32.1/bin/perl" "-Iinc" -MExtUtils::Command::MM -e 'cp_nonempty' -- X509.bs blib/arch/auto/Crypt/OpenSSL/X509/X509.bs 644
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/skaji/env/plenv/versions/5.32.1/lib/perl5/site_perl/5.32.1/darwin-2level/auto/Crypt/OpenSSL/X509/X509.bundle
Installing /Users/skaji/env/plenv/versions/5.32.1/lib/perl5/site_perl/5.32.1/darwin-2level/Crypt/OpenSSL/X509.pm
Appending installation info to /Users/skaji/env/plenv/versions/5.32.1/lib/perl5/5.32.1/darwin-2level/perllocal.pod

❯ perl -MCrypt::OpenSSL::X509\ 999999
Crypt::OpenSSL::X509 version 999999 required--this is only version 1.903.
BEGIN failed--compilation aborted.