forked from trinitrix/core
build(flake): Replace self-packaged cranelift with rustup's
Motivation ========== The self-packed one sort-of worked, but was rather flaky, while the one from rustup obviously works, as it's an officially distributed part. Running it ========== Instead of the `cargo clif [build, etc.]` you now need to run (on nightly): ``` RUSTFLAGS="-Zcodegen-backend=cranelift" cargo build ``` Performance =========== On my system I noticed, that a debug build takes around 20 sec *more* with cranelift, compared to the default LLVM backend. One possible hypothesis, for that could be, that cranelift does not link via `mold` but instead still uses GNU's `gold`. On the other hand, the performance decrease could also be caused by the fact, that it's an early preview and some optimizations are still lacking.
This commit is contained in:
parent
c1b426d590
commit
df07c3fc24
34
flake.lock
34
flake.lock
|
@ -76,9 +76,7 @@
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust-overlay": "rust-overlay",
|
"rust-overlay": "rust-overlay"
|
||||||
"rustc_cranelift_backend": "rustc_cranelift_backend",
|
|
||||||
"rustc_cranelift_backend_src": "rustc_cranelift_backend_src"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-overlay": {
|
||||||
|
@ -104,36 +102,6 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rustc_cranelift_backend": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1698679294,
|
|
||||||
"narHash": "sha256-plG6ifmuMwy7pr0KE19Oz+HKLH+4UDuuXZ1u0s9RtNQ=",
|
|
||||||
"owner": "bjorn3",
|
|
||||||
"repo": "rustc_codegen_cranelift",
|
|
||||||
"rev": "9a33f82140c6da6e5808253309c674554b93e9fe",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "bjorn3",
|
|
||||||
"ref": "dev",
|
|
||||||
"repo": "rustc_codegen_cranelift",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rustc_cranelift_backend_src": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1698679361,
|
|
||||||
"narHash": "sha256-vc7T92wEfufuPc8q2/xq4mQK/uFfoG7pKOVWYxbHzds=",
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://github.com/bjorn3/rustc_codegen_cranelift/releases/download/dev/cg_clif-x86_64-unknown-linux-gnu.tar.xz"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://github.com/bjorn3/rustc_codegen_cranelift/releases/download/dev/cg_clif-x86_64-unknown-linux-gnu.tar.xz"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"systems": {
|
"systems": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681028828,
|
"lastModified": 1681028828,
|
||||||
|
|
101
flake.nix
101
flake.nix
|
@ -29,16 +29,6 @@
|
||||||
flake-utils.follows = "flake-utils";
|
flake-utils.follows = "flake-utils";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# cranelift
|
|
||||||
rustc_cranelift_backend = {
|
|
||||||
url = "github:bjorn3/rustc_codegen_cranelift/dev";
|
|
||||||
flake = false;
|
|
||||||
};
|
|
||||||
rustc_cranelift_backend_src = {
|
|
||||||
url = "https://github.com/bjorn3/rustc_codegen_cranelift/releases/download/dev/cg_clif-x86_64-unknown-linux-gnu.tar.xz";
|
|
||||||
flake = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
|
@ -47,8 +37,6 @@
|
||||||
crane,
|
crane,
|
||||||
flake-utils,
|
flake-utils,
|
||||||
rust-overlay,
|
rust-overlay,
|
||||||
rustc_cranelift_backend,
|
|
||||||
rustc_cranelift_backend_src,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (system: let
|
flake-utils.lib.eachDefaultSystem (system: let
|
||||||
|
@ -74,94 +62,20 @@
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
c_rust = pkgs.rust-bin.fromRustupToolchainFile "${rustc_cranelift_backend}/rust-toolchain";
|
|
||||||
rcb = pkgs.stdenv.mkDerivation {
|
|
||||||
pname = "rustc_cranelift_backend";
|
|
||||||
version = "1.0";
|
|
||||||
buildInputs = [c_rust];
|
|
||||||
nativeBuildInputs = with pkgs; [gawk fd];
|
|
||||||
srcs = ["${rustc_cranelift_backend_src}" "${c_rust}"];
|
|
||||||
sourceRoot = ".";
|
|
||||||
postUnpack = ''
|
|
||||||
rust_dir="$(fd . --max-depth 1 | awk '!/source/ && !/env-vars/')"
|
|
||||||
|
|
||||||
# remove unneeded stuff
|
|
||||||
rm -r "$rust_dir"/{bin,nix-support,share};
|
|
||||||
rm -r "$rust_dir"/lib/rustlib/{etc,src,rustc-src};
|
|
||||||
|
|
||||||
cp -r "$rust_dir"/. source/extra_dependencies
|
|
||||||
rm -r "$rust_dir"
|
|
||||||
cd source
|
|
||||||
'';
|
|
||||||
postPatch = ''
|
|
||||||
# patch bins
|
|
||||||
for file in $(fd . --type file);do
|
|
||||||
file="$(file --mime "$file" | awk 'BEGIN{FS=":"}/application\/x-pie-executable/{print $1}')";
|
|
||||||
if [ "$file" ]; then
|
|
||||||
echo "file: '$file' matches";
|
|
||||||
correct_interpreter_path="$(ldd "$file" | tail -n1 | awk 'BEGIN{FS="=> "} {print $2}' | awk 'BEGIN{FS=" "}{print $1}')"
|
|
||||||
echo "correct interpreter path is: '$correct_interpreter_path'"
|
|
||||||
patchelf --set-interpreter "$correct_interpreter_path" "$file"
|
|
||||||
|
|
||||||
if [ "$(patchelf --print-interpreter "$file")" = "$correct_interpreter_path" ];then
|
|
||||||
echo "Set interpreter";
|
|
||||||
else
|
|
||||||
echo "Failed to set interprter, the interpreter still is $(patchelf --print-interpreter )";
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# patch libs
|
|
||||||
all_files=$(mktemp);
|
|
||||||
for file in $(fd .);do
|
|
||||||
canonical_path="$(readlink -f "$file")"
|
|
||||||
file="$(file --mime "$canonical_path" | awk 'BEGIN{FS=":"}/application\/x-sharedlib/{print $1}')";
|
|
||||||
if [ "$file" ]; then
|
|
||||||
echo "$file" >> $all_files;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
while read -r file; do
|
|
||||||
echo "___________________";
|
|
||||||
echo "Checking file: '$file'";
|
|
||||||
is_missing="$(ldd "$file" | awk 'BEGIN{FS="=>"}{if (/not found/){print $1}}')"
|
|
||||||
if [ "$is_missing" ];then
|
|
||||||
echo "Warning: The following things are missing:";
|
|
||||||
for line in $is_missing; do
|
|
||||||
echo " $line";
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
for line in $is_missing; do
|
|
||||||
echo "Searching for a substitute for '$line'"
|
|
||||||
substitute="$(grep "$line" "$all_files" | awk 'BEGIN{FS=" "}{print $1}' | tail -n1)";
|
|
||||||
if [ "$substitute" ]; then
|
|
||||||
echo "Found '$substitute', which can substitute '$line'"
|
|
||||||
echo "Patching.."
|
|
||||||
patchelf --replace-needed "$line" "$(readlink -f "$substitute")" "$file";
|
|
||||||
else
|
|
||||||
echo "Error: Failed to find a substitute"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo "This file is not missing anything"
|
|
||||||
fi
|
|
||||||
done < $all_files
|
|
||||||
rm $all_files
|
|
||||||
'';
|
|
||||||
installPhase = ''
|
|
||||||
install -d $out/
|
|
||||||
cp -r ./. $out/
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
overlays = [(import rust-overlay)];
|
overlays = [(import rust-overlay)];
|
||||||
};
|
};
|
||||||
|
|
||||||
nightly = false;
|
nightly = true;
|
||||||
rust =
|
rust =
|
||||||
if nightly
|
if nightly
|
||||||
then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)
|
then
|
||||||
|
(pkgs.rust-bin.selectLatestNightlyWith (toolchain:
|
||||||
|
toolchain.default))
|
||||||
|
.override {
|
||||||
|
extensions = ["rustc-codegen-cranelift-preview"];
|
||||||
|
}
|
||||||
else pkgs.rust-bin.stable.latest.default;
|
else pkgs.rust-bin.stable.latest.default;
|
||||||
|
|
||||||
craneLib = (crane.mkLib pkgs).overrideToolchain rust;
|
craneLib = (crane.mkLib pkgs).overrideToolchain rust;
|
||||||
|
@ -169,7 +83,6 @@
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
pkg-config
|
pkg-config
|
||||||
mold'
|
mold'
|
||||||
rcb
|
|
||||||
];
|
];
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
openssl
|
openssl
|
||||||
|
|
Loading…
Reference in New Issue