1
Fork 0

make it all work

This commit is contained in:
Jan-Erik Rediger 2024-05-15 12:19:36 +02:00
parent 4eaf069485
commit 98e1f635c8
3 changed files with 36 additions and 14 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
hello*
tmp

View file

@ -3,17 +3,14 @@
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";
@ -21,7 +18,7 @@ let
}.${arch};
hareAs = ./hare-as.py;
hareLd = stdenv.mkDerivation (finalAttrs: {
pname = "rust-ld";
pname = "hare-ld";
version = "1.0";
src = [ ./ld.rs ];
buildInputs = [ rustc ];
@ -31,11 +28,33 @@ let
done
'';
buildPhase = ''
rustc -o rust-ld.bin $src
rustc -o hare-ld.bin ld.rs
'';
installPhase = ''
mkdir -p $out/bin
cp rust-ld.bin $out/bin/rust-ld
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
@ -72,9 +91,9 @@ stdenv.mkDerivation (finalAttrs: {
"ARCH=${arch}"
"VERSION=${finalAttrs.version}-nixpkgs"
"QBEFLAGS=-t${qbePlatform}"
"CC=${stdenv.cc.targetPrefix}cc"
"CC=${hareCc}/bin/hare-cc"
"AS=${hareAs}"
"LD=${hareLd}/bin/rust-ld"
"LD=${hareLd}/bin/hare-ld"
# Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
# not follow the FHS.
"HAREPATH=$(SRCDIR)/hare/stdlib"
@ -90,8 +109,9 @@ stdenv.mkDerivation (finalAttrs: {
postFixup = ''
wrapProgram $out/bin/hare \
--prefix PATH : ${lib.makeBinPath [harec qbe]} \
--set LD ${hareLd}/bin/rust-ld \
--set AS ${hareAs}
--set CC ${hareCc}/bin/hare-cc \
--set AS ${hareAs} \
--set LD ${hareLd}/bin/hare-ld
'';
setupHook = ./setup-hook.sh;

View file

@ -18,10 +18,11 @@ fn main() {
// Skip next one too
_ = argv.remove(0);
}
"--gc-sections" => { }
_ if arg.starts_with("-T") => { }
_ if arg.starts_with("-z") => { }
_ if arg.starts_with("--script=") => { }
"--gc-sections" => {}
"-Wl,--gc-sections" | "-Wl,--no-gc-sections" => {}
_ if arg.starts_with("-T") => {}
_ if arg.starts_with("-z") => {}
_ if arg.starts_with("--script=") => {}
_ => {
args.push(arg);
}