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* hello*
tmp

View file

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

View file

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