google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11k stars 2.1k forks source link

Python bindings fail to build on 32bit archs (e.g. x86, armv7) #3271

Closed StefanBruens closed 2 years ago

StefanBruens commented 2 years ago

Version: 9.3

GCC 11.2.1, Python 3.8, SWIG 4.0.2

What did you do? cmake ... -DBUILD_PYTHON:BOOL=ON make

What did you expect to see build succeeds

What did you see instead?

[  636s] cd /home/abuild/rpmbuild/BUILD/or-tools-9.3/build/ortools/init/python && /usr/bin/c++ -DOR_TOOLS_AS_DYNAMIC_LIB -DPY3 -DUSE_BOP -DUSE_GLOP -DUSE_PDLP -Dpywrapinit_EXPORTS -I/usr/include/python3.8 -I/home/abuild/rpmbuild/BUILD/or-tools-9.3 -I/home/abuild/rpmbuild/BUILD/or-tools-9.3/build -isystem /usr/include/eigen3 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -Wno-error=return-type -DNDEBUG -O2 -g -DNDEBUG -fPIC -fwrapv -std=c++17 -MD -MT ortools/init/python/CMakeFiles/pywrapinit.dir/__/__/__/python/ortools/init/initPYTHON_wrap.cxx.o -MF CMakeFiles/pywrapinit.dir/__/__/__/python/ortools/init/initPYTHON_wrap.cxx.o.d -o CMakeFiles/pywrapinit.dir/__/__/__/python/ortools/init/initPYTHON_wrap.cxx.o -c /home/abuild/rpmbuild/BUILD/or-tools-9.3/build/python/ortools/init/initPYTHON_wrap.cxx
[  636s] /home/abuild/rpmbuild/BUILD/or-tools-9.3/build/python/ortools/init/initPYTHON_wrap.cxx:2827:3: error: #error "SWIG wrapped code invalid in 32 bit architecture, regenerate code using -DSWIGWORDSIZE32"
[  636s]  2827 | # error "SWIG wrapped code invalid in 32 bit architecture, regenerate code using -DSWIGWORDSIZE32"
[  636s]       |   ^~~~~
lperron commented 2 years ago

32 bit archs are not supported.

Mizux commented 2 years ago

What Laurent means is: 1) OR-Tools do not support x86 platform anymore, so even the C++ part could fail to compile, overflow and have some undefined behaviour, corner cases here and there.

2) For the python wrapper side, we have also "hard coded" the usage of a 64bits compiler for SWIG e.g. https://github.com/google/or-tools/blob/8fc5d663898e02501721dc9704dff0006f9e97fe/cmake/python.cmake#L21-L23

You may try to build it but we have no time and lack of resources to make a real support.

StefanBruens commented 2 years ago

Changing the lines to

-  list(APPEND CMAKE_SWIG_FLAGS "-DSWIGWORDSIZE64") 
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    list(APPEND CMAKE_SWIG_FLAGS "-DSWIGWORDSIZE64")
+  else()
+    list(APPEND CMAKE_SWIG_FLAGS "-DSWIGWORDSIZE32")
+  endif()

lets the build pass.

Unfortunately, there are quite some failing test cases (most due to either std::bad_alloc, or a SEGFAULT - probably also a failing/unchecked allocation).

Mizux commented 2 years ago

Please note 32bits is still unsupported...

StefanBruens commented 2 years ago

Fully understood.

For x86, I totally agree with this motion, as it would be a niche target (e.g. someone could use an old decommissioned PC to control their CNC router for PCB milling).

But there are also 32bit ARM and Risc-V, where new SoCs are issued still. There are lots of specialized chips (e.g. FPGAs, AI accelerators) where 32 bit is common, and 64 bit is only available on the higher, much more expensive tiers.