duckdb: Build fails on Pi Zero

I was trying to build on a Raspberry Pi Zero M, and it took a very long time at 11% (hours) and eventually failed; make:

mkdir -p build/release && \
cd build/release && \
cmake      -DBUILD_PARQUET_EXTENSION=TRUE -DCMAKE_BUILD_TYPE=Release ../.. && \
cmake --build .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/git/duckdb/build/release
make[1]: Entering directory '/home/pi/git/duckdb/build/release'
make[2]: Entering directory '/home/pi/git/duckdb/build/release'
make[3]: Entering directory '/home/pi/git/duckdb/build/release'
make[3]: Leaving directory '/home/pi/git/duckdb/build/release'
[  9%] Built target parquet_extension
make[3]: Entering directory '/home/pi/git/duckdb/build/release'
make[3]: Leaving directory '/home/pi/git/duckdb/build/release'
[ 11%] Built target utf8proc
make[3]: Entering directory '/home/pi/git/duckdb/build/release'
make[3]: Leaving directory '/home/pi/git/duckdb/build/release'
make[3]: Entering directory '/home/pi/git/duckdb/build/release'
make[3]: Leaving directory '/home/pi/git/duckdb/build/release'
make[3]: Entering directory '/home/pi/git/duckdb/build/release'
[ 11%] Building CXX object src/optimizer/CMakeFiles/duckdb_optimizer.dir/ub_duckdb_optimizer.cpp.o
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[3]: *** [src/optimizer/CMakeFiles/duckdb_optimizer.dir/build.make:63: src/optimizer/CMakeFiles/duckdb_optimizer.dir/ub_duckdb_optimizer.cpp.o] Error 1
make[3]: Leaving directory '/home/pi/git/duckdb/build/release'
make[2]: *** [CMakeFiles/Makefile2:467: src/optimizer/CMakeFiles/duckdb_optimizer.dir/all] Error 2
make[2]: Leaving directory '/home/pi/git/duckdb/build/release'
make[1]: *** [Makefile:130: all] Error 2
make[1]: Leaving directory '/home/pi/git/duckdb/build/release'
make: *** [Makefile:103: release] Error 2

Anything that can be done here?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (7 by maintainers)

Most upvoted comments

Just for you people I got a Raspberry Pi to get DuckDB to work here ^^

IMG_0037

The Hypriot OS is a minimal Debian OS with a kernel optimized for Docker, for ARM units. The HypriotOS also runs on many other boards besides the Raspberry Pi variants, such as ODROIDs, NVIDIA ShieldTV. Its base is smaller than Rasbian Lite, and not overkill in that sense. I think the overhead is quite small. The stock OS for rpi0, say Raspbian Lite, could also install Docker of course, but it doesn’t come included there.

This demo at https://github.com/hypriot/rpi-nano-httpd shows an example with hundreds of containerized instances of lightweight web servers running on one of these units. That tiny application is “statically linked” when built. For those that prefer a as-much-as-possible portable binary over using containers/lightweight virtualization, would it be possible to statically link to the libstdc++ of the correct version and bundle it in the duckdb cli binary that gets built, perhaps through some switches to the make command (-static-libstdc++)?

Confirmed to work on the Pi Zero (W) as well!

We now build and provide binaries for Raspberry Pi as part of our nightly builds and releases.

You could try this cloud build of duckdb CLI to get a arm/v6 binary (see build logs here), but it needs to be extracted from the docker image first, which can be done like this:

# extract binary from image (this doesn't need to happen on the rpi0)
docker cp $(docker create ghcr.io/mskyttner/duckdb-cli-arm:1.0.6@sha256:57f66b46eeec66ba7b8e989964da64af56a5474d15e63bed025d2b8c5a03faf8):/usr/local/bin/duckdb .

# move the duckdb file to your rpi0 Alpine box and run it there
chmod +x duckdb
scp duckdb rpi0:/usr/local/bin

Caveat if you are not running Alpine on the rpi0 is that you probably need musl-armhf support:

$file duckdb
duckdb: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-armhf.so.1, with debug_info, not stripped

This seems to be an error in building one of the tests. Try skipping the build of those as well by setting the BUILD_UNITTESTS flag to 0 in CMake, e.g. as follows:

mkdir build
cd build
cmake -G "Unix Makefiles" -DBUILD_UNITTESTS=0 -DDISABLE_UNITY=1 ..
make

Installing Docker on a Pi Zero seems like serious overkill to me.

I tried cross-compiling on my laptop with this multistage Dockerfile:

FROM alpine

RUN apk update -qq && apk upgrade && apk add --no-cache \
	build-base \
	cmake clang clang-dev make gcc g++ libc-dev linux-headers \
	ninja \
	unzip \
	curl

WORKDIR /build

RUN curl -fL https://github.com/cwida/duckdb/archive/v0.2.2.tar.gz -o duckdb.tgz && \
	tar xfz duckdb.tgz --strip-components=1 && \
	rm duckdb.tgz

RUN cmake . -G Ninja

RUN N_CPU=$((`nproc --all`-1)) && \
	echo "Number of CPUs: $N_CPU" && \
	ninja -j $N_CPU

FROM alpine

# add system library required for duckdb cli to run
RUN apk update -qq && apk add --no-cache libstdc++

WORKDIR /usr/local/bin
COPY --from=0 /build/duckdb .
RUN chmod +x duckdb

WORKDIR /data
VOLUME ["/data"]

CMD ["duckdb --help"]

For this you need docker and a cli-plugin (that comes with Docker Desktop) called buildx. I didn’t have Docker Desktop (needed only if you’re on MacOS or Windows), I had just the docker Community Edition. So I did these commands to set up the required tools for the crossbuild on my laptop:


# use docker and "buildx" cli plugin, to build for linux/arm* and some other archs:
# see https://github.com/docker/buildx

# some commands to set up buildx for a cross build
docker run --privileged --rm tonistiigi/binfmt --install all
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
sudo systemctl restart docker
export DOCKER_CLI_EXPERIMENTAL=enabled
docker buildx install
docker buildx create --use

The buildx setup above gave support for building for these archs: Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6

I was then able to do do the crossbuild for arm/v6, arm/v7 (I think rpi0 uses that?) and amd64, which took more than one hour to complete, but is claimed to do good concurrent builds for the different architectures:

docker buildx build -t mskyttner/duckdb --push --platform=linux/arm/v6,linux/arm/v7,linux/amd64 .

Once the build is complete you can copy out the binary from the resulting image and if the correct version of the libstdc++ is present on the host it should run there too (haven’t tried it on rpi0 though, but that is my understanding).

You should be able to run the container without that present, though. But you’d need Docker on the Zero… If you installed Hypriot OS on the Pi Zero (see https://blog.hypriot.com/post/releasing-HypriotOS-1-11/) you should be able to run it with docker run --rm -it ${SLUG} duckdb --help, which would pull the relevant slug from Docker Hub if not already available locally.

The image generated from the build ended up being 25.7MB large (which includes the Alpine base OS with libstdc++ installed and duckdb otherwise pretty bare bones).

Another thing you could try is to disable unity builds like so: DISABLE_UNITY=1 make. It could fix the running out of memory issue in the compiler but will also greatly increase your already massive compilation time ^^

Your compiler runs out of memory there, which is not that surprising on a Raspberri Pi Zero. Try cross-compiling from a beefier box. In the future, we should also provide those binaries.