building zig tutorial
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.zig-cache/
|
||||||
19
build.zig
Normal file
19
build.zig
Normal 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);
|
||||||
|
}
|
||||||
@@ -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 ];
|
||||||
|
|||||||
12
src/main.zig
Normal file
12
src/main.zig
Normal 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});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user