Skip to content

Instantly share code, notes, and snippets.

@ivan
Created April 1, 2021 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/c44ac985a9975097380780c148e648a5 to your computer and use it in GitHub Desktop.
Save ivan/c44ac985a9975097380780c148e648a5 to your computer and use it in GitHub Desktop.
nixpkgs: ripgrep: build with lto = true
From 8a92c363d9b2ef435e3b6eb7183b84b1fcf44a15 Mon Sep 17 00:00:00 2001
From: Ivan Kozik <ivan@ludios.org>
Date: Tue, 14 Jul 2020 06:19:32 +0000
Subject: [PATCH] ripgrep: build with lto = true
This reduces the size of the amd64 binary from 5.7MB to 4.6MB.
---
pkgs/tools/text/ripgrep/default.nix | 4 ++++
pkgs/tools/text/ripgrep/lto.patch | 10 ++++++++++
2 files changed, 14 insertions(+)
create mode 100644 pkgs/tools/text/ripgrep/lto.patch
diff --git a/pkgs/tools/text/ripgrep/default.nix b/pkgs/tools/text/ripgrep/default.nix
index 8c9eef9cc3d..6dbccea4451 100644
--- a/pkgs/tools/text/ripgrep/default.nix
+++ b/pkgs/tools/text/ripgrep/default.nix
@@ -20,6 +20,10 @@ rustPlatform.buildRustPackage rec {
sha256 = "1hqps7l5qrjh9f914r5i6kmcz6f1yb951nv4lby0cjnp5l253kps";
};
+ patches = [
+ ./lto.patch
+ ];
+
cargoSha256 = "03wf9r2csi6jpa7v5sw5lpxkrk4wfzwmzx7k3991q3bdjzcwnnwp";
cargoBuildFlags = lib.optional withPCRE2 "--features pcre2";
diff --git a/pkgs/tools/text/ripgrep/lto.patch b/pkgs/tools/text/ripgrep/lto.patch
new file mode 100644
index 00000000000..facafe948a3
--- /dev/null
+++ b/pkgs/tools/text/ripgrep/lto.patch
@@ -0,0 +1,10 @@
+diff --git a/Cargo.toml b/Cargo.toml
+index a4c216a..e75a707 100644
+--- a/Cargo.toml
++++ b/Cargo.toml
+@@ -80,3 +80,4 @@ pcre2 = ["grep/pcre2"]
+ [profile.release]
+-debug = 1
++lto = true
++codegen-units = 1
+
--
2.31.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment