Skip to content

Commit

Permalink
enable zig modules (llvm & clang)
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Nov 20, 2023
1 parent 35d3570 commit 3527843
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
21 changes: 12 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("llvm", .{
.source_file = .{
.path = "src/llvm.zig",
},
});
_ = b.addModule("clang", .{
.source_file = .{
.path = "src/clang.zig",
},
});

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

if (examples) {
Expand Down Expand Up @@ -31,7 +42,7 @@ fn buildExample(b: *std.Build, i: BuildInfo) void {
exe.defineCMacro("__STDC_CONSTANT_MACROS", null);
exe.defineCMacro("__STDC_FORMAT_MACROS", null);
exe.defineCMacro("__STDC_LIMIT_MACROS", null);
exe.addModule("llvm", module(b));
exe.addModule("llvm", b.modules.get("llvm").?);
exe.linkSystemLibrary("z");
switch (i.target.getOsTag()) {
.linux => exe.linkSystemLibrary("LLVM-16"), // Ubuntu
Expand All @@ -57,14 +68,6 @@ fn buildExample(b: *std.Build, i: BuildInfo) void {
run_step.dependOn(&run_cmd.step);
}

pub fn module(b: *std.Build) *std.Build.Module {
return b.createModule(.{
.source_file = .{
.path = "src/llvm.zig",
},
});
}

const BuildInfo = struct {
filepath: []const u8,
target: std.zig.CrossTarget,
Expand Down
25 changes: 25 additions & 0 deletions src/clang.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub const CXString = @import("clang/CXString.zig");
pub const CXErrorCode = @import("clang/CXErrorCode.zig");
pub const CXSourceLocation = @import("clang/CXSourceLocation.zig");
pub const CXFile = @import("clang/CXFile.zig");
pub const CXDiagnostic = @import("clang/CXDiagnostic.zig");
pub const CXIndex = @import("clang/Index.zig");
pub const BuildSystem = @import("clang/BuildSystem.zig");
pub const CXCompilationDatabase = @import("clang/CXCompilationDatabase.zig");
pub const Rewrite = @import("clang/Rewrite.zig");
pub const FatalErrorHandler = @import("clang/FatalErrorHandler.zig");
pub const Documentation = @import("clang/Documentation.zig");

test "all clang modules" {
_ = CXString;
_ = CXErrorCode;
_ = CXSourceLocation;
_ = CXIndex;
_ = CXFile;
_ = CXDiagnostic;
_ = CXCompilationDatabase;
_ = BuildSystem;
_ = Rewrite;
_ = FatalErrorHandler;
_ = Documentation;
}
5 changes: 0 additions & 5 deletions src/llvm.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const std = @import("std");

pub const analysis = @import("analysis.zig");
pub const blake3 = @import("blake3.zig");
pub const bitreader = @import("bitreader.zig");
Expand Down Expand Up @@ -47,7 +45,4 @@ test "all LLVM modules" {
_ = target;
_ = target_machine;
_ = transform;

const testing = std.testing;
testing.refAllDeclsRecursive(@This());
}

0 comments on commit 3527843

Please sign in to comment.