zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 09bc4d6ba366c1a642b3c92c7ec554e95a369053 (tree)
parent afa80da85745913123caebdfa6bb1aad76f2a1c0
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Wed, 26 Apr 2017 12:56:10 -0400

build system: addAssembly and addObject functions

for building executables

Diffstat:
Mstd/build.zig | 26++++++++++++++++++++++++++
Mtest/tests.zig | 9+++------
2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/std/build.zig b/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 { diff --git a/test/tests.zig b/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,