ankane / or-tools-ruby

Operations research tools for Ruby
Apache License 2.0
179 stars 25 forks source link

Fails to build with Docker on Apple M1 Max #65

Closed tdegrunt closed 2 months ago

tdegrunt commented 2 months ago

Compile errors must be your most favorite issue, my apologies beforehand. Running Docker desktop on Apple M1 Max.

Do you have any pointers?

Base image: docker.io/library/ruby:3.3.4-slim

uname -a: Linux 93a3be4fa0d0 6.10.0-linuxkit #1 SMP Wed Jul 17 10:51:09 UTC 2024 aarch64 GNU/Linux

cat /etc/debian_version: 12.6

/usr/local/lib has:

lrwxrwxrwx  1 root root   15 May 23 07:51 libortools.so -> libortools.so.9
lrwxrwxrwx  1 root root   23 May 23 07:51 libortools.so.9 -> libortools.so.9.10.4067
-rw-r--r--  1 root root  43M May 23 07:51 libortools.so.9.10.4067
lrwxrwxrwx  1 root root   24 May 23 07:51 libortools_flatzinc.so -> libortools_flatzinc.so.9
lrwxrwxrwx  1 root root   32 May 23 07:51 libortools_flatzinc.so.9 -> libortools_flatzinc.so.9.10.4067
-rw-r--r--  1 root root 2.8M May 23 07:51 libortools_flatzinc.so.9.10.4067

I used the following to install (pretty naive?):

curl -LO https://github.com/google/or-tools/releases/download/v9.10/or-tools_amd64_debian-11_cpp_v9.10.4067.tar.gz && \
    tar -xf or-tools_amd64_debian-11_cpp_v9.10.4067.tar.gz && \
    cd or-tools_x86_64_Debian-11_cpp_v9.10.4067 && \
    cp -rp * /usr/local && \
    cd ..

I'm running gem install or-tools -- --with-or-tools-dir=/usr/local:

root@93a3be4fa0d0:/usr/local/lib# gem install or-tools -- --with-or-tools-dir=/usr/local
Building native extensions with: '--with-or-tools-dir=/usr/local'
This could take a while...
ERROR:  Error installing or-tools:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/or-tools-0.12.0/ext/or-tools
/usr/local/bin/ruby extconf.rb --with-or-tools-dir\=/usr/local
checking for rice/rice.hpp in /usr/local/bundle/gems/rice-4.3.1/include... yes
checking for -lstdc++fs... yes
checking for -lortools... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include=${opt-dir}/include
    --without-opt-include
    --with-opt-lib=${opt-dir}/lib
    --without-opt-lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/$(RUBY_BASE_NAME)
    --with-stdc++fs-dir
    --without-stdc++fs-dir
    --with-stdc++fs-include=${stdc++fs-dir}/include
    --without-stdc++fs-include
    --with-stdc++fs-lib=${stdc++fs-dir}/lib
    --without-stdc++fs-lib
    --with-stdc++fslib
    --without-stdc++fslib
    --with-or-tools-dir
    --with-or-tools-include=${or-tools-dir}/include
    --without-or-tools-include
    --with-or-tools-lib=${or-tools-dir}/lib
    --without-or-tools-lib
    --with-ortools-dir
    --without-ortools-dir
    --with-ortools-include=${ortools-dir}/include
    --without-ortools-include
    --with-ortools-lib=${ortools-dir}/lib
    --without-ortools-lib
    --with-ortoolslib
    --without-ortoolslib
extconf.rb:33:in `<main>': OR-Tools not found (RuntimeError)

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/bundle/extensions/aarch64-linux/3.3.0/or-tools-0.12.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/or-tools-0.12.0 for inspection.
Results logged to /usr/local/bundle/extensions/aarch64-linux/3.3.0/or-tools-0.12.0/gem_make.out
ankane commented 2 months ago

Hi @tdegrunt, it looks like you're trying to use the x86-64 version on aarch64. You'll need to compile the library from source for Debian aarch64.

tdegrunt commented 2 months ago

You can easily read over these things sadly, the solution - for me - was to use: export DOCKER_DEFAULT_PLATFORM=linux/amd64. Also based on: https://stackoverflow.com/a/69636473

tdegrunt commented 2 months ago

Not wanting to reopen this, but there seems to be this binary build (you requested that with google?): https://github.com/google/or-tools/releases/download/v9.9/or-tools_arm64_debian-11_cpp_v9.9.3963.tar.gz Would that work? They didn't make one for 9.10 it seems. Referring to https://github.com/google/or-tools/issues/4136

ankane commented 2 months ago

Yes, it was added in version 0.11.1 of the gem and removed in 0.12.0, as it's not part of the automated OR-Tools release process.