commaai / opendbc

democratize access to car decoder rings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker build fails on arm

series8217 opened this issue · comments

There are some issues preventing the Dockerfile from building on arm, because wheels aren't available for all the Python dependencies, and the Dockerfile doesn't set up an environment capable of building python modules from source.

a) The pinned version of pycapnp (1.0.0) in opendbc's requirements.txt has a bugcausing installation to fail. A workaround is to install pkgconfig separately before trying to install pycapnp. Alternatively, the bug is fixed in 1.1.0 (changelog here). So changing requirements.txt to have pycapnp==1.1.0 is probably a better solution.

b) building pycapnp from source requires having libcapnp available. pycapnp's setup.py will try to build capnproto-c++ from source, but it fails due to cmake not being installed in the docker container.

I'm working on a fix, which is currently looking like:

  1. Bump pycapnp from 1.0.0 to 1.1.0. I don't see any breaking changes in the changelog but I'm also pretty new to this project so I could be missing something.
  2. Adding cmake so pycapnp can build libcapnp as required.

Here is the failure in the build log for opendbc's Dockerfile. Docker version is 20.10.17, build 100c701:

 ---> Running in ce2fc87cbf2d
Collecting Cython==0.29.14
  Downloading Cython-0.29.14.tar.gz (2.1 MB)
Collecting flake8==3.7.9
  Downloading flake8-3.7.9-py2.py3-none-any.whl (69 kB)
Collecting Jinja2==3.0.3
  Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
Collecting numpy==1.21.0
  Downloading numpy-1.21.0.zip (10.3 MB)
  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'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Collecting pycapnp==1.0.0
  Downloading pycapnp-1.0.0.tar.gz (528 kB)
    ERROR: Command errored out with exit status 1:
     command: /root/.pyenv/versions/3.8.10/bin/python3.8 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5kbwmb_p/pycapnp_e8e8914b3bdf4ee590be2773883c39af/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5kbwmb_p/pycapnp_e8e8914b3bdf4ee590be2773883c39af/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1sbqaq8s
         cwd: /tmp/pip-install-5kbwmb_p/pycapnp_e8e8914b3bdf4ee590be2773883c39af/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-5kbwmb_p/pycapnp_e8e8914b3bdf4ee590be2773883c39af/setup.py", line 12, in <module>
        import pkgconfig
    ModuleNotFoundError: No module named 'pkgconfig'
    ----------------------------------------

This bug also affects the build of panda since Dockerfile.panda needs to build opendbc.

I found manually install pkgconfig and cython before pip install -r requirements could skip pycapnp issue. (not sure if it breaks something)

but after that, it fails to build cereal.

Step 25/25 : RUN scons -c && scons -j$(nproc)
 ---> Running in 4882f43ec85b
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
scons: done cleaning targets.
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
mkdir -p cereal/gen/c/include && touch cereal/gen/c/include/c++.capnp.h
capnpc --src-prefix=cereal cereal/log.capnp cereal/car.capnp cereal/legacy.capnp -o c++:cereal/gen/cpp/
python3 cereal/services.py > cereal/services.h
clang++ -o cereal/messaging/msgq.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/messaging/msgq.cc
clang++ -o cereal/visionipc/ipc.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/visionipc/ipc.cc
clang++ -o cereal/visionipc/visionbuf.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/visionipc/visionbuf.cc
clang++ -o cereal/gen/cpp/log.capnp.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/gen/cpp/log.capnp.c++
clang++ -o cereal/messaging/impl_zmq.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/messaging/impl_zmq.cc
clang++ -o cereal/visionipc/visionipc_server.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/visionipc/visionipc_server.cc
clang++ -o cereal/messaging/impl_msgq.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/messaging/impl_msgq.cc
clang++ -o cereal/visionipc/visionipc_client.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/visionipc/visionipc_client.cc
clang++ -o cereal/messaging/socketmaster.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/messaging/socketmaster.cc
clang++ -o cereal/messaging/messaging.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/messaging/messaging.cc
clang++ -o cereal/gen/cpp/legacy.capnp.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/gen/cpp/legacy.capnp.c++
clang++ -o cereal/gen/cpp/car.capnp.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/gen/cpp/car.capnp.c++
clang++ -o cereal/visionipc/visionbuf_ion.os -c -std=c++1z -g -fPIC -O2 -Wunused -Werror -Wshadow -fPIC -I. -Icereal -Icereal/messaging -Iopendbc/can -I/usr/lib/include -I/root/.pyenv/versions/3.8.10/include/python3.8 cereal/visionipc/visionbuf_ion.cc
cereal/visionipc/visionbuf_ion.cc:12:10: fatal error: 'linux/ion.h' file not found
#include <linux/ion.h>
         ^~~~~~~~~~~~~
1 error generated.
scons: *** [cereal/visionipc/visionbuf_ion.os] Error 1
scons: building terminated because of errors.
The command '/bin/sh -c scons -c && scons -j$(nproc)' returned a non-zero code: 2

the Dockerfile i used:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
    autoconf \
    build-essential \
    ca-certificates \
    capnproto \
    clang \
    cppcheck \
    curl \
    git \
    libtool \
    make \
    libbz2-dev \
    libffi-dev \
    libcapnp-dev \
    liblzma-dev \
    libncurses5-dev \
    libncursesw5-dev \
    libreadline-dev \
    libssl-dev \
    libsqlite3-dev \
    libzmq3-dev \
    llvm \
    ocl-icd-opencl-dev \
    opencl-headers \
    tk-dev \
    xz-utils \
    zlib1g-dev \
    cmake \
  && rm -rf /var/lib/apt/lists/*

RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"
RUN pyenv install -v 3.8.10
RUN pyenv global 3.8.10
RUN pyenv rehash

RUN python -m pip install --upgrade pip

RUN python --version
RUN pip --version

RUN pip install --no-cache-dir pkgconfig Cython

COPY requirements.txt /tmp/
RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN pip install --no-cache-dir pre-commit==2.15.0 pylint==2.5.2

ENV PYTHONPATH=/project

WORKDIR /project
# TODO: Add tag to cereal
RUN git clone https://github.com/commaai/cereal.git /project/cereal && cd /project/cereal && git checkout d46f37c314bb92306207db44693b2f58c31f66b9

COPY SConstruct .
COPY ./site_scons /project/site_scons
COPY . /project/opendbc

RUN rm -rf /project/opendbc/.git
RUN rm -rf /project/cereal/.git

RUN scons -c && scons -j$(nproc)

I also tried debian bullseye-slim base. it shows the same issue. It seems there is linux-headers missing in arm64 version docker image. Haven't found a proper way to install it.

We've fixed the ARM build of openpilot, so this should work now too.