1
0
Fork 0
mirror of https://github.com/ratfactor/ziglings synced 2024-05-11 04:36:04 +02:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Manlio Perillo 3a7feae2b7
Merge 9b0bf26e8d into 7417f01d5d 2023-09-21 16:34:27 -07:00
Dave Gauer 7417f01d5d
Update README.md with new clone instructions 2023-09-19 20:51:05 -04:00
Dave Gauer d699fc1824 Announce move to Codeberg in README 2023-09-19 21:18:27 -04:00
Manlio Perillo 9b0bf26e8d Add the find-zig-release-branch.sh tool
The tool is used to find the latest commit, from the HEAD in date order,
that is compatible with the specified Zig compiler.

The commit found can be used as a base for a branch that can be used by
users that can only install a released version of Zig, e.g. v0.10.1.
2023-05-05 19:08:53 +02:00
2 changed files with 82 additions and 2 deletions

View File

@ -1,5 +1,13 @@
# Ziglings
## ⚠️ Attention! Ziglings has moved to Codeberg!
Check out our handy new URL: https://ziglings.org
Or visit the repo directly at: https://codeberg.org/ziglings/exercises
***
Welcome to Ziglings! This project contains a series of tiny
broken programs (and one nasty surprise). By fixing them, you'll
learn how to read and write [Zig](https://ziglang.org/) code.
@ -51,8 +59,8 @@ $ zig version
Clone this repository with Git:
```
$ git clone https://github.com/ratfactor/ziglings
$ cd ziglings
$ git clone https://ziglings.org
$ cd ziglings.org
```
Then run `zig build` and follow the instructions to begin!

View File

@ -0,0 +1,72 @@
#!/bin/sh
# Find the latest commit that is compatible with a specified Zig version, like
# 0.10.1.
#
# The zig executable can be set using the ZIG_EXE environment variable.
#
# This script will clone the ziglings repository to the path specified by the
# first parameter, that is required. Commits are processed in date order.
# Heals all the exercises.
heal() {
if [ ! -d exercises ]
then
echo "Must be run from the project root directory."
exit 1
fi
mkdir -p patches/healed
for original in exercises/*.zig; do
name=$(basename "$original" .zig)
patch_name="patches/patches/$name.patch"
output="patches/healed/$name.zig"
if [ -f "$patch_name" ]; then
patch -i "$patch_name" -o "$output" -s "$original"
else
printf "Cannot heal %s: no patch found\n" "$name"
fi
done
}
# Configure input parameters.
if [ -z "$ZIG_EXE" ]; then
echo '$ZIG_EXE is required'
exit 1
fi
work_path="$1"
if [ -z "$work_path" ] ; then
echo "The work_path parameter is required and must be a directory"
exit 1
elif [ ! -d "$work_path" ]; then
printf "%s does not exist\n" "$work_path"
exit 1
fi
# Clone ziglings repository.
cd "$work_path" || exit 1
echo "Cloning into 'ziglings'"
git clone -q https://github.com/ratfactor/ziglings.git ziglings || exit 1
# Find a commit compatible with the specified Zig version.
cd ziglings || exit 1
for commit in $(git log --date-order --pretty=format:"%H"); do
git checkout --detach -q "$commit"
printf "\nTesting commit %s\n" "$commit"
heal
# Some versions exits with exit code 0 instead of 1, if version check fails.
sed -i 's/exit(0)/exit(1)/g' build.zig
"$ZIG_EXE" build -Dhealed
zig_ret=$?
git restore build.zig
if [ "$zig_ret" -eq 0 ]; then
printf "Find working commit: %s\n" "$commit"
exit 0
fi
done