@@ -10,10 +10,14 @@ pub const KiB = 1024;
10
10
pub const MiB = 1024 * KiB ;
11
11
pub const GiB = 1024 * MiB ;
12
12
13
- fn usageDemo (b : * std.Build , debug_step : * std.Build.Step ) void {
14
- installDebugDisk (debug_step , "uninitialized.img" , 50 * MiB , .uninitialized );
13
+ fn usageDemo (
14
+ b : * std.Build ,
15
+ dependency : * std.Build.Dependency ,
16
+ debug_step : * std.Build.Step ,
17
+ ) void {
18
+ installDebugDisk (dependency , debug_step , "uninitialized.img" , 50 * MiB , .uninitialized );
15
19
16
- installDebugDisk (debug_step , "empty-mbr.img" , 50 * MiB , .{
20
+ installDebugDisk (dependency , debug_step , "empty-mbr.img" , 50 * MiB , .{
17
21
.mbr = .{
18
22
.partitions = .{
19
23
null ,
@@ -24,7 +28,7 @@ fn usageDemo(b: *std.Build, debug_step: *std.Build.Step) void {
24
28
},
25
29
});
26
30
27
- installDebugDisk (debug_step , "manual-offset-mbr.img" , 50 * MiB , .{
31
+ installDebugDisk (dependency , debug_step , "manual-offset-mbr.img" , 50 * MiB , .{
28
32
.mbr = .{
29
33
.partitions = .{
30
34
&.{ .offset = 2048 + 0 * 10 * MiB , .size = 10 * MiB , .bootable = true , .type = .fat32_lba , .data = .uninitialized },
@@ -35,7 +39,7 @@ fn usageDemo(b: *std.Build, debug_step: *std.Build.Step) void {
35
39
},
36
40
});
37
41
38
- installDebugDisk (debug_step , "auto-offset-mbr.img" , 50 * MiB , .{
42
+ installDebugDisk (dependency , debug_step , "auto-offset-mbr.img" , 50 * MiB , .{
39
43
.mbr = .{
40
44
.partitions = .{
41
45
&.{ .size = 7 * MiB , .bootable = true , .type = .fat32_lba , .data = .uninitialized },
@@ -46,29 +50,29 @@ fn usageDemo(b: *std.Build, debug_step: *std.Build.Step) void {
46
50
},
47
51
});
48
52
49
- installDebugDisk (debug_step , "empty-fat32.img" , 50 * MiB , .{
53
+ installDebugDisk (dependency , debug_step , "empty-fat32.img" , 50 * MiB , .{
50
54
.fs = .{
51
55
.format = .fat32 ,
52
56
.label = "EMPTY" ,
53
57
.items = &.{},
54
58
},
55
59
});
56
60
57
- installDebugDisk (debug_step , "initialized-fat32.img" , 50 * MiB , .{
61
+ installDebugDisk (dependency , debug_step , "initialized-fat32.img" , 50 * MiB , .{
58
62
.fs = .{
59
63
.format = .fat32 ,
60
64
.label = "ROOTFS" ,
61
65
.items = &.{
62
66
.{ .empty_dir = "boot/EFI/refind/icons" },
63
67
.{ .empty_dir = "/boot/EFI/nixos/.extra-files/" },
64
68
.{ .empty_dir = "Users/xq/" },
65
- .{ .copy_dir = .{ .source = relpath ( b , "dummy/Windows" ), .destination = "Windows" } },
66
- .{ .copy_file = .{ .source = relpath ( b , "dummy/README.md" ), .destination = "Users/xq/README.md" } },
69
+ .{ .copy_dir = .{ .source = b . path ( "dummy/Windows" ), .destination = "Windows" } },
70
+ .{ .copy_file = .{ .source = b . path ( "dummy/README.md" ), .destination = "Users/xq/README.md" } },
67
71
},
68
72
},
69
73
});
70
74
71
- installDebugDisk (debug_step , "initialized-fat32-in-mbr-partitions.img" , 100 * MiB , .{
75
+ installDebugDisk (dependency , debug_step , "initialized-fat32-in-mbr-partitions.img" , 100 * MiB , .{
72
76
.mbr = .{
73
77
.partitions = .{
74
78
&.{
@@ -83,8 +87,8 @@ fn usageDemo(b: *std.Build, debug_step: *std.Build.Step) void {
83
87
.{ .empty_dir = "boot/EFI/refind/icons" },
84
88
.{ .empty_dir = "/boot/EFI/nixos/.extra-files/" },
85
89
.{ .empty_dir = "Users/xq/" },
86
- .{ .copy_dir = .{ .source = relpath ( b , "dummy/Windows" ), .destination = "Windows" } },
87
- .{ .copy_file = .{ .source = relpath ( b , "dummy/README.md" ), .destination = "Users/xq/README.md" } },
90
+ .{ .copy_dir = .{ .source = b . path ( "dummy/Windows" ), .destination = "Windows" } },
91
+ .{ .copy_file = .{ .source = b . path ( "dummy/README.md" ), .destination = "Users/xq/README.md" } },
88
92
},
89
93
},
90
94
},
@@ -104,45 +108,49 @@ fn usageDemo(b: *std.Build, debug_step: *std.Build.Step) void {
104
108
// });
105
109
}
106
110
107
- const MyBuild = @This ();
111
+ pub fn build (b : * std.Build ) void {
112
+ // Steps:
108
113
109
- const FatFS = @import ( "zfat " );
114
+ const debug_step = b . step ( "debug" , "Builds a basic exemplary disk image. " );
110
115
111
- const fatfs_config = FatFS.Config {
112
- // .max_long_name_len = 121,
113
- .code_page = .us ,
114
- .volumes = .{ .count = 1 },
115
- .rtc = .dynamic ,
116
- .mkfs = true ,
117
- .exfat = true ,
118
- };
116
+ // Dependency Setup:
119
117
120
- pub fn build (b : * std.Build ) void {
121
- const debug_step = b .step ("debug" , "Builds a basic exemplary disk image." );
118
+ const zfat_dep = b .dependency ("zfat" , .{
119
+ // .max_long_name_len = 121,
120
+ .code_page = .us ,
121
+ .@"volume-count" = @as (u32 , 1 ),
122
+ // .rtc = .dynamic,
123
+ .mkfs = true ,
124
+ .exfat = true ,
125
+ });
122
126
123
- usageDemo (b , debug_step );
124
- }
127
+ const zfat_mod = zfat_dep .module ("zfat" );
125
128
126
- fn resolveFilesystemMaker (b : * std.Build , fs : FileSystem.Format ) std.Build.LazyPath {
127
- switch (fs ) {
128
- .fat12 , .fat16 , .fat32 , .exfat = > {
129
- const fatfs_module = FatFS .createModule (b , fatfs_config );
129
+ const mkfs_fat = b .addExecutable (.{
130
+ .name = "mkfs.fat" ,
131
+ .target = b .host ,
132
+ .optimize = .ReleaseSafe ,
133
+ .root_source_file = .{ .cwd_relative = build_root ++ "/src/mkfs.fat.zig" },
134
+ });
135
+ mkfs_fat .root_module .addImport ("fat" , zfat_mod );
136
+ mkfs_fat .linkLibC ();
137
+ b .installArtifact (mkfs_fat );
130
138
131
- const mkfs_fat = b .addExecutable (.{
132
- .name = "mkfs.fat" ,
133
- .root_source_file = .{ .cwd_relative = build_root ++ "/src/mkfs.fat.zig" },
134
- });
135
- mkfs_fat .addModule ("fat" , fatfs_module );
136
- mkfs_fat .linkLibC ();
137
- FatFS .link (mkfs_fat , fatfs_config );
139
+ // Usage:
140
+ var self_dep = std.Build.Dependency {
141
+ .builder = b ,
142
+ };
143
+ usageDemo (b , & self_dep , debug_step );
144
+ }
138
145
139
- return mkfs_fat .getEmittedBin ();
140
- },
146
+ fn resolveFilesystemMaker (dependency : * std.Build.Dependency , fs : FileSystem.Format ) std.Build.LazyPath {
147
+ return switch (fs ) {
148
+ .fat12 , .fat16 , .fat32 , .exfat = > dependency .artifact ("mkfs.fat" ).getEmittedBin (),
141
149
142
- .custom = > | path | return path ,
150
+ .custom = > | path | path ,
143
151
144
152
else = > std .debug .panic ("Unsupported builtin file system: {s}" , .{@tagName (fs )}),
145
- }
153
+ };
146
154
}
147
155
148
156
fn relpath (b : * std.Build , path : []const u8 ) std.Build.LazyPath {
@@ -151,30 +159,36 @@ fn relpath(b: *std.Build, path: []const u8) std.Build.LazyPath {
151
159
};
152
160
}
153
161
154
- fn installDebugDisk (install_step : * std.Build.Step , name : []const u8 , size : u64 , content : Content ) void {
155
- const initialize_disk = initializeDisk (install_step .owner , size , content );
162
+ fn installDebugDisk (
163
+ dependency : * std.Build.Dependency ,
164
+ install_step : * std.Build.Step ,
165
+ name : []const u8 ,
166
+ size : u64 ,
167
+ content : Content ,
168
+ ) void {
169
+ const initialize_disk = initializeDisk (dependency , size , content );
156
170
const install_disk = install_step .owner .addInstallFile (initialize_disk .getImageFile (), name );
157
171
install_step .dependOn (& install_disk .step );
158
172
}
159
173
160
- pub fn initializeDisk (b : * std.Build , size : u64 , content : Content ) * InitializeDiskStep {
161
- const ids = b .allocator .create (InitializeDiskStep ) catch @panic ("out of memory" );
174
+ pub fn initializeDisk (dependency : * std.Build.Dependency , size : u64 , content : Content ) * InitializeDiskStep {
175
+ const ids = dependency . builder .allocator .create (InitializeDiskStep ) catch @panic ("out of memory" );
162
176
163
177
ids .* = InitializeDiskStep {
164
178
.step = std .Build .Step .init (.{
165
- .owner = b ,
179
+ .owner = dependency . builder , // TODO: Is this correct?
166
180
.id = .custom ,
167
181
.name = "initialize disk" ,
168
182
.makeFn = InitializeDiskStep .make ,
169
183
.first_ret_addr = @returnAddress (),
170
184
.max_rss = 0 ,
171
185
}),
172
186
.disk_file = .{ .step = & ids .step },
173
- .content = content .dupe (b ) catch @panic ("out of memory" ),
187
+ .content = content .dupe (dependency . builder ) catch @panic ("out of memory" ),
174
188
.size = size ,
175
189
};
176
190
177
- ids .content .resolveFileSystems (b );
191
+ ids .content .resolveFileSystems (dependency );
178
192
179
193
ids .content .pushDependenciesTo (& ids .step );
180
194
@@ -192,11 +206,13 @@ pub const InitializeDiskStep = struct {
192
206
disk_file : std.Build.GeneratedFile ,
193
207
194
208
pub fn getImageFile (ids : * InitializeDiskStep ) std.Build.LazyPath {
195
- return .{ .generated = & ids .disk_file };
209
+ return .{ .generated = .{
210
+ .file = & ids .disk_file ,
211
+ } };
196
212
}
197
213
198
214
fn addDirectoryToCache (b : * std.Build , manifest : * std.Build.Cache.Manifest , parent : std.fs.Dir , path : []const u8 ) ! void {
199
- var dir = try parent .openIterableDir (path , .{});
215
+ var dir = try parent .openDir (path , .{ . iterate = true });
200
216
defer dir .close ();
201
217
202
218
var walker = try dir .walk (b .allocator );
@@ -307,8 +323,8 @@ pub const InitializeDiskStep = struct {
307
323
308
324
@memcpy (boot_sector [0.. table .bootloader .len ], & table .bootloader );
309
325
310
- std .mem .writeIntLittle (u32 , boot_sector [0x1B8.. 0x1BC], if (table .disk_id ) | disk_id | disk_id else 0x0000_0000 );
311
- std .mem .writeIntLittle (u16 , boot_sector [0x1BC.. 0x1BE], 0x0000 );
326
+ std .mem .writeInt (u32 , boot_sector [0x1B8.. 0x1BC], if (table .disk_id ) | disk_id | disk_id else 0x0000_0000 , .little );
327
+ std .mem .writeInt (u16 , boot_sector [0x1BC.. 0x1BE], 0x0000 , .little );
312
328
313
329
var all_auto = true ;
314
330
var all_manual = true ;
@@ -369,8 +385,8 @@ pub const InitializeDiskStep = struct {
369
385
desc [1.. 4].* = mbr .encodeMbrChsEntry (lba ); // chs_start
370
386
desc [4 ] = @intFromEnum (part .type );
371
387
desc [5.. 8].* = mbr .encodeMbrChsEntry (lba + size - 1 ); // chs_end
372
- std .mem .writeIntLittle (u32 , desc [8.. 12], lba ); // lba_start
373
- std .mem .writeIntLittle (u32 , desc [12.. 16], size ); // block_count
388
+ std .mem .writeInt (u32 , desc [8.. 12], lba , .little ); // lba_start
389
+ std .mem .writeInt (u32 , desc [12.. 16], size , .little ); // block_count
374
390
375
391
auto_offset += part .size ;
376
392
} else {
@@ -455,7 +471,7 @@ pub const InitializeDiskStep = struct {
455
471
}
456
472
457
473
// use shared access to the file:
458
- const stdout = b .exec (argv .items );
474
+ const stdout = b .run (argv .items );
459
475
460
476
try disk .sync ();
461
477
@@ -502,13 +518,13 @@ pub const InitializeDiskStep = struct {
502
518
}
503
519
}
504
520
505
- fn make (step : * std.Build.Step , progress : * std.Progress.Node ) ! void {
521
+ fn make (step : * std.Build.Step , progress : std.Progress.Node ) ! void {
506
522
const b = step .owner ;
507
523
_ = progress ;
508
524
509
525
const ids : * InitializeDiskStep = @fieldParentPtr ("step" , step );
510
526
511
- var man = b .cache .obtain ();
527
+ var man = b .graph . cache .obtain ();
512
528
defer man .deinit ();
513
529
514
530
man .hash .addBytes (&.{ 232 , 8 , 75 , 249 , 2 , 210 , 51 , 118 , 171 , 12 }); // Change when impl changes
@@ -561,7 +577,7 @@ pub const Content = union(enum) {
561
577
562
578
data : std.Build.LazyPath ,
563
579
564
- binary : * std.Build.CompileStep ,
580
+ binary : * std.Build.Step.Compile ,
565
581
566
582
pub fn dupe (content : Content , b : * std.Build ) ! Content {
567
583
const allocator = b .allocator ;
@@ -660,23 +676,23 @@ pub const Content = union(enum) {
660
676
}
661
677
}
662
678
663
- pub fn resolveFileSystems (content : * Content , b : * std.Build ) void {
679
+ pub fn resolveFileSystems (content : * Content , dependency : * std.Build.Dependency ) void {
664
680
switch (content .* ) {
665
681
.uninitialized = > {},
666
682
.mbr = > | * table | {
667
683
for (& table .partitions ) | * part | {
668
684
if (part .* ) | p | {
669
- @constCast (& p .data ).resolveFileSystems (b );
685
+ @constCast (& p .data ).resolveFileSystems (dependency );
670
686
}
671
687
}
672
688
},
673
689
.gpt = > | * table | {
674
690
for (table .partitions ) | * part | {
675
- @constCast (& part .data ).resolveFileSystems (b );
691
+ @constCast (& part .data ).resolveFileSystems (dependency );
676
692
}
677
693
},
678
694
.fs = > | * fs | {
679
- fs .executable = resolveFilesystemMaker (b , fs .format );
695
+ fs .executable = resolveFilesystemMaker (dependency , fs .format );
680
696
},
681
697
.data , .binary = > {},
682
698
}
0 commit comments