isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.3k stars 2.29k forks source link

Cannot cross compile from mac intel to mac arm #5732

Open protoism opened 1 year ago

protoism commented 1 year ago

Checklist

Steps to reproduce the issue

I first cloned Open3D by:

It's CI build of a private CI, steps should be...

git clone https://github.com/isl-org/Open3D.git cd Open3D git checkout v0.16.1

Then, I build Open3D (on Ubuntu 20.04, with CUDA 11.5) with:

  cmake -DCMAKE_MACOSX_RPATH=0 -DCMAKE_CXX_FLAGS="-I $BUILDDIR/libjxl/lib/include/jxl" \
          -DCMAKE_OSX_ARCHITECTURES=$ARCHITECTURE \
          -DBUILD_GUI=OFF \
      -DBUILD_PYTHON_MODULE=OFF \
          -DWITH_OPENMP=ON \
          -DWITH_SIMD=ON \
          -DBUILD_EXAMPLES=OFF \
          -DBUILD_JUPYTER_EXTENSION=OFF \
          -DBUILD_WEBRTC=OFF \
          -DDEVELOPER_BUILD=OFF \
          -DBUILD_COMMON_ISPC_ISAS=ON \
          -DUSE_SYSTEM_BLAS=OFF \
          -DGLIBCXX_USE_CXX11_ABI=1 \
          -DCMAKE_INSTALL_PREFIX=$BUILDDIR/sysroot ..
  make -j$(nproc) install

ARCHITECTURE is arm64, I'm on Intel MAC (actually it's github CI)

Error message:

Here an extract, full log attached

    [ 27%] Linking CXX executable ../../../bin/ShaderEncoder
    -- [download 41% complete]
    [ 27%] No configure step for 'ext_vtk'
    -- Performing Test has_std_0x_flag - Success
    -- Performing Test SUPPORTS_VARIADIC_TEMPLATES
    -- [download 42% complete]
    [ 27%] No build step for 'ext_vtk'
    [ 27%] Built target ShaderEncoder
    -- [download 43% complete]
    [ 28%] Building Encoded Shader object ImageFragmentShader.h
    [ 29%] Building Encoded Shader object PhongVertexShader.h
    /bin/sh: ../../../bin/ShaderEncoder: Bad CPU type in executable
    make[2]: *** [cpp/open3d/visualization/ImageFragmentShader.h] Error 126
    make[2]: *** Waiting for unfinished jobs....
    /bin/sh: ../../../bin/ShaderEncoder: Bad CPU type in executable

logs_11.zip

Error message

/bin/sh: ../../../bin/ShaderEncoder: Bad CPU type in executable

Full log attached

Open3D, Python and System information

- Operating system: github CI, should be macOS 10.12
- Python version: Python 3.8`
- Open3D version: checked out 1.6.1
- System architecture: x86 (mac)
- Is this a remote workstation?: yes
- How did you install Open3D?: build from source
- Compiler version (if built from source): should be clang

Additional information

The problem is due to cross-compilation environment: ShaderEncoder should be built for host and not for target (or for both?)

On MacOS, the error can be solved forcing ShaderEncoder to be a universal build, something like:

diff --git a/cmake/Open3DAddEncodedShader.cmake b/cmake/Open3DAddEncodedShader.cmake
index 36bcbb83..edb5e28e 100644
--- a/cmake/Open3DAddEncodedShader.cmake
+++ b/cmake/Open3DAddEncodedShader.cmake
@@ -65,6 +65,7 @@ function(open3d_add_encoded_shader target)
     )
 endfunction()

+set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
 # Helper target for open3d_add_encoded_shader
 if (NOT TARGET ShaderEncoder)
     add_executable(ShaderEncoder EXCLUDE_FROM_ALL)

I also believe that in 3rdparty/find_dependencies.cmake the parameter MAKE_OSX_ARCHITECTURES should be propagated.

Here a link to a patched branch:

https://github.com/foosoftsrl/Open3D/commit/70bb28d3decf95618281741d64b06679cbdac27b#diff-b474bf2fb16431c8115f15abca15f531c08d72b9955133662c2be5db058fbd3e

ssheorey commented 1 year ago

Sorry, we can't help with complex builds like this - happy to accept a PR if you get it working.