Skip to content

Commit 6ce7ef4

Browse files
committed
updated to zig v0.13.0/v0.14.0-dev
1 parent 6cb8d82 commit 6ce7ef4

File tree

6 files changed

+77
-56
lines changed

6 files changed

+77
-56
lines changed

.github/workflows/zigbuild.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ jobs:
1414
with:
1515
submodules: recursive
1616
fetch-depth: 0
17-
- uses: goto-bus-stop/setup-zig@v2
18-
17+
- uses: mlugg/setup-zig@v1
18+
1919
- name: Install LLVM (Linux)
2020
if: startsWith(matrix.runs-on, 'ubuntu')
2121
run: |
2222
sudo apt update
2323
sudo apt install -y wget
24-
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
24+
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
2525
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
2626
sudo apt update
27-
sudo apt install -y llvm-17
27+
sudo apt install -y llvm-18
2828
2929
- name: Install LLVM (MacOS)
3030
if: startsWith(matrix.runs-on, 'macos')
3131
run: brew install llvm
3232

3333
- name: Build Summary
3434
run: |
35-
zig build -DExamples --summary all -freference-trace && \
36-
zig build test --summary all -freference-trace
35+
zig build -DExamples --summary all -freference-trace

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
zig-cache/
2-
zig-out/
3-
vendor/
1+
*zig-*/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ implement every chapter in zig.
1010

1111
### Requirement
1212

13-
- [zig v0.12.0](https://ziglang.org/download) or higher.
13+
- [zig v0.13.0](https://ziglang.org/download) or higher.
1414

1515

1616
## References

build.zig

+60-44
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,89 @@
11
const std = @import("std");
22

33
pub fn build(b: *std.Build) !void {
4-
const target_query: std.Target.Query = .{};
5-
const target = b.resolveTargetQuery(target_query);
4+
const target = b.standardTargetOptions(.{});
65
const optimize = b.standardOptimizeOption(.{});
76

8-
const lib = b.addStaticLibrary(.{
9-
.name = "llvm",
10-
.root_source_file = .{.path = "src/llvm-zig.zig"},
7+
// LLVM MODULE
8+
const llvm_module = b.addModule("llvm", .{
9+
.root_source_file = b.path("src/llvm.zig"),
1110
.target = target,
12-
.optimize = optimize
11+
.optimize = optimize,
1312
});
1413

15-
lib.defineCMacro("_FILE_OFFSET_BITS", "64");
16-
lib.defineCMacro("__STDC_CONSTANT_MACROS", null);
17-
lib.defineCMacro("__STDC_FORMAT_MACROS", null);
18-
lib.defineCMacro("__STDC_LIMIT_MACROS", null);
19-
lib.linkSystemLibrary("z");
20-
lib.linkLibC();
14+
llvm_module.addCMacro("_FILE_OFFSET_BITS", "64");
15+
llvm_module.addCMacro("__STDC_CONSTANT_MACROS", "");
16+
llvm_module.addCMacro("__STDC_FORMAT_MACROS", "");
17+
llvm_module.addCMacro("__STDC_LIMIT_MACROS", "");
18+
llvm_module.linkSystemLibrary("z", .{});
19+
20+
if (target.result.abi != .msvc)
21+
llvm_module.link_libc = true
22+
else
23+
llvm_module.link_libcpp = true;
24+
2125
switch (target.result.os.tag) {
22-
.linux => lib.linkSystemLibrary("LLVM-17"), // Ubuntu
26+
.linux => llvm_module.linkSystemLibrary("LLVM-18", .{}), // Ubuntu
2327
.macos => {
24-
lib.addLibraryPath(.{ .path = "/usr/local/opt/llvm/lib" });
25-
lib.linkSystemLibrary("LLVM");
28+
llvm_module.addLibraryPath(.{
29+
.cwd_relative = "/opt/homebrew/opt/llvm/lib",
30+
});
31+
llvm_module.linkSystemLibrary("LLVM", .{
32+
.use_pkg_config = .no,
33+
});
2634
},
27-
else => lib.linkSystemLibrary("LLVM"),
35+
else => llvm_module.linkSystemLibrary("LLVM", .{
36+
.use_pkg_config = .no,
37+
}),
2838
}
2939

30-
b.installArtifact(lib);
31-
32-
_ = try b.modules.put("llvm", &lib.root_module);
33-
34-
_ = b.addModule("clang", .{
35-
.root_source_file = .{
36-
.path = "src/clang.zig",
37-
},
40+
// CLANG MODULE
41+
const clang_module = b.addModule("clang", .{
42+
.root_source_file = b.path("src/clang.zig"),
43+
.target = target,
44+
.optimize = optimize,
3845
});
46+
switch (target.result.os.tag) {
47+
.linux => clang_module.linkSystemLibrary("clang-18", .{}), // Ubuntu
48+
.macos => {
49+
clang_module.addLibraryPath(.{
50+
.cwd_relative = "/opt/homebrew/opt/llvm/lib",
51+
});
52+
clang_module.linkSystemLibrary("clang", .{
53+
.use_pkg_config = .no,
54+
});
55+
},
56+
else => clang_module.linkSystemLibrary("clang", .{
57+
.use_pkg_config = .no,
58+
}),
59+
}
60+
if (target.result.abi != .msvc)
61+
clang_module.link_libc = true
62+
else
63+
clang_module.link_libcpp = true;
3964

4065
const examples = b.option(bool, "Examples", "Build all examples [default: false]") orelse false;
4166
if (examples) {
42-
buildExample(b, target, .{
67+
buildExample(b, .{
4368
.filepath = "examples/sum_module.zig",
44-
.target = target.query,
69+
.target = target,
4570
.optimize = optimize,
4671
});
47-
buildExample(b, target, .{
72+
buildExample(b, .{
4873
.filepath = "examples/factorial_module.zig",
49-
.target = target.query,
74+
.target = target,
5075
.optimize = optimize,
5176
});
5277
}
5378

5479
buildTests(b, target);
5580
}
5681

57-
fn buildExample(b: *std.Build, target: std.Build.ResolvedTarget, i: BuildInfo) void {
82+
fn buildExample(b: *std.Build, i: BuildInfo) void {
5883
const exe = b.addExecutable(.{
5984
.name = i.filename(),
60-
.root_source_file = .{ .path = i.filepath },
61-
.target = target,
85+
.root_source_file = b.path(i.filepath),
86+
.target = i.target,
6287
.optimize = i.optimize,
6388
});
6489
exe.root_module.addImport("llvm", b.modules.get("llvm").?);
@@ -79,7 +104,7 @@ fn buildExample(b: *std.Build, target: std.Build.ResolvedTarget, i: BuildInfo) v
79104

80105
const BuildInfo = struct {
81106
filepath: []const u8,
82-
target: std.zig.CrossTarget,
107+
target: std.Build.ResolvedTarget,
83108
optimize: std.builtin.OptimizeMode,
84109

85110
fn filename(self: BuildInfo) []const u8 {
@@ -90,28 +115,19 @@ const BuildInfo = struct {
90115

91116
fn buildTests(b: *std.Build, target: std.Build.ResolvedTarget) void {
92117
const llvm_tests = b.addTest(.{
93-
.root_source_file = .{ .path = "src/llvm-zig.zig" },
118+
.root_source_file = b.path("src/llvm.zig"),
94119
.target = target,
95120
.optimize = .Debug,
96121
.name = "llvm-tests",
97122
});
98123
const clang_tests = b.addTest(.{
99-
.root_source_file = .{ .path = "src/clang.zig" },
124+
.root_source_file = b.path("src/clang.zig"),
100125
.target = target,
101126
.optimize = .Debug,
102127
.name = "clang-tests",
103128
});
104-
switch (target.result.os.tag) {
105-
.linux => clang_tests.linkSystemLibrary("clang-17"), // Ubuntu
106-
.macos => {
107-
clang_tests.addLibraryPath(.{ .path = "/usr/local/opt/llvm/lib" });
108-
clang_tests.linkSystemLibrary("clang");
109-
},
110-
else => clang_tests.linkSystemLibrary("clang"),
111-
}
112-
clang_tests.linkLibC();
113-
114129
llvm_tests.root_module.addImport("llvm", b.modules.get("llvm").?);
130+
clang_tests.root_module.addImport("clang", b.modules.get("clang").?);
115131

116132
// TODO: CI build LLVM tests with clang
117133
// llvm_tests.step.dependOn(&clang_tests.step);

build.zig.zon

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
.{
22
.name = "llvm-zig",
3-
.version = "0.0.0",
4-
.paths = .{"."},
3+
.version = "18.1.8",
4+
.minimum_zig_version = "0.13.0",
5+
.paths = .{
6+
"src",
7+
"build.zig",
8+
"build.zig.zon",
9+
"README.md",
10+
"LICENSE",
11+
"examples",
12+
},
513
}

src/llvm-zig.zig src/llvm.zig

File renamed without changes.

0 commit comments

Comments
 (0)