1
Fork 0
hare-nix/pkgs/hare.nix

99 lines
1.9 KiB
Nix
Raw Normal View History

2024-05-14 19:06:04 +00:00
{
2024-05-14 19:02:43 +00:00
stdenv,
lib,
makeWrapper,
scdoc,
substituteAll,
qbe,
harec,
binutils-unwrapped,
2024-05-14 19:06:04 +00:00
tzdata,
python3,
writeScript,
rustc,
2024-05-14 19:02:43 +00:00
}:
let
platform = lib.toLower stdenv.hostPlatform.uname.system;
arch = stdenv.hostPlatform.uname.processor;
qbePlatform = {
2024-05-14 19:06:04 +00:00
x86_64 = "amd64_apple";
aarch64 = "arm64_apple";
2024-05-14 19:02:43 +00:00
}.${arch};
2024-05-14 19:06:04 +00:00
hareAs = ./hare-as.py;
hareLd = stdenv.mkDerivation (finalAttrs: {
pname = "rust-ld";
version = "1.0";
src = [ ./ld.rs ];
buildInputs = [ rustc ];
unpackPhase = ''
for srcFile in $src; do
cp $srcFile $(stripHash $srcFile)
done
'';
buildPhase = ''
rustc -o rust-ld.bin $src
'';
installPhase = ''
mkdir -p $out/bin
cp rust-ld.bin $out/bin/rust-ld
'';
});
2024-05-14 19:02:43 +00:00
in
stdenv.mkDerivation (finalAttrs: {
pname = "hare";
version = "0.24";
src = builtins.fetchGit {
2024-05-14 19:06:04 +00:00
url = "https://github.com/hshq/harelang";
2024-05-14 19:02:43 +00:00
ref = "master";
2024-05-14 19:06:04 +00:00
rev = "30d097a7c7f3ccf9e4fc783d1cdae1fd506673c7";
2024-05-14 19:02:43 +00:00
};
patches = [
];
nativeBuildInputs = [
harec
makeWrapper
qbe
scdoc
2024-05-14 19:06:04 +00:00
python3
2024-05-14 19:02:43 +00:00
];
buildInputs = [
binutils-unwrapped
harec
qbe
tzdata
];
makeFlags = [
"HARECACHE=.harecache"
"PREFIX=${builtins.placeholder "out"}"
"ARCH=${arch}"
"VERSION=${finalAttrs.version}-nixpkgs"
"QBEFLAGS=-t${qbePlatform}"
"CC=${stdenv.cc.targetPrefix}cc"
2024-05-14 19:06:04 +00:00
"AS=${hareAs}"
"LD=${hareLd}/bin/rust-ld"
2024-05-14 19:02:43 +00:00
# Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
# not follow the FHS.
"HAREPATH=$(SRCDIR)/hare/stdlib"
];
postConfigure = ''
2024-05-14 19:06:04 +00:00
ln -s configs/darwin.mk config.mk
sed -i 's/ @#/ /' Makefile
sed -i 's/ @/ /' Makefile
sed -i 's/ @/ /' makefiles/darwin.aarch64.mk
2024-05-14 19:02:43 +00:00
'';
postFixup = ''
wrapProgram $out/bin/hare \
2024-05-14 19:06:04 +00:00
--prefix PATH : ${lib.makeBinPath [harec qbe]} \
--set LD ${hareLd}/bin/rust-ld \
--set AS ${hareAs}
2024-05-14 19:02:43 +00:00
'';
setupHook = ./setup-hook.sh;
})