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

99 lines
1.9 KiB
Nix

{
stdenv,
lib,
makeWrapper,
scdoc,
substituteAll,
qbe,
harec,
binutils-unwrapped,
tzdata,
python3,
writeScript,
rustc,
}:
let
platform = lib.toLower stdenv.hostPlatform.uname.system;
arch = stdenv.hostPlatform.uname.processor;
qbePlatform = {
x86_64 = "amd64_apple";
aarch64 = "arm64_apple";
}.${arch};
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
'';
});
in
stdenv.mkDerivation (finalAttrs: {
pname = "hare";
version = "0.24";
src = builtins.fetchGit {
url = "https://github.com/hshq/harelang";
ref = "master";
rev = "30d097a7c7f3ccf9e4fc783d1cdae1fd506673c7";
};
patches = [
];
nativeBuildInputs = [
harec
makeWrapper
qbe
scdoc
python3
];
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"
"AS=${hareAs}"
"LD=${hareLd}/bin/rust-ld"
# Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
# not follow the FHS.
"HAREPATH=$(SRCDIR)/hare/stdlib"
];
postConfigure = ''
ln -s configs/darwin.mk config.mk
sed -i 's/ @#/ /' Makefile
sed -i 's/ @/ /' Makefile
sed -i 's/ @/ /' makefiles/darwin.aarch64.mk
'';
postFixup = ''
wrapProgram $out/bin/hare \
--prefix PATH : ${lib.makeBinPath [harec qbe]} \
--set LD ${hareLd}/bin/rust-ld \
--set AS ${hareAs}
'';
setupHook = ./setup-hook.sh;
})