build: add PIE (Position Independent Executable) option (#1013)

* build: add PIE (Position Independent Executable) option
This commit is contained in:
Orhun Parmaksız 2023-02-20 23:40:05 +02:00 committed by GitHub
parent 8bd5358748
commit b635317e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ pub fn build(b: *std.build.Builder) !void {
const exe_options = b.addOptions(); const exe_options = b.addOptions();
exe.addOptions("build_options", exe_options); exe.addOptions("build_options", exe_options);
const pie = b.option(bool, "pie", "Build a Position Independent Executable");
const enable_tracy = b.option(bool, "enable_tracy", "Whether tracy should be enabled.") orelse false; const enable_tracy = b.option(bool, "enable_tracy", "Whether tracy should be enabled.") orelse false;
const coverage = b.option(bool, "generate_coverage", "Generate coverage data with kcov") orelse false; const coverage = b.option(bool, "generate_coverage", "Generate coverage data with kcov") orelse false;
const coverage_output_dir = b.option([]const u8, "coverage_output_dir", "Output directory for coverage data") orelse b.pathJoin(&.{ b.install_prefix, "kcov" }); const coverage_output_dir = b.option([]const u8, "coverage_output_dir", "Output directory for coverage data") orelse b.pathJoin(&.{ b.install_prefix, "kcov" });
@ -154,6 +155,7 @@ pub fn build(b: *std.build.Builder) !void {
} }
} }
exe.pie = pie;
exe.install(); exe.install();
const gen_exe = b.addExecutable(.{ const gen_exe = b.addExecutable(.{
@ -183,7 +185,7 @@ pub fn build(b: *std.build.Builder) !void {
"test-filter", "test-filter",
"Skip tests that do not match filter", "Skip tests that do not match filter",
); );
var tests = b.addTest(.{ var tests = b.addTest(.{
.root_source_file = .{ .path = "tests/tests.zig" }, .root_source_file = .{ .path = "tests/tests.zig" },
.target = target, .target = target,