In zig 0.10 I sometimes put this into build.zig
:
const exe = b.addExecutable("prog", "src/prog.zig");
exe.strip = true;
But it seems now (0.11) this field has disappeared from ExecutableOptions
structure.
Is there a way to set it inside build.zig
still?
P.S.
I noticed several times that setting strip
to true
may speed up compilation.
(writing 3 MB to a storage or writing 30KB matters)
1 Like
The strip
field is still part of the Step.Compile
returned from addExecutable
, so your example should still work fine as long as you update the addExecutable
call to use ExecutableOptions
.
1 Like
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "srz",
.root_source_file = .{ .path = "src/srz.zig" },
.target = target,
.optimize = optimize,
.single_threaded = true,
.strip = true,
});
b.installArtifact(exe);
}
@mono:~/2-coding/zig-lang/srz4$ /opt/zig-0.11/zig build
/home/zed/2-coding/zig-lang/srz4/build.zig:14:10: error: no field named 'strip' in struct 'Build.ExecutableOptions'
.strip = true,
^~~~~
/opt/zig-0.11/lib/std/Build.zig:473:31: note: struct declared here
pub const ExecutableOptions = struct {
^~~~~~
referenced by:
runBuild__anon_7124: /opt/zig-0.11/lib/std/Build.zig:1638:27
As I said there is no strip
in ExecutableOptions
.
var exe = b.addExecutable(.{
.name = "srz",
.root_source_file = .{ .path = "src/srz.zig" },
.target = target,
.optimize = optimize,
.single_threaded = true,
});
exe.strip = true;
3 Likes
Thanks!
It was not so obvious for me.
Wow, it reduces compile-time by 30% for me. Thanks for sharing!
I did not investigate this issue thorough, probably it is a cache effect, I do not know TBH.
It’s because it avoids compiling the stack trace printing code. The long term plan to address this is incremental compilation so you only have to wait for that logic to compile once instead of every time you build.
4 Likes