• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Values: debian:<version>, ubuntu:<version>
16BASE_IMAGE ?= ubuntu:18.04
17PYTHON_VERSION ?= 3.9
18# Values: rpi, aarch64, native
19TENSORFLOW_TARGET ?= native
20WHEEL_PROJECT_NAME ?= tflite_runtime
21# Values: according to https://www.python.org/dev/peps/pep-0440/
22VERSION_SUFFIX ?=
23
24MAKEFILE_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
25TENSORFLOW_DIR := $(MAKEFILE_DIR)/../../../..
26TAG_IMAGE := "tflite-runtime-builder-$(subst :,-,$(BASE_IMAGE))"
27
28DOCKER_PARAMS := --pid=host \
29    --env "CI_BUILD_USER=$(shell id -u -n)" \
30    --env "CI_BUILD_UID=$(shell id -u)" \
31    --env "CI_BUILD_GROUP=$(shell id -g -n)" \
32    --env "CI_BUILD_GID=$(shell id -g)" \
33    --env "CI_BUILD_HOME=$(TENSORFLOW_DIR)/bazel-ci_build-cache" \
34    --env "WHEEL_PROJECT_NAME=$(WHEEL_PROJECT_NAME)" \
35    --env "VERSION_SUFFIX=$(VERSION_SUFFIX)" \
36    --volume $(TENSORFLOW_DIR):/tensorflow \
37    --workdir /tensorflow
38
39ifneq ($(WHEEL_PLATFORM_NAME),)
40	DOCKER_PARAMS += --env WHEEL_PLATFORM_NAME=$(WHEEL_PLATFORM_NAME)
41endif
42
43.PHONY: help \
44        docker-image \
45        docker-shell \
46        docker-build \
47        clean
48
49help:
50	@echo "make docker-image -- build docker image"
51	@echo "make docker-shell -- run shell inside the docker image"
52	@echo "make docker-build -- build wheel and deb inside the docker image"
53	@echo "make clean        -- remove wheel and deb files"
54
55docker-image:
56	docker build -t $(TAG_IMAGE) --build-arg IMAGE=$(BASE_IMAGE) --build-arg PYTHON_VERSION=$(PYTHON_VERSION) -f $(MAKEFILE_DIR)/Dockerfile.py3 $(MAKEFILE_DIR)/.
57
58docker-shell: docker-image
59	mkdir -p $(TENSORFLOW_DIR)/bazel-ci_build-cache
60	docker run --rm --interactive --tty \
61		$(DOCKER_PARAMS) \
62		$(TAG_IMAGE) /with_the_same_user /bin/bash
63
64docker-build: docker-image
65	mkdir -p $(TENSORFLOW_DIR)/bazel-ci_build-cache
66	docker run \
67		--rm --interactive $(shell tty -s && echo --tty) \
68		$(DOCKER_PARAMS) \
69		$(TAG_IMAGE) \
70		/with_the_same_user /bin/bash -C /tensorflow/tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh $(TENSORFLOW_TARGET)
71