build: migrate from Make to Zig build system + Just
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I7585121a5ec8e797adc43ba8e30d4ac86a6a6964
This commit is contained in:
parent
62c030527f
commit
7af642612b
7 changed files with 144 additions and 52 deletions
|
|
@ -5,6 +5,8 @@ charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
indent_size = 2
|
||||||
|
tab_width = 2
|
||||||
|
|
||||||
[*.c]
|
[*.c]
|
||||||
ident_style = space
|
ident_style = space
|
||||||
|
|
|
||||||
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -1,6 +1,12 @@
|
||||||
# ignore build artifacts
|
# Nix
|
||||||
result
|
/.direnv/
|
||||||
|
result*
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
build
|
build
|
||||||
obj
|
obj
|
||||||
roguelike
|
roguelike
|
||||||
|
|
||||||
|
# Zig
|
||||||
.zig-cache
|
.zig-cache
|
||||||
|
.zig-out
|
||||||
|
|
|
||||||
20
Justfile
Normal file
20
Justfile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Build the project
|
||||||
|
build:
|
||||||
|
zig build
|
||||||
|
|
||||||
|
# Build and run
|
||||||
|
dev:
|
||||||
|
zig build run
|
||||||
|
|
||||||
|
# Clean build artifacts
|
||||||
|
clean:
|
||||||
|
rm -rf zig-out .zig-cache
|
||||||
|
|
||||||
|
# Format all C source files
|
||||||
|
fmt:
|
||||||
|
clang-format -i src/*.c src/*.h
|
||||||
|
zig fmt **/*.zig
|
||||||
|
|
||||||
|
# Check formatting
|
||||||
|
fmt-check:
|
||||||
|
clang-format --dry-run --Werror src/*.c src/*.h
|
||||||
45
Makefile
45
Makefile
|
|
@ -1,45 +0,0 @@
|
||||||
# Makefile for Roguelike Game
|
|
||||||
# Requires raylib, pkg-config
|
|
||||||
|
|
||||||
CC := cc
|
|
||||||
CFLAGS := -Wall -Wextra -O2 -std=c99 -Isrc
|
|
||||||
LDFLAGS := -lraylib -lm -lpthread -ldl -lrt
|
|
||||||
|
|
||||||
TARGET := roguelike
|
|
||||||
SRCDIR := src
|
|
||||||
OBJDIR := obj
|
|
||||||
|
|
||||||
SOURCES := $(wildcard $(SRCDIR)/*.c)
|
|
||||||
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
|
|
||||||
|
|
||||||
.PHONY: all clean format format-check
|
|
||||||
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
$(TARGET): $(OBJECTS)
|
|
||||||
$(CC) $^ -o $@ $(LDFLAGS)
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c
|
|
||||||
@mkdir -p $(dir $@)
|
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(OBJDIR) $(TARGET)
|
|
||||||
|
|
||||||
# Alias for development
|
|
||||||
dev: all
|
|
||||||
./$(TARGET)
|
|
||||||
|
|
||||||
# Format all source files with clang-format
|
|
||||||
fmt:
|
|
||||||
@command -v clang-format >/dev/null 2>&1 || { echo "Error: clang-format is missing"; exit 1; }
|
|
||||||
@echo "Formatting source files..."
|
|
||||||
@clang-format -i $(SOURCES) $(wildcard $(SRCDIR)/*.h)
|
|
||||||
@echo "Done formatting."
|
|
||||||
|
|
||||||
# Check formatting without modifying files
|
|
||||||
fmt-check:
|
|
||||||
@command -v clang-format >/dev/null 2>&1 || { echo "Error: clang-format is missing"; exit 1; }
|
|
||||||
@echo "Checking formatting..."
|
|
||||||
@clang-format --dry-run --Werror \
|
|
||||||
$(SOURCES) $(wildcard $(SRCDIR)/*.h) && echo "All files properly formatted." || { echo "Formatting issues found. Run 'make fmt' to fix."; exit 1; }
|
|
||||||
73
build.zig
Normal file
73
build.zig
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.Build) void {
|
||||||
|
const target = b.standardTargetOptions(.{});
|
||||||
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
|
// Zig combat library
|
||||||
|
const combat_lib = b.addLibrary(.{
|
||||||
|
.name = "combat",
|
||||||
|
.root_module = b.createModule(.{
|
||||||
|
.root_source_file = b.path("libs/combat/combat.zig"),
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
.link_libc = true,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
combat_lib.addIncludePath(b.path("src"));
|
||||||
|
|
||||||
|
// C sources (everything except combat, which is now Zig)
|
||||||
|
const c_sources = [_][]const u8{
|
||||||
|
"src/audio.c",
|
||||||
|
"src/enemy.c",
|
||||||
|
"src/items.c",
|
||||||
|
"src/main.c",
|
||||||
|
"src/map.c",
|
||||||
|
"src/player.c",
|
||||||
|
"src/render.c",
|
||||||
|
"src/rng.c",
|
||||||
|
"src/settings.c",
|
||||||
|
"src/utils.c",
|
||||||
|
};
|
||||||
|
|
||||||
|
const c_flags = [_][]const u8{
|
||||||
|
"-std=c99",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-O2",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Main executable
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "roguelike",
|
||||||
|
.root_module = b.createModule(.{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
.link_libc = true,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
exe.addCSourceFiles(.{
|
||||||
|
.files = &c_sources,
|
||||||
|
.flags = &c_flags,
|
||||||
|
});
|
||||||
|
|
||||||
|
exe.addIncludePath(b.path("src"));
|
||||||
|
exe.linkLibrary(combat_lib);
|
||||||
|
exe.linkSystemLibrary("raylib");
|
||||||
|
exe.linkSystemLibrary("m");
|
||||||
|
exe.linkSystemLibrary("pthread");
|
||||||
|
exe.linkSystemLibrary("dl");
|
||||||
|
exe.linkSystemLibrary("rt");
|
||||||
|
|
||||||
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
// Run step
|
||||||
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
if (b.args) |args| {
|
||||||
|
run_cmd.addArgs(args);
|
||||||
|
}
|
||||||
|
const run_step = b.step("run", "Build and run the roguelike");
|
||||||
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
{stdenv}:
|
{
|
||||||
|
lib,
|
||||||
|
stdenv,
|
||||||
|
zig,
|
||||||
|
raylib,
|
||||||
|
pkg-config,
|
||||||
|
}:
|
||||||
stdenv.mkDerivation (finalAttrs: {
|
stdenv.mkDerivation (finalAttrs: {
|
||||||
pname = "sample-c-cpp";
|
pname = "rogged";
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
|
|
||||||
src = builtins.path {
|
src = builtins.path {
|
||||||
|
|
@ -8,5 +14,32 @@ stdenv.mkDerivation (finalAttrs: {
|
||||||
name = finalAttrs.pname;
|
name = finalAttrs.pname;
|
||||||
};
|
};
|
||||||
|
|
||||||
makeFlags = ["PREFIX=$(out)"];
|
nativeBuildInputs = [
|
||||||
|
zig
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [raylib];
|
||||||
|
|
||||||
|
dontConfigure = true;
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache"
|
||||||
|
zig build --release=fast
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
mkdir -p $out/bin
|
||||||
|
cp zig-out/bin/roguelike $out/bin/
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "A turn-based roguelike game";
|
||||||
|
license = lib.licenses.mit;
|
||||||
|
mainProgram = "roguelike";
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
mkShell,
|
mkShell,
|
||||||
clang-tools,
|
clang-tools,
|
||||||
raylib,
|
raylib,
|
||||||
gnumake,
|
|
||||||
pkg-config,
|
pkg-config,
|
||||||
|
just,
|
||||||
zig,
|
zig,
|
||||||
|
zig-zlint,
|
||||||
}:
|
}:
|
||||||
mkShell {
|
mkShell {
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
|
|
@ -14,7 +15,9 @@ mkShell {
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
pkg-config
|
pkg-config
|
||||||
clang-tools
|
clang-tools
|
||||||
gnumake
|
just
|
||||||
|
|
||||||
zig
|
zig
|
||||||
|
zig-zlint
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue