Skip to content

Commit

Permalink
test: trying to not have to link llvm from projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dwclake committed Mar 3, 2024
1 parent 52c63a0 commit b014323
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,34 @@ pub fn build(b: *std.Build) !void {
},
});

buildTests(b, target, lib);

const examples = b.option(bool, "Examples", "Build all examples [default: false]") orelse false;

if (examples) {
buildExample(b, target, lib, .{
buildExample(b, target, .{
.filepath = "examples/sum_module.zig",
.target = target.query,
.optimize = optimize,
});
buildExample(b, target, lib, .{
.filepath = "examples/fatorial_module.zig",
buildExample(b, target, .{
.filepath = "examples/factorial_module.zig",
.target = target.query,
.optimize = optimize,
});
}

const tests = b.option(bool, "Tests", "Build all tests [default: false]") orelse false;
if (tests) {
buildTests(b, target);
}
}

fn buildExample(b: *std.Build, target: std.Build.ResolvedTarget, lib: *std.Build.Step.Compile, i: BuildInfo) void {
fn buildExample(b: *std.Build, target: std.Build.ResolvedTarget, i: BuildInfo) void {
const exe = b.addExecutable(.{
.name = i.filename(),
.root_source_file = .{ .path = i.filepath },
.target = target,
.optimize = i.optimize,
});
exe.root_module.addImport("llvm", &lib.root_module);
exe.root_module.addImport("llvm", b.modules.get("llvm").?);

b.installArtifact(exe);

Expand All @@ -89,7 +91,7 @@ const BuildInfo = struct {
}
};

fn buildTests(b: *std.Build, target: std.Build.ResolvedTarget, lib: *std.Build.Step.Compile) void {
fn buildTests(b: *std.Build, target: std.Build.ResolvedTarget) void {
const llvm_tests = b.addTest(.{
.root_source_file = .{ .path = "src/llvm.zig" },
.target = target,
Expand All @@ -112,7 +114,7 @@ fn buildTests(b: *std.Build, target: std.Build.ResolvedTarget, lib: *std.Build.S
}
clang_tests.linkLibC();

llvm_tests.root_module.addImport("llvm", &lib.root_module);
llvm_tests.root_module.addImport("llvm", b.modules.get("llvm").?);

// TODO: CI build LLVM tests with clang
// llvm_tests.step.dependOn(&clang_tests.step);
Expand Down
File renamed without changes.

0 comments on commit b014323

Please sign in to comment.