From 6da12dd2b408d72be04c6c8c5fe39c05811490e4 Mon Sep 17 00:00:00 2001 From: Dan Vargas Date: Tue, 1 Feb 2022 13:18:40 -0700 Subject: [PATCH] add zig 0.9.0 --- runtimes/default.nix | 1 + runtimes/zig.nix | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 runtimes/zig.nix diff --git a/runtimes/default.nix b/runtimes/default.nix index bfc0e2a..0272a43 100644 --- a/runtimes/default.nix +++ b/runtimes/default.nix @@ -14,4 +14,5 @@ args: { "erlang" = import ./erlang.nix args; "gawk-awk" = import ./gawk-awk.nix args; "openjdk11_headless-java" = import ./openjdk11_headless-java.nix args; + "zig" = import ./zig.nix args; } diff --git a/runtimes/zig.nix b/runtimes/zig.nix new file mode 100644 index 0000000..97c90d9 --- /dev/null +++ b/runtimes/zig.nix @@ -0,0 +1,43 @@ +{pkgs, piston, ...}: +let + pkg = pkgs.zig; +in piston.mkRuntime { + language = "zig"; + version = pkg.version; + aliases = []; + + # Add .zig extension for compile script and optimize compiler for small programs + compile = '' + rename 's/$/\.zig/' "$@" + ${pkg}/bin/zig build-exe -O ReleaseSafe --color off --cache-dir . --global-cache-dir . --name out *.zig + ''; + + # Remove first arg filename and run binary with remaining args + run = '' + shift + ./out "$@" + ''; + + # These should output "OK" to STDOUT if everything looks good + # Run the following command to test the package: + # $ ./piston test zig + tests = [ + # Standard output test + (piston.mkTest { + files = { + "test.zig" = '' + const std = @import("std"); + + pub fn main() !void { + const stdout = std.io.getStdOut().writer(); + try stdout.print("OK\n", .{}); + } + ''; + }; + args = []; + stdin = ""; + packages = []; + main = "test.zig"; + }) + ]; +}