|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eo pipefail |
| 4 | + |
| 5 | +usage() { |
| 6 | + cat << EOF |
| 7 | +USAGE: $0 -o <os> -e <github-event> -b <build-type> [-t -a] |
| 8 | +
|
| 9 | +Generate a JSON payload to drive unifiedBuildAndTest* scripts. |
| 10 | +
|
| 11 | +OPTIONS: |
| 12 | + -a Enable assertions |
| 13 | + -b The CMAKE build type: [release, relwithdebinfo, debug] |
| 14 | + -e GitHub event name: [workflow_dispatch, schedule] |
| 15 | + -h Display available options |
| 16 | + -o OS to target: [linux, macos, windows] |
| 17 | + -t Run tests |
| 18 | +EOF |
| 19 | +} |
| 20 | + |
| 21 | +OPT_ASSERTIONS=OFF |
| 22 | +OPT_CMAKE_BUILD_TYPE= |
| 23 | +OPT_GITHUB_EVENT_NAME= |
| 24 | +OPT_OS=() |
| 25 | +OPT_RUN_TESTS=false |
| 26 | +while getopts "ab:e:ho:t" option; do |
| 27 | + case $option in |
| 28 | + a) |
| 29 | + OPT_ASSERTIONS=ON |
| 30 | + ;; |
| 31 | + b) |
| 32 | + case "$OPTARG" in |
| 33 | + "release" | "relwithdebinfo" | "debug") |
| 34 | + OPT_CMAKE_BUILD_TYPE=$OPTARG |
| 35 | + ;; |
| 36 | + *) |
| 37 | + echo "unknown argument '$OPTARG' for '-b', must be one of ['release', 'relwithdebinfo', 'debug']" |
| 38 | + exit 1 |
| 39 | + ;; |
| 40 | + esac |
| 41 | + ;; |
| 42 | + e) |
| 43 | + case "$OPTARG" in |
| 44 | + "workflow_dispatch" | "schedule") |
| 45 | + OPT_GITHUB_EVENT_NAME=$OPTARG |
| 46 | + ;; |
| 47 | + *) |
| 48 | + echo "unsupported GitHub event '$OPTARG', must be one of ['workflow_dispatch', 'schedule']" |
| 49 | + exit 1 |
| 50 | + ;; |
| 51 | + esac |
| 52 | + ;; |
| 53 | + h) |
| 54 | + usage |
| 55 | + exit 0 |
| 56 | + ;; |
| 57 | + o) |
| 58 | + case "$OPTARG" in |
| 59 | + "linux" | "macos" | "windows") |
| 60 | + OPT_OS+=("$OPTARG") |
| 61 | + ;; |
| 62 | + *) |
| 63 | + echo "unknown argument '$OPTARG' for '-o', must be one of ['linux', 'macos', 'windows']" |
| 64 | + exit 1 |
| 65 | + ;; |
| 66 | + esac |
| 67 | + ;; |
| 68 | + t) |
| 69 | + OPT_RUN_TESTS=true |
| 70 | + ;; |
| 71 | + *) |
| 72 | + echo "uknown option" |
| 73 | + usage |
| 74 | + exit 1 |
| 75 | + ;; |
| 76 | + esac |
| 77 | +done |
| 78 | + |
| 79 | +if [[ ! $OPT_GITHUB_EVENT_NAME ]] ; then |
| 80 | + echo "missing mandatory '-e <github-event>' option" |
| 81 | + usage |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +# Set default options for scheduled event only. |
| 86 | +if [ "$OPT_GITHUB_EVENT_NAME" == "schedule" ]; then |
| 87 | + OPT_ASSERTIONS=ON |
| 88 | + OPT_CMAKE_BUILD_TYPE=release |
| 89 | + OPT_OS=("linux") |
| 90 | +fi |
| 91 | + |
| 92 | +if [[ ! $OPT_CMAKE_BUILD_TYPE ]]; then |
| 93 | + echo "missing mandatory '-b <build-type>' option" |
| 94 | + usage |
| 95 | + exit 1 |
| 96 | +fi |
| 97 | + |
| 98 | +if [[ "${#OPT_OS[@]}" == 0 ]] ; then |
| 99 | + echo "at least one '-o <os>' options must be specified" |
| 100 | + usage |
| 101 | + exit 1 |
| 102 | +fi |
| 103 | + |
| 104 | +# Configuration for a run of the static UBTI script. |
| 105 | +staticJson=$(cat <<EOF |
| 106 | +{ |
| 107 | + "cmake_build_type": "$OPT_CMAKE_BUILD_TYPE", |
| 108 | + "llvm_enable_assertions": "$OPT_ASSERTIONS", |
| 109 | + "llvm_force_enable_stats": "ON", |
| 110 | + "runTests": "$OPT_RUN_TESTS", |
| 111 | + "install": "install-firtool install-om-linker", |
| 112 | + "package_name_prefix": "firrtl-bin" |
| 113 | +} |
| 114 | +EOF |
| 115 | +) |
| 116 | + |
| 117 | +# Configuration snippets for a run of the native runner UBTI script. |
| 118 | +runnerLinux=$(cat <<EOF |
| 119 | +{ |
| 120 | + "os": "linux", |
| 121 | + "runner": "ubuntu-22.04", |
| 122 | + "arch": "x64", |
| 123 | + "tar": "tar czf", |
| 124 | + "archive": "tar.gz", |
| 125 | + "sha256": "shasum -a 256", |
| 126 | + "setup": "", |
| 127 | + "cmake_c_compiler": "clang", |
| 128 | + "cmake_cxx_compiler": "clang++" |
| 129 | +} |
| 130 | +EOF |
| 131 | +) |
| 132 | +runnerMacOS=$(cat <<EOF |
| 133 | +{ |
| 134 | + "os": "macos", |
| 135 | + "runner": "macos-13", |
| 136 | + "arch": "x64", |
| 137 | + "tar": "gtar czf", |
| 138 | + "archive": "tar.gz", |
| 139 | + "sha256": "shasum -a 256", |
| 140 | + "setup": "", |
| 141 | + "cmake-args": "", |
| 142 | + "cmake_c_compiler": "clang", |
| 143 | + "cmake_cxx_compiler": "clang++" |
| 144 | +} |
| 145 | +EOF |
| 146 | +) |
| 147 | +runnerWindows=$(cat <<EOF |
| 148 | +{ |
| 149 | + "os": "windows", |
| 150 | + "runner": "windows-2022", |
| 151 | + "arch": "x64", |
| 152 | + "tar": "tar czf", |
| 153 | + "archive": "zip", |
| 154 | + "sha256": "sha256sum", |
| 155 | + "setup": "./utils/find-vs.ps1", |
| 156 | + "cmake-args": "", |
| 157 | + "cmake_c_compiler": "cl", |
| 158 | + "cmake_cxx_compiler": "cl" |
| 159 | +} |
| 160 | +EOF |
| 161 | +) |
| 162 | +runnerFullShared=$(cat <<EOF |
| 163 | +[ |
| 164 | + { |
| 165 | + "name":"CIRCT-full shared", |
| 166 | + "install_target":"install", |
| 167 | + "package_name_prefix":"circt-full-shared", |
| 168 | + "mode":"release", |
| 169 | + "assert":"OFF", |
| 170 | + "shared":"ON", |
| 171 | + "stats":"ON", |
| 172 | + "runTests": "$OPT_RUN_TESTS" |
| 173 | + } |
| 174 | +] |
| 175 | +EOF |
| 176 | +) |
| 177 | +runnerFullStatic=$(cat <<EOF |
| 178 | +[ |
| 179 | + { |
| 180 | + "name":"CIRCT-full static", |
| 181 | + "install_target":"install", |
| 182 | + "package_name_prefix":"circt-full-static", |
| 183 | + "mode":"release", |
| 184 | + "assert":"OFF", |
| 185 | + "shared":"OFF", |
| 186 | + "stats":"ON", |
| 187 | + "runTests": "$OPT_RUN_TESTS" |
| 188 | + } |
| 189 | +] |
| 190 | +EOF |
| 191 | +) |
| 192 | +runnerFirtool=$(cat <<EOF |
| 193 | +[ |
| 194 | + { |
| 195 | + "name": "firtool", |
| 196 | + "install_target": "install-firtool install-om-linker", |
| 197 | + "package_name_prefix": "firrtl-bin", |
| 198 | + "mode":"$OPT_CMAKE_BUILD_TYPE", |
| 199 | + "assert":"$OPT_ASSERTIONS", |
| 200 | + "shared":"OFF", |
| 201 | + "stats":"ON", |
| 202 | + "runTests": "$OPT_RUN_TESTS" |
| 203 | + } |
| 204 | +] |
| 205 | +EOF |
| 206 | +) |
| 207 | + |
| 208 | +# Populate the `config` JSON with the configuration of static and native UBTI |
| 209 | +# scripts. |
| 210 | +config=$(cat <<EOF |
| 211 | +{ |
| 212 | + "static": [], |
| 213 | + "native": [] |
| 214 | +} |
| 215 | +EOF |
| 216 | +) |
| 217 | +for os in "${OPT_OS[@]}"; do |
| 218 | + case "$os" in |
| 219 | + "linux") |
| 220 | + config=$(echo "$config" | jq '.static += [$a]' --argjson a "$staticJson") |
| 221 | + runners=$(echo "$runnerFullShared" "$runnerFullStatic" | jq -s 'add') |
| 222 | + new=$(echo "$runners" "[$runnerLinux]" | jq -s '[combinations | add]') |
| 223 | + config=$(echo "$config" | jq '.native += $a' --argjson a "$new") |
| 224 | + ;; |
| 225 | + "macos") |
| 226 | + runners=$(echo "$runnerFullShared" "$runnerFullStatic" "$runnerFirtool" | jq -s 'add') |
| 227 | + new=$(echo "$runners" "[$runnerMacOS]" | jq -s '[combinations | add]') |
| 228 | + config=$(echo "$config" | jq '.native += $a' --argjson a "$new") |
| 229 | + ;; |
| 230 | + "windows") |
| 231 | + runnerAll=$(echo "$runnerFullStatic" "$runnerFirtool" | jq -s 'add') |
| 232 | + new=$(echo "$runnerAll" "[$runnerWindows]" | jq -s '[combinations | add]') |
| 233 | + config=$(echo "$config" | jq '.native += $a' --argjson a "$new") |
| 234 | + ;; |
| 235 | + *) |
| 236 | + echo "unknown os '$os'" |
| 237 | + exit 1 |
| 238 | + ;; |
| 239 | + esac |
| 240 | +done |
| 241 | + |
| 242 | +# Return the final `config` JSON. |
| 243 | +echo "$config" |
0 commit comments