2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
callPackage,
|
|
|
|
cmake,
|
|
|
|
coreutils,
|
|
|
|
fetchFromGitHub,
|
|
|
|
libxml2,
|
|
|
|
llvmPackages,
|
|
|
|
stdenv,
|
|
|
|
testers,
|
|
|
|
zlib,
|
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
|
|
pname = "zig";
|
2024-06-20 14:57:18 +00:00
|
|
|
version = "0.12.1";
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "ziglang";
|
|
|
|
repo = "zig";
|
|
|
|
rev = finalAttrs.version;
|
2024-06-20 14:57:18 +00:00
|
|
|
hash = "sha256-C56jyVf16Co/XCloMLSRsbG9r/gBc8mzCdeEMHV2T2s=";
|
2024-06-05 15:53:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
(lib.getDev llvmPackages.llvm)
|
|
|
|
];
|
|
|
|
|
|
|
|
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.
|
|
|
|
__impureHostDeps = lib.optionals stdenv.isDarwin [
|
|
|
|
"/System/Library/CoreServices/.SystemVersionPlatform.plist"
|
|
|
|
"/System/Library/CoreServices/SystemVersion.plist"
|
|
|
|
];
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
"doc"
|
|
|
|
];
|
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
# file RPATH_CHANGE could not write new RPATH
|
|
|
|
(lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true)
|
|
|
|
# ensure determinism in the compiler build
|
|
|
|
(lib.cmakeFeature "ZIG_TARGET_MCPU" "baseline")
|
|
|
|
# always link against static build of LLVM
|
|
|
|
(lib.cmakeBool "ZIG_STATIC_LLVM" true)
|
|
|
|
];
|
|
|
|
|
|
|
|
env.ZIG_GLOBAL_CACHE_DIR = "$TMPDIR/zig-cache";
|
|
|
|
|
|
|
|
doInstallCheck = true;
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
# strictDeps breaks zig when clang is being used.
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/317055#issuecomment-2148438395
|
|
|
|
strictDeps = !stdenv.cc.isClang;
|
2024-06-05 15:53:02 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace lib/std/zig/system.zig \
|
|
|
|
--replace "/usr/bin/env" "${lib.getExe' coreutils "env"}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
postBuild = ''
|
|
|
|
stage3/bin/zig run ../tools/docgen.zig -- ../doc/langref.html.in langref.html --zig $PWD/stage3/bin/zig
|
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
install -Dm444 langref.html -t $doc/share/doc/zig-${finalAttrs.version}/html
|
|
|
|
'';
|
|
|
|
|
|
|
|
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; };
|
2024-06-05 15:53:02 +00:00
|
|
|
tests = {
|
|
|
|
version = testers.testVersion {
|
|
|
|
package = finalAttrs.finalPackage;
|
|
|
|
command = "zig version";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software";
|
|
|
|
changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html";
|
|
|
|
homepage = "https://ziglang.org/";
|
|
|
|
license = lib.licenses.mit;
|
|
|
|
mainProgram = "zig";
|
|
|
|
maintainers = with lib.maintainers; [ andrewrk ] ++ lib.teams.zig.members;
|
|
|
|
platforms = lib.platforms.unix;
|
|
|
|
};
|
|
|
|
})
|