1
Fork 0

run checks and deploy hare-* as derivations

This commit is contained in:
Jan-Erik Rediger 2024-05-15 12:50:04 +02:00
parent 5200cf3c88
commit 6b765abc4b
7 changed files with 66 additions and 58 deletions

View file

@ -10,8 +10,11 @@
devShells = forAllSystems (system:
let
pkgs = nixpkgs.legacyPackages.${system};
harec = pkgs.callPackage ./pkgs/harec.nix { };
hare = pkgs.callPackage ./pkgs/hare.nix { inherit harec; };
hareAs = pkgs.callPackage ./pkgs/hare-as.nix { };
hareCc = pkgs.callPackage ./pkgs/hare-cc.nix { };
hareLd = pkgs.callPackage ./pkgs/hare-ld.nix { };
harec = pkgs.callPackage ./pkgs/harec.nix { inherit hareAs hareCc hareLd; };
hare = pkgs.callPackage ./pkgs/hare.nix { inherit harec hareAs hareCc hareLd; };
in
{
default = pkgs.mkShell {

11
pkgs/hare-as.nix Normal file
View file

@ -0,0 +1,11 @@
{
stdenv,
python3,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "hare-as";
version = "1.0";
unpackPhase = ":";
buildInputs = [ python3 ];
installPhase = "install -m755 -D ${./hare-as.py} $out/bin/hare-as";
})

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python3
#!python3
import re
import sys
from subprocess import Popen, PIPE, STDOUT
from subprocess import Popen, PIPE
def header(filename):
return f"""

19
pkgs/hare-cc.nix Normal file
View file

@ -0,0 +1,19 @@
{
stdenv,
rustc,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "hare-cc";
version = "1.0";
buildInputs = [ rustc ];
unpackPhase = ":";
buildPhase = ''
sed \
-e 's/"ld"/"cc"/g' \
-e 's/let mut args/let mut _args/' \
-e '11 a let mut args = vec![];' \
${./ld.rs} > ld.rs
rustc -o hare-cc.bin ld.rs
'';
installPhase = "install -m755 -D hare-cc.bin $out/bin/hare-cc";
})

15
pkgs/hare-ld.nix Normal file
View file

@ -0,0 +1,15 @@
{
stdenv,
rustc,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "hare-ld";
version = "1.0";
buildInputs = [ rustc ];
unpackPhase = ":";
buildPhase = ''
cp ${./ld.rs} ld.rs
rustc -o hare-ld.bin ld.rs
'';
installPhase = "install -m755 -D hare-ld.bin $out/bin/hare-ld";
})

View file

@ -5,10 +5,11 @@
scdoc,
qbe,
harec,
binutils-unwrapped,
tzdata,
python3,
rustc,
hareAs,
hareCc,
hareLd,
}:
let
arch = stdenv.hostPlatform.uname.processor;
@ -16,47 +17,6 @@ let
x86_64 = "amd64_apple";
aarch64 = "arm64_apple";
}.${arch};
hareAs = ./hare-as.py;
hareLd = stdenv.mkDerivation (finalAttrs: {
pname = "hare-ld";
version = "1.0";
src = [ ./ld.rs ];
buildInputs = [ rustc ];
unpackPhase = ''
for srcFile in $src; do
cp $srcFile $(stripHash $srcFile)
done
'';
buildPhase = ''
rustc -o hare-ld.bin ld.rs
'';
installPhase = ''
mkdir -p $out/bin
cp hare-ld.bin $out/bin/hare-ld
'';
});
hareCc = stdenv.mkDerivation (finalAttrs: {
pname = "hare-cc";
version = "1.0";
src = [ ./ld.rs ];
buildInputs = [ rustc ];
unpackPhase = ''
for srcFile in $src; do
cp $srcFile $(stripHash $srcFile)
done
'';
buildPhase = ''
sed -i \
-e 's/"ld"/"cc"/g' \
-e '11 a let mut args = vec![];' \
ld.rs
rustc -o hare-cc.bin ld.rs
'';
installPhase = ''
mkdir -p $out/bin
cp hare-cc.bin $out/bin/hare-cc
'';
});
in
stdenv.mkDerivation (finalAttrs: {
pname = "hare";
@ -66,9 +26,7 @@ stdenv.mkDerivation (finalAttrs: {
ref = "master";
rev = "30d097a7c7f3ccf9e4fc783d1cdae1fd506673c7";
};
patches = [
];
doCheck = true;
nativeBuildInputs = [
harec
@ -79,7 +37,6 @@ stdenv.mkDerivation (finalAttrs: {
];
buildInputs = [
binutils-unwrapped
harec
qbe
tzdata
@ -92,7 +49,7 @@ stdenv.mkDerivation (finalAttrs: {
"VERSION=${finalAttrs.version}-nixpkgs"
"QBEFLAGS=-t${qbePlatform}"
"CC=${hareCc}/bin/hare-cc"
"AS=${hareAs}"
"AS=${hareAs}/bin/hare-as"
"LD=${hareLd}/bin/hare-ld"
# Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
# not follow the FHS.
@ -110,8 +67,11 @@ stdenv.mkDerivation (finalAttrs: {
wrapProgram $out/bin/hare \
--prefix PATH : ${lib.makeBinPath [harec qbe]} \
--set CC ${hareCc}/bin/hare-cc \
--set AS ${hareAs} \
--set AS ${hareAs}/bin/hare-as \
--set LD ${hareLd}/bin/hare-ld
wrapProgram $out/bin/haredoc \
--prefix PATH : ${lib.makeBinPath [scdoc]}
'';
setupHook = ./setup-hook.sh;

View file

@ -1,6 +1,5 @@
{ lib, stdenv, qbe }:
{ stdenv, qbe, hareAs, hareCc, hareLd }:
let
platform = lib.toLower stdenv.hostPlatform.uname.system;
arch = stdenv.hostPlatform.uname.processor;
qbePlatform = {
x86_64 = "amd64_apple";
@ -17,15 +16,16 @@ stdenv.mkDerivation (finalAttrs: {
};
buildInputs = [ qbe ];
nativeBuildInputs = [ qbe ];
doCheck = true;
makeFlags = [
"PREFIX=${builtins.placeholder "out"}"
"ARCH=${arch}"
"VERSION=${finalAttrs.version}-nixpkgs"
"QBEFLAGS=-t${qbePlatform}"
"CC=${stdenv.cc.targetPrefix}cc"
"AS=${stdenv.cc.targetPrefix}as"
"LD=${stdenv.cc.targetPrefix}ld"
"CC=${hareCc}/bin/hare-cc"
"AS=${hareAs}/bin/hare-as"
"LD=${hareLd}/bin/hare-ld"
];
postConfigure = ''