From dfe33dc9bb0f766953203c41c1fa3546758f5a82 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Nov 2024 19:23:34 -0800 Subject: [PATCH] build.zig: add -Dpie option for position independent executables This is required by some packaging ecosytems. --- build.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build.zig b/build.zig index c50932b63..f93e18b7b 100644 --- a/build.zig +++ b/build.zig @@ -98,6 +98,12 @@ pub fn build(b: *std.Build) !void { "Enables the use of Adwaita when using the GTK rendering backend.", ) orelse true; + const pie = b.option( + bool, + "pie", + "Build a Position Independent Executable", + ) orelse false; + const conformance = b.option( []const u8, "conformance", @@ -282,6 +288,9 @@ pub fn build(b: *std.Build) !void { // Exe if (exe_) |exe| { + // Set PIE if requested + if (pie) exe.pie = true; + // Add the shared dependencies _ = try addDeps(b, exe, config);