authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-26 12:56:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-26 12:56:10-04:00
log09bc4d6ba366c1a642b3c92c7ec554e95a369053
treecbac0e31042478f82bcf0a48e14a0d875e270d91
parentafa80da85745913123caebdfa6bb1aad76f2a1c0

build system: addAssembly and addObject functions

for building executables

2 files changed, 29 insertions(+), 6 deletions(-)

std/build.zig+26
......@@ -1130,6 +1130,32 @@ pub const LinkStep = struct {
11301130 %%self.object_files.append(file);
11311131 }
11321132
1133 pub fn addObject(self: &LinkStep, obj: &ObjectStep) {
1134 self.step.dependOn(&obj.step);
1135
1136 const path_to_obj = test (obj.output_path) |explicit_out_path| {
1137 explicit_out_path
1138 } else {
1139 // TODO make it so we always know where this will be
1140 %%os.path.join(self.builder.allocator, self.builder.out_dir,
1141 self.builder.fmt("{}{}", obj.name, obj.target.oFileExt()))
1142 };
1143 %%self.object_files.append(path_to_obj);
1144 }
1145
1146 pub fn addAssembly(self: &LinkStep, assembly: &AsmStep) {
1147 self.step.dependOn(&assembly.step);
1148
1149 const path_to_obj = test (assembly.output_path) |explicit_out_path| {
1150 explicit_out_path
1151 } else {
1152 // TODO make it so we always know where this will be
1153 %%os.path.join(self.builder.allocator, self.builder.out_dir,
1154 self.builder.fmt("{}{}", assembly.name, assembly.target.oFileExt()))
1155 };
1156 %%self.object_files.append(path_to_obj);
1157 }
1158
11331159 pub fn setTarget(self: &LinkStep, target_arch: Arch, target_os: Os, target_environ: Environ) {
11341160 self.target = Target.Cross {
11351161 CrossTarget {
test/tests.zig+3-6
......@@ -349,25 +349,22 @@ pub const CompareOutputContext = struct {
349349
350350 switch (case.special) {
351351 Special.Asm => {
352 const obj_path = %%os.path.join(b.allocator, "test_artifacts", "test.o");
353352 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);
354353 test (self.test_filter) |filter| {
355354 if (mem.indexOf(u8, annotated_case_name, filter) == null)
356355 return;
357356 }
358357
359 const obj = b.addAssemble("test", root_src);
360 obj.setOutputPath(obj_path);
358 const assembly = b.addAssemble("test", root_src);
361359
362360 for (case.sources.toSliceConst()) |src_file| {
363361 const expanded_src_path = %%os.path.join(b.allocator, "test_artifacts", src_file.filename);
364362 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
365 obj.step.dependOn(&write_src.step);
363 assembly.step.dependOn(&write_src.step);
366364 }
367365
368366 const exe = b.addLinkExecutable("test");
369 exe.step.dependOn(&obj.step);
370 exe.addObjectFile(obj_path);
367 exe.addAssembly(assembly);
371368 exe.setOutputPath(exe_path);
372369
373370 const run_and_cmp_output = RunCompareOutputStep.create(self, exe_path, annotated_case_name,