authorgravatar for xq@random-projects.netFelix "xq" Queißner <xq@random-projects.net> 2021-05-21 20:56:15+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-11 10:43:52+03:00
log1c1ea2baa7514babb2a39031753ce3a0036c5278
tree5b796893bcfca232f92a9d46a8702828666712ee
parent98941cf27c523cd02e5c1a5fb95418a6f220e396

Code quality improvements to GeneratedFile, and manual implementation of Builder.addObjectSource.


2 files changed, 24 insertions(+), 9 deletions(-)

lib/std/build.zig+23-8
...@@ -215,13 +215,17 @@ pub const Builder = struct {...@@ -215,13 +215,17 @@ pub const Builder = struct {
215 return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src), .static);215 return addExecutableSource(self, name, convertOptionalPathToFileSource(root_src), .static);
216 }216 }
217217
218 pub const addExecutableSource = LibExeObjStep.createExecutable;218 pub fn addExecutableSource(builder: *Builder, name: []const u8, root_src: ?FileSource, linkage: LibExeObjStep.Linkage) *LibExeObjStep {
219 return LibExeObjStep.createExecutable(builder, name, root_src, linkage);
220 }
219221
220 pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {222 pub fn addObject(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
221 return addObjectSource(self, name, convertOptionalPathToFileSource(root_src));223 return addObjectSource(self, name, convertOptionalPathToFileSource(root_src));
222 }224 }
223225
224 pub const addObjectSource = LibExeObjStep.createObject;226 pub fn addObjectSource(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
227 return LibExeObjStep.createObject(builder, name, root_src);
228 }
225229
226 pub fn addSharedLibrary(230 pub fn addSharedLibrary(
227 self: *Builder,231 self: *Builder,
...@@ -232,14 +236,22 @@ pub const Builder = struct {...@@ -232,14 +236,22 @@ pub const Builder = struct {
232 return addSharedLibrarySource(self, name, convertOptionalPathToFileSource(root_src), kind);236 return addSharedLibrarySource(self, name, convertOptionalPathToFileSource(root_src), kind);
233 }237 }
234238
235 pub const addSharedLibrarySource = LibExeObjStep.createSharedLibrary;239 pub fn addSharedLibrarySource(
240 self: *Builder,
241 name: []const u8,
242 root_src: ?FileSource,
243 kind: LibExeObjStep.SharedLibKind,
244 ) *LibExeObjStep {
245 return LibExeObjStep.createSharedLibrary(self, name, root_src, kind);
246 }
236247
237 pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {248 pub fn addStaticLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
238 const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;249 return addStaticLibrarySource(self, name, convertOptionalPathToFileSource(root_src));
239 return LibExeObjStep.createStaticLibrary(self, name, root_src_param);
240 }250 }
241251
242 pub const addStaticLibrarySource = LibExeObjStep.createStaticLibrary;252 pub fn addStaticLibrarySource(self: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
253 return LibExeObjStep.createStaticLibrary(self, name, root_src);
254 }
243255
244 pub fn addTest(self: *Builder, root_src: []const u8) *LibExeObjStep {256 pub fn addTest(self: *Builder, root_src: []const u8) *LibExeObjStep {
245 return LibExeObjStep.createTest(self, "test", .{ .path = root_src });257 return LibExeObjStep.createTest(self, "test", .{ .path = root_src });
...@@ -1232,8 +1244,11 @@ pub const GeneratedFile = struct {...@@ -1232,8 +1244,11 @@ pub const GeneratedFile = struct {
1232 /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards.1244 /// This value must be set in the `fn make()` of the `step` and must not be `null` afterwards.
1233 path: ?[]const u8 = null,1245 path: ?[]const u8 = null,
12341246
1235 pub fn getPath(self: *const GeneratedFile) []const u8 {1247 pub fn getPath(self: GeneratedFile) []const u8 {
1236 return self.path orelse @panic("getPath() was called on a GeneratedFile that wasn't build yet. Is there a missing Step dependency?");1248 return self.path orelse std.debug.panic(
1249 "getPath() was called on a GeneratedFile that wasn't build yet. Is there a missing Step dependency on step '{s}'?",
1250 .{self.step.name},
1251 );
1237 }1252 }
1238};1253};
12391254
test/standalone/issue_8550/build.zig+1-1
...@@ -11,7 +11,7 @@ pub fn build(b: *std.build.Builder) !void {...@@ -11,7 +11,7 @@ pub fn build(b: *std.build.Builder) !void {
11 const mode = b.standardReleaseOptions();11 const mode = b.standardReleaseOptions();
12 const kernel = b.addExecutable("kernel", "./main.zig");12 const kernel = b.addExecutable("kernel", "./main.zig");
13 kernel.addObjectFile("./boot.S");13 kernel.addObjectFile("./boot.S");
14 kernel.setLinkerScriptPath("./linker.ld");14 kernel.setLinkerScriptPath(.{ .path = "./linker.ld" });
15 kernel.setBuildMode(mode);15 kernel.setBuildMode(mode);
16 kernel.setTarget(target);16 kernel.setTarget(target);
17 kernel.install();17 kernel.install();