hexops / mach

zig game engine & graphics toolkit
https://machengine.org
Other
3.37k stars 160 forks source link

all: nominate Zig 2024.1.0-mach #1135

Closed slimsag closed 10 months ago

slimsag commented 10 months ago

Periodically we nominate a new Zig nightly version to be the version that Mach targets, and begin the meticulous process of updating every Mach project to use that new version.

This is the tracking issue to do that for the next scheduled nomination (see the date in the issue title.)

You may have been linked to this issue because you sent a pull request to update a Mach project to use a new Zig API - if that is the case we do appreciate the PR and will look at merging it once this process begins. In the meantime, your PR may stay open for a while. You can either use a fork of the project, or use the version of Zig that Mach currently supports.

Update process

We've just finalized nominating and updating to Zig 2024.1.0-mach. We encourage you to update your projects to that Zig version now. :)

First-order projects

These projects have zero build.zig.zon dependencies, we update them first - and in any order.

Second-order projects

These projects have dependencies on other projects. We update them in the exact order below, top-to-bottom.

slimsag commented 10 months ago

First-order dependencies are almost finished, awesome! Remaining blockers:

Additionally, let's try eliminating direct3d-headers in favor of directx-headers during this update process.

slimsag commented 10 months ago

Tips for updating code to Zig 2024.1.0-mach

Renamed:

Error resolutions:

error: no field named 'source_file' in struct 'Build.Module.CreateOptions'

Change .source_file -> .root_source_file

error: expected type expression, found 'invalid bytes'

error: expected type expression, found 'invalid bytes'
#include "hb-aat-layout.cc"
^
src/harfbuzz.cc:1:1: note: invalid byte: '#'

.root_source_file can no longer be C/C++ files, only .zig. Remove .root_source_file entirely and add the C/C++ file to the module using e.g. this instead:

    lib.addCSourceFile(.{ .file = .{ .path = "src/harfbuzz.cc" } });

panic: @memcpy arguments have non-equal lengths

Ensure both arguments to memcpy have the same lengths. For example a previously valid copy can be updated like this:

-@memcpy(title[0..], opt.title);
+@memcpy(title[0..opt.title.len], opt.title);
Techatrix commented 10 months ago
  • unnecessary var -> const changes must be made, if you have ZLS installed and open each Zig file and save, it will do it automatically for you.

That feature has been removed from autofix in https://github.com/zigtools/zls/pull/1652 so it is only an ordinary code action. The autofix feature has also been disabled by default in https://github.com/zigtools/zls/pull/1657 😭.

Cloudef commented 10 months ago

gnused, bash alternative

if [[ ! -d "$1" ]]; then
  printf 'error: no such directory: %s\n' "$1"
  exit 1
fi

cd "$1"
has_wontfix=0

while {
    IFS=$':' read -r file line col msg;
} do
  if [[ "$msg" ]]; then
    case "$msg" in
      *"local variable is never mutated")
        printf 'autofix: %s\n' "$file:$line:$col:$msg" 1>&2
        sed -i "''${line}s/var/const/" "$file"
        ;;
      *)
        printf 'wontfix: %s\n' "$file:$line:$col:$msg" 1>&2
        has_wontfix=1
        ;;
    esac
  fi
done < <(zig build 2>&1 | grep "error:")

exit $has_wontfix
Srekel commented 9 months ago

Super useful!!

A couple extra things I had to do when updating Tides (from a pretty old Zig build):

std.builtin.Endian.Little -> little

Actually not sure if this one is correct but I guess so? comptime var arg_count = ecsu.meta.argCount(function); -> const arg_count = comptime ecsu.meta.argCount(function);

std.zig.system.NativeTargetInfo.detect(target) -> std.zig.system.resolveTargetQuery(target.query)

exe.linkSystemLibraryName("imm32"); -> exe.linkSystemLibrary("imm32");