Skip to content

Commit

Permalink
Merge pull request #11 from booniepepper/dev
Browse files Browse the repository at this point in the history
Add Zig versioning requirements
  • Loading branch information
booniepepper committed Jul 12, 2023
2 parents e23cd1b + 4ac43cf commit 014ef71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ An installation script may come soon.

To build from source, clone the repo and run `./build help` for instructions.
The project currently builds with Zig 0.11.+ and a recent Cargo toolchain. The
resulting binary for your machine will be produced in `./zig-out/bin/dt`
resulting binary for your machine will be produced as `./zig-out/bin/dt`

## The nerdy stuff

Expand Down
30 changes: 29 additions & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,28 @@ set -euo pipefail
cd "$(dirname "$0")" || exit 1
project_root="$(pwd)"

required_zig_version='0.11.0'

help() {
>&2 echo "USAGE: $(basename "$0") [build, test, ...]"
>&2 echo "USAGE: $(basename "$0") [clean|compile|release|test|cross-clean|cross-release|cross-tar]..."
>&2 echo "A simple build will be './build release'"
>&2 echo "Compiling requires Zig ${required_zig_version}, and tests require a recent Rust toolchain installation."
}

require-zig() {
# First we check Zig's available
if ! command -v zig > /dev/null; then
>&2 echo "Zig is not installed or not found on PATH."
>&2 echo "Building this project currently requires Zig ${required_zig_version}"
exit 1
fi

# Then we check Zig is a version we can build with
_zig_version="$(zig version)"
if [[ ! ${_zig_version} =~ ^${required_zig_version} ]]; then
>&2 echo "Zig ${_zig_version} was found, but only version ${required_zig_version} is supported."
exit 1
fi
}

clean() {
Expand All @@ -16,16 +36,22 @@ clean() {
}

compile() {
require-zig

zig build
}

test() {
require-zig

zig build test
cd "$project_root"/old-rust-tests || exit 1
cargo test
}

release() {
require-zig

zig build -Doptimize=ReleaseSmall
}

Expand All @@ -34,6 +60,8 @@ cross-clean() {
}

cross-release() {
require-zig

local triples=(
aarch64-linux-gnu
aarch64-linux-musleabi
Expand Down

0 comments on commit 014ef71

Please sign in to comment.