RubixML / Tensor

A library and extension that provides objects for scientific computing in PHP.
https://rubixml.com
MIT License
232 stars 28 forks source link

Docker php:7.4-fpm-alpine pecl install and build from source fails #31

Open Anecho opened 2 years ago

Anecho commented 2 years ago

Versions according to https://pkgs.alpinelinux.org/packages

.Dockerfile for pecl install tensor

FROM php:7.4-fpm-alpine

RUN apk update && apk --no-cache add --update \
    # Optional To Compile Extension
    # A C compiler v12.1.1_git20220630-r5
    autoconf gcc musl-dev g++ \
    # A Fortran compiler v12.1.1_git20220630-r5
    bash bash-doc bash-completion musl-dev gfortran gdb make \
    # OpenBLAS development package v0.3.21-r0
    openblas-dev \
    # LAPACKE C interface to LAPACK v3.10.1-r0
    lapack \
    # re2c v3.0-r0
    re2c \
    # make v4.3-r0
    make \
    # autoconf v2.71-r0
    autoconf \
    # automake v1.16.5-r1
    automake \
    # build-essentials for Alpine 
    alpine-sdk build-base
    # execinfo.h missing error: 
    # libexecinfo-dev

RUN pecl install tensor

Error from pecl install tensor:

#0 10.20 /tmp/pear/temp/tensor/ext/kernel/backtrace.c:15:10: fatal error: execinfo.h: No such file or directory
#0 10.20    15 | #include <execinfo.h>
#0 10.20       |          ^~~~~~~~~~~~
#0 10.20 compilation terminated.
#0 10.20 make: *** [Makefile:202: kernel/backtrace.lo] Error 1
#0 10.20 ERROR: `make' failed

Fixed by apk add libexecinfo-dev https://github.com/awslabs/aws-lambda-cpp/issues/124#issuecomment-968302646

But then other error pops up:

#0 85.60 /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -llapacke: No such file or directory
#0 85.61 collect2: error: ld returned 1 exit status
#0 85.61 make: *** [Makefile:289: tensor.la] Error 1
#0 85.62 ERROR: `make' failed

musl/bin/ld file is there.

bash-5.1# ls /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ -l
total 4936
-rwxr-xr-x    2 root     root         59536 Jul  7 13:57 ar
-rwxr-xr-x    2 root     root        659448 Jul  7 13:57 as
-rwxr-xr-x    4 root     root       1469904 Jul  7 13:57 ld
-rwxr-xr-x    4 root     root       1469904 Jul  7 13:57 ld.bfd
-rwxr-xr-x    2 root     root         52392 Jul  7 13:57 nm
-rwxr-xr-x    2 root     root        157808 Jul  7 13:57 objcopy
-rwxr-xr-x    2 root     root        332720 Jul  7 13:57 objdump
-rwxr-xr-x    2 root     root         59568 Jul  7 13:57 ranlib
-rwxr-xr-x    2 root     root        620928 Jul  7 13:57 readelf
-rwxr-xr-x    2 root     root        157808 Jul  7 13:57 strip

Also tried building from source - same error on make step pops up.

.Dockerfile for build tensor from source

RUN apk update && apk --no-cache add --update \
    # A C compiler v12.1.1_git20220630-r5
    autoconf gcc musl-dev g++ cmake \
    # A Fortran compiler v12.1.1_git20220630-r5
    bash bash-doc bash-completion musl-dev gfortran gdb make \
    # OpenBLAS development package v0.3.21-r0
    openblas-dev \
    # LAPACKE C interface to LAPACK v3.10.1-r0
    lapack \
    # re2c v3.0-r0
    re2c \
    # make v4.3-r0
    make \
    # autoconf v2.71-r0
    autoconf \
    # automake v1.16.5-r1
    automake \
    # build-essentials for Alpine 
    alpine-sdk build-base \
    # execinfo.h missing: https://github.com/awslabs/aws-lambda-cpp/issues/124#issuecomment-968302646
    libexecinfo-dev

# RUN pecl install tensor

RUN git clone https://github.com/RubixML/Tensor Tensor

WORKDIR /var/www/html/Tensor/ext

RUN phpize \
    && ./configure \
    && make \
    && make install

Error from build tensor from source:

#0 86.23 /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -llapacke: No such file or directory
#0 86.27 collect2: error: ld returned 1 exit status
#0 86.28 make: *** [Makefile:289: tensor.la] Error 1

What am I missing here?

adrolter commented 1 year ago

Is there a known solution to this? I'm running into the same problem with PHP 8.1.10 on Alpine 3.16. I also have lapack-dev installed.

adrolter commented 1 year ago

@Kabingeran Why would anyone message you privately to discuss this topic? Just post your solution here if you have one

Kabingeran commented 1 year ago

@adrianguenter In each case, it will probably be different. Why write to me in private? To get your solution. Well, try making symbolic links. This should help.

epoxa commented 1 year ago

@adrianguenter In each case, it will probably be different. Why write to me in private? To get your solution. Well, try making symbolic links. This should help.

What symbolic links do you mean? I have exactly the same issue when trying to build the extension from source.

adrolter commented 1 year ago

@epoxa Yeah, I don't know why they're being so cryptic. There's definitely a general purpose solution to this, so if they've solved it I wish they'd just share it with the community.

Kabingeran commented 1 year ago

There is no universal solution. Try installing lapack with the specified version and making symlinks if needed. There are several deprecation errors after installing on 8.1. No need to install on 8.1 yet.

adrolter commented 1 year ago

Most things can be generalized to a certain degree, though, and I'm sure that is the case here as well. You're being intentionally cryptic for some strange reason.

mlocati commented 1 year ago

You need to know the Alpine version you are using (cat /etc/os-release):

mlocati commented 1 year ago

PS: if and once #39 will be merged, and a new version is published on PECL, I can update my install-php-extensions script so that you can install tensor very easily.

Kabingeran commented 1 year ago

It seems PECL has been updated. For Alpine in Docker this worked for me:

RUN apk add --no-cache openblas-dev libexecinfo-dev lapack=3.10.1-r0 RUN ln -s /usr/lib/liblapack.so.3 /usr/lib/liblapack.so \ && ln -s /usr/lib/liblapacke.so.3 /usr/lib/liblapacke.so RUN pecl install tensor RUN docker-php-ext-enable tensor

mlocati commented 1 year ago

Yep, that works. You an also check here to see what should be done in order to have the correct apk (and apt) dependencies:

https://github.com/RubixML/Tensor/blob/master/.github/workflows/ci-ext.yml#L40

mlocati commented 1 year ago

@Kabingeran you can also use this script of mine to install tensor (and a ton of other PHP extensions) without having to worry about the system requirements (apk/apt libraries, symbolic links, and so on). Simply write

install-php-extensions tensor

and you are done.

Kabingeran commented 1 year ago

I tried it on Alpine 3.16. It is unlikely that anyone will need older versions. Alpine 3.19: RUN apk add --no-cache openblas-dev lapack-dev RUN pecl install tensor RUN docker-php-ext-enable tensor