PerlAlien / Alien-Build

Build external dependencies for use in CPAN
16 stars 25 forks source link

alien.json LD flags contain -R option which was removed by recent versions of gcc #306

Closed robrwo closed 2 years ago

robrwo commented 2 years ago

The JSON data for Alien::Brotli contains the -R parameter, but this is not supported by gcc.

{
   "alien_build_version" : "2.48",
   "alt" : {
      "libbrotlicommon" : {
         "cflags" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
         "cflags_static" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
         "libs" : "-L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -W1,-rpath,/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon ",
         "libs_static" : "-L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -w1,-rpath,/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon ",
         "version" : "1.0.9"
      },
      "libbrotlidec" : {
         "cflags" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
         "cflags_static" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
         "libs" : "-L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -W1,-rpath,/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlidec ",
         "libs_static" : "-L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -W1,-rpath,/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlidec -W1,-rpath,/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon ",
         "version" : "1.0.9"
      },
      "libbrotlienc" : {
         "cflags" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
         "cflags_static" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
         "libs" : "-L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -R/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlienc ",
         "libs_static" : "-L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -R/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlienc -R/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon ",
         "version" : "1.0.9"
      }
   },
   "cflags" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
   "cflags_static" : "-I/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/include ",
   "command" : "brotli",
   "install_type" : "share",
   "legacy" : {
      "finished_installing" : 1,
      "install_type" : "share",
      "name" : "libbrotlicommon",
      "original_prefix" : "/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli",
      "version" : "1.0.9"
   },
   "libs" : " -L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -R/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon ",
   "libs_static" : " -L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -R/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon ",
   "perl_module_version" : "v0.2.0",
   "prefix" : "/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli",
   "version" : "1.0.9"
}

So when I run make, I get the error:

LD_RUN_PATH="/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib" cc  -L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -R/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -shared -O2 -L/usr/local/lib -fstack-protector-strong  Brotli.o  -o blib/arch/auto/IO/Compress/Brotli/Brotli.so  \
   -L/home/rr/perl5/perlbrew/perls/perl-5.34.0/lib/site_perl/5.34.0/x86_64-linux/auto/share/dist/Alien-Brotli/lib -lbrotlicommon   \

cc: error: unrecognized command line option ‘-R’
Makefile:489: recipe for target 'blib/arch/auto/IO/Compress/Brotli/Brotli.so' failed
make: *** [blib/arch/auto/IO/Compress/Brotli/Brotli.so] Error 1
plicease commented 2 years ago

Looks like this is coming from the .pc file not Alien::Build:

✅ starscream% more lib/pkgconfig/libbrotli*
::::::::::::::
lib/pkgconfig/libbrotlicommon.pc
::::::::::::::
prefix=/home/ollisg/opt/perl/5.36.0-RC3/lib/site_perl/5.36.0/x86_64-linux/auto/share/dist/Alien-Brotli
exec_prefix=/home/ollisg/opt/perl/5.36.0-RC3/lib/site_perl/5.36.0/x86_64-linux/auto/share/dist/Alien-Brotli
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libbrotlicommon
URL: https://github.com/google/brotli
Description: Brotli common dictionary library
Version: 1.0.9
Libs: -L${libdir} -R${libdir} -lbrotlicommon
Cflags: -I${includedir}
::::::::::::::
lib/pkgconfig/libbrotlidec.pc
::::::::::::::
prefix=/home/ollisg/opt/perl/5.36.0-RC3/lib/site_perl/5.36.0/x86_64-linux/auto/share/dist/Alien-Brotli
exec_prefix=/home/ollisg/opt/perl/5.36.0-RC3/lib/site_perl/5.36.0/x86_64-linux/auto/share/dist/Alien-Brotli
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libbrotlidec
URL: https://github.com/google/brotli
Description: Brotli decoder library
Version: 1.0.9
Libs: -L${libdir} -R${libdir} -lbrotlidec
Requires.private: libbrotlicommon >= 1.0.2
Cflags: -I${includedir}
::::::::::::::
lib/pkgconfig/libbrotlienc.pc
::::::::::::::
prefix=/home/ollisg/opt/perl/5.36.0-RC3/lib/site_perl/5.36.0/x86_64-linux/auto/share/dist/Alien-Brotli
exec_prefix=/home/ollisg/opt/perl/5.36.0-RC3/lib/site_perl/5.36.0/x86_64-linux/auto/share/dist/Alien-Brotli
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libbrotlienc
URL: https://github.com/google/brotli
Description: Brotli encoder library
Version: 1.0.9
Libs: -L${libdir} -R${libdir} -lbrotlienc
Requires.private: libbrotlicommon >= 1.0.2
Cflags: -I${includedir}

If you need to support this version then you can patch the .pc.in file in the patch phase, or the installed .pc file before the gather phase. Alien::FFI has is an example that does the former.

https://metacpan.org/release/PLICEASE/Alien-FFI-0.25/source/alienfile#L59-74

You could also adjust the linker flags using an around the gather phase, but keep in mind that Aliens that use Alien::Brotli might not work right.

Consider opening a ticket to have Brotli fixed as well so that future versions might not have this problem.

robrwo commented 2 years ago

When I build brotli directly, the pc files don't have the -R options. So how is Alien::Build calling pkg-config?

plicease commented 2 years ago

I suspect it isn't pkg-config since that doesn't get called until after the .pc files are generated, but the configuration. AB adds --with-pic (and possibly other flags) and it may be keying off of that to add -R. If you build brotli with identical configure flags I suspect you may see the same .pc file.

plicease commented 2 years ago

I verified that the tarball source has .pc.in files with -R flags:

sandy% more `find -name \*.pc.in`
::::::::::::::
./scripts/libbrotlidec.pc.in
::::::::::::::
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: libbrotlidec
URL: https://github.com/google/brotli
Description: Brotli decoder library
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -R${libdir} -lbrotlidec
Requires.private: libbrotlicommon >= 1.0.2
Cflags: -I${includedir}
::::::::::::::
./scripts/libbrotlienc.pc.in
::::::::::::::
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: libbrotlienc
URL: https://github.com/google/brotli
Description: Brotli encoder library
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -R${libdir} -lbrotlienc
Requires.private: libbrotlicommon >= 1.0.2
Cflags: -I${includedir}
::::::::::::::
./scripts/libbrotlicommon.pc.in
::::::::::::::
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: libbrotlicommon
URL: https://github.com/google/brotli
Description: Brotli common dictionary library
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -R${libdir} -lbrotlicommon
Cflags: -I${includedir}

and configuring with --with-pic does indeed produce a .pc file with the -R flag (at least for me). I did not try a configure without --with-pic. I did this without AB so I don't believe this is a bug in AB. If you need help patching the .pc.in or .pc files let me know.