Skip to content

Commit 6c65d9c

Browse files
committed
zig build: change "-Drelease" to "-Doptimize"
I find myself quite often creating ReleaseSafe builds and putting them to production for certain experiments: - Debug info are for stack traces. An ongoing example where those would help is #14815. - Safety checks would have saved a couple of mine and @kubkon's hours in #15098. This is a breaking change for scripts that make Zig releases -- I will submit another PR to zig-bootstrap and release-cutter after this is merged.
1 parent 8853005 commit 6c65d9c

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,9 @@ endif()
810810
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
811811
set(ZIG_RELEASE_ARG "")
812812
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
813-
set(ZIG_RELEASE_ARG -Drelease)
813+
set(ZIG_RELEASE_ARG -Doptimize=ReleaseFast)
814814
else()
815-
set(ZIG_RELEASE_ARG -Drelease -Dstrip)
815+
set(ZIG_RELEASE_ARG -Doptimize=ReleaseFast -Dstrip)
816816
endif()
817817
if(ZIG_NO_LIB)
818818
set(ZIG_NO_LIB_ARG "-Dno-lib")

build.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 };
1313
const stack_size = 32 * 1024 * 1024;
1414

1515
pub fn build(b: *std.Build) !void {
16-
const release = b.option(bool, "release", "Build in release mode") orelse false;
1716
const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false;
1817
const target = t: {
1918
var default_target: std.zig.CrossTarget = .{};
@@ -22,10 +21,10 @@ pub fn build(b: *std.Build) !void {
2221
}
2322
break :t b.standardTargetOptions(.{ .default_target = default_target });
2423
};
25-
const optimize: std.builtin.OptimizeMode = if (release) switch (target.getCpuArch()) {
26-
.wasm32 => .ReleaseSmall,
27-
else => .ReleaseFast,
28-
} else .Debug;
24+
25+
// TODO remove type annotation with ziglang/zig#13749
26+
const optimize: std.builtin.Mode = b.option(std.builtin.Mode, "optimize", "Prioritize performance, safety, or binary size (-O flag)") orelse
27+
if (target.getCpuArch() == .wasm32) .ReleaseSmall else .Debug;
2928

3029
const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode");
3130
const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false;

ci/aarch64-macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ stage3-release/bin/zig build \
5858
--prefix stage4-release \
5959
-Denable-llvm \
6060
-Dno-lib \
61-
-Drelease \
61+
-Doptimize=ReleaseFast \
6262
-Dstrip \
6363
-Dtarget=$TARGET \
6464
-Duse-zig-libcxx \

ci/x86_64-linux-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ stage3-release/bin/zig build \
7777
--prefix stage4-release \
7878
-Denable-llvm \
7979
-Dno-lib \
80-
-Drelease \
80+
-Doptimize=ReleaseFast \
8181
-Dstrip \
8282
-Dtarget=$TARGET \
8383
-Duse-zig-libcxx \

ci/x86_64-macos-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ stage3/bin/zig build \
6262
--prefix stage4 \
6363
-Denable-llvm \
6464
-Dno-lib \
65-
-Drelease \
65+
-Doptimize=ReleaseFast \
6666
-Dstrip \
6767
-Dtarget=$TARGET \
6868
-Duse-zig-libcxx \

0 commit comments

Comments
 (0)