zig: add cc wrapper

This commit is contained in:
Tristan Ross 2024-06-07 07:46:36 -07:00
parent 2c5b5ebf5e
commit 65c81d4eae
No known key found for this signature in database
GPG Key ID: B09C422035669AF8
6 changed files with 57 additions and 0 deletions

View File

@ -89,6 +89,9 @@ stdenv.mkDerivation (finalAttrs: {
passthru = {
hook = callPackage ./hook.nix { zig = finalAttrs.finalPackage; };
cc = callPackage ../cc.nix {
zig = finalAttrs.finalPackage;
};
tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;

View File

@ -83,6 +83,9 @@ stdenv.mkDerivation (finalAttrs: {
passthru = {
hook = callPackage ./hook.nix { zig = finalAttrs.finalPackage; };
cc = callPackage ../cc.nix {
zig = finalAttrs.finalPackage;
};
tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;

View File

@ -95,6 +95,9 @@ stdenv.mkDerivation (finalAttrs: {
passthru = {
hook = callPackage ./hook.nix { zig = finalAttrs.finalPackage; };
cc = callPackage ../cc.nix {
zig = finalAttrs.finalPackage;
};
tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;

View File

@ -91,6 +91,9 @@ stdenv.mkDerivation (finalAttrs: {
passthru = {
hook = callPackage ./hook.nix { zig = finalAttrs.finalPackage; };
cc = callPackage ../cc.nix {
zig = finalAttrs.finalPackage;
};
tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;

View File

@ -0,0 +1,42 @@
{
lib,
wrapCCWith,
makeWrapper,
runCommand,
targetPlatform,
targetPackages,
zig,
}:
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 ar cc c++ objcopy; 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
'';
nixSupport.cc-cflags =
[
"-target"
"${targetPlatform.parsed.cpu.name}-${targetPlatform.parsed.kernel.name}-${targetPlatform.parsed.abi.name}"
]
++ lib.optional (
targetPlatform.isLinux && !(targetPackages.isStatic or false)
) "-Wl,-dynamic-linker=${targetPackages.stdenv.cc.bintools.dynamicLinker}";
}

View File

@ -71,6 +71,9 @@ stdenv.mkDerivation (finalAttrs: {
hook = callPackage ./hook.nix {
zig = finalAttrs.finalPackage;
};
cc = callPackage ./cc.nix {
zig = finalAttrs.finalPackage;
};
};
meta = {