diff --git a/Dockerfile b/Dockerfile index 5b7609c..c6ad2ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:latest +FROM rust:1-bookworm # Install cross-compilation tools and dependencies RUN dpkg --add-architecture arm64 && \ diff --git a/Dockerfile.codico b/Dockerfile.codico new file mode 100644 index 0000000..0897a30 --- /dev/null +++ b/Dockerfile.codico @@ -0,0 +1,120 @@ +FROM ubuntu:20.04 + +# Set environment variables to avoid interactive prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Install cross-compilation tools and dependencies +RUN dpkg --add-architecture arm64 && \ + apt-get update && \ + apt-get install -y \ + gcc-aarch64-linux-gnu \ + g++-aarch64-linux-gnu \ + build-essential \ + pkg-config \ + libclang-dev \ + clang \ + cmake \ + make \ + libstdc++-8-dev:arm64 \ + libc6-dev:arm64 \ + curl \ + wget \ + unzip \ + git \ + # GStreamer and GLib development packages for aarch64 + libgstreamer1.0-dev:arm64 \ + libgstreamer-plugins-base1.0-dev:arm64 \ + libglib2.0-dev:arm64 \ + libcairo2-dev:arm64 \ + libpango1.0-dev:arm64 \ + libatk1.0-dev:arm64 \ + libgdk-pixbuf2.0-dev:arm64 \ + libgtk-3-dev:arm64 \ + # GStreamer and GLib development packages for host + libgstreamer1.0-dev \ + libgstreamer-plugins-base1.0-dev \ + gstreamer1.0-plugins-base \ + gstreamer1.0-plugins-good \ + gstreamer1.0-libav \ + gstreamer1.0-tools \ + gstreamer1.0-x \ + gstreamer1.0-alsa \ + gstreamer1.0-gl \ + gstreamer1.0-gtk3 \ + gstreamer1.0-qt5 \ + gstreamer1.0-pulseaudio \ + libglib2.0-dev \ + libcairo2-dev \ + libpango1.0-dev \ + libatk1.0-dev \ + libgdk-pixbuf2.0-dev \ + libgtk-3-dev \ + libavcodec-dev \ + libavformat-dev \ + libswscale-dev \ + libv4l-dev \ + libxvidcore-dev \ + libx264-dev \ + libjpeg-dev \ + libpng-dev \ + libtiff-dev \ + libatlas-base-dev \ + gfortran + +# Install Rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +WORKDIR /app + +# Install rustfmt for aarch64 target +RUN rustup target add aarch64-unknown-linux-gnu && \ + rustup component add rustfmt + +# Git SSH configuration +RUN mkdir -p /root/.ssh && \ + ssh-keyscan github.com >> /root/.ssh/known_hosts + +# This is required to set the right permissions (600) for the SSH key +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +# Set up environment for cross-compilation +ENV TARGET_LINUX_AARCH64=1 +ENV USE_FULL_TFLITE=1 +ENV USE_QUALCOMM_QNN=1 +ENV EI_ENGINE=tflite +ENV QNN_SDK_ROOT=/Users/msani/git_src/codico/qairt/2.26.0.240828/ +ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc +ENV CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ + +# Create a build script +RUN echo '#!/bin/bash\n\ +set -e\n\ +\n\ +echo "Building for aarch64-unknown-linux-gnu..."\n\ +\n\ +# Set cross-compilation environment variables\n\ +export TARGET_LINUX_AARCH64=1\n\ +export USE_FULL_TFLITE=1\n\ +export USE_QUALCOMM_QNN=1\n\ +export EI_ENGINE=tflite\n\ +export QNN_SDK_ROOT=/Users/msani/git_src/codico/qairt/2.26.0.240828/\n\ +export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc\n\ +export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++\n\ +\n\ +# Build for aarch64 with FFI feature enabled\n\ +cargo build --target aarch64-unknown-linux-gnu --features ffi --release --verbose \n\ +\n\ +# Build examples\n\ +echo "Building examples..."\n\ +cargo build --target aarch64-unknown-linux-gnu --features ffi --release --examples\n\ +\n\ +echo "Build completed successfully!"\n\ +echo "Output files:"\n\ +ls -la target/aarch64-unknown-linux-gnu/release/\n\ +' > /usr/local/bin/build-aarch64.sh && chmod +x /usr/local/bin/build-aarch64.sh + +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] +# Default command +CMD ["/usr/local/bin/build-aarch64.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 0cd67ac..1b74f6c 100644 --- a/README.md +++ b/README.md @@ -304,35 +304,32 @@ export EI_MODEL="~/Downloads/new-model-directory" cargo build --release ``` -### Docker-based Cross Compilation +## Docker-based Cross Compilation -For cross-compilation to ARM64 Linux from macOS or other platforms, we provide a Docker-based setup: +For cross-compilation to ARM64 Linux from macOS or other platforms, two Dockerfiles are provided: -**Prerequisites:** -- Docker and Docker Compose installed +- `Dockerfile` (default): For Qualcomm RB3 Gen2 platform +- `Dockerfile.codico`: For Codico Triple Camera box -**Quick Start:** -```bash -# Set up environment variables -export EI_PROJECT_ID="your_project_id" -export EI_API_KEY="your_api_key" -export EI_MODEL="/path/to/your/model" # Optional: for local models +### Using Docker Compose -```bash -# Build the Docker image -docker-compose build +You can build for either platform using the provided `docker-compose.yml` services: -# Build the plugin for ARM64 +#### Qualcomm RB3 Gen2 +```bash +docker-compose build aarch64-build docker-compose run --rm aarch64-build +``` -# Test a specific example -docker-compose run --rm aarch64-build bash -c " - ./target/aarch64-unknown-linux-gnu/release/examples/audio_inference --audio examples/assets/test_audio.wav -" +#### Codico Triple Camera box +```bash +docker-compose build codico-build +docker-compose run --rm codico-build ``` The compiled plugin will be available at `target/aarch64-unknown-linux-gnu/release/libgstedgeimpulse.so`. +--- ## Elements ### edgeimpulseaudioinfer diff --git a/docker-compose.yml b/docker-compose.yml index 995cf4f..5e32a58 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,6 +32,36 @@ services: # Remove container after build restart: "no" + codico-build: + build: + context: . + dockerfile: Dockerfile.codico + volumes: + # Mount the current directory to /app + - .:/app + # Mount cargo cache to speed up builds + - cargo-cache:/usr/local/cargo + # Mount rustup cache + - rustup-cache:/root/.rustup + # Mount model directory if EI_MODEL is set + - ${EI_MODEL:-./model}:/host-model:ro + # Mount test assets + - ./examples/assets:/assets:ro + environment: + # Pass through environment variables + - EI_MODEL=/host-model + - EI_PROJECT_ID=${EI_PROJECT_ID:-} + - EI_API_KEY=${EI_API_KEY:-} + - EI_ENGINE=${EI_ENGINE:-tflite} + - USE_FULL_TFLITE=${USE_FULL_TFLITE:-} + - TARGET_LINUX_AARCH64=1 + - CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc + - CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ + working_dir: /app + command: ["/usr/local/bin/build-aarch64.sh"] + # Remove container after build + restart: "no" + volumes: cargo-cache: rustup-cache: \ No newline at end of file