trimesh / cascadio

A Python module using OpenCASCADE to convert STEP files to GLB
12 stars 3 forks source link

cibuildwheel ( docker-in-docker on MacOS arm64 ) fails #15

Open manuel-koch opened 23 hours ago

manuel-koch commented 23 hours ago

I'm trying to build cascadio for evaluation the functionality and how it could be extended for my purposes. Using the example description to run cibuildwheel on MacOS ( arm64 ). Since native support/usability is limited for cibuildwheel on MacOS, I'm trying to use a docker-in-docker run as suggested here and here.

I'm using a locally build docker image ( tagged cibuildwheel ) that includes pipx and docker. Cloned cascadio repo locally ( main ) and updated its submodules, hence the full source tree should now be available in my local setup.

# Run the docker image 'cibuildwheel', mounting docker socket to support docker-in-docker.
# Assuming the python project to build wheels for is at current working directory.
$ docker run --rm --name cibuildwheel -it -v .:/opt/project -v /var/run/docker.sock:/var/run/docker.sock cibuildwheel bash -i

# Now within the `cibuildwheel` container

# Running the wheel builds
root@8ea8f28a0489:/opt/project $ pipx run cibuildwheel
# It fails with build error, see logs below

# searching for the header that is mentioned in the build error
root@8ea8f28a0489:/opt/project/upstream/OCCT $ find $(pwd) -name "*.hxx" | grep Message_ProgressRange
/opt/project/upstream/OCCT/src/Message/Message_ProgressRange.hxx
root@8ea8f28a0489:/opt/project/upstream/OCCT# find / -name "*.hxx" 2>/dev/null | grep Message_ProgressRange
/opt/project/upstream/OCCT/src/Message/Message_ProgressRange.hxx

# directory structure inside OCCT sources
root@8ea8f28a0489:/opt/project/upstream/OCCT# ls
CMakeLists.txt       OCCT_LGPL_EXCEPTION.txt  adm   dox      genconf.bat  gendoc.bat  genproj.bat  src    tools
LICENSE_LGPL_21.txt  README.txt           data  genconf  gendoc   genproj     samples      tests  upgrade.bat

Looks like the used header search paths in the compiler commands don't exist in the used OCCT sources:

-I/project/upstream/OCCT/include/opencascade
-I/project/upstream/OCCT/inc

The output of the cibuildwheel run is as follows:

     _ _       _ _   _       _           _
 ___|_| |_ _ _|_| |_| |_ _ _| |_ ___ ___| |
|  _| | . | | | | | . | | | |   | -_| -_| |
|___|_|___|___|_|_|___|_____|_|_|___|___|_|

cibuildwheel version 2.21.3

Build options:
  platform: linux
  allow_empty: False
  architectures: aarch64
  build_selector:
    build_config: cp312-*
    skip_config: *musl* *win32*
    requires_python: >=3.7
    prerelease_pythons: False
    free_threaded_support: False
  output_dir: /opt/project/wheelhouse
  package_dir: /opt/project
  test_selector:
    skip_config: pp* *i686
  before_all: uname -a
  before_build:
  before_test:
  build_frontend: None
  build_verbosity: 0
  config_settings:
  container_engine: docker
  dependency_constraints: pinned
  environment:
  manylinux_images:
    x86_64: quay.io/pypa/manylinux2014_x86_64:2024.10.07-1
    i686: quay.io/pypa/manylinux2014_i686:2024.10.07-1
    pypy_x86_64: quay.io/pypa/manylinux2014_x86_64:2024.10.07-1
    aarch64: quay.io/pypa/manylinux2014_aarch64:2024.10.07-1
    ppc64le: quay.io/pypa/manylinux2014_ppc64le:2024.10.07-1
    s390x: quay.io/pypa/manylinux2014_s390x:2024.10.07-1
    pypy_aarch64: quay.io/pypa/manylinux2014_aarch64:2024.10.07-1
    pypy_i686: quay.io/pypa/manylinux2014_i686:2024.10.07-1
  musllinux_images:
    x86_64: quay.io/pypa/musllinux_1_2_x86_64:2024.10.07-1
    i686: quay.io/pypa/musllinux_1_2_i686:2024.10.07-1
    aarch64: quay.io/pypa/musllinux_1_2_aarch64:2024.10.07-1
    ppc64le: quay.io/pypa/musllinux_1_2_ppc64le:2024.10.07-1
    s390x: quay.io/pypa/musllinux_1_2_s390x:2024.10.07-1
    armv7l: quay.io/pypa/musllinux_1_2_armv7l:2024.10.07-1
  repair_command: LD_LIBRARY_PATH=/project/upstream/OCCT/lin64/gcc/lib:/project/upstream/OCCT/lin32/gcc/lib auditwheel repair --exclude libGL.so.1 --lib-sdir . -w {dest_dir} {wheel}
  test_command: pytest {project}/tests
  test_extras: [tests]
  test_requires:

Cache folder: /root/.cache/cibuildwheel

Here we go!

Starting container image quay.io/pypa/manylinux2014_aarch64:2024.10.07-1...

info: This container will host the build for cp312-manylinux_aarch64...
+ docker version -f '{{json .}}'
+ docker image inspect quay.io/pypa/manylinux2014_aarch64:2024.10.07-1 --format '{{.Os}}/{{.Architecture}}'
61f659fcf00aef1746a14c649e497c69ea96111df8982f1b4e26714542e128a6
    + /bin/true
    + mkdir -p /project
    + manylinux-interpreters --help
    + manylinux-interpreters ensure cp312-cp312
'cp312-cp312' already installed at '/opt/python/cp312-cp312'
    + test -x /opt/python/cp312-cp312/bin/python

                                                              ✓ 0.40s
Copying project into container...

    + mkdir -p /project

                                                             ✓ 12.01s
Running before_all...

    + /opt/python/cp38-cp38/bin/python -c 'import sys, json, os; json.dump(os.environ.copy(), sys.stdout)'
    + sh -c 'uname -a'
Linux 61f659fcf00a 6.10.14-linuxkit #1 SMP Thu Oct 24 19:28:55 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

                                                              ✓ 0.10s

Building cp312-manylinux_aarch64 wheel
CPython 3.12 manylinux aarch64

Setting up build environment...

    + /opt/python/cp38-cp38/bin/python -c 'import sys, json, os; json.dump(os.environ.copy(), sys.stdout)'
    + which python
    + which pip

                                                              ✓ 0.07s
Building wheel...

    + rm -rf /tmp/cibuildwheel/built_wheel
    + mkdir -p /tmp/cibuildwheel/built_wheel
    + python -m pip wheel /project --wheel-dir=/tmp/cibuildwheel/built_wheel --no-deps
Processing /project
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Installing backend dependencies: started
  Installing backend dependencies: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: cascadio
  Building wheel for cascadio (pyproject.toml): started
  Building wheel for cascadio (pyproject.toml): finished with status 'error'
  error: subprocess-exited-with-error

  × Building wheel for cascadio (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [28 lines of output]
      *** scikit-build-core 0.10.7 using CMake 3.30.4 (wheel)
      *** Configuring CMake...
      loading initial cache file /tmp/tmpgzzhqcus/build/CMakeInit.txt
      -- The CXX compiler identification is GNU 10.2.1
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /opt/rh/devtoolset-10/root/usr/bin/g++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Found Python: /opt/python/cp312-cp312/bin/python (found version "3.12.7") found components: Interpreter Development.Module
      -- Performing Test HAS_FLTO
      -- Performing Test HAS_FLTO - Success
      -- Found pybind11: /tmp/pip-build-env-qmjkipik/overlay/lib/python3.12/site-packages/pybind11/include (found version "2.13.6")
      -- Configuring done (0.3s)
      -- Generating done (0.0s)
      -- Build files have been written to: /tmp/tmpgzzhqcus/build
      *** Building project with Ninja...
      [1/2] Building CXX object CMakeFiles/cascadio.dir/src/main.cpp.o
      FAILED: CMakeFiles/cascadio.dir/src/main.cpp.o
      /opt/rh/devtoolset-10/root/usr/bin/g++  -pthread -DVERSION_INFO=0.0.14 -Dcascadio_EXPORTS -I/project/upstream/OCCT/include/opencascade -I/project/upstream/OCCT/inc -isystem /opt/python/cp312-cp312/include/python3.12 -isystem /tmp/pip-build-env-qmjkipik/overlay/lib/python3.12/site-packages/pybind11/include -std=c++11 -O3 -DNDEBUG -fPIC -fvisibility=hidden -flto -fno-fat-lto-objects -MD -MT CMakeFiles/cascadio.dir/src/main.cpp.o -MF CMakeFiles/cascadio.dir/src/main.cpp.o.d -o CMakeFiles/cascadio.dir/src/main.cpp.o -c /project/src/main.cpp
      In file included from /project/src/main.cpp:1:
      /project/src/convert.hpp:1:10: fatal error: Message_ProgressRange.hxx: No such file or directory
          1 | #include <Message_ProgressRange.hxx>
            |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      compilation terminated.
      ninja: build stopped: subcommand failed.

      *** CMake build failed
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cascadio
Failed to build cascadio
ERROR: Failed to build one or more wheels

                                                              ✕ 5.96s
Error: Command ['python', '-m', 'pip', 'wheel', PurePosixPath('/project'), '--wheel-dir=/tmp/cibuildwheel/built_wheel', '--no-deps'] failed with code 1.
manuel-koch commented 23 hours ago

Oh, I was mislead by an envvar from the cibuildwheeldocumentation. I used envvar CIBW_BEFORE_ALL='uname -a'.

That likely caused skipping the mandatory build steps for OpenCascade and hence the headers/libs are not available.

Not using CIBW_BEFORE_ALL='uname -a' seems to fix my build issue partly.

Now the build ends with this error:

[2192/5539] Building CXX object src/TKDE/CMakeFiles/TKDE.dir/__/DE/DE_ShapeFixConfigurationNode.cxx.o
FAILED: src/TKDE/CMakeFiles/TKDE.dir/__/DE/DE_ShapeFixConfigurationNode.cxx.o
/opt/rh/devtoolset-10/root/usr/bin/c++ -DHAVE_RAPIDJSON -DOCC_CONVERT_SIGNALS -DTKDE_EXPORTS -I/project/upstream/OCCT/../rapidjson/include -I/project/upstream/OCCT/include/opencascade -fexceptions -fPIC -Wall -Wextra -O3 -DNDEBUG -s -DNo_Exception -std=gnu++11 -fPIC -MD -MT src/TKDE/CMakeFiles/TKDE.dir/__/DE/DE_ShapeFixConfigurationNode.cxx.o -MF src/TKDE/CMakeFiles/TKDE.dir/__/DE/DE_ShapeFixConfigurationNode.cxx.o.d -o src/TKDE/CMakeFiles/TKDE.dir/__/DE/DE_ShapeFixConfigurationNode.cxx.o -c /project/upstream/OCCT/src/DE/DE_ShapeFixConfigurationNode.cxx
In file included from /project/upstream/OCCT/include/opencascade/DE_ShapeFixParameters.hxx:1,
                 from /project/upstream/OCCT/src/DE/DE_ShapeFixConfigurationNode.hxx:18,
                 from /project/upstream/OCCT/include/opencascade/DE_ShapeFixConfigurationNode.hxx:1,
                 from /project/upstream/OCCT/src/DE/DE_ShapeFixConfigurationNode.cxx:14:
/project/upstream/OCCT/src/DE/DE_ShapeFixParameters.hxx:23:17: error: enumerator value ‘-1’ is outside the range of underlying type ‘char’
   23 |     FixOrNot = -1, //!< Procedure will be executed or not (depending on the situation)
      |                 ^
manuel-koch commented 19 hours ago

Replacing the failing line in the OCCT sources seems to fix the build issue: ( not sure if that is the actually intend of the original line - is this a bunch of flags and FixOrNot is all of them set ? Why does the flag "NotFix" has value zero ? )

// replace
    FixOrNot = -1, //!< Procedure will be executed or not (depending on the situation)
// by
    FixOrNot = static_cast<uint_fast8_t>(-1), //!< Procedure will be executed or not (depending on the situation)