piston/runtimes/zig.nix

44 lines
1.2 KiB
Nix
Raw Permalink Normal View History

2022-02-01 21:18:40 +01:00
{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/' "$@"
2022-02-01 21:18:40 +01:00
${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 = [
2022-02-04 03:55:08 +01:00
# Standard output test with generic file extension
2022-02-01 21:18:40 +01:00
(piston.mkTest {
files = {
2022-02-04 03:55:08 +01:00
"file0.code" = ''
2022-02-01 21:18:40 +01:00
const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("OK\n", .{});
}
'';
};
args = [];
stdin = "";
packages = [];
2022-02-04 03:55:08 +01:00
main = "file0.code";
2022-02-01 21:18:40 +01:00
})
];
}