From 35278432d0a37346247a40bafe01290efc39a85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Catarino=20Fran=C3=A7a?= Date: Mon, 20 Nov 2023 17:14:56 -0300 Subject: [PATCH] enable zig modules (llvm & clang) --- build.zig | 21 ++++++++++++--------- src/clang.zig | 25 +++++++++++++++++++++++++ src/llvm.zig | 5 ----- 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 src/clang.zig diff --git a/build.zig b/build.zig index ad315d1..4d77e19 100644 --- a/build.zig +++ b/build.zig @@ -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) { @@ -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 @@ -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, diff --git a/src/clang.zig b/src/clang.zig new file mode 100644 index 0000000..ef57bb0 --- /dev/null +++ b/src/clang.zig @@ -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; +} diff --git a/src/llvm.zig b/src/llvm.zig index 538c8e2..aefc818 100644 --- a/src/llvm.zig +++ b/src/llvm.zig @@ -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"); @@ -47,7 +45,4 @@ test "all LLVM modules" { _ = target; _ = target_machine; _ = transform; - - const testing = std.testing; - testing.refAllDeclsRecursive(@This()); }