Commit graph

164 commits

Author SHA1 Message Date
Manlio Perillo
a5d93c0b20 build: improve coding style in ZiglingStep
- Use an anonymous struct when initializing std.Build.Step.
  - Rename the builder parameter in the create method to b
  - Avoid lines too long

Additionally:
  - In the run method, rename output to raw_output in order to make the
    next variable names shorter.
  - In the compile method, rename zig_file to path.
2023-05-03 18:13:55 +02:00
Manlio Perillo
771b499cbc build: use @panic("OOM") instead of unreachable
The code in ZiglingStep copied the error handling used in std.Build in
the past.

Use @panic("OOM") when the error is caused by the allocator failing to
allocate memory.
2023-05-03 18:13:55 +02:00
Manlio Perillo
c6c6a32270 build: improve the exercise output check
Make the error message consistent with the one in std.Build.RunStep,
using the "=" character instead of "-" and correctly aligning the text.
2023-05-03 18:13:55 +02:00
Manlio Perillo
feeba51940 build: don't use @This() in ZiglingStep
Use ZiglingStep, instead.

This is consistent with the coding style in std.Build.
2023-05-03 18:13:55 +02:00
Manlio Perillo
3ec978d73f build: remove ZiglingStep.builder field
It is not necessary, since the builder is available in self.step.owner.
2023-05-03 18:13:55 +02:00
Manlio Perillo
11d8468539 build: use Child.exec in ZiglingStep.run
Update the run method to use Child.exec, instead of Child.spawn followed
by Child.wait.
This simplifies the code.
2023-05-03 18:13:55 +02:00
Manlio Perillo
40cbee8fa2 build: fix incorrect error handling in ZiglingStep.compile
When handling the error from the eval method, some possible errors are
ignored.  The make method will only print the exercise hint and the
help message.

Print the unexpected error message, in the else prong.
Note that FileNotFound can also be considered unexpected.
2023-05-03 18:13:55 +02:00
Manlio Perillo
27b941fdaf build: remove the ZiglingStep.makeInternal method
Rename the doCompile method to compile and add the run method.
The two methods are now called from the make method.

Add the help method, since the error handling of compile and run methods
are now separate.

Remove the obsolete comment for the compile method.
2023-05-03 18:13:55 +02:00
Chris Boesch
72a6287a5f Merge pull request #275 from perillo/heal-only-in-test
Heal only in test
2023-05-02 21:30:29 +02:00
Dave Gauer
e2f3a5e519 Added Ex 101 "for loops part 5" (Closes #271)
Also gave a shot at explaining data-oriented design, a Zig "hot
topic" ever since the red Hawaiian shirt talk(s).
2023-05-02 08:26:32 -04:00
Manlio Perillo
7a40c4584e Restore unit tests 2023-05-02 11:13:31 +02:00
Chris Boesch
f02389e925 comment for the issue added 2023-05-01 20:14:52 +02:00
Chris Boesch
44d51eb9ed cli tests removed to solve 272 2023-05-01 19:54:13 +02:00
Manlio Perillo
a86d4c2795 build: don't override the top level steps
When running `zig build -Dn=n`, the install and uninstall steps where
overridden in order to improve the description.

In recent version of Zig this is no longer allowed.
2023-05-01 18:39:54 +02:00
Manlio Perillo
5c20e2b553 build: rename Exercise.baseName to name
The name "baseName" is confusing, since it refers to the UNIX basename
command, and not to the basename function in some programming languages
including Zig.

Use the std.fs.path.stem function to remove the file extension, instead
of slicing.

Remove the use of the assertion, since it is no longer necessary.
Instead, add a check to ensure that the exercise must be a Zig source
file in the validate_exercises function.

Update the validate_exercises function to check the last exercise, too.
2023-05-01 18:39:54 +02:00
Manlio Perillo
69103a3b82 build: add the Exercise.addExecutable method
Currently addExecutable is called 3 times, unnecessarily making the code
more complex.

The method takes as argument the path to the exercises directory.

Additionally, use the new std.Build.ExecutableOptions.link_libc field.
The new field was added in ziglang/zig@adc9b77d5f on 2023-04-13.

Update the required Zig compiler version.
Note that I added the **current** zig version to the changelog, since
the reason for the change is known only to the person updating the
version.
2023-05-01 18:39:54 +02:00
Manlio Perillo
123fd4b105 build: rename the Exercise.C field to link_libc
The name "C" does not follow the naming conventions for container
fields.
2023-05-01 18:39:54 +02:00
Manlio Perillo
ec1976e9ab build: reduce code duplication when setting the work path
Currently, the code for defining the path to the exercises directory is
duplicate 4 times.

Add the constants `healed_path` and `work_path`, and use work_path
instead of the duplicated if expression.  Update ZiglingStep to take
`work_path` instead of `use_healed` as argument.

Reduce code length by using `join` instead of `std.fs.path.join` and
replace the use of a slice with a tuple.

Additionally, in case of an error from the `join` function, use @panic
instead of unreachable.

Document why the special branch, when the exercises are healed by the
eowyn script, has been disabled.
2023-05-01 18:39:54 +02:00
Manlio Perillo
070734a520 build: remove the Exercise.async field
The stage1 C++ compiler is gone forever.

Remove the custom support and documentation for the old stage1 compiler
in build.zig and README.md.
2023-05-01 18:39:54 +02:00
Manlio Perillo
6f482a1f7a build: move exercises at the end of the file
The exercises slice takes about 460 lines, making it hard to read the
source code of build.zig.

Closes #225
2023-05-01 18:39:42 +02:00
Dave Gauer
2e2924abdb Added Ex. 100 fourth for (as foretold in #261) 2023-04-30 21:23:54 -04:00
Dave Gauer
bef099fee6 Renamed 095 to "for3" to match feature sequence
So 100 will be the next in line.
2023-04-30 17:11:37 -04:00
Manlio Perillo
3dd7cdcb3b build: make exercise output more reliable
Currently, ZiglingStep prints the raw exercise output.  This is not a
problem when executing `zig build` from the shell, but in a unit test it
is necessary to know when the exercise output ends.

Document that Exercise.output should not have trailing whitespace.
Ensure this is true by adding a check in the validate_exercises
function.

Remove trailing whitespace in exercises 68 and 99.

Simplify the output validation in ZiglingStep.makeInternal.
Checking that the length of the actual and expected output is the same
is not necessary, since trailing whitespace has been removed.  Simply do
an exact comparison.

Print the trimmed exercise output, instead of the raw output.
This will ensure that the exercise output always ends with only one LF
character.

Fix some small coding style issues.
2023-04-24 11:31:16 +02:00
Chris Boesch
4435cebe7a Merge pull request #247 from chrboesch/formatting
added first formatting exercise
2023-04-19 22:09:32 +02:00
Chris Boesch
d6d30934db added first formatting exercise 2023-04-19 21:57:37 +02:00
Manlio Perillo
30db9d105a build: avoid intermixed messages on the same line
In same cases, the progress messages from the compiler are intermixed
with the messages printed by ZiglingStep.

This intermixing appears in two cases:
  - when printing, e.g., the message "Checking 0_arrays2.zig..."
  - when printing the compiler errors

Closes #230
2023-04-18 14:43:17 +02:00
Manlio Perillo
c6e055dd83 build: don't print errors in ZiglingStep.eval
Move the code for printing compiler errors and messages to the new
ZiglingStep.printErrors method.

Call printErrors in the Zigling.doCompile method, both in the normal and
error flow.

When handling an error from the Zig IPC, add the case when the compiler
was unable to return the executable path.

Before using the IPC, the error was
  "The following command exited with error code 1"
now it is
  "The following command failed to communicate the compilation result"
2023-04-18 12:57:03 +02:00
Manlio Perillo
b39c7e61ef build: restore compatibility support again
Commit e214c44 (build: update ZiglingStep to the new API) broke again
the compatibility support for old compilers, due to the use of the
multi-object for loop syntax.

Move the Zig IPC support code to src/ipc.zig.

Use the while statement, instead of the for statement.
2023-04-18 12:22:30 +02:00
Manlio Perillo
e3c5cb2175 build: update ZiglingStep to the new API
Update the code to the breaking change in ziglang
commit c96cb98ad (CLI: remove --enable-cache option).

Replace the --enable-cache option with the --listen=- option and use the
Zig IPC to get the path to the executable.

Closes #236
2023-04-13 18:39:51 +02:00
Manlio Perillo
e91c7a24f2 build: disable special case for zig build -Dhealed
The special case was added because it was used by the Eowyn github
workflow.

As a side effect, however, it prevents testing the normal case used by
users.

Disable it, until a better solution is found.
2023-04-13 17:47:17 +02:00
Chris Boesch
bf013df4bf Merge pull request #235 from perillo/update-to-version-0.11.0-dev.2560
Update the code to the new zig version
2023-04-12 19:02:43 +02:00
Manlio Perillo
bc98057d66 Update the code to the new zig version
Update the code to the breaking change in ziglang commit
60eabc0ec (std.Build.CompileStep: remove run() and install())

Update the zig version in the README.md file.
2023-04-12 18:50:30 +02:00
Chris Boesch
9f48d84ac8 added the second exercise for bit manipulation 2023-04-12 17:00:26 +02:00
Chris Boesch
3c19500827 added first exercise for bit manipulation 2023-04-12 15:44:12 +02:00
Manlio Perillo
47876e6371 build: make PrintStep thread safe
Update PrintStep to always printing to stderr, using std.debug.print, so
that the message is written atomically.

Note that currently it is not an issue, since PrintStep prints the
message before everything else.
2023-04-11 12:52:48 +02:00
Manlio Perillo
1ee8aabcf3 build: simplify the code when solving all the exercises
Initialize the first step in the chain to the header_step, instead of
making the code more complex handling the first step as a special case
in the for loop.
2023-04-11 12:45:55 +02:00
Manlio Perillo
be782af7a3 build: restore compatibility support
Commit 0d56ba3 (build: restore the exercise chain) broke the
compatibility support for old compilers, due to the use of the
multi-object for loop syntax.

Use the normal for loop syntax; the change still keep the code readable.

Use the variable `n`, instead of `i`, when referring to the exercise
number; this will improve the readability.

Closes #227
2023-04-11 12:45:55 +02:00
Manlio Perillo
647a24afae build: improve PrintStep, SkipStep and PatchStep names
Use lover case for the step names.

Add the exercise name for the SkipStep and PatchStep step name.
2023-04-11 12:45:55 +02:00
Manlio Perillo
c656536d3f build: simplify code and add tests
Simplify the code finding the exercise number from the exercise index,
when the -Dn option is set.  This is now possible since the exercise
numbers have no holes.

Add the validate_exercises function to check that exercise number are in
the correct order, and call it at the start of the build function.

Add tests, with 2 test cases.
2023-04-11 12:45:55 +02:00
Manlio Perillo
d43f19ded8 build: add support for skipping exercises
Currently, exercises not working with the current Zig compiler are
commented. This is problematic, since the exercise key and exercise
index are no longer consistent.

Add the skip field to the Excercise struct.  Update ZiglingStep to
support it and add a new SkipStep step to support it when using the
standard build step.
2023-04-11 12:45:55 +02:00
Manlio Perillo
67f369484c build: ensure the exercise links libc, when needed
When running, as an example, `zig build -Dhealed -Dn=93 test`, the build
fails, because the `test` step use the standard CompileStep, instead of
ZiglingStep.

Ensure that exercises using libc are correctly built.

Closes #229
2023-04-11 12:45:27 +02:00
Manlio Perillo
1cf910fb51 build: enable full parallelism when -Dhealed is set
The eowyn.sh script is used in a github workflow, but after
commit 0d56ba3 (build: restore the exercise chain), the github action
will take more time to complete.

Enable full build parallelism, when -Dhealed is true and -Dn is null.
Use the standard CompileStep and RunStep, instead of ZiglingStep.

On my PC, this change reduces the build time by about 30%.
2023-04-08 09:31:03 +02:00
Chris Boesch
0fd80d6cba help text for parameters adapted 2023-04-07 18:06:13 +02:00
Manlio Perillo
59e28987da build: restore the exercise chain
The new parallel build support in Zig broke the exercise chain, so that
each esercise check is no longer strictly serialized.

  1. Add the Dexno option, in order to isolate the chain starting from a
     named exercise from the normal chain, thus simplify the code.

     The current code have an additional issue: it added 4 x n steps,
     making reading the help message or the list of steps very hard.

     Add only the `install`, `uninstall`, `zigling`, `test` and `start`
     steps.  The last three steps match the old steps `n`, `n_test` and
     `n_start`.

     The default step is zigling (note the singular form).

     The `install` step override the builtin install step, showing a
     custom description and matches the old `n_install` step.
     The uninstall step was added for consistency, so that the
     description is consistent.

     Setup a new chain starting at `zig build -Dexno=n start` so that it
     is stricly serialized.

     The behavior should be the same as the old one.

  2. Handle the code for all the exercises separately.

     Add only the `ziglings step`, making it the default step, in
     addition to the install and uninstall steps.

     Setup a new chain starting at the first exercise, to that it is
     strictly serialized.

     The behavior should be the same as the old one.

The current code has a know issue: the messages from the ZiglingStep and
the ones from the compiler compilation progress are interleaved, but each
message is written atomically, due to the use of `std.debug.getStderrMutex()`.

Update the README.md file.

Closes #202
2023-04-07 11:36:26 +02:00
Manlio Perillo
75a1600626 build: fix the description of the named_install step
Replace the description of the named_install step from
"Install {s} to zig-cache/bin" to "Copy {s} to prefix path".  The latter
has been adapded from the description of the builtin install step.

Ad an empty line before the build_step variable, in order to improve
readability.

Closes #213
2023-04-05 21:19:17 +02:00
Manlio Perillo
36e3f577ca build: replace the logo step with the header step
Remove the logo step, and use PrintStep for the header step.

The logo step was added as a quick fix after the Builder.addLog function
was removed.

Now the logo is no longer shown when running `zig build -l` or
`zig build -h`.
2023-04-04 18:32:30 +02:00
Manlio Perillo
45713ec8ab build: restore support for Zig 0.6.0
The version check for Zig 0.6.0 was incorrect since commit
971ab7f (Use a zig build script to run ziglings).

Move compatibility support to a separate file, in order to simplify
build.zig.

In case of incompatible version, exit with code 3 instead of 0, in order
to detect the case of failure in a test (to be implemented).

Remove the use of comptime when checking compatibility at the start of
the build function, since it is not necessary.

Closes #210.
2023-04-03 11:37:12 +02:00
Manlio Perillo
dd15cb94fd build: make the logo a build step
Currently, the logo is always printed when the build script is executed,
resulting in the logo being printed twice with `zig build -h` and
`zig build -l`.

Make the logo a build step, so that the logo is printed to stderr only
when necessary.

Closes #211
2023-04-02 15:09:51 +02:00
Chris Boesch
3b85c24694 workaround for parallel processing of the build steps 2023-03-19 18:23:35 +01:00
Chris Boesch
78e856f602 first test for new build system 2023-03-19 00:59:42 +01:00