Commit 09bc4d6ba3

Andrew Kelley <superjoe30@gmail.com>
2017-04-26 18:56:10
build system: addAssembly and addObject functions
for building executables
1 parent afa80da
Changed files (2)
std/build.zig
@@ -1130,6 +1130,32 @@ pub const LinkStep = struct {
         %%self.object_files.append(file);
     }
 
+    pub fn addObject(self: &LinkStep, obj: &ObjectStep) {
+        self.step.dependOn(&obj.step);
+
+        const path_to_obj = test (obj.output_path) |explicit_out_path| {
+            explicit_out_path
+        } else {
+            // TODO make it so we always know where this will be
+            %%os.path.join(self.builder.allocator, self.builder.out_dir,
+                self.builder.fmt("{}{}", obj.name, obj.target.oFileExt()))
+        };
+        %%self.object_files.append(path_to_obj);
+    }
+
+    pub fn addAssembly(self: &LinkStep, assembly: &AsmStep) {
+        self.step.dependOn(&assembly.step);
+
+        const path_to_obj = test (assembly.output_path) |explicit_out_path| {
+            explicit_out_path
+        } else {
+            // TODO make it so we always know where this will be
+            %%os.path.join(self.builder.allocator, self.builder.out_dir,
+                self.builder.fmt("{}{}", assembly.name, assembly.target.oFileExt()))
+        };
+        %%self.object_files.append(path_to_obj);
+    }
+
     pub fn setTarget(self: &LinkStep, target_arch: Arch, target_os: Os, target_environ: Environ) {
         self.target = Target.Cross {
             CrossTarget {
test/tests.zig
@@ -349,25 +349,22 @@ pub const CompareOutputContext = struct {
 
         switch (case.special) {
             Special.Asm => {
-                const obj_path = %%os.path.join(b.allocator, "test_artifacts", "test.o");
                 const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);
                 test (self.test_filter) |filter| {
                     if (mem.indexOf(u8, annotated_case_name, filter) == null)
                         return;
                 }
 
-                const obj = b.addAssemble("test", root_src);
-                obj.setOutputPath(obj_path);
+                const assembly = b.addAssemble("test", root_src);
 
                 for (case.sources.toSliceConst()) |src_file| {
                     const expanded_src_path = %%os.path.join(b.allocator, "test_artifacts", src_file.filename);
                     const write_src = b.addWriteFile(expanded_src_path, src_file.source);
-                    obj.step.dependOn(&write_src.step);
+                    assembly.step.dependOn(&write_src.step);
                 }
 
                 const exe = b.addLinkExecutable("test");
-                exe.step.dependOn(&obj.step);
-                exe.addObjectFile(obj_path);
+                exe.addAssembly(assembly);
                 exe.setOutputPath(exe_path);
 
                 const run_and_cmp_output = RunCompareOutputStep.create(self, exe_path, annotated_case_name,