Skip to content

docs: update to 0.14.0 #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub fn build(b: *Build) void {
12 => @import("build/0.12.zig").build(b),
13 => @import("build/0.13.zig").build(b),
14 => @import("build/0.14.zig").build(b),
15 => @import("build/0.15.zig").build(b),
else => @compileError("unknown zig version"),
}
}
6 changes: 3 additions & 3 deletions build/0.11.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub fn build(b: *Build) void {
// open dir
var dir =
std.fs.openIterableDirAbsolute(full_path, .{}) catch |err| {
log.err("open 11 path failed, err is {}", .{err});
std.os.exit(1);
};
log.err("open 11 path failed, err is {}", .{err});
std.os.exit(1);
};
defer dir.close();

// make a iterate for path
Expand Down
2 changes: 1 addition & 1 deletion build/0.13.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const log = std.log.scoped(.For_0_13_0);

const args = [_][]const u8{ "zig", "build" };

const version = "release";
const version = "13";

const relative_path = "course/code/" ++ version;

Expand Down
101 changes: 101 additions & 0 deletions build/0.15.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const std = @import("std");
const Build = std.Build;
const ChildProcess = std.process.Child;

const log = std.log.scoped(.For_0_14_0);

const args = [_][]const u8{ "zig", "build" };

const version = "15";

const relative_path = "course/code/" ++ version;

pub fn build(b: *Build) void {
// get target and optimize
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

var lazy_path = b.path(relative_path);

const full_path = lazy_path.getPath(b);

// open dir
var dir = std.fs.openDirAbsolute(full_path, .{ .iterate = true }) catch |err| {
log.err("open 14 path failed, err is {}", .{err});
std.process.exit(1);
};
defer dir.close();

// make a iterate for release ath
var iterate = dir.iterate();

while (iterate.next()) |val| {
if (val) |entry| {
// get the entry name, entry can be file or directory
const output_name = std.mem.trimRight(u8, entry.name, ".zig");
if (entry.kind == .file) {

// connect path
const path = std.fs.path.join(b.allocator, &[_][]const u8{ relative_path, entry.name }) catch |err| {
log.err("fmt path for examples failed, err is {}", .{err});
std.process.exit(1);
};

// build exe
const exe = b.addExecutable(.{
.name = output_name,
.root_source_file = b.path(path),
.target = target,
.optimize = optimize,
});
exe.linkLibC();

// add to default install
b.installArtifact(exe);

// build test
const unit_tests = b.addTest(.{
.root_source_file = b.path(path),
.target = target,
.optimize = optimize,
});

// add to default install
b.getInstallStep().dependOn(&b.addRunArtifact(unit_tests).step);
} else if (entry.kind == .directory) {

// build child process
var child = ChildProcess.init(&args, b.allocator);

// build cwd
const cwd = std.fs.path.join(b.allocator, &[_][]const u8{
full_path,
entry.name,
}) catch |err| {
log.err("fmt path for examples failed, err is {}", .{err});
std.process.exit(1);
};

// open entry dir
const entry_dir = std.fs.openDirAbsolute(cwd, .{}) catch unreachable;
entry_dir.access("build.zig", .{}) catch {
log.err("not found build.zig in path {s}", .{cwd});
std.process.exit(1);
};

// set child cwd
// this api maybe changed in the future
child.cwd = cwd;

// spawn and wait child process
_ = child.spawnAndWait() catch unreachable;
}
} else {
// Stop endless loop
break;
}
} else |err| {
log.err("iterate examples_path failed, err is {}", .{err});
std.process.exit(1);
}
}
17 changes: 13 additions & 4 deletions course/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,14 @@ export default [
collapsed: true,
items: [
{
text: "0.12.0 升级指南",
link: "/update/upgrade-0.12.0",
text: "0.14.0 升级指南",
link: "/update/upgrade-0.14.0",
},
{
text: "0.12.0 版本说明",
link: "/update/0.12.0-description",
text: "0.14.0 版本说明",
link: "/update/0.14.0-description",
},

{
text: "0.13.0 升级指南",
link: "/update/upgrade-0.13.0",
Expand All @@ -232,6 +233,14 @@ export default [
text: "0.13.0 版本说明",
link: "/update/0.13.0-description",
},
{
text: "0.12.0 升级指南",
link: "/update/upgrade-0.12.0",
},
{
text: "0.12.0 版本说明",
link: "/update/0.12.0-description",
},
],
},
{
Expand Down
10 changes: 0 additions & 10 deletions course/advanced/atomic.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,6 @@ outline: deep

强原子的比较与交换操作,如果目标指针是给定值,那么赋值为参数的新值,并返回 null,否则仅读取值返回。

### [`@fence`](https://ziglang.org/documentation/master/#fence)

函数原型:

```zig
@fence(order: AtomicOrder) void
```

用于创建一个内存屏障,防止某些类型的内存重新排序,具体细节可以查看内存屏障的相关信息。

## `std.atomic` 包

### 原子数据结构
Expand Down
1 change: 1 addition & 0 deletions course/code/13
3 changes: 2 additions & 1 deletion course/code/14/build_system/basic/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "basic",
.name = .basic,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x907975534fe79435,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/cli/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "cli",
.name = .cli,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x48f6513c15de5e44,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/docs/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "docs",
.name = .docs,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x51572bb73db54779,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/embedfile/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "embedfile",
.name = .embedfile,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x3e6a9e8b250bb664,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/externalfile/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "externalfile",
.name = .externalfile,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x61de81227ca0d23c,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/lib/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "library",
.name = .library,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0xa18098bc77aad8e8,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/options/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "options",
.name = .options,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0xd035fa8769f41b1a,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/step/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "step",
.name = .step,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x43b9fe3c8067cab6,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/system_lib/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "system_lib",
.name = .system_lib,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x64b791172db5c549,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/test/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "test",
.name = .ttest,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x334b1002be4b456c,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/build_system/tinytetris/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "tinytetris",
.name = .tinytetris,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x5f03916d4d995c27,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/import_dependency_build/pkg1/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.{
.name = "pkg1",
.name = .pkg1,
.version = "0.0.0",
.fingerprint = 0x759ba61b105d16f9,
.dependencies = .{
.pkg2 = .{
// path 为本地包的路径
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/import_dependency_build/pkg2/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.{
.name = "pkg2",
.name = .pkg2,
.version = "0.0.0",
.fingerprint = 0xec92f7a1a7362798,
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/import_vcpkg/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = "import_vcpkg",
.name = .import_vcpkg,

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.fingerprint = 0x75583b9623cebdcb,

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
3 changes: 2 additions & 1 deletion course/code/14/package_management_exporter/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// #region package_management
.{
// 包名字
.name = "exporter",
.name = .exporter,
// 包版本
.version = "0.0.0",
.fingerprint = 0x6a125ce7eaa53f2,
// 包所包含的源文件,一般用于在对外提供包时才使用,还是建议养成写清楚paths的习惯
.paths = .{
"build.zig",
Expand Down
Loading