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: devShells = forAllSystems (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
harec = pkgs.callPackage ./pkgs/harec.nix { }; hareAs = pkgs.callPackage ./pkgs/hare-as.nix { };
hare = pkgs.callPackage ./pkgs/hare.nix { inherit harec; }; 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 in
{ {
default = pkgs.mkShell { 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 re
import sys import sys
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE
def header(filename): def header(filename):
return f""" 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, scdoc,
qbe, qbe,
harec, harec,
binutils-unwrapped,
tzdata, tzdata,
python3, python3,
rustc, hareAs,
hareCc,
hareLd,
}: }:
let let
arch = stdenv.hostPlatform.uname.processor; arch = stdenv.hostPlatform.uname.processor;
@ -16,47 +17,6 @@ let
x86_64 = "amd64_apple"; x86_64 = "amd64_apple";
aarch64 = "arm64_apple"; aarch64 = "arm64_apple";
}.${arch}; }.${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 in
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "hare"; pname = "hare";
@ -66,9 +26,7 @@ stdenv.mkDerivation (finalAttrs: {
ref = "master"; ref = "master";
rev = "30d097a7c7f3ccf9e4fc783d1cdae1fd506673c7"; rev = "30d097a7c7f3ccf9e4fc783d1cdae1fd506673c7";
}; };
doCheck = true;
patches = [
];
nativeBuildInputs = [ nativeBuildInputs = [
harec harec
@ -79,7 +37,6 @@ stdenv.mkDerivation (finalAttrs: {
]; ];
buildInputs = [ buildInputs = [
binutils-unwrapped
harec harec
qbe qbe
tzdata tzdata
@ -92,7 +49,7 @@ stdenv.mkDerivation (finalAttrs: {
"VERSION=${finalAttrs.version}-nixpkgs" "VERSION=${finalAttrs.version}-nixpkgs"
"QBEFLAGS=-t${qbePlatform}" "QBEFLAGS=-t${qbePlatform}"
"CC=${hareCc}/bin/hare-cc" "CC=${hareCc}/bin/hare-cc"
"AS=${hareAs}" "AS=${hareAs}/bin/hare-as"
"LD=${hareLd}/bin/hare-ld" "LD=${hareLd}/bin/hare-ld"
# Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does # Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
# not follow the FHS. # not follow the FHS.
@ -110,8 +67,11 @@ stdenv.mkDerivation (finalAttrs: {
wrapProgram $out/bin/hare \ wrapProgram $out/bin/hare \
--prefix PATH : ${lib.makeBinPath [harec qbe]} \ --prefix PATH : ${lib.makeBinPath [harec qbe]} \
--set CC ${hareCc}/bin/hare-cc \ --set CC ${hareCc}/bin/hare-cc \
--set AS ${hareAs} \ --set AS ${hareAs}/bin/hare-as \
--set LD ${hareLd}/bin/hare-ld --set LD ${hareLd}/bin/hare-ld
wrapProgram $out/bin/haredoc \
--prefix PATH : ${lib.makeBinPath [scdoc]}
''; '';
setupHook = ./setup-hook.sh; setupHook = ./setup-hook.sh;

View file

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