Skip to content

Commit aa47ec8

Browse files
authored
docs: update to 0.14.0 (#232)
* update code * remove `@fence` * docs: code switch `0.14.0` * map zig `0.13.0` * fix: code runner * 增加语法部分升级指南 * 小更新 * `0.14.0` 语言升级完成 * `0.14.0` 部分版本说明 * format * 文档更新完成 * little fix
1 parent 6cc966d commit aa47ec8

File tree

27 files changed

+1984
-39
lines changed

27 files changed

+1984
-39
lines changed

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn build(b: *Build) void {
1010
12 => @import("build/0.12.zig").build(b),
1111
13 => @import("build/0.13.zig").build(b),
1212
14 => @import("build/0.14.zig").build(b),
13+
15 => @import("build/0.15.zig").build(b),
1314
else => @compileError("unknown zig version"),
1415
}
1516
}

build/0.11.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub fn build(b: *Build) void {
2222
// open dir
2323
var dir =
2424
std.fs.openIterableDirAbsolute(full_path, .{}) catch |err| {
25-
log.err("open 11 path failed, err is {}", .{err});
26-
std.os.exit(1);
27-
};
25+
log.err("open 11 path failed, err is {}", .{err});
26+
std.os.exit(1);
27+
};
2828
defer dir.close();
2929

3030
// make a iterate for path

build/0.13.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const log = std.log.scoped(.For_0_13_0);
66

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

9-
const version = "release";
9+
const version = "13";
1010

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

build/0.15.zig

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const std = @import("std");
2+
const Build = std.Build;
3+
const ChildProcess = std.process.Child;
4+
5+
const log = std.log.scoped(.For_0_14_0);
6+
7+
const args = [_][]const u8{ "zig", "build" };
8+
9+
const version = "15";
10+
11+
const relative_path = "course/code/" ++ version;
12+
13+
pub fn build(b: *Build) void {
14+
// get target and optimize
15+
const target = b.standardTargetOptions(.{});
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
var lazy_path = b.path(relative_path);
19+
20+
const full_path = lazy_path.getPath(b);
21+
22+
// open dir
23+
var dir = std.fs.openDirAbsolute(full_path, .{ .iterate = true }) catch |err| {
24+
log.err("open 14 path failed, err is {}", .{err});
25+
std.process.exit(1);
26+
};
27+
defer dir.close();
28+
29+
// make a iterate for release ath
30+
var iterate = dir.iterate();
31+
32+
while (iterate.next()) |val| {
33+
if (val) |entry| {
34+
// get the entry name, entry can be file or directory
35+
const output_name = std.mem.trimRight(u8, entry.name, ".zig");
36+
if (entry.kind == .file) {
37+
38+
// connect path
39+
const path = std.fs.path.join(b.allocator, &[_][]const u8{ relative_path, entry.name }) catch |err| {
40+
log.err("fmt path for examples failed, err is {}", .{err});
41+
std.process.exit(1);
42+
};
43+
44+
// build exe
45+
const exe = b.addExecutable(.{
46+
.name = output_name,
47+
.root_source_file = b.path(path),
48+
.target = target,
49+
.optimize = optimize,
50+
});
51+
exe.linkLibC();
52+
53+
// add to default install
54+
b.installArtifact(exe);
55+
56+
// build test
57+
const unit_tests = b.addTest(.{
58+
.root_source_file = b.path(path),
59+
.target = target,
60+
.optimize = optimize,
61+
});
62+
63+
// add to default install
64+
b.getInstallStep().dependOn(&b.addRunArtifact(unit_tests).step);
65+
} else if (entry.kind == .directory) {
66+
67+
// build child process
68+
var child = ChildProcess.init(&args, b.allocator);
69+
70+
// build cwd
71+
const cwd = std.fs.path.join(b.allocator, &[_][]const u8{
72+
full_path,
73+
entry.name,
74+
}) catch |err| {
75+
log.err("fmt path for examples failed, err is {}", .{err});
76+
std.process.exit(1);
77+
};
78+
79+
// open entry dir
80+
const entry_dir = std.fs.openDirAbsolute(cwd, .{}) catch unreachable;
81+
entry_dir.access("build.zig", .{}) catch {
82+
log.err("not found build.zig in path {s}", .{cwd});
83+
std.process.exit(1);
84+
};
85+
86+
// set child cwd
87+
// this api maybe changed in the future
88+
child.cwd = cwd;
89+
90+
// spawn and wait child process
91+
_ = child.spawnAndWait() catch unreachable;
92+
}
93+
} else {
94+
// Stop endless loop
95+
break;
96+
}
97+
} else |err| {
98+
log.err("iterate examples_path failed, err is {}", .{err});
99+
std.process.exit(1);
100+
}
101+
}

course/.vitepress/sidebar.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,14 @@ export default [
217217
collapsed: true,
218218
items: [
219219
{
220-
text: "0.12.0 升级指南",
221-
link: "/update/upgrade-0.12.0",
220+
text: "0.14.0 升级指南",
221+
link: "/update/upgrade-0.14.0",
222222
},
223223
{
224-
text: "0.12.0 版本说明",
225-
link: "/update/0.12.0-description",
224+
text: "0.14.0 版本说明",
225+
link: "/update/0.14.0-description",
226226
},
227+
227228
{
228229
text: "0.13.0 升级指南",
229230
link: "/update/upgrade-0.13.0",
@@ -232,6 +233,14 @@ export default [
232233
text: "0.13.0 版本说明",
233234
link: "/update/0.13.0-description",
234235
},
236+
{
237+
text: "0.12.0 升级指南",
238+
link: "/update/upgrade-0.12.0",
239+
},
240+
{
241+
text: "0.12.0 版本说明",
242+
link: "/update/0.12.0-description",
243+
},
235244
],
236245
},
237246
{

course/advanced/atomic.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,6 @@ outline: deep
112112

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

115-
### [`@fence`](https://ziglang.org/documentation/master/#fence)
116-
117-
函数原型:
118-
119-
```zig
120-
@fence(order: AtomicOrder) void
121-
```
122-
123-
用于创建一个内存屏障,防止某些类型的内存重新排序,具体细节可以查看内存屏障的相关信息。
124-
125115
## `std.atomic`
126116

127117
### 原子数据结构

course/code/13

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./12

course/code/14/build_system/basic/build.zig.zon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = "basic",
9+
.name = .basic,
1010

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

1516
// This field is optional.
1617
// This is currently advisory only; Zig does not yet do anything

course/code/14/build_system/cli/build.zig.zon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = "cli",
9+
.name = .cli,
1010

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

1516
// This field is optional.
1617
// This is currently advisory only; Zig does not yet do anything

course/code/14/build_system/docs/build.zig.zon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
//
77
// It is redundant to include "zig" in this name because it is already
88
// within the Zig package namespace.
9-
.name = "docs",
9+
.name = .docs,
1010

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

1516
// This field is optional.
1617
// This is currently advisory only; Zig does not yet do anything

0 commit comments

Comments
 (0)