diff --git a/.github/scripts/.build.zsh b/.github/scripts/.build.zsh new file mode 100755 index 000000000..4ae7beec1 --- /dev/null +++ b/.github/scripts/.build.zsh @@ -0,0 +1,296 @@ +#!/usr/bin/env zsh + +builtin emulate -L zsh +setopt EXTENDED_GLOB +setopt PUSHD_SILENT +setopt ERR_EXIT +setopt ERR_RETURN +setopt NO_UNSET +setopt PIPE_FAIL +setopt NO_AUTO_PUSHD +setopt NO_PUSHD_IGNORE_DUPS +setopt FUNCTION_ARGZERO + +## Enable for script debugging +#setopt WARN_CREATE_GLOBAL +#setopt WARN_NESTED_VAR +#setopt XTRACE + +autoload -Uz is-at-least && if ! is-at-least 5.2; then + print -u2 -PR "%F{1}${funcstack[1]##*/}:%f Running on Zsh version %B${ZSH_VERSION}%b, but Zsh %B5.2%b is the minimum supported version. Upgrade Zsh to fix this issue." + exit 1 +fi + +TRAPEXIT() { + local return_value=$? + + if (( ${+CI} )) unset NSUnbufferedIO + + return ${return_value} +} + +TRAPZERR() { + if (( ${_loglevel:-3} > 2 )) { + print -u2 -PR "${CI:+::error::}%F{1} ✖︎ script execution error%f" + print -PR -e " + Callstack: + ${(j:\n :)funcfiletrace} + " + } + + exit 2 +} + +build() { + if (( ! ${+SCRIPT_HOME} )) typeset -g SCRIPT_HOME=${ZSH_ARGZERO:A:h} + local host_os=${${(s:-:)ZSH_ARGZERO:t:r}[2]} + local project_root=${SCRIPT_HOME:A:h:h} + local buildspec_file=${project_root}/buildspec.json + + fpath=(${SCRIPT_HOME}/utils.zsh ${fpath}) + autoload -Uz log_group log_info log_status log_error log_output set_loglevel check_${host_os} setup_ccache + + if [[ ! -r ${buildspec_file} ]] { + log_error \ + 'No buildspec.json found. Please create a build specification for your project.' \ + 'A buildspec.json.template file is provided in the repository to get you started.' + return 2 + } + + typeset -g -a skips=() + local -i verbosity=1 + local -r _version='1.0.0' + local -r -a _valid_targets=( + macos-x86_64 + macos-arm64 + ) + local target + local config='RelWithDebInfo' + local -r -a _valid_configs=(Debug RelWithDebInfo Release MinSizeRel) + local -i codesign=0 + + if [[ ${host_os} == linux ]] { + local -r -a _valid_generators=(Ninja 'Unix Makefiles') + local generator='Ninja' + local -r _usage_host=" +%F{yellow} Additional options for Linux builds%f + ----------------------------------------------------------------------------- + %B--generator%b Specify build system to generate + Available generators: + - Ninja + - Unix Makefiles" + } elif [[ ${host_os} == macos ]] { + local -r _usage_host=" +%F{yellow} Additional options for macOS builds%f + ----------------------------------------------------------------------------- + %B-s | --codesign%b Enable codesigning (macOS only)" + } + + local -i _print_config=0 + local -r _usage=" +Usage: %B${functrace[1]%:*}%b