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 {...@@ -1130,6 +1130,32 @@ pub const LinkStep = struct {
1130 %%self.object_files.append(file);1130 %%self.object_files.append(file);
1131 }1131 }
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
1133 pub fn setTarget(self: &LinkStep, target_arch: Arch, target_os: Os, target_environ: Environ) {1159 pub fn setTarget(self: &LinkStep, target_arch: Arch, target_os: Os, target_environ: Environ) {
1134 self.target = Target.Cross {1160 self.target = Target.Cross {
1135 CrossTarget {1161 CrossTarget {
test/tests.zig+3-6
...@@ -349,25 +349,22 @@ pub const CompareOutputContext = struct {...@@ -349,25 +349,22 @@ pub const CompareOutputContext = struct {
349349
350 switch (case.special) {350 switch (case.special) {
351 Special.Asm => {351 Special.Asm => {
352 const obj_path = %%os.path.join(b.allocator, "test_artifacts", "test.o");
353 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);352 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);
354 test (self.test_filter) |filter| {353 test (self.test_filter) |filter| {
355 if (mem.indexOf(u8, annotated_case_name, filter) == null)354 if (mem.indexOf(u8, annotated_case_name, filter) == null)
356 return;355 return;
357 }356 }
358357
359 const obj = b.addAssemble("test", root_src);358 const assembly = b.addAssemble("test", root_src);
360 obj.setOutputPath(obj_path);
361359
362 for (case.sources.toSliceConst()) |src_file| {360 for (case.sources.toSliceConst()) |src_file| {
363 const expanded_src_path = %%os.path.join(b.allocator, "test_artifacts", src_file.filename);361 const expanded_src_path = %%os.path.join(b.allocator, "test_artifacts", src_file.filename);
364 const write_src = b.addWriteFile(expanded_src_path, src_file.source);362 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);
366 }364 }
367365
368 const exe = b.addLinkExecutable("test");366 const exe = b.addLinkExecutable("test");
369 exe.step.dependOn(&obj.step);367 exe.addAssembly(assembly);
370 exe.addObjectFile(obj_path);
371 exe.setOutputPath(exe_path);368 exe.setOutputPath(exe_path);
372369
373 const run_and_cmp_output = RunCompareOutputStep.create(self, exe_path, annotated_case_name,370 const run_and_cmp_output = RunCompareOutputStep.create(self, exe_path, annotated_case_name,