Skip to content

Commit ab2d22f

Browse files
committed
initial zig build system as alternative to cmake
1 parent 0175579 commit ab2d22f

File tree

12 files changed

+220
-111
lines changed

12 files changed

+220
-111
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/.claude/
22
/.cache/
33
/build/
4+
/.zig-cache/
5+
/zig-out/
46
# /buildtools/bin/
57
# /buildtools/downloads/
68
# /buildtools/llvm-*/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule ".cspell/cesium"]
55
path = .cspell/cesium
66
url = https://github.com/cesiumlang/cspell-cesium.git
7+
[submodule "thirdparty/tree-sitter"]
8+
path = thirdparty/tree-sitter
9+
url = https://github.com/tree-sitter/tree-sitter.git

.vscode/ltex.dictionary.en-US.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ CPACK
66
darkgray
77
Darkmode
88
Deallocation
9+
dlopen
10+
dlsym
11+
dylib
912
EBNF
1013
Enums
1114
Fallthrough
@@ -18,21 +21,29 @@ Interop
1821
intrinsics
1922
katex
2023
lexer
24+
libtree
2125
lightgray
2226
Monomorphization
2327
MSVC
2428
Namespacing
29+
nlohmann
2530
PYRANDYOS
2631
PYTHONUNBUFFERED
2732
RRGGBB
2833
Schibsted
2934
scrutinising
3035
shadowable
3136
shiki
37+
subprocessing
3238
szenius
3339
unistd
40+
userland
3441
vaddps
3542
Variadic
3643
variadics
3744
vmovups
45+
windarkmode
46+
yyjson
3847
Zig
48+
49+
cesium-buildtools

CMakeLists.txt

Lines changed: 0 additions & 65 deletions
This file was deleted.

CMakePresets.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

build.zig

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const std = @import("std");
2+
3+
fn setupYyJsonDependency(b: *std.Build, exe: *std.Build.Step.Compile) void {
4+
const yyjson_dep = b.dependency("yyjson", .{});
5+
6+
exe.addCSourceFiles(.{
7+
.root = yyjson_dep.path(""),
8+
.files = &[_][]const u8{
9+
"src/yyjson.c",
10+
},
11+
.flags = &[_][]const u8{
12+
"-std=c99",
13+
},
14+
});
15+
16+
exe.addIncludePath(yyjson_dep.path("src"));
17+
}
18+
19+
fn setupTreeSitterCppDependency(b: *std.Build, exe: *std.Build.Step.Compile) void {
20+
const tree_sitter_cpp_dep = b.dependency("tree_sitter_cpp", .{});
21+
22+
exe.addCSourceFiles(.{
23+
.root = tree_sitter_cpp_dep.path(""),
24+
.files = &[_][]const u8{
25+
"src/parser.c",
26+
"src/scanner.c",
27+
},
28+
.flags = &[_][]const u8{
29+
"-std=c11", // Use C11 for static_assert support
30+
},
31+
});
32+
}
33+
34+
fn setupTreeSitterCoreDependency(b: *std.Build, exe: *std.Build.Step.Compile) void {
35+
// Add tree-sitter core from git submodule
36+
exe.addCSourceFiles(.{
37+
.root = b.path("."),
38+
.files = &[_][]const u8{
39+
"thirdparty/tree-sitter/lib/src/lib.c", // Amalgamated source
40+
},
41+
.flags = &[_][]const u8{
42+
"-std=c11",
43+
},
44+
});
45+
46+
// Add tree-sitter include paths
47+
exe.addIncludePath(b.path("thirdparty/tree-sitter/lib/include"));
48+
exe.addIncludePath(b.path("thirdparty/tree-sitter/lib/src"));
49+
50+
// Add tree-sitter macros
51+
exe.root_module.addCMacro("_POSIX_C_SOURCE", "200112L");
52+
exe.root_module.addCMacro("_DEFAULT_SOURCE", "");
53+
}
54+
55+
fn configureExecutable(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile {
56+
const exe = b.addExecutable(.{
57+
.name = "cesium",
58+
.root_module = b.createModule(.{
59+
.target = target,
60+
.optimize = optimize,
61+
}),
62+
});
63+
64+
// Add C++ source files
65+
exe.addCSourceFiles(.{
66+
.files = &[_][]const u8{
67+
"cesium/src/main.cpp",
68+
},
69+
.flags = &[_][]const u8{
70+
"-std=c++20", // CMAKE_CXX_STANDARD 20
71+
"-Wall", // target_compile_options
72+
"-Wextra",
73+
"-Wpedantic",
74+
"-Wno-unused-parameter", // Clang-specific flag from CMake
75+
},
76+
});
77+
78+
// Link libraries
79+
exe.linkLibCpp();
80+
exe.linkLibC();
81+
82+
return exe;
83+
}
84+
85+
fn setupBuildSteps(b: *std.Build, exe: *std.Build.Step.Compile) void {
86+
// Install the executable
87+
b.installArtifact(exe);
88+
89+
// Create a run step
90+
const run_cmd = b.addRunArtifact(exe);
91+
run_cmd.step.dependOn(b.getInstallStep());
92+
93+
// Allow passing arguments to the application
94+
if (b.args) |args| {
95+
run_cmd.addArgs(args);
96+
}
97+
98+
// Create a run step that can be executed with `zig build run`
99+
const run_step = b.step("run", "Run the cesium compiler");
100+
run_step.dependOn(&run_cmd.step);
101+
102+
// Create test step for future use
103+
const test_step = b.step("test", "Run unit tests");
104+
_ = test_step; // Suppress unused variable warning for now
105+
}
106+
107+
pub fn build(b: *std.Build) void {
108+
// Standard target and optimization options
109+
const target = b.standardTargetOptions(.{});
110+
const optimize = b.standardOptimizeOption(.{});
111+
112+
// Configure the main executable
113+
const exe = configureExecutable(b, target, optimize);
114+
115+
// Setup all dependencies
116+
setupYyJsonDependency(b, exe);
117+
setupTreeSitterCppDependency(b, exe);
118+
setupTreeSitterCoreDependency(b, exe);
119+
120+
// Setup build steps
121+
setupBuildSteps(b, exe);
122+
}

build.zig.zon

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.{
2+
// This is the default name used by packages depending on this one. For
3+
// example, when a user runs `zig fetch --save <url>`, this field is used
4+
// as the key in the `dependencies` table. Although the user can choose a
5+
// different name, most users will stick with this provided value.
6+
//
7+
// It is redundant to include "zig" in this name because it is already
8+
// within the Zig package namespace.
9+
.name = .cesium,
10+
// This is a [Semantic Version](https://semver.org/).
11+
// In a future version of Zig it will be used for package deduplication.
12+
.version = "0.1.0",
13+
// Together with name, this represents a globally unique package
14+
// identifier. This field is generated by the Zig toolchain when the
15+
// package is first created, and then *never changes*. This allows
16+
// unambiguous detection of one package being an updated version of
17+
// another.
18+
//
19+
// When forking a Zig project, this id should be regenerated (delete the
20+
// field and run `zig build`) if the upstream project is still maintained.
21+
// Otherwise, the fork is *hostile*, attempting to take control over the
22+
// original project's identity. Thus it is recommended to leave the comment
23+
// on the following line intact, so that it shows up in code reviews that
24+
// modify the field.
25+
.fingerprint = 0x31b74be1c2c745f5, // Changing this has security and trust implications.
26+
// Tracks the earliest Zig version that the package considers to be a
27+
// supported use case.
28+
.minimum_zig_version = "0.15.1",
29+
// This field is optional.
30+
// Each dependency must either provide a `url` and `hash`, or a `path`.
31+
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
32+
// Once all dependencies are fetched, `zig build` no longer requires
33+
// internet connectivity.
34+
.dependencies = .{
35+
.yyjson = .{
36+
.url = "https://github.com/ibireme/yyjson/archive/refs/tags/0.12.0.tar.gz",
37+
.hash = "N-V-__8AADJobAAfcT3EULUqTBZto6rfWBxzeDyfBxrSCP_b",
38+
},
39+
.tree_sitter_cpp = .{
40+
.url = "https://github.com/tree-sitter/tree-sitter-cpp/archive/refs/tags/v0.23.4.tar.gz",
41+
.hash = "N-V-__8AABV0FwFoNpDVbhYQMEJgss9bkxDorw6hbZVJPCdg",
42+
},
43+
},
44+
// Specifies the set of files and directories that are included in this package.
45+
// Only files and directories listed here are included in the `hash` that
46+
// is computed for this package. Only files listed here will remain on disk
47+
// when using the zig package manager. As a rule of thumb, one should list
48+
// files required for compilation plus any license(s).
49+
// Paths are relative to the build root. Use the empty string (`""`) to refer to
50+
// the build root itself.
51+
// A directory listed here means that all files within, recursively, are included.
52+
.paths = .{
53+
"build.zig",
54+
"build.zig.zon",
55+
"cesium",
56+
// For example...
57+
//"LICENSE",
58+
//"README.md",
59+
},
60+
}

buildtools

cesium.code-workspace

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
"files.watcherExclude": {
1313
"buildtools/clang+llvm-*/": true,
1414
"buildtools/llvm-*/": true,
15+
"buildtools/bin/zig-*/": true,
16+
"buildtools/bin/zig-x86_64-windows-*/": true,
1517
"buildtools/bin/cmake-*-windows-x86_64/**": true,
1618
"buildtools/bin/cmake-*/**": true,
17-
"build/CMakeFiles/**": true,
19+
"build/**": true,
20+
"**/.zig-cache/**": true,
1821
"**/node_modules/**": true,
1922
"**/.cache/**": true,
23+
"**/.git/**": true,
2024
},
2125
"files.exclude": {
2226
"**/node_modules/**": true,
@@ -40,16 +44,20 @@
4044
// "foam.files.newNotePath": "currentDir",
4145
// "foam.completion.useAlias": "whenPathDiffersFromTitle",
4246
// "foam.preview.embedNoteType": "content-inline",
43-
"cmake.environment": {
44-
"PATH": "${workspaceFolder}/buildtools/bin;${workspaceFolder}/buildtools/llvm-21.1.0/bin;${env:PATH}"
45-
},
46-
"cmake.additionalCompilerSearchDirs": [
47-
"${workspaceFolder:cesium-src}/buildtools/bin",
48-
"${workspaceFolder:cesium-src}/buildtools/llvm-21.1.0/bin",
49-
],
50-
"cmake.cmakePath": "${workspaceFolder}/buildtools/bin/cmake-4.1.1/bin/cmake",
47+
// "cmake.environment": {
48+
// "PATH": "${workspaceFolder}/buildtools/bin;${workspaceFolder}/buildtools/llvm-21.1.0/bin;${env:PATH}"
49+
// },
50+
// "cmake.additionalCompilerSearchDirs": [
51+
// "${workspaceFolder:cesium-src}/buildtools/bin",
52+
// "${workspaceFolder:cesium-src}/buildtools/llvm-21.1.0/bin",
53+
// ],
54+
// "cmake.cmakePath": "${workspaceFolder}/buildtools/bin/cmake-4.1.1/bin/cmake",
5155
"clangd.path": "${workspaceFolder}/buildtools/llvm-21.1.0/bin/clangd.exe",
52-
// "cmake.configureOnOpen": false,
56+
"cmake.configureOnOpen": false,
57+
"cmake.configureOnEdit": false,
58+
"terminal.integrated.env.windows": {
59+
"PATH": "${workspaceFolder}/buildtools/bin/zig-0.15.1;${workspaceFolder}/buildtools/llvm-21.1.0/bin;${env:PATH}"
60+
},
5361
},
5462
"extensions": {
5563
// See http://go.microsoft.com/fwlink/?LinkId=827846
File renamed without changes.

0 commit comments

Comments
 (0)