Leont / extutils-hascompiler

Check for the presence of a compiler
5 stars 3 forks source link

Test compare.t fails on macOS Big Sur using system perl 5.28.2 #13

Closed hakonhagland closed 3 years ago

hakonhagland commented 3 years ago

I am on macOS Big Sur 11.1:

$ perl --version | head -2
This is perl 5, version 28, subversion 2 (v5.28.2) built for darwin-thread-multi-2level
$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for ExtUtils::HasCompiler
Writing MYMETA.yml and MYMETA.json
$ make
cp lib/ExtUtils/HasCompiler.pm blib/lib/ExtUtils/HasCompiler.pm
Manifying 1 pod document
$ make test
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/compare.t .. 1/3 HASCOMPILERiHHX/TESTy9Go.c:2:10: fatal error: 'EXTERN.h' file not found
#include "EXTERN.h"
         ^~~~~~~~~~
1 error generated.
t/compare.t .. 2/3
#   Failed test 'MakeMaker agrees we can't compile dynamic'
#   at t/compare.t line 67.
#          got: undef
#     expected: '1'
# Couldn't execute cc -arch x86_64 -g -pipe -fno-strict-aliasing -fstack-protector-strong -DPERL_USE_SAFE_PUTENV -Os "-I/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE"   -c HASCOMPILERiHHX/TESTy9Go.c -o HASCOMPILERiHHX/TESTy9Go.o: Inappropriate ioctl for device at t/compare.t line 64.
HASCOMPILERiHHX/TESTwNX1.c:2:10: fatal error: 'EXTERN.h' file not found
#include "EXTERN.h"
         ^~~~~~~~~~
1 error generated.
t/compare.t .. 3/3
#   Failed test 'MakeMaker agrees we can't compile default'
#   at t/compare.t line 67.
#          got: undef
#     expected: '1'
# Couldn't execute cc -arch x86_64 -g -pipe -fno-strict-aliasing -fstack-protector-strong -DPERL_USE_SAFE_PUTENV -Os "-I/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE"   -c HASCOMPILERiHHX/TESTwNX1.c -o HASCOMPILERiHHX/TESTwNX1.o: Inappropriate ioctl for device at t/compare.t line 64.
# Looks like you failed 2 tests of 3.
t/compare.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/3 subtests

Test Summary Report
-------------------
t/compare.t (Wstat: 512 Tests: 3 Failed: 2)
  Failed tests:  2-3
  Non-zero exit status: 2
Files=1, Tests=3,  6 wallclock secs ( 0.03 usr  0.01 sys +  2.95 cusr  1.26 csys =  4.25 CPU)
Result: FAIL
Failed 1/1 test programs. 2/3 subtests failed.
make: *** [test_dynamic] Error 2

See also this isssue on stackoverflow.com

hakonhagland commented 3 years ago
Couldn't execute cc -arch x86_64 -g -pipe -fno-strict-aliasing -fstack-protector-strong \
-DPERL_USE_SAFE_PUTENV -Os "-I/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE"   \
-c HASCOMPILERiHHX/TESTy9Go.c -o HASCOMPILERiHHX/TESTy9Go.o

I think the problem is the include path:

-I/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE

On my machine EXTERN.h is located in another place, here:

/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE
hakonhagland commented 3 years ago

The tests run fine if I include that directory:

$ CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE make test
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/compare.t .. ok
All tests successful.
Files=1, Tests=3,  6 wallclock secs ( 0.02 usr  0.01 sys +  3.44 cusr  1.45 csys =  4.92 CPU)
Result: PASS
Leont commented 3 years ago

Does this patch solve the problem?

diff --git lib/ExtUtils/HasCompiler.pm lib/ExtUtils/HasCompiler.pm
index 08dd74b..ede455d 100644
--- lib/ExtUtils/HasCompiler.pm
+++ lib/ExtUtils/HasCompiler.pm
@@ -83,6 +83,9 @@ sub can_compile_loadable_object {
    my $object_file = $abs_basename.$_o;
    my $loadable_object = "$abs_basename.$dlext";

+   my $apple_core = $^O eq 'darwin' && $^X eq '/usr/bin/perl' && ($config->get('osvers') =~ /(\d+)/)[0] >= 18;
+   $incdir =~  s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/g if $apple_core;
+
    my @commands;
    if ($^O eq 'MSWin32' && $cc =~ /^cl/) {
        push @commands, qq{$cc $ccflags $cccdlflags $optimize /I "$incdir" /c $source_name /Fo$object_file};
hakonhagland commented 3 years ago

Unfortunately, it does not work.

First, I checked in the debugger $^X is perl and not /usr/bin/perl, second, $incdir is /System/Library/Perl/5.28/darwin-thread-multi-2level/CORE so even if $apple_core was true, the line:

$incdir =~  s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/g if $apple_core;

will not do anything.

Leont commented 3 years ago

How about this?

--- lib/ExtUtils/HasCompiler.pm
+++ lib/ExtUtils/HasCompiler.pm
@@ -100,6 +100,7 @@ sub can_compile_loadable_object {
    }
    else {
        my @extra;
+       my $inc = qq{"-I$incdir"};
        if ($^O eq 'MSWin32') {
            my $lib = '-l' . ($libperl =~ /lib([^.]+)\./)[0];
            push @extra, "$abs_basename.def", $lib, $perllibs;
@@ -114,7 +115,10 @@ sub can_compile_loadable_object {
        elsif ($^O eq 'android') {
            push @extra, qq{"-L$incdir"}, '-lperl', $perllibs;
        }
-       push @commands, qq{$cc $ccflags $optimize "-I$incdir" $cccdlflags -c $source_name -o $object_file};
+       elsif ($^O eq 'darwin' && $config->get('perlpath') eq '/usr/bin/perl' && ($config->get('osvers') =~ /(\d+)/)[0] >= 18) {
+           $inc = qq{-iwithsysroot "$incdir"};
+       }
+       push @commands, qq{$cc $ccflags $optimize $inc $cccdlflags -c $source_name -o $object_file};
        push @commands, qq{$ld $object_file -o $loadable_object $lddlflags @extra};
    }
hakonhagland commented 3 years ago

Yes it works!

Leont commented 3 years ago

Released as 0.023.

I'd bet good money on ExtUtils::CBuilder having the same bug, an issue for that should probably be filed as well.

ikegami commented 3 years ago

Nevermind X_X Comment deleted.