2023-08-10 07:59:29 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, cmake
|
|
|
|
, llvmPackages
|
|
|
|
, libxml2
|
|
|
|
, zlib
|
|
|
|
, coreutils
|
|
|
|
, callPackage
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
args:
|
|
|
|
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
|
|
pname = "zig";
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ziglang";
|
|
|
|
repo = "zig";
|
|
|
|
rev = finalAttrs.version;
|
|
|
|
inherit (args) hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
llvmPackages.llvm.dev
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
libxml2
|
|
|
|
zlib
|
|
|
|
] ++ (with llvmPackages; [
|
|
|
|
libclang
|
|
|
|
lld
|
|
|
|
llvm
|
|
|
|
]);
|
|
|
|
|
2024-06-24 18:47:55 +00:00
|
|
|
# On Darwin, Zig calls std.zig.system.darwin.macos.detect during the build,
|
|
|
|
# which parses /System/Library/CoreServices/SystemVersion.plist and
|
|
|
|
# /System/Library/CoreServices/.SystemVersionPlatform.plist to determine the
|
|
|
|
# OS version. This causes the build to fail during stage 3 with
|
|
|
|
# OSVersionDetectionFail when the sandbox is enabled.
|
2024-09-26 11:04:55 +00:00
|
|
|
__impureHostDeps = lib.optionals stdenv.hostPlatform.isDarwin [
|
2024-06-24 18:47:55 +00:00
|
|
|
"/System/Library/CoreServices/.SystemVersionPlatform.plist"
|
|
|
|
"/System/Library/CoreServices/SystemVersion.plist"
|
|
|
|
];
|
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
env.ZIG_GLOBAL_CACHE_DIR = "$TMPDIR/zig-cache";
|
|
|
|
|
|
|
|
# Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't
|
|
|
|
# work in Nix's sandbox. Use env from our coreutils instead.
|
2024-04-21 15:54:59 +00:00
|
|
|
postPatch = if lib.versionAtLeast args.version "0.12" then ''
|
|
|
|
substituteInPlace lib/std/zig/system.zig \
|
|
|
|
--replace "/usr/bin/env" "${coreutils}/bin/env"
|
|
|
|
'' else ''
|
2023-08-10 07:59:29 +00:00
|
|
|
substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \
|
|
|
|
--replace "/usr/bin/env" "${coreutils}/bin/env"
|
|
|
|
'';
|
|
|
|
|
|
|
|
doInstallCheck = true;
|
|
|
|
installCheckPhase = ''
|
|
|
|
runHook preInstallCheck
|
|
|
|
|
|
|
|
$out/bin/zig test --cache-dir "$TMPDIR/zig-test-cache" -I $src/test $src/test/behavior.zig
|
|
|
|
|
|
|
|
runHook postInstallCheck
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
hook = callPackage ./hook.nix {
|
|
|
|
zig = finalAttrs.finalPackage;
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
cc = callPackage ./cc.nix {
|
|
|
|
zig = finalAttrs.finalPackage;
|
|
|
|
};
|
|
|
|
stdenv = callPackage ./stdenv.nix {
|
|
|
|
zig = finalAttrs.finalPackage;
|
|
|
|
};
|
2023-08-10 07:59:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software";
|
|
|
|
homepage = "https://ziglang.org/";
|
|
|
|
changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html";
|
|
|
|
license = lib.licenses.mit;
|
2023-08-22 20:05:09 +00:00
|
|
|
maintainers = with lib.maintainers; [ andrewrk ] ++ lib.teams.zig.members;
|
2024-01-13 08:15:51 +00:00
|
|
|
mainProgram = "zig";
|
2023-08-10 07:59:29 +00:00
|
|
|
platforms = lib.platforms.unix;
|
|
|
|
};
|
|
|
|
} // removeAttrs args [ "hash" ])
|