jeylabs / aws-lambda-poppler-layer

AWS Lambda Poppler Layer
51 stars 28 forks source link

Force Poppler build to use custom (new) version of a library instead of default (old) one #3

Closed asterikx closed 4 years ago

asterikx commented 4 years ago

Hi @pavinthan!

First, I want to second #2. Thank you for open-sourcing this lambda-layer!

I need to build libvips with poppler support. I'm using the lambci/lambda:build-go1.x as base image as it matches the lambda environment very closely.

The lambda environment includes old versions of libraries such as libpng (which are not included in the amazonlinux:2018.03 image). Still, I'm building the newest version of those libraries from source as the older ones have known security problems (see https://github.com/libvips/libvips/issues/1749#issuecomment-666606745).

However, Poppler picks up the pre-installed (old) versions /usr/lib64/ instead of the new version from /opt/lib during the build, e.g. it uses /usr/lib64/libpng.so instead of /opt/lib/libpng.so.

-- Found Freetype: /usr/lib64/libfreetype.so (found version "2.3.11") 
-- Checking for module 'fontconfig'
--   Found fontconfig, version 2.13.1
-- Found Fontconfig: /usr/lib64/libfontconfig.so  
-- Found JPEG: /usr/lib64/libjpeg.so (found version "62") 
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.8") 
-- Found PNG: /usr/lib64/libpng.so (found version "1.2.49") 
-- Found TIFF: /usr/lib64/libtiff.so (found version "4.0.3")

I can reproduce this issue using the Dockerfile from this repository by adding libpng and libpng-devel via yum to the image.

https://github.com/jeylabs/aws-lambda-poppler-layer/blob/50e6d79d83b7ac28029f138db420f479fb953d2b/compiler.Dockerfile#L31

Original output of Poppler build:

-- Found Freetype: /opt/lib/libfreetype.so (found version "2.10.1") 
-- Checking for module 'fontconfig'
--   Found fontconfig, version 2.13.1
-- Found Fontconfig: /opt/lib/libfontconfig.so  
-- Found JPEG: /opt/lib/libjpeg.so (found version "62") 
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.8") 
-- Found PNG: /opt/lib/libpng.so (found version "1.6.37") 
-- Found TIFF: /opt/lib/libtiff.so (found version "4.1.0")

Output of Poppler build after installing libpng and libpng-devel via yum:

-- Found Freetype: /opt/lib/libfreetype.so (found version "2.10.1") 
-- Checking for module 'fontconfig'
--   Found fontconfig, version 2.13.1
-- Found Fontconfig: /opt/lib/libfontconfig.so  
-- Found JPEG: /opt/lib/libjpeg.so (found version "62") 
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.8") 
-- Found PNG: /usr/lib64/libpng.so (found version "1.2.49") // <=== Poppler uses old verion instead of new one
-- Found TIFF: /opt/lib/libtiff.so (found version "4.1.0") 

Question: How can I "force" Poppler to build with a custom (new) version of a library instead of the default (old) one?

I appreciate any help on this

pavinthan commented 4 years ago

@asterikx did you try with setting LD_LIBRARY_PATH to $LAMBDA_TASK_ROOT/lib:$LAMBDA_TASK_ROOT/lib64:$LAMBDA_RUNTIME_DIR:$LAMBDA_RUNTIME_DIR/lib:$LAMBDA_TASK_ROOT:/opt/lib:/opt/lib64:/lib64:/usr/lib64

asterikx commented 4 years ago

Hey @pavinthan, I solved the problem by adding the option -DCMAKE_PREFIX_PATH=${INSTALL_DIR} to any cmake invocation (see this discussion).

By default cmake does not use pkg-config so it's not aware of any non-default installations. I would recommend adding it to you compiler.Dockerfile as well.