|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2023 DeepMind Technologies Limited. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Installs dmlab2d from source on Linux/macOS. |
| 18 | + |
| 19 | +set -euxo pipefail |
| 20 | + |
| 21 | +function check_version_gt() { |
| 22 | + local required="$1" |
| 23 | + local input lowest |
| 24 | + input="$(grep -Eo '[0-9]+\.[0-9]+' /dev/stdin | head -n 1)" |
| 25 | + lowest="$(printf "${required}\n${input}" | sort -V | head -n 1)" |
| 26 | + [[ ${lowest} == ${required} ]] |
| 27 | +} |
| 28 | + |
| 29 | +function check_setup() { |
| 30 | + echo -e "\nChecking OS is Linux or macOS..." |
| 31 | + uname -a |
| 32 | + [[ "$(uname -s)" =~ (Linux|Darwin) ]] |
| 33 | + |
| 34 | + echo -e "\nChecking python version..." |
| 35 | + python --version | tee /dev/stdout | check_version_gt '3.8' |
| 36 | + |
| 37 | + echo -e "\nChecking pip version..." |
| 38 | + pip install --upgrade pip |
| 39 | + pip --version | tee /dev/stdout | check_version_gt '20.3' |
| 40 | + |
| 41 | + echo -e "\nChecking clang version ..." |
| 42 | + clang --version | tee /dev/stdout | check_version_gt '14.0' |
| 43 | + |
| 44 | + echo -e "\nChecking bazel version..." |
| 45 | + bazel --version | tee /dev/stdout | check_version_gt '6.2' |
| 46 | +} |
| 47 | + |
| 48 | +function install_dmlab2d() { |
| 49 | + echo -e "\nInstalling dmlab2d requirements..." |
| 50 | + pip install packaging |
| 51 | + |
| 52 | + echo -e "\nBuilding dmlab2d wheel..." |
| 53 | + case "$(uname -srp)" in |
| 54 | + Linux*) |
| 55 | + local -r EXTRA_CONFIG=( |
| 56 | + --linkopt=-fuse-ld=lld |
| 57 | + ) |
| 58 | + ;; |
| 59 | + 'Darwin 22.'*arm) |
| 60 | + local -r EXTRA_CONFIG=( |
| 61 | + --config=libc++ |
| 62 | + --config=macos_arm64 |
| 63 | + --repo_env=PY_PLATFORM_OVERRIDE=macosx_13_0_arm64 |
| 64 | + ) |
| 65 | + ;; |
| 66 | + 'Darwin 21.'*arm) |
| 67 | + local -r EXTRA_CONFIG=( |
| 68 | + --config=libc++ |
| 69 | + --config=macos_arm64 |
| 70 | + --repo_env=PY_PLATFORM_OVERRIDE=macosx_12_0_arm64 |
| 71 | + ) |
| 72 | + ;; |
| 73 | + Darwin*i386) |
| 74 | + local -r EXTRA_CONFIG=( |
| 75 | + --config=libc++ |
| 76 | + --config=macos |
| 77 | + ) |
| 78 | + ;; |
| 79 | + *) |
| 80 | + echo "ERROR: no supported config for ${platform}..." >&2 |
| 81 | + exit 1 |
| 82 | + ;; |
| 83 | + esac |
| 84 | + C=clang CXX=clang++ bazel --bazelrc=.bazelrc build \ |
| 85 | + --compilation_mode=opt \ |
| 86 | + --dynamic_mode=off \ |
| 87 | + --config=luajit \ |
| 88 | + "${EXTRA_CONFIG[@]}" \ |
| 89 | + --subcommands \ |
| 90 | + --verbose_failures \ |
| 91 | + --experimental_ui_max_stdouterr_bytes=-1 \ |
| 92 | + --sandbox_debug \ |
| 93 | + //dmlab2d:dmlab2d_wheel |
| 94 | + |
| 95 | + echo -e "\nInstalling dmlab2d..." |
| 96 | + pip install -vvv --find-links=bazel-bin/dmlab2d dmlab2d |
| 97 | +} |
| 98 | + |
| 99 | +function test_dmlab2d() { |
| 100 | + echo -e "\nTesting dmlab2d..." |
| 101 | + python dmlab2d/dmlab2d_test.py |
| 102 | +} |
| 103 | + |
| 104 | +function main() { |
| 105 | + check_setup |
| 106 | + install_dmlab2d |
| 107 | + test_dmlab2d |
| 108 | +} |
| 109 | + |
| 110 | +main "$@" |
0 commit comments