summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseth <[email protected]>2024-09-20 22:22:24 -0400
committerGitHub <[email protected]>2024-09-20 22:22:24 -0400
commit44e4ec57de3b3e2fdfa6dfef91a3ca72b8cb2d94 (patch)
tree3876df05ecdfd650bee4b26e8153c6c1c2454985
parent6f9929cfb3f2a4bf12b383b3e6d7a9113ce5cf72 (diff)
feat: update to zig 0.13.0 (#24)
* chore: update flake.lock Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/9bb1e7571aadf31ddb4af77fc64b2d59580f9a39' (2024-09-05) → 'github:NixOS/nixpkgs/268bb5090a3c6ac5e1615b38542a868b52ef8088' (2024-09-19) • Updated input 'zig-overlay': 'github:mitchellh/zig-overlay/9e2cc0e99621be1b765dc95a8ec80740a685b660' (2024-09-06) → 'github:mitchellh/zig-overlay/2419eb9f968f451e2c342a69ec44112de5aa36b9' (2024-09-21) * style: use nixfmt * style: format with nixfmt * refactor: use flake-utils * fix: only use `zig` in dev shell Pulling in `zig.hook` sets variables like `ZIG_GLOBAL_CACHE_DIR` that don't work too nicely outside of a Nix build process -- as in, Zig can't access files and fails * feat: update to zig 0.13.0 * chore: remove library output This isn't needed for this example
-rw-r--r--.gitignore87
-rw-r--r--build.zig29
-rw-r--r--build.zig.zon4
-rw-r--r--deps.nix6
-rw-r--r--flake.lock41
-rw-r--r--flake.nix117
-rw-r--r--src/root.zig10
7 files changed, 155 insertions, 139 deletions
diff --git a/.gitignore b/.gitignore
index 4e91702..9b1c19e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,84 @@
-# zig
-zig-cache/
+### Zig
+.zig-cache/
zig-out/
-build/
-build-*/
-docgen_tmp/
-# direnv
-.direnv
-.envrc
-# nix
+### Nix
result
result-*
repl-result-*
+
+
+### https://raw.github.com/github/gitignore/8779ee73af62c669e7ca371aaab8399d87127693/Global/Linux.gitignore
+
+*~
+
+# temporary files which can be created if a process still has a handle open of a deleted file
+.fuse_hidden*
+
+# KDE directory preferences
+.directory
+
+# Linux trash folder which might appear on any partition or disk
+.Trash-*
+
+# .nfs files are created when an open file is removed but is still being accessed
+.nfs*
+
+
+### https://raw.github.com/github/gitignore/8779ee73af62c669e7ca371aaab8399d87127693/Global/macOS.gitignore
+
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdisk
+
+
+### https://raw.github.com/github/gitignore/8779ee73af62c669e7ca371aaab8399d87127693/Global/Windows.gitignore
+
+# Windows thumbnail cache files
+Thumbs.db
+Thumbs.db:encryptable
+ehthumbs.db
+ehthumbs_vista.db
+
+# Dump file
+*.stackdump
+
+# Folder config file
+[Dd]esktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
diff --git a/build.zig b/build.zig
index 4316aaa..78147d3 100644
--- a/build.zig
+++ b/build.zig
@@ -15,23 +15,9 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
- const lib = b.addStaticLibrary(.{
- .name = "ziggy-with-it",
- // In this case the main source file is merely a path, however, in more
- // complicated build scripts, this could be a generated file.
- .root_source_file = .{ .path = "src/root.zig" },
- .target = target,
- .optimize = optimize,
- });
-
- // This declares intent for the library to be installed into the standard
- // location when the user invokes the "install" step (the default step when
- // running `zig build`).
- b.installArtifact(lib);
-
const exe = b.addExecutable(.{
.name = "ziggy-with-it",
- .root_source_file = .{ .path = "src/main.zig" },
+ .root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
@@ -64,18 +50,8 @@ pub fn build(b: *std.Build) void {
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
- // Creates a step for unit testing. This only builds the test executable
- // but does not run it.
- const lib_unit_tests = b.addTest(.{
- .root_source_file = .{ .path = "src/root.zig" },
- .target = target,
- .optimize = optimize,
- });
-
- const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
-
const exe_unit_tests = b.addTest(.{
- .root_source_file = .{ .path = "src/main.zig" },
+ .root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
@@ -86,7 +62,6 @@ pub fn build(b: *std.Build) void {
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
- test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
const dep = b.dependency("known-folders", .{});
diff --git a/build.zig.zon b/build.zig.zon
index 19b2806..ffe8a80 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -16,8 +16,8 @@
// internet connectivity.
.dependencies = .{
.@"known-folders" = .{
- .url = "https://github.com/ziglibs/known-folders/archive/bf79988adcfce166f848e4b11e718c1966365329.tar.gz",
- .hash = "12201314cffeb40c5e4e3da166217d2c74628c74486414aaf97422bcd2279915b9fd",
+ .url = "https://github.com/ziglibs/known-folders/archive/1cceeb70e77dec941a4178160ff6c8d05a74de6f.tar.gz",
+ .hash = "12205f5e7505c96573f6fc5144592ec38942fb0a326d692f9cddc0c7dd38f9028f29",
},
},
.paths = .{
diff --git a/deps.nix b/deps.nix
index d205853..432fce1 100644
--- a/deps.nix
+++ b/deps.nix
@@ -4,10 +4,10 @@
linkFarm "zig-packages" [
{
- name = "12201314cffeb40c5e4e3da166217d2c74628c74486414aaf97422bcd2279915b9fd";
+ name = "12205f5e7505c96573f6fc5144592ec38942fb0a326d692f9cddc0c7dd38f9028f29";
path = fetchzip {
- url = "https://github.com/ziglibs/known-folders/archive/bf79988adcfce166f848e4b11e718c1966365329.tar.gz";
- hash = "sha256-Q7eMdyScqj8qEiAHg1BnGRTsWSQOKWWTc6hUYHNlgGg=";
+ url = "https://github.com/ziglibs/known-folders/archive/1cceeb70e77dec941a4178160ff6c8d05a74de6f.tar.gz";
+ hash = "sha256-jVqUWsSYm84/8XYTHOdWUuz+RyaMO6BvEtOa9lRGJc8=";
};
}
]
diff --git a/flake.lock b/flake.lock
index 74f4c0a..25a42a7 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,31 +1,15 @@
{
"nodes": {
- "flake-compat": {
- "flake": false,
- "locked": {
- "lastModified": 1696426674,
- "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
- "owner": "edolstra",
- "repo": "flake-compat",
- "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
- "type": "github"
- },
- "original": {
- "owner": "edolstra",
- "repo": "flake-compat",
- "type": "github"
- }
- },
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
- "lastModified": 1705309234,
- "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
+ "lastModified": 1726560853,
+ "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
- "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
+ "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
@@ -36,11 +20,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1725534445,
- "narHash": "sha256-Yd0FK9SkWy+ZPuNqUgmVPXokxDgMJoGuNpMEtkfcf84=",
+ "lastModified": 1726745986,
+ "narHash": "sha256-xB35C2fpz7iyNcj9sn0a+wM2C4CQ6DGTn5VUHogstYs=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "9bb1e7571aadf31ddb4af77fc64b2d59580f9a39",
+ "rev": "268bb5090a3c6ac5e1615b38542a868b52ef8088",
"type": "github"
},
"original": {
@@ -52,6 +36,7 @@
},
"root": {
"inputs": {
+ "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"zig-overlay": "zig-overlay"
}
@@ -73,18 +58,20 @@
},
"zig-overlay": {
"inputs": {
- "flake-compat": "flake-compat",
- "flake-utils": "flake-utils",
+ "flake-compat": [],
+ "flake-utils": [
+ "flake-utils"
+ ],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
- "lastModified": 1725582447,
- "narHash": "sha256-h/CNQeQNw6dy5Vg5Nq23GqWpGWmEZIskTHBcdzgQlig=",
+ "lastModified": 1726878449,
+ "narHash": "sha256-gchxeelL+IdgL/LoEsg3FnO4Dv5z+lmRVHqIE3tq6NA=",
"owner": "mitchellh",
"repo": "zig-overlay",
- "rev": "9e2cc0e99621be1b765dc95a8ec80740a685b660",
+ "rev": "2419eb9f968f451e2c342a69ec44112de5aa36b9",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index 0733e33..e86a61d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,76 +3,71 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ flake-utils.url = "github:numtide/flake-utils";
+
zig-overlay = {
url = "github:mitchellh/zig-overlay";
- inputs.nixpkgs.follows = "nixpkgs";
+ inputs = {
+ nixpkgs.follows = "nixpkgs";
+ flake-utils.follows = "flake-utils";
+ # We don't use this
+ flake-compat.follows = "";
+ };
};
};
- outputs = {
- self,
- nixpkgs,
- zig-overlay,
- ...
- }: let
- systems = [
- "x86_64-linux"
- "aarch64-linux"
- "x86_64-darwin"
- "aarch64-darwin"
- ];
+ outputs =
+ {
+ self,
+ nixpkgs,
+ flake-utils,
+ zig-overlay,
+ }:
+ let
+ # https://github.com/mitchellh/zig-overlay?tab=readme-ov-file#usage
+ zigVersion = "0.13.0";
+ in
+ flake-utils.lib.eachDefaultSystem (
+ system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
- forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
+ zig = zig-overlay.packages.${system}.${zigVersion}.overrideAttrs {
+ # FIXME: `zig.hook` requires `zig` to have it's `meta` attribute
+ # zig-overlay doesn't provide this...yay
+ inherit (pkgs.zig) meta;
+ };
+ in
+ rec {
+ devShells.default = pkgs.mkShellNoCC {
+ packages = [ zig ];
+ };
- # https://github.com/mitchellh/zig-overlay?tab=readme-ov-file#usage
- zigVersion = "master-2024-05-08";
- zigFor = system: zig-overlay.packages.${system}.${zigVersion};
- in {
- devShells = forAllSystems ({
- pkgs,
- system,
- ...
- }: {
- default = pkgs.mkShellNoCC {
- inputsFrom = [self.packages.${system}.ziggy-with-it];
- };
- });
+ formatter = pkgs.nixfmt-rfc-style;
- packages = forAllSystems ({
- lib,
- pkgs,
- system,
- ...
- }: rec {
- default = ziggy-with-it;
- ziggy-with-it = pkgs.stdenvNoCC.mkDerivation {
- pname = "ziggy-with-it";
- version = self.shortRev or self.dirtyShortRev or "waaaa";
+ packages = {
+ default = packages.ziggy-with-it;
- src = with lib.fileset;
- toSource {
- root = ./.;
- fileset = unions [
- (gitTracked ./src)
- ./build.zig
- ./build.zig.zon
- ];
- };
+ # NOTE: We use `stdenvNoCC` here as `zig` is all we need
+ ziggy-with-it = pkgs.stdenvNoCC.mkDerivation {
+ pname = "ziggy-with-it";
+ version = self.shortRev or self.dirtyShortRev or "waaaa";
- # `deps.nix` is generated with by running `zon2nix`
- # https://github.com/nix-community/zon2nix
- postPatch = ''
- ln -s ${pkgs.callPackage ./deps.nix {}} $ZIG_GLOBAL_CACHE_DIR/p
- '';
+ src = self;
- nativeBuildInputs = [
- (pkgs.zig.hook.override {
- # FIXME: `zig.hook` requires `zig` to have it's `meta` attribute
- # zig-overlay requires this `meta` attribute..yay
- zig = zigFor system // {inherit (pkgs.zig) meta;};
- })
- ];
- };
- });
- };
+ # `deps.nix` is generated with by running `zon2nix`
+ # https://github.com/nix-community/zon2nix
+ postPatch = ''
+ ln -s ${pkgs.callPackage ./deps.nix { }} $ZIG_GLOBAL_CACHE_DIR/p
+ '';
+
+ nativeBuildInputs = [
+ # We can use nixpkgs' `zig.hook`, but with our own `zig`
+ (pkgs.zig.hook.override { inherit zig; })
+ ];
+ };
+ };
+ }
+ );
}
diff --git a/src/root.zig b/src/root.zig
deleted file mode 100644
index ecfeade..0000000
--- a/src/root.zig
+++ /dev/null
@@ -1,10 +0,0 @@
-const std = @import("std");
-const testing = std.testing;
-
-export fn add(a: i32, b: i32) i32 {
- return a + b;
-}
-
-test "basic add functionality" {
- try testing.expect(add(3, 7) == 10);
-}