Skip to content

Commit

Permalink
zig: split cc and bintools wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Nov 21, 2024
1 parent 5cbdabe commit 0a2ad4b
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 200 deletions.
34 changes: 34 additions & 0 deletions pkgs/development/compilers/zig/bintools.nix
Original file line number Diff line number Diff line change
@@ -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; do
makeWrapper "$zig/bin/zig" "$out/bin/${targetPrefix}$tool" \
--add-flags "$tool" \
--run "export ZIG_GLOBAL_CACHE_DIR=\$(mktemp -d)"
done
''
99 changes: 30 additions & 69 deletions pkgs/development/compilers/zig/cc.nix
Original file line number Diff line number Diff line change
@@ -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/${targetPrefix}$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
''
Loading

0 comments on commit 0a2ad4b

Please sign in to comment.