From 3fc45e16ab9bf685ea92436ee0ae0e55ef1623f9 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Mon, 29 Jul 2024 20:31:21 -0700 Subject: [PATCH 1/5] zig: commonify --- .../compilers/zig/0.10/default.nix | 111 -------------- pkgs/development/compilers/zig/0.10/hook.nix | 43 ------ .../compilers/zig/0.10/setup-hook.sh | 69 --------- .../compilers/zig/0.11/default.nix | 105 ------------- pkgs/development/compilers/zig/0.11/hook.nix | 43 ------ .../compilers/zig/0.11/setup-hook.sh | 69 --------- .../compilers/zig/0.12/default.nix | 117 -------------- pkgs/development/compilers/zig/0.12/hook.nix | 43 ------ .../compilers/zig/0.12/setup-hook.sh | 69 --------- .../compilers/zig/0.13/default.nix | 117 -------------- pkgs/development/compilers/zig/0.13/hook.nix | 29 ---- .../compilers/zig/0.13/setup-hook.sh | 69 --------- .../development/compilers/zig/0.9/default.nix | 113 -------------- pkgs/development/compilers/zig/0.9/hook.nix | 43 ------ .../compilers/zig/0.9/setup-hook.sh | 69 --------- pkgs/development/compilers/zig/default.nix | 48 ++++++ pkgs/development/compilers/zig/generic.nix | 143 ++++++++++++------ .../0.10-macho-fixes.patch} | 0 .../0.9-bump-macos-supported-version.patch} | 0 .../0.9-read-dynstr-at-rpath-offset.patch} | 0 pkgs/top-level/all-packages.nix | 35 ++--- 21 files changed, 162 insertions(+), 1173 deletions(-) delete mode 100644 pkgs/development/compilers/zig/0.10/default.nix delete mode 100644 pkgs/development/compilers/zig/0.10/hook.nix delete mode 100644 pkgs/development/compilers/zig/0.10/setup-hook.sh delete mode 100644 pkgs/development/compilers/zig/0.11/default.nix delete mode 100644 pkgs/development/compilers/zig/0.11/hook.nix delete mode 100644 pkgs/development/compilers/zig/0.11/setup-hook.sh delete mode 100644 pkgs/development/compilers/zig/0.12/default.nix delete mode 100644 pkgs/development/compilers/zig/0.12/hook.nix delete mode 100644 pkgs/development/compilers/zig/0.12/setup-hook.sh delete mode 100644 pkgs/development/compilers/zig/0.13/default.nix delete mode 100644 pkgs/development/compilers/zig/0.13/hook.nix delete mode 100644 pkgs/development/compilers/zig/0.13/setup-hook.sh delete mode 100644 pkgs/development/compilers/zig/0.9/default.nix delete mode 100644 pkgs/development/compilers/zig/0.9/hook.nix delete mode 100644 pkgs/development/compilers/zig/0.9/setup-hook.sh create mode 100644 pkgs/development/compilers/zig/default.nix rename pkgs/development/compilers/zig/{0.10/001-0.10-macho-fixes.patch => patches/0.10-macho-fixes.patch} (100%) rename pkgs/development/compilers/zig/{0.9/001-0.9-bump-macos-supported-version.patch => patches/0.9-bump-macos-supported-version.patch} (100%) rename pkgs/development/compilers/zig/{0.9/000-0.9-read-dynstr-at-rpath-offset.patch => patches/0.9-read-dynstr-at-rpath-offset.patch} (100%) diff --git a/pkgs/development/compilers/zig/0.10/default.nix b/pkgs/development/compilers/zig/0.10/default.nix deleted file mode 100644 index 5c01521f08fd..000000000000 --- a/pkgs/development/compilers/zig/0.10/default.nix +++ /dev/null @@ -1,111 +0,0 @@ -{ - lib, - callPackage, - cmake, - coreutils, - fetchFromGitHub, - libxml2, - llvmPackages, - stdenv, - testers, - zlib, -}: - -stdenv.mkDerivation (finalAttrs: { - pname = "zig"; - version = "0.10.1"; - - src = fetchFromGitHub { - owner = "ziglang"; - repo = "zig"; - rev = finalAttrs.version; - hash = "sha256-69QIkkKzApOGfrBdgtmxFMDytRkSh+0YiaJQPbXsBeo="; - }; - - patches = [ - # Backport alignment related panics from zig-master to 0.10. - # Upstream issue: https://github.com/ziglang/zig/issues/14559 - ./001-0.10-macho-fixes.patch - ]; - - nativeBuildInputs = [ - cmake - (lib.getDev llvmPackages.llvm) - ]; - - buildInputs = - [ - libxml2 - zlib - ] - ++ (with llvmPackages; [ - libclang - lld - llvm - ]); - - outputs = [ - "out" - "doc" - ]; - - cmakeFlags = [ - # file RPATH_CHANGE could not write new RPATH - (lib.cmakeBool "CMAKE_SKIP_BUILD_RPATH" true) - # always link against static build of LLVM - (lib.cmakeBool "ZIG_STATIC_LLVM" true) - # ensure determinism in the compiler build - (lib.cmakeFeature "ZIG_TARGET_MCPU" "baseline") - ]; - - env.ZIG_GLOBAL_CACHE_DIR = "$TMPDIR/zig-cache"; - - doInstallCheck = true; - - strictDeps = true; - - # 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/NativeTargetInfo.zig \ - --replace "/usr/bin/env" "${lib.getExe' coreutils "env"}" - ''; - - postBuild = '' - ./zig2 run ../doc/docgen.zig -- ./zig2 ../doc/langref.html.in langref.html - ''; - - postInstall = '' - install -Dm644 -t $doc/share/doc/zig-$version/html ./langref.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; }; - cc = callPackage ../cc.nix { zig = finalAttrs.finalPackage; }; - stdenv = callPackage ../stdenv.nix { zig = finalAttrs.finalPackage; }; - 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"; - homepage = "https://ziglang.org/"; - changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html"; - license = lib.licenses.mit; - mainProgram = "zig"; - maintainers = with lib.maintainers; [ andrewrk ] ++ lib.teams.zig.members; - platforms = lib.platforms.unix; - }; -}) diff --git a/pkgs/development/compilers/zig/0.10/hook.nix b/pkgs/development/compilers/zig/0.10/hook.nix deleted file mode 100644 index aec36a2c0a82..000000000000 --- a/pkgs/development/compilers/zig/0.10/hook.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ makeSetupHook, zig }: - -makeSetupHook { - name = "zig-hook"; - - propagatedBuildInputs = [ zig ]; - - substitutions = { - # This zig_default_flags below is meant to avoid CPU feature impurity in - # Nixpkgs. However, this flagset is "unstable": it is specifically meant to - # be controlled by the upstream development team - being up to that team - # exposing or not that flags to the outside (especially the package manager - # teams). - - # Because of this hurdle, @andrewrk from Zig Software Foundation proposed - # some solutions for this issue. Hopefully they will be implemented in - # future releases of Zig. When this happens, this flagset should be - # revisited accordingly. - - # Below are some useful links describing the discovery process of this 'bug' - # in Nixpkgs: - - # https://github.com/NixOS/nixpkgs/issues/169461 - # https://github.com/NixOS/nixpkgs/issues/185644 - # https://github.com/NixOS/nixpkgs/pull/197046 - # https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485 - # https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653 - - zig_default_flags = [ - "-Dcpu=baseline" - "-Drelease-safe=true" - ]; - }; - - passthru = { - inherit zig; - }; - - meta = { - description = "Setup hook for using the Zig compiler in Nixpkgs"; - inherit (zig.meta) maintainers platforms broken; - }; -} ./setup-hook.sh diff --git a/pkgs/development/compilers/zig/0.10/setup-hook.sh b/pkgs/development/compilers/zig/0.10/setup-hook.sh deleted file mode 100644 index 0053c5997da6..000000000000 --- a/pkgs/development/compilers/zig/0.10/setup-hook.sh +++ /dev/null @@ -1,69 +0,0 @@ -# shellcheck shell=bash - -# shellcheck disable=SC2034 -readonly zigDefaultFlagsArray=(@zig_default_flags@) - -function zigSetGlobalCacheDir { - ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) - export ZIG_GLOBAL_CACHE_DIR -} - -function zigBuildPhase { - runHook preBuild - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray - - echoCmd 'zig build flags' "${flagsArray[@]}" - zig build "${flagsArray[@]}" - - runHook postBuild -} - -function zigCheckPhase { - runHook preCheck - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigCheckFlags zigCheckFlagsArray - - echoCmd 'zig check flags' "${flagsArray[@]}" - zig build test "${flagsArray[@]}" - - runHook postCheck -} - -function zigInstallPhase { - runHook preInstall - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray \ - zigInstallFlags zigInstallFlagsArray - - if [ -z "${dontAddPrefix-}" ]; then - # Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/` - flagsArray+=("${prefixKey:---prefix}" "$prefix") - fi - - echoCmd 'zig install flags' "${flagsArray[@]}" - zig build install "${flagsArray[@]}" - - runHook postInstall -} - -# shellcheck disable=SC2154 -addEnvHooks "$targetOffset" zigSetGlobalCacheDir - -if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then - buildPhase=zigBuildPhase -fi - -if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then - checkPhase=zigCheckPhase -fi - -if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then - installPhase=zigInstallPhase -fi diff --git a/pkgs/development/compilers/zig/0.11/default.nix b/pkgs/development/compilers/zig/0.11/default.nix deleted file mode 100644 index 91e753dbf0fe..000000000000 --- a/pkgs/development/compilers/zig/0.11/default.nix +++ /dev/null @@ -1,105 +0,0 @@ -{ - lib, - callPackage, - cmake, - coreutils, - fetchFromGitHub, - libxml2, - llvmPackages, - stdenv, - testers, - zlib, -}: - -stdenv.mkDerivation (finalAttrs: { - pname = "zig"; - version = "0.11.0"; - - src = fetchFromGitHub { - owner = "ziglang"; - repo = "zig"; - rev = finalAttrs.version; - hash = "sha256-iuU1fzkbJxI+0N1PiLQM013Pd1bzrgqkbIyTxo5gB2I="; - }; - - nativeBuildInputs = [ - cmake - (lib.getDev llvmPackages.llvm) - ]; - - buildInputs = - [ - libxml2 - zlib - ] - ++ (with llvmPackages; [ - libclang - lld - llvm - ]); - - 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; - - strictDeps = true; - - # 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/NativeTargetInfo.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 -t $doc/share/doc/zig-$version/html langref.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; }; - cc = callPackage ../cc.nix { zig = finalAttrs.finalPackage; }; - stdenv = callPackage ../stdenv.nix { zig = finalAttrs.finalPackage; }; - 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"; - homepage = "https://ziglang.org/"; - changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html"; - license = lib.licenses.mit; - mainProgram = "zig"; - maintainers = with lib.maintainers; [ andrewrk ] ++ lib.teams.zig.members; - platforms = lib.platforms.unix; - }; -}) diff --git a/pkgs/development/compilers/zig/0.11/hook.nix b/pkgs/development/compilers/zig/0.11/hook.nix deleted file mode 100644 index 399b3889a226..000000000000 --- a/pkgs/development/compilers/zig/0.11/hook.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ makeSetupHook, zig }: - -makeSetupHook { - name = "zig-hook"; - - propagatedBuildInputs = [ zig ]; - - substitutions = { - # This zig_default_flags below is meant to avoid CPU feature impurity in - # Nixpkgs. However, this flagset is "unstable": it is specifically meant to - # be controlled by the upstream development team - being up to that team - # exposing or not that flags to the outside (especially the package manager - # teams). - - # Because of this hurdle, @andrewrk from Zig Software Foundation proposed - # some solutions for this issue. Hopefully they will be implemented in - # future releases of Zig. When this happens, this flagset should be - # revisited accordingly. - - # Below are some useful links describing the discovery process of this 'bug' - # in Nixpkgs: - - # https://github.com/NixOS/nixpkgs/issues/169461 - # https://github.com/NixOS/nixpkgs/issues/185644 - # https://github.com/NixOS/nixpkgs/pull/197046 - # https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485 - # https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653 - - zig_default_flags = [ - "-Dcpu=baseline" - "-Doptimize=ReleaseSafe" - ]; - }; - - passthru = { - inherit zig; - }; - - meta = { - description = "Setup hook for using the Zig compiler in Nixpkgs"; - inherit (zig.meta) maintainers platforms broken; - }; -} ./setup-hook.sh diff --git a/pkgs/development/compilers/zig/0.11/setup-hook.sh b/pkgs/development/compilers/zig/0.11/setup-hook.sh deleted file mode 100644 index 0053c5997da6..000000000000 --- a/pkgs/development/compilers/zig/0.11/setup-hook.sh +++ /dev/null @@ -1,69 +0,0 @@ -# shellcheck shell=bash - -# shellcheck disable=SC2034 -readonly zigDefaultFlagsArray=(@zig_default_flags@) - -function zigSetGlobalCacheDir { - ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) - export ZIG_GLOBAL_CACHE_DIR -} - -function zigBuildPhase { - runHook preBuild - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray - - echoCmd 'zig build flags' "${flagsArray[@]}" - zig build "${flagsArray[@]}" - - runHook postBuild -} - -function zigCheckPhase { - runHook preCheck - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigCheckFlags zigCheckFlagsArray - - echoCmd 'zig check flags' "${flagsArray[@]}" - zig build test "${flagsArray[@]}" - - runHook postCheck -} - -function zigInstallPhase { - runHook preInstall - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray \ - zigInstallFlags zigInstallFlagsArray - - if [ -z "${dontAddPrefix-}" ]; then - # Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/` - flagsArray+=("${prefixKey:---prefix}" "$prefix") - fi - - echoCmd 'zig install flags' "${flagsArray[@]}" - zig build install "${flagsArray[@]}" - - runHook postInstall -} - -# shellcheck disable=SC2154 -addEnvHooks "$targetOffset" zigSetGlobalCacheDir - -if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then - buildPhase=zigBuildPhase -fi - -if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then - checkPhase=zigCheckPhase -fi - -if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then - installPhase=zigInstallPhase -fi diff --git a/pkgs/development/compilers/zig/0.12/default.nix b/pkgs/development/compilers/zig/0.12/default.nix deleted file mode 100644 index f359140df234..000000000000 --- a/pkgs/development/compilers/zig/0.12/default.nix +++ /dev/null @@ -1,117 +0,0 @@ -{ - lib, - callPackage, - cmake, - coreutils, - fetchFromGitHub, - libxml2, - llvmPackages, - stdenv, - testers, - zlib, -}: - -stdenv.mkDerivation (finalAttrs: { - pname = "zig"; - version = "0.12.1"; - - src = fetchFromGitHub { - owner = "ziglang"; - repo = "zig"; - rev = finalAttrs.version; - hash = "sha256-C56jyVf16Co/XCloMLSRsbG9r/gBc8mzCdeEMHV2T2s="; - }; - - nativeBuildInputs = [ - cmake - (lib.getDev llvmPackages.llvm) - ]; - - buildInputs = - [ - libxml2 - zlib - ] - ++ (with llvmPackages; [ - libclang - lld - llvm - ]); - - # 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.hostPlatform.isDarwin [ - "/System/Library/CoreServices/.SystemVersionPlatform.plist" - "/System/Library/CoreServices/SystemVersion.plist" - ]; - - 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; - - # strictDeps breaks zig when clang is being used. - # https://github.com/NixOS/nixpkgs/issues/317055#issuecomment-2148438395 - strictDeps = !stdenv.cc.isClang; - - # 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; }; - cc = callPackage ../cc.nix { zig = finalAttrs.finalPackage; }; - stdenv = callPackage ../stdenv.nix { zig = finalAttrs.finalPackage; }; - 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; - }; -}) diff --git a/pkgs/development/compilers/zig/0.12/hook.nix b/pkgs/development/compilers/zig/0.12/hook.nix deleted file mode 100644 index 1f920af318be..000000000000 --- a/pkgs/development/compilers/zig/0.12/hook.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ makeSetupHook, zig }: - -makeSetupHook { - name = "zig-hook"; - - propagatedBuildInputs = [ zig ]; - - substitutions = { - # This zig_default_flags below is meant to avoid CPU feature impurity in - # Nixpkgs. However, this flagset is "unstable": it is specifically meant to - # be controlled by the upstream development team - being up to that team - # exposing or not that flags to the outside (especially the package manager - # teams). - - # Because of this hurdle, @andrewrk from Zig Software Foundation proposed - # some solutions for this issue. Hopefully they will be implemented in - # future releases of Zig. When this happens, this flagset should be - # revisited accordingly. - - # Below are some useful links describing the discovery process of this 'bug' - # in Nixpkgs: - - # https://github.com/NixOS/nixpkgs/issues/169461 - # https://github.com/NixOS/nixpkgs/issues/185644 - # https://github.com/NixOS/nixpkgs/pull/197046 - # https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485 - # https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653 - - zig_default_flags = [ - "-Dcpu=baseline" - "--release=safe" - ]; - }; - - passthru = { - inherit zig; - }; - - meta = { - description = "Setup hook for using the Zig compiler in Nixpkgs"; - inherit (zig.meta) maintainers platforms broken; - }; -} ./setup-hook.sh diff --git a/pkgs/development/compilers/zig/0.12/setup-hook.sh b/pkgs/development/compilers/zig/0.12/setup-hook.sh deleted file mode 100644 index 0053c5997da6..000000000000 --- a/pkgs/development/compilers/zig/0.12/setup-hook.sh +++ /dev/null @@ -1,69 +0,0 @@ -# shellcheck shell=bash - -# shellcheck disable=SC2034 -readonly zigDefaultFlagsArray=(@zig_default_flags@) - -function zigSetGlobalCacheDir { - ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) - export ZIG_GLOBAL_CACHE_DIR -} - -function zigBuildPhase { - runHook preBuild - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray - - echoCmd 'zig build flags' "${flagsArray[@]}" - zig build "${flagsArray[@]}" - - runHook postBuild -} - -function zigCheckPhase { - runHook preCheck - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigCheckFlags zigCheckFlagsArray - - echoCmd 'zig check flags' "${flagsArray[@]}" - zig build test "${flagsArray[@]}" - - runHook postCheck -} - -function zigInstallPhase { - runHook preInstall - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray \ - zigInstallFlags zigInstallFlagsArray - - if [ -z "${dontAddPrefix-}" ]; then - # Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/` - flagsArray+=("${prefixKey:---prefix}" "$prefix") - fi - - echoCmd 'zig install flags' "${flagsArray[@]}" - zig build install "${flagsArray[@]}" - - runHook postInstall -} - -# shellcheck disable=SC2154 -addEnvHooks "$targetOffset" zigSetGlobalCacheDir - -if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then - buildPhase=zigBuildPhase -fi - -if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then - checkPhase=zigCheckPhase -fi - -if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then - installPhase=zigInstallPhase -fi diff --git a/pkgs/development/compilers/zig/0.13/default.nix b/pkgs/development/compilers/zig/0.13/default.nix deleted file mode 100644 index 8ec68f20260f..000000000000 --- a/pkgs/development/compilers/zig/0.13/default.nix +++ /dev/null @@ -1,117 +0,0 @@ -{ - lib, - callPackage, - cmake, - coreutils, - fetchFromGitHub, - libxml2, - llvmPackages, - stdenv, - testers, - zlib, -}: - -stdenv.mkDerivation (finalAttrs: { - pname = "zig"; - version = "0.13.0"; - - src = fetchFromGitHub { - owner = "ziglang"; - repo = "zig"; - rev = finalAttrs.version; - hash = "sha256-5qSiTq+UWGOwjDVZMIrAt2cDKHkyNPBSAEjpRQUByFM="; - }; - - nativeBuildInputs = [ - cmake - (lib.getDev llvmPackages.llvm) - ]; - - buildInputs = - [ - libxml2 - zlib - ] - ++ (with llvmPackages; [ - libclang - lld - llvm - ]); - - # 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.hostPlatform.isDarwin [ - "/System/Library/CoreServices/.SystemVersionPlatform.plist" - "/System/Library/CoreServices/SystemVersion.plist" - ]; - - 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; - - # strictDeps breaks zig when clang is being used. - # https://github.com/NixOS/nixpkgs/issues/317055#issuecomment-2148438395 - strictDeps = !stdenv.cc.isClang; - - # 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 build langref - ''; - - postInstall = '' - install -Dm444 ../zig-out/doc/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; }; - cc = callPackage ../cc.nix { zig = finalAttrs.finalPackage; }; - stdenv = callPackage ../stdenv.nix { zig = finalAttrs.finalPackage; }; - 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; - }; -}) diff --git a/pkgs/development/compilers/zig/0.13/hook.nix b/pkgs/development/compilers/zig/0.13/hook.nix deleted file mode 100644 index 1618702ecaec..000000000000 --- a/pkgs/development/compilers/zig/0.13/hook.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ makeSetupHook, zig }: - -makeSetupHook { - name = "zig-hook"; - - propagatedBuildInputs = [ zig ]; - - substitutions = { - # This zig_default_flags below is meant to avoid CPU feature impurity in - # Nixpkgs. However, this flagset is "unstable": it is specifically meant to - # be controlled by the upstream development team - being up to that team - # exposing or not that flags to the outside (especially the package manager - # teams). - zig_default_flags = [ - "-Dcpu=baseline" - "--release=safe" - "--color off" # Turn off progress output - ]; - }; - - passthru = { - inherit zig; - }; - - meta = { - description = "A setup hook for using the Zig compiler in Nixpkgs"; - inherit (zig.meta) maintainers platforms broken; - }; -} ./setup-hook.sh diff --git a/pkgs/development/compilers/zig/0.13/setup-hook.sh b/pkgs/development/compilers/zig/0.13/setup-hook.sh deleted file mode 100644 index 0053c5997da6..000000000000 --- a/pkgs/development/compilers/zig/0.13/setup-hook.sh +++ /dev/null @@ -1,69 +0,0 @@ -# shellcheck shell=bash - -# shellcheck disable=SC2034 -readonly zigDefaultFlagsArray=(@zig_default_flags@) - -function zigSetGlobalCacheDir { - ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) - export ZIG_GLOBAL_CACHE_DIR -} - -function zigBuildPhase { - runHook preBuild - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray - - echoCmd 'zig build flags' "${flagsArray[@]}" - zig build "${flagsArray[@]}" - - runHook postBuild -} - -function zigCheckPhase { - runHook preCheck - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigCheckFlags zigCheckFlagsArray - - echoCmd 'zig check flags' "${flagsArray[@]}" - zig build test "${flagsArray[@]}" - - runHook postCheck -} - -function zigInstallPhase { - runHook preInstall - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray \ - zigInstallFlags zigInstallFlagsArray - - if [ -z "${dontAddPrefix-}" ]; then - # Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/` - flagsArray+=("${prefixKey:---prefix}" "$prefix") - fi - - echoCmd 'zig install flags' "${flagsArray[@]}" - zig build install "${flagsArray[@]}" - - runHook postInstall -} - -# shellcheck disable=SC2154 -addEnvHooks "$targetOffset" zigSetGlobalCacheDir - -if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then - buildPhase=zigBuildPhase -fi - -if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then - checkPhase=zigCheckPhase -fi - -if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then - installPhase=zigInstallPhase -fi diff --git a/pkgs/development/compilers/zig/0.9/default.nix b/pkgs/development/compilers/zig/0.9/default.nix deleted file mode 100644 index 72e05c879a59..000000000000 --- a/pkgs/development/compilers/zig/0.9/default.nix +++ /dev/null @@ -1,113 +0,0 @@ -{ - lib, - callPackage, - cmake, - coreutils, - fetchFromGitHub, - libxml2, - llvmPackages, - stdenv, - testers, - zlib, -}: - -stdenv.mkDerivation (finalAttrs: { - pname = "zig"; - version = "0.9.1"; - - src = fetchFromGitHub { - owner = "ziglang"; - repo = "zig"; - rev = finalAttrs.version; - hash = "sha256-x2c4c9RSrNWGqEngio4ArW7dJjW0gg+8nqBwPcR721k="; - }; - - patches = [ - # Fix index out of bounds reading RPATH (cherry-picked from 0.10-dev) - ./000-0.9-read-dynstr-at-rpath-offset.patch - # Fix build on macOS 13 (cherry-picked from 0.10-dev) - ./001-0.9-bump-macos-supported-version.patch - ]; - - nativeBuildInputs = [ - cmake - (lib.getDev llvmPackages.llvm) - ]; - - buildInputs = - [ - libxml2 - zlib - ] - ++ (with llvmPackages; [ - libclang - lld - llvm - ]); - - 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") - ]; - - env.ZIG_GLOBAL_CACHE_DIR = "$TMPDIR/zig-cache"; - - doInstallCheck = true; - - strictDeps = true; - - prePatch = - let - zig_0_10_0 = fetchFromGitHub { - owner = "ziglang"; - repo = "zig"; - rev = "0.10.0"; - hash = "sha256-DNs937N7PLQimuM2anya4npYXcj6cyH+dRS7AiOX7tw="; - }; - in - '' - cp -R ${zig_0_10_0}/lib/libc/include/any-macos.13-any lib/libc/include/any-macos.13-any - cp -R ${zig_0_10_0}/lib/libc/include/aarch64-macos.13-none lib/libc/include/aarch64-macos.13-gnu - cp -R ${zig_0_10_0}/lib/libc/include/x86_64-macos.13-none lib/libc/include/x86_64-macos.13-gnu - cp ${zig_0_10_0}/lib/libc/darwin/libSystem.13.tbd lib/libc/darwin/ - ''; - - # 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/NativeTargetInfo.zig \ - --replace "/usr/bin/env" "${lib.getExe' coreutils "env"}" - ''; - - 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; }; - cc = callPackage ../cc.nix { zig = finalAttrs.finalPackage; }; - stdenv = callPackage ../stdenv.nix { zig = finalAttrs.finalPackage; }; - 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"; - homepage = "https://ziglang.org/"; - changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html"; - license = lib.licenses.mit; - mainProgram = "zig"; - maintainers = with lib.maintainers; [ andrewrk ] ++ lib.teams.zig.members; - platforms = lib.platforms.unix; - }; -}) diff --git a/pkgs/development/compilers/zig/0.9/hook.nix b/pkgs/development/compilers/zig/0.9/hook.nix deleted file mode 100644 index aec36a2c0a82..000000000000 --- a/pkgs/development/compilers/zig/0.9/hook.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ makeSetupHook, zig }: - -makeSetupHook { - name = "zig-hook"; - - propagatedBuildInputs = [ zig ]; - - substitutions = { - # This zig_default_flags below is meant to avoid CPU feature impurity in - # Nixpkgs. However, this flagset is "unstable": it is specifically meant to - # be controlled by the upstream development team - being up to that team - # exposing or not that flags to the outside (especially the package manager - # teams). - - # Because of this hurdle, @andrewrk from Zig Software Foundation proposed - # some solutions for this issue. Hopefully they will be implemented in - # future releases of Zig. When this happens, this flagset should be - # revisited accordingly. - - # Below are some useful links describing the discovery process of this 'bug' - # in Nixpkgs: - - # https://github.com/NixOS/nixpkgs/issues/169461 - # https://github.com/NixOS/nixpkgs/issues/185644 - # https://github.com/NixOS/nixpkgs/pull/197046 - # https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485 - # https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653 - - zig_default_flags = [ - "-Dcpu=baseline" - "-Drelease-safe=true" - ]; - }; - - passthru = { - inherit zig; - }; - - meta = { - description = "Setup hook for using the Zig compiler in Nixpkgs"; - inherit (zig.meta) maintainers platforms broken; - }; -} ./setup-hook.sh diff --git a/pkgs/development/compilers/zig/0.9/setup-hook.sh b/pkgs/development/compilers/zig/0.9/setup-hook.sh deleted file mode 100644 index 0053c5997da6..000000000000 --- a/pkgs/development/compilers/zig/0.9/setup-hook.sh +++ /dev/null @@ -1,69 +0,0 @@ -# shellcheck shell=bash - -# shellcheck disable=SC2034 -readonly zigDefaultFlagsArray=(@zig_default_flags@) - -function zigSetGlobalCacheDir { - ZIG_GLOBAL_CACHE_DIR=$(mktemp -d) - export ZIG_GLOBAL_CACHE_DIR -} - -function zigBuildPhase { - runHook preBuild - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray - - echoCmd 'zig build flags' "${flagsArray[@]}" - zig build "${flagsArray[@]}" - - runHook postBuild -} - -function zigCheckPhase { - runHook preCheck - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigCheckFlags zigCheckFlagsArray - - echoCmd 'zig check flags' "${flagsArray[@]}" - zig build test "${flagsArray[@]}" - - runHook postCheck -} - -function zigInstallPhase { - runHook preInstall - - local flagsArray=() - concatTo flagsArray zigDefaultFlagsArray \ - zigBuildFlags zigBuildFlagsArray \ - zigInstallFlags zigInstallFlagsArray - - if [ -z "${dontAddPrefix-}" ]; then - # Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/` - flagsArray+=("${prefixKey:---prefix}" "$prefix") - fi - - echoCmd 'zig install flags' "${flagsArray[@]}" - zig build install "${flagsArray[@]}" - - runHook postInstall -} - -# shellcheck disable=SC2154 -addEnvHooks "$targetOffset" zigSetGlobalCacheDir - -if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then - buildPhase=zigBuildPhase -fi - -if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then - checkPhase=zigCheckPhase -fi - -if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then - installPhase=zigInstallPhase -fi diff --git a/pkgs/development/compilers/zig/default.nix b/pkgs/development/compilers/zig/default.nix new file mode 100644 index 000000000000..7387b16820fe --- /dev/null +++ b/pkgs/development/compilers/zig/default.nix @@ -0,0 +1,48 @@ +{ + lib, + callPackage, + llvmPackages_13, + llvmPackages_15, + llvmPackages_16, + llvmPackages_17, + llvmPackages_18, + zigVersions ? { }, +}: +let + versions = { + "0.9.1" = { + llvmPackages = llvmPackages_13; + hash = "sha256-x2c4c9RSrNWGqEngio4ArW7dJjW0gg+8nqBwPcR721k="; + }; + "0.10.1" = { + llvmPackages = llvmPackages_15; + hash = "sha256-69QIkkKzApOGfrBdgtmxFMDytRkSh+0YiaJQPbXsBeo="; + }; + "0.11.0" = { + llvmPackages = llvmPackages_16; + hash = "sha256-iuU1fzkbJxI+0N1PiLQM013Pd1bzrgqkbIyTxo5gB2I="; + }; + "0.12.1" = { + llvmPackages = llvmPackages_17; + hash = "sha256-C56jyVf16Co/XCloMLSRsbG9r/gBc8mzCdeEMHV2T2s="; + }; + "0.13.0" = { + llvmPackages = llvmPackages_18; + hash = "sha256-5qSiTq+UWGOwjDVZMIrAt2cDKHkyNPBSAEjpRQUByFM="; + }; + } // zigVersions; + + mkPackage = + { + version, + hash, + llvmPackages, + }@args: + callPackage ./generic.nix args; + + zigPackages = lib.mapAttrs' ( + version: args: + lib.nameValuePair (lib.versions.majorMinor version) (mkPackage (args // { inherit version; })) + ) versions; +in +zigPackages diff --git a/pkgs/development/compilers/zig/generic.nix b/pkgs/development/compilers/zig/generic.nix index 3da36c083bd3..a952880fff3f 100644 --- a/pkgs/development/compilers/zig/generic.nix +++ b/pkgs/development/compilers/zig/generic.nix @@ -1,40 +1,75 @@ -{ lib -, stdenv -, fetchFromGitHub -, cmake -, llvmPackages -, libxml2 -, zlib -, coreutils -, callPackage -, ... -}: - -args: +{ + lib, + stdenv, + fetchFromGitHub, + cmake, + llvmPackages, + libxml2, + zlib, + coreutils, + callPackage, + version, + hash, + patches ? [ ], +}@args: stdenv.mkDerivation (finalAttrs: { pname = "zig"; + inherit version; src = fetchFromGitHub { owner = "ziglang"; repo = "zig"; rev = finalAttrs.version; - inherit (args) hash; + inherit hash; }; + patches = + args.patches or [ ] + ++ lib.optionals (lib.versions.majorMinor finalAttrs.version == "0.9") [ + # Fix index out of bounds reading RPATH (cherry-picked from 0.10-dev) + ./patches/0.9-read-dynstr-at-rpath-offset.patch + # Fix build on macOS 13 (cherry-picked from 0.10-dev) + ./patches/0.9-bump-macos-supported-version.patch + ] + ++ + lib.optional (lib.versions.majorMinor finalAttrs.version == "0.10") + # Backport alignment related panics from zig-master to 0.10. + # Upstream issue: https://github.com/ziglang/zig/issues/14559 + ./patches/0.10-macho-fixes.patch; + nativeBuildInputs = [ cmake - llvmPackages.llvm.dev + (lib.getDev llvmPackages.llvm.dev) ]; - buildInputs = [ - libxml2 - zlib - ] ++ (with llvmPackages; [ - libclang - lld - llvm - ]); + buildInputs = + [ + libxml2 + zlib + ] + ++ (with llvmPackages; [ + libclang + lld + llvm + ]); + + 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) + ]; + + outputs = [ + "out" + ] ++ lib.optional (lib.versionAtLeast finalAttrs.version "0.10") "doc"; + + # strictDeps breaks zig when clang is being used. + # https://github.com/NixOS/nixpkgs/issues/317055#issuecomment-2148438395 + strictDeps = !stdenv.cc.isClang; # On Darwin, Zig calls std.zig.system.darwin.macos.detect during the build, # which parses /System/Library/CoreServices/SystemVersion.plist and @@ -52,35 +87,55 @@ stdenv.mkDerivation (finalAttrs: { # 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 = if lib.versionAtLeast args.version "0.12" then '' - substituteInPlace lib/std/zig/system.zig \ - --replace "/usr/bin/env" "${coreutils}/bin/env" - '' else '' - substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ - --replace-fail "/usr/bin/env" "${coreutils}/bin/env" - ''; + postPatch = + if lib.versionAtLeast finalAttrs.version "0.12" then + '' + substituteInPlace lib/std/zig/system.zig \ + --replace-fail "/usr/bin/env" "${coreutils}/bin/env" + '' + else + '' + substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ + --replace-fail "/usr/bin/env" "${coreutils}/bin/env" + ''; + + postBuild = + if lib.versionAtLeast finalAttrs.version "0.13" then + '' + stage3/bin/zig build langref + '' + else if lib.versionAtLeast finalAttrs.version "0.11" then + '' + stage3/bin/zig run ../tools/docgen.zig -- ../doc/langref.html.in langref.html --zig $PWD/stage3/bin/zig + '' + else if lib.versionAtLeast finalAttrs.version "0.10" then + '' + ./zig2 run ../doc/docgen.zig -- ./zig2 ../doc/langref.html.in langref.html + '' + else + null; + + postInstall = + if lib.versionAtLeast finalAttrs.version "0.13" then + '' + install -Dm444 ../zig-out/doc/langref.html -t $doc/share/doc/zig-${finalAttrs.version}/html + '' + else if lib.versionAtLeast finalAttrs.version "0.10" then + '' + install -Dm444 langref.html -t $doc/share/doc/zig-${finalAttrs.version}/html + '' + else + null; doInstallCheck = true; installCheckPhase = '' runHook preInstallCheck - $out/bin/zig test -I $src/test $src/test/behavior.zig + $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; - }; - cc = callPackage ./cc.nix { - zig = finalAttrs.finalPackage; - }; - stdenv = callPackage ./stdenv.nix { - zig = finalAttrs.finalPackage; - }; - }; - meta = { description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software"; homepage = "https://ziglang.org/"; @@ -90,4 +145,4 @@ stdenv.mkDerivation (finalAttrs: { mainProgram = "zig"; platforms = lib.platforms.unix; }; -} // removeAttrs args [ "hash" ]) +}) diff --git a/pkgs/development/compilers/zig/0.10/001-0.10-macho-fixes.patch b/pkgs/development/compilers/zig/patches/0.10-macho-fixes.patch similarity index 100% rename from pkgs/development/compilers/zig/0.10/001-0.10-macho-fixes.patch rename to pkgs/development/compilers/zig/patches/0.10-macho-fixes.patch diff --git a/pkgs/development/compilers/zig/0.9/001-0.9-bump-macos-supported-version.patch b/pkgs/development/compilers/zig/patches/0.9-bump-macos-supported-version.patch similarity index 100% rename from pkgs/development/compilers/zig/0.9/001-0.9-bump-macos-supported-version.patch rename to pkgs/development/compilers/zig/patches/0.9-bump-macos-supported-version.patch diff --git a/pkgs/development/compilers/zig/0.9/000-0.9-read-dynstr-at-rpath-offset.patch b/pkgs/development/compilers/zig/patches/0.9-read-dynstr-at-rpath-offset.patch similarity index 100% rename from pkgs/development/compilers/zig/0.9/000-0.9-read-dynstr-at-rpath-offset.patch rename to pkgs/development/compilers/zig/patches/0.9-read-dynstr-at-rpath-offset.patch diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e4c00c5bcb56..83310602882b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10875,26 +10875,21 @@ with pkgs; stdenv; }; - # requires a newer Apple SDK - zig_0_9 = darwin.apple_sdk_11_0.callPackage ../development/compilers/zig/0.9 { - llvmPackages = llvmPackages_13; - }; - # requires a newer Apple SDK - zig_0_10 = darwin.apple_sdk_11_0.callPackage ../development/compilers/zig/0.10 { - llvmPackages = llvmPackages_15; - }; - # requires a newer Apple SDK - zig_0_11 = darwin.apple_sdk_11_0.callPackage ../development/compilers/zig/0.11 { - llvmPackages = llvmPackages_16; - }; - # requires a newer Apple SDK - zig_0_12 = darwin.apple_sdk_11_0.callPackage ../development/compilers/zig/0.12 { - llvmPackages = llvmPackages_17; - }; - # requires a newer Apple SDK - zig_0_13 = darwin.apple_sdk_11_0.callPackage ../development/compilers/zig/0.13 { - llvmPackages = llvmPackages_18; - }; + inherit (rec { + zigPackages = recurseIntoAttrs (callPackage ../development/compilers/zig {}); + + zig_0_9 = zigPackages."0.9"; + zig_0_10 = zigPackages."0.10"; + zig_0_11 = zigPackages."0.11"; + zig_0_12 = zigPackages."0.12"; + zig_0_13 = zigPackages."0.13"; + }) zigPackages + zig_0_9 + zig_0_10 + zig_0_11 + zig_0_12 + zig_0_13; + zig = zig_0_13; zigStdenv = if stdenv.cc.isZig then stdenv else lowPrio zig.passthru.stdenv; From 54dbd8ba51611c2b1d0b465cdd53740e91f00468 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Mon, 29 Jul 2024 21:37:20 -0700 Subject: [PATCH 2/5] maintainers/teams: add RossComputerGuy to zig --- maintainers/team-list.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/maintainers/team-list.nix b/maintainers/team-list.nix index 4778365d5c9a..51972a4276b7 100644 --- a/maintainers/team-list.nix +++ b/maintainers/team-list.nix @@ -1145,7 +1145,10 @@ with lib.maintainers; }; zig = { - members = [ figsoda ]; + members = [ + figsoda + RossComputerGuy + ]; scope = "Maintain the Zig compiler toolchain and nixpkgs integration."; shortName = "Zig"; enableFeatureFreezePing = true; From bccdfa1a5930fc430b40230fd5076b5223dec2b7 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Mon, 29 Jul 2024 22:51:42 -0700 Subject: [PATCH 3/5] CODEOWNERS: add RossComputerGuy for Zig --- ci/OWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/OWNERS b/ci/OWNERS index 8547d650348a..1cb4d06cb1a7 100644 --- a/ci/OWNERS +++ b/ci/OWNERS @@ -395,8 +395,8 @@ pkgs/by-name/fo/forgejo/ @adamcstephens @bendlas @emilylange /pkgs/development/ocaml-modules @ulrikstrid # Zig -/pkgs/development/compilers/zig @figsoda -/doc/hooks/zig.section.md @figsoda +/pkgs/development/compilers/zig @figsoda @RossComputerGuy +/doc/hooks/zig.section.md @figsoda @RossComputerGuy # Buildbot nixos/modules/services/continuous-integration/buildbot @Mic92 @zowoq From 50e0d27a0ef6cdfee6ade30c1a25583670271f13 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Tue, 30 Jul 2024 19:45:34 -0700 Subject: [PATCH 4/5] zig.cc: add bintools --- pkgs/development/compilers/zig/cc.nix | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/pkgs/development/compilers/zig/cc.nix b/pkgs/development/compilers/zig/cc.nix index 115a71ca4900..763cf6033e68 100644 --- a/pkgs/development/compilers/zig/cc.nix +++ b/pkgs/development/compilers/zig/cc.nix @@ -1,7 +1,9 @@ { lib, wrapCCWith, + wrapBintoolsWith, makeWrapper, + stdenv, runCommand, stdenv, targetPackages, @@ -21,7 +23,7 @@ wrapCCWith { } '' mkdir -p $out/bin - for tool in ar cc c++ objcopy; do + for tool in cc c++; do makeWrapper "$zig/bin/zig" "$out/bin/$tool" \ --add-flags "$tool" \ --run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)" @@ -31,6 +33,38 @@ wrapCCWith { mv $out/bin/cc $out/bin/clang ''; + bintools = + let + targetPrefix = lib.optionalString ( + stdenv.hostPlatform != stdenv.targetPlatform + ) "${stdenv.targetPlatform.config}-"; + in + wrapBintoolsWith { + bintools = + runCommand "zig-bintools-${zig.version}" + { + pname = "zig-bintools"; + inherit (zig) version meta; + + nativeBuildInputs = [ makeWrapper ]; + + passthru = { + isZig = true; + inherit targetPrefix; + }; + + inherit zig; + } + '' + mkdir -p $out/bin + for tool in ar objcopy; do + makeWrapper "$zig/bin/zig" "$out/bin/${targetPrefix}-$tool" \ + --add-flags "$tool" \ + --run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)" + done + ''; + }; + nixSupport.cc-cflags = [ "-target" From 2ca29c56efb89d4b0af50e4feb0a681a6a7af2f9 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Dec 2024 19:48:01 -0800 Subject: [PATCH 5/5] zig: split cc and bintools wrappers --- pkgs/development/compilers/zig/bintools.nix | 34 ++++++++ pkgs/development/compilers/zig/cc.nix | 96 +++++++-------------- pkgs/development/compilers/zig/generic.nix | 27 ++++++ pkgs/development/compilers/zig/stdenv.nix | 6 -- 4 files changed, 90 insertions(+), 73 deletions(-) create mode 100644 pkgs/development/compilers/zig/bintools.nix delete mode 100644 pkgs/development/compilers/zig/stdenv.nix diff --git a/pkgs/development/compilers/zig/bintools.nix b/pkgs/development/compilers/zig/bintools.nix new file mode 100644 index 000000000000..db5803ef1865 --- /dev/null +++ b/pkgs/development/compilers/zig/bintools.nix @@ -0,0 +1,34 @@ +{ + lib, + stdenv, + zig, + runCommand, + makeWrapper, +}: +let + targetPrefix = lib.optionalString ( + stdenv.hostPlatform != stdenv.targetPlatform + ) "${stdenv.targetPlatform.config}-"; +in +runCommand "zig-bintools-${zig.version}" + { + pname = "zig-bintools"; + inherit (zig) version meta; + + nativeBuildInputs = [ makeWrapper ]; + + passthru = { + isZig = true; + inherit targetPrefix; + }; + + inherit zig; + } + '' + mkdir -p $out/bin + for tool in ar objcopy ranlib; do + makeWrapper "$zig/bin/zig" "$out/bin/${targetPrefix}$tool" \ + --add-flags "$tool" \ + --run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)" + done + '' diff --git a/pkgs/development/compilers/zig/cc.nix b/pkgs/development/compilers/zig/cc.nix index 763cf6033e68..71d1211d89fa 100644 --- a/pkgs/development/compilers/zig/cc.nix +++ b/pkgs/development/compilers/zig/cc.nix @@ -1,76 +1,38 @@ { lib, - wrapCCWith, - wrapBintoolsWith, - makeWrapper, - stdenv, runCommand, - stdenv, - targetPackages, zig, + stdenv, + makeWrapper, }: -wrapCCWith { - cc = - runCommand "zig-cc-${zig.version}" - { - pname = "zig-cc"; - inherit (zig) version meta; +let + targetPrefix = lib.optionalString ( + stdenv.hostPlatform != stdenv.targetPlatform + ) "${stdenv.targetPlatform.config}-"; +in +runCommand "zig-cc-${zig.version}" + { + pname = "zig-cc"; + inherit (zig) version meta; - nativeBuildInputs = [ makeWrapper ]; + nativeBuildInputs = [ makeWrapper ]; - passthru.isZig = true; - inherit zig; - } - '' - mkdir -p $out/bin - for tool in cc c++; do - makeWrapper "$zig/bin/zig" "$out/bin/$tool" \ - --add-flags "$tool" \ - --run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)" - done - - mv $out/bin/c++ $out/bin/clang++ - mv $out/bin/cc $out/bin/clang - ''; - - bintools = - let - targetPrefix = lib.optionalString ( - stdenv.hostPlatform != stdenv.targetPlatform - ) "${stdenv.targetPlatform.config}-"; - in - wrapBintoolsWith { - bintools = - runCommand "zig-bintools-${zig.version}" - { - pname = "zig-bintools"; - inherit (zig) version meta; - - nativeBuildInputs = [ makeWrapper ]; - - passthru = { - isZig = true; - inherit targetPrefix; - }; - - inherit zig; - } - '' - mkdir -p $out/bin - for tool in ar objcopy; do - makeWrapper "$zig/bin/zig" "$out/bin/${targetPrefix}-$tool" \ - --add-flags "$tool" \ - --run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)" - done - ''; + passthru = { + isZig = true; + inherit targetPrefix; }; - nixSupport.cc-cflags = - [ - "-target" - "${stdenv.targetPlatform.parsed.cpu.name}-${stdenv.targetPlatform.parsed.kernel.name}-${stdenv.targetPlatform.parsed.abi.name}" - ] - ++ lib.optional ( - stdenv.targetPlatform.isLinux && !(targetPackages.isStatic or false) - ) "-Wl,-dynamic-linker=${targetPackages.stdenv.cc.bintools.dynamicLinker}"; -} + inherit zig; + } + '' + mkdir -p $out/bin + for tool in cc c++ ld.lld; do + makeWrapper "$zig/bin/zig" "$out/bin/${targetPrefix}$tool" \ + --add-flags "$tool" \ + --run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)" + done + + mv $out/bin/${targetPrefix}c++ $out/bin/${targetPrefix}clang++ + mv $out/bin/${targetPrefix}cc $out/bin/${targetPrefix}clang + mv $out/bin/${targetPrefix}ld.lld $out/bin/${targetPrefix}ld + '' diff --git a/pkgs/development/compilers/zig/generic.nix b/pkgs/development/compilers/zig/generic.nix index a952880fff3f..0fd210f5da14 100644 --- a/pkgs/development/compilers/zig/generic.nix +++ b/pkgs/development/compilers/zig/generic.nix @@ -4,6 +4,7 @@ fetchFromGitHub, cmake, llvmPackages, + targetPackages, libxml2, zlib, coreutils, @@ -11,6 +12,9 @@ version, hash, patches ? [ ], + overrideCC, + wrapCCWith, + wrapBintoolsWith, }@args: stdenv.mkDerivation (finalAttrs: { @@ -136,6 +140,29 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstallCheck ''; + passthru = { + hook = callPackage ./hook.nix { zig = finalAttrs.finalPackage; }; + + bintools-unwrapped = callPackage ./bintools.nix { zig = finalAttrs.finalPackage; }; + bintools = wrapBintoolsWith { bintools = finalAttrs.finalPackage.bintools-unwrapped; }; + + cc-unwrapped = callPackage ./cc.nix { zig = finalAttrs.finalPackage; }; + cc = wrapCCWith { + cc = finalAttrs.finalPackage.cc-unwrapped; + bintools = finalAttrs.finalPackage.bintools; + nixSupport.cc-cflags = + [ + "-target" + "${stdenv.targetPlatform.parsed.cpu.name}-${stdenv.targetPlatform.parsed.kernel.name}-${stdenv.targetPlatform.parsed.abi.name}" + ] + ++ lib.optional ( + stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.isStatic or false) + ) "-Wl,-dynamic-linker=${targetPackages.stdenv.cc.bintools.dynamicLinker}"; + }; + + stdenv = overrideCC stdenv finalAttrs.finalPackage.cc; + }; + meta = { description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software"; homepage = "https://ziglang.org/"; diff --git a/pkgs/development/compilers/zig/stdenv.nix b/pkgs/development/compilers/zig/stdenv.nix deleted file mode 100644 index e8b29a7c8aba..000000000000 --- a/pkgs/development/compilers/zig/stdenv.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - stdenv, - overrideCC, - zig, -}: -overrideCC stdenv zig.cc