Skip to content

Conversation

@generalmimon
Copy link
Contributor

As you can see at https://web.archive.org/web/20250924165935/https://ziglang.org/learn/build-system/#testing, this example failed to compile with:

$ zig build test --summary all
/home/ci/actions-runner-website/_work/www.ziglang.org/www.ziglang.org/zig-code/build-system/unit-testing/build.zig:20:14: error: no field named 'root_source_file' in struct 'Build.TestOptions'
            .root_source_file = b.path("main.zig"),
             ^~~~~~~~~~~~~~~~
/home/ci/deps/zig-x86_64-linux-0.15.1/lib/std/Build.zig:856:25: note: struct declared here
pub const TestOptions = struct {
                        ^~~~~~

Despite the fact that this build.zig example apparently should fail to compile (since it contains build=fail at the end), this is clearly not the compile error that was intended. I'm sure of that because this example is followed by the diff that should be enough to fix the compile error:

In this case it might be a nice adjustment to enable `skip_foreign_checks` for
the unit tests:
```diff
@@ -23,6 +23,7 @@
});
const run_unit_tests = b.addRunArtifact(unit_tests);
+ run_unit_tests.skip_foreign_checks = true;
test_step.dependOn(&run_unit_tests.step);
}
}
```

Therefore, this commit fixes the above compile error by following the build.zig example with this skip_foreign_checks patch applied:

.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = b.resolveTargetQuery(target),
}),

As you can see at
https://web.archive.org/web/20250924165935/https://ziglang.org/learn/build-system/#testing,
this example failed to compile with:

```console
$ zig build test --summary all
/home/ci/actions-runner-website/_work/www.ziglang.org/www.ziglang.org/zig-code/build-system/unit-testing/build.zig:20:14: error: no field named 'root_source_file' in struct 'Build.TestOptions'
            .root_source_file = b.path("main.zig"),
             ^~~~~~~~~~~~~~~~
/home/ci/deps/zig-x86_64-linux-0.15.1/lib/std/Build.zig:856:25: note: struct declared here
pub const TestOptions = struct {
                        ^~~~~~
```

Despite the fact that this build.zig example apparently *should* fail to
compile (since it contains `build=fail` at the end), this is clearly not
the compile error that was intended. I'm sure of that because this
example is followed by the diff that should be enough to fix the compile
error: https://github.com/ziglang/www.ziglang.org/blob/a69386eea1310f74551870d92250005eb49c191a/content/en-US/learn/build-system.smd#L240-L252

> In this case it might be a nice adjustment to enable
> `skip_foreign_checks` for the unit tests:
> 
> ```diff
> @@ -23,6 +23,7 @@
>          });
> 
>          const run_unit_tests = b.addRunArtifact(unit_tests);
> +        run_unit_tests.skip_foreign_checks = true;
>          test_step.dependOn(&run_unit_tests.step);
>      }
>  }
> ```

Therefore, this commit fixes the above compile error by following the
build.zig example with this `skip_foreign_checks` patch applied:
https://github.com/ziglang/www.ziglang.org/blob/a69386eea1310f74551870d92250005eb49c191a/zig-code/build-system/unit-testing-skip-foreign/build.zig#L20-L23
@alexrp alexrp enabled auto-merge (rebase) October 3, 2025 19:38
@alexrp alexrp merged commit 37bc00f into ziglang:main Oct 3, 2025
1 check passed
@generalmimon generalmimon deleted the patch-1 branch November 12, 2025 20:32
generalmimon added a commit to generalmimon/www.ziglang.org that referenced this pull request Nov 12, 2025
This follows up on ziglang#545.
Although it did fix one compile error, fixing it actually revealed other
issues that are addressed by this pull request:

1. Both versions of `main.zig` were using the old `std.ArrayList` API
   from when it was managed, but as of Zig 0.15.1, it is no longer
   managed:
   https://ziglang.org/download/0.15.1/release-notes.html#ArrayList-make-unmanaged-the-default

2. The file `unit-testing-skip-foreign/build.zig` was missing
   `additional_option=test`, so the command `zig build --summary all`
   was run instead of the intended command `zig build test --summary all`.
generalmimon added a commit to generalmimon/www.ziglang.org that referenced this pull request Nov 25, 2025
This follows up on ziglang#545.
Although it did fix one compile error, fixing it actually revealed other
issues that are addressed by this pull request:

1. Both versions of `main.zig` were using the old `std.ArrayList` API
   from when it was managed, but as of Zig 0.15.1, it is no longer
   managed:
   https://ziglang.org/download/0.15.1/release-notes.html#ArrayList-make-unmanaged-the-default

2. The file `unit-testing-skip-foreign/build.zig` was missing
   `additional_option=test`, so the command `zig build --summary all`
   was run instead of the intended command `zig build test --summary all`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants