feat: 支持 Zig 0.17.0(版本说明、升级指南与示例代码适配) - #390
Merged
Merged
Conversation
- build.zig 增加 0.17 分支,新增 build/0.17.zig(适配 configure/make 分离、b.root、dependOnDirectoryContents) - 新增 course/code/17,适配数组乘法移除、errdefer 捕获移除、@backingInt、SoA 类型信息、@hasDecl、SafeAllocator、@bitcast 新语义等 - 构建系统示例改用 addPassthruArgs 与 Run 步骤,import_vcpkg 迁移到 translate-c 包
- course/code/release 同步为 17 的内容 - 更新数组、枚举、指针、结构体、错误处理、反射、内存管理、与 C 交互、构建系统等章节 - 站点显示版本更新为 0.17.0
|
Important Review skippedToo many files! This PR contains 146 files, which is 46 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry. ⚙️ Run configuration
📒 Files selected for processing (146)
You can disable this status message by setting the
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
3 of 5 tasks
jinzhongjia
force-pushed
the
feat/zig-0.17
branch
2 times, most recently
from
October 5, 2026 05:48
81a3e91 to
1b89447
Compare
basic、cli、test 子项目中的测试沿用了旧版 init 模板的写法,在 0.17 下无法通过;同时根构建只执行了 zig build,测试代码从未被编译。现在对带 test 步骤的子项目额外执行 zig build test。
0.17 起 build 函数应当没有副作用,原脚本在配置阶段直接读取 cwd 并执行操作,改为通过 b.root 与构建步骤完成。
WhileBasic 是文档中用来讲解 continue 表达式的反例,在 i == 5 时会陷入死循环,导致 loop 示例运行后无法退出。保留对该函数的引用以确保它仍会被编译检查。
包括 **、void{}、i0、std.builtin、addTranslateC 推荐写法,并补充 @bitcast 在 0.17 中的语义变化。
- zig fmt 只会在 ** 与 errdefer |err| 上解析失败,void{} 与 i0 仍可解析;并且会自动为 @fromBackingInt 补上 @intcast
- std.zon.parse 的前后对照示例改为实际可编译的写法(std.zon 并未导出 fromSlice)
- 补充 std.fs.path 自 0.16.0 起已被弃用的说明
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为教程增加 Zig
0.17.0(2026/10/2 发布)的支持:新增版本说明与升级指南,新增0.17构建脚本与示例代码,并把release示例与正文同步到0.17。主要改动
文档
0.17.0版本说明(course/update/0.17.0-description.md):目标支持、系统最低版本、语言、标准库、构建系统、编译器、链接器、工具链、已知回归与路线图0.17.0升级指南(course/update/upgrade-0.17.0.md):推荐的升级顺序 + 逐项迁移前后对比代码(指南中的新写法均已在 0.17 下编译验证)0.17.0**→@splat)、枚举(@backingInt/@fromBackingInt)、指针对齐、结构体(@bitCast新语义)、错误处理(errdefer捕获移除)、反射(SoA 风格类型信息、@hasDecl)、内存管理(SafeAllocator、BufferFirstAllocator)、与 C 交互(@cImport移除 → translate-c 包)、构建系统(configure / make 分离)等代码
build.zig增加0.17分支,新增build/0.17.zigb.root代替已移除的b.build_rootb.dependOnDirectoryContents,保证新增示例后配置缓存能正确失效course/code/17/,course/code/release/同步为其内容build_system示例:不再在build函数中直接 spawn 子进程,改为Run步骤;b.args→addPassthruArgs()import_vcpkg示例迁移到官方 translate-c 包(2.0.0)CI
0.17.0(0.17要求 macOS 15+,现有macos-15runner 满足)lint-0_17任务:0.17的zig fmt无法解析旧版本示例中已移除的语法,因此只检查0.17相关代码;原有0.16lint 保持不变其他
0.11-0.17验证
0.17.0:根目录zig build全部 132 个步骤通过(含所有单文件示例的运行与测试、子项目构建)0.16.0:根目录回归构建通过(仅tinytetris在本机因 0.16 自带 libcxx 与本机 macOS SDK 不兼容而失败,与本 PR 无关,course/code/16未改动)zig fmt --check:0.16全仓库通过,0.17对build.zig、build/0.17.zig、course/code/17、course/code/release通过prettier --check通过vitepress build通过;全部 285 处<<<@/code/...#anchor引用均能在release中找到对应 region需要关注
StackFallbackAllocator,但0.17.0标准库中的实际名称是std.heap.BufferFirstAllocator,文档以标准库为准并做了说明import_vcpkg依赖 Windows + vcpkg + gsl,仍保持“仅用于文档展示、默认构建为空操作”,translate-c 的用法用桩模块验证过编译0.16.0,本 PR 未改变这一点