# Copyright (C) 2019 Intel Corporation.  All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

FROM ubuntu:20.04 AS base

ENV DEBIAN_FRONTEND=noninteractive

# hadolint ignore=DL3008
RUN apt-get update && apt-get install -y \
    cmake build-essential git curl gnupg --no-install-recommends && \
    rm -rf /var/lib/apt/lists/*

# hadolint ignore=DL3008,DL4006
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list && \
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
    apt-get update && apt-get install -y libedgetpu1-std --no-install-recommends && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /home/wamr

COPY . .

WORKDIR /home/wamr/product-mini/platforms/linux/build

RUN cmake \
  -DWAMR_BUILD_WASI_NN=1 \
  -DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \
  -DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \
  -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \
  ..

RUN make -j "$(grep -c ^processor /proc/cpuinfo)" && \
    cp /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm

WORKDIR /assets

ENTRYPOINT [ "/iwasm" ]
