diff --git a/pkgs/development/compilers/zig/bintools.nix b/pkgs/development/compilers/zig/bintools.nix new file mode 100644 index 00000000000000..05e9d85724bdf5 --- /dev/null +++ b/pkgs/development/compilers/zig/bintools.nix @@ -0,0 +1,36 @@ +{ + 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 ld.lld; do + makeWrapper "$zig/bin/zig" "$out/bin/${targetPrefix}$tool" \ + --add-flags "$tool" \ + --run "export ZIG_GLOBAL_CACHE_DIR=\''${TMPDIR-/tmp}/zig-cache" + done + + mv $out/bin/${targetPrefix}ld.lld $out/bin/${targetPrefix}ld + '' diff --git a/pkgs/development/compilers/zig/cc.nix b/pkgs/development/compilers/zig/cc.nix index 763cf6033e683f..01d2553979013a 100644 --- a/pkgs/development/compilers/zig/cc.nix +++ b/pkgs/development/compilers/zig/cc.nix @@ -1,76 +1,37 @@ { 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; - - 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 - ''; +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 ]; + + 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++; do + makeWrapper "$zig/bin/zig" "$out/bin/$tool" \ + --add-flags "$tool" \ + --run "export ZIG_GLOBAL_CACHE_DIR=\''${TMPDIR-/tmp}/zig-cache" + done + + mv $out/bin/c++ $out/bin/clang++ + mv $out/bin/cc $out/bin/clang + '' diff --git a/pkgs/development/compilers/zig/generic.nix b/pkgs/development/compilers/zig/generic.nix index a952880fff3f78..4dd5356601ce53 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: { @@ -82,7 +86,7 @@ stdenv.mkDerivation (finalAttrs: { ]; preBuild = '' - export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache"; + export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache" ''; # Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't @@ -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 e8b29a7c8aba2e..00000000000000 --- a/pkgs/development/compilers/zig/stdenv.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - stdenv, - overrideCC, - zig, -}: -overrideCC stdenv zig.cc