building zig tutorial

This commit is contained in:
Filipriec
2026-03-07 09:46:09 +01:00
parent d01cb27daa
commit 54237c8ade
5 changed files with 33 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.zig-cache/

19
build.zig Normal file
View File

@@ -0,0 +1,19 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "zig-learn",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}

View File

@@ -12,7 +12,7 @@
system = "x86_64-linux"; system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
zig = zig-overlay.packages.${system}.master; zig = zig-overlay.packages.${system}.master;
zls = zls-overlay.packages.${system}.zls; zls = pkgs.zls;
in { in {
devShells.${system}.default = pkgs.mkShell { devShells.${system}.default = pkgs.mkShell {
buildInputs = [ zig zls ]; buildInputs = [ zig zls ];

BIN
main Executable file

Binary file not shown.

12
src/main.zig Normal file
View File

@@ -0,0 +1,12 @@
// src/main.zig
const std = @import("std");
var x: u32 = 42;
const name = "world";
var buf: [64]u8 = undefined;
pub fn main() void {
std.debug.print("{d} {s}\n", .{x, name});
x += 1;
std.debug.print("{d}\n", .{x});
}