From 311c58fb0bab7419ae0d5ced1be8d7476157daaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 6 Apr 2023 10:32:05 +0300 Subject: [PATCH] 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. --- CMakeLists.txt | 4 ++-- build.zig | 6 +----- ci/aarch64-macos.sh | 2 +- ci/x86_64-linux-release.sh | 2 +- ci/x86_64-macos-release.sh | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eef03325fecd..708ad37513af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -810,9 +810,9 @@ endif() if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(ZIG_RELEASE_ARG "") elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - set(ZIG_RELEASE_ARG -Drelease) + set(ZIG_RELEASE_ARG -Doptimize=ReleaseFast) else() - set(ZIG_RELEASE_ARG -Drelease -Dstrip) + set(ZIG_RELEASE_ARG -Doptimize=ReleaseFast -Dstrip) endif() if(ZIG_NO_LIB) set(ZIG_NO_LIB_ARG "-Dno-lib") diff --git a/build.zig b/build.zig index 9926d6e5ec1a..b49799a811a0 100644 --- a/build.zig +++ b/build.zig @@ -13,7 +13,7 @@ const zig_version = std.builtin.Version{ .major = 0, .minor = 11, .patch = 0 }; const stack_size = 32 * 1024 * 1024; pub fn build(b: *std.Build) !void { - const release = b.option(bool, "release", "Build in release mode") orelse false; + const optimize = b.standardOptimizeOption(.{}); const only_c = b.option(bool, "only-c", "Translate the Zig compiler to C code, with only the C backend enabled") orelse false; const target = t: { var default_target: std.zig.CrossTarget = .{}; @@ -22,10 +22,6 @@ pub fn build(b: *std.Build) !void { } break :t b.standardTargetOptions(.{ .default_target = default_target }); }; - const optimize: std.builtin.OptimizeMode = if (release) switch (target.getCpuArch()) { - .wasm32 => .ReleaseSmall, - else => .ReleaseFast, - } else .Debug; const single_threaded = b.option(bool, "single-threaded", "Build artifacts that run in single threaded mode"); 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; diff --git a/ci/aarch64-macos.sh b/ci/aarch64-macos.sh index b4533e149f27..76aa91c01bc1 100755 --- a/ci/aarch64-macos.sh +++ b/ci/aarch64-macos.sh @@ -58,7 +58,7 @@ stage3-release/bin/zig build \ --prefix stage4-release \ -Denable-llvm \ -Dno-lib \ - -Drelease \ + -Doptimize=ReleaseFast \ -Dstrip \ -Dtarget=$TARGET \ -Duse-zig-libcxx \ diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index 01088a793c8c..c7425d18f2ab 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -77,7 +77,7 @@ stage3-release/bin/zig build \ --prefix stage4-release \ -Denable-llvm \ -Dno-lib \ - -Drelease \ + -Doptimize=ReleaseFast \ -Dstrip \ -Dtarget=$TARGET \ -Duse-zig-libcxx \ diff --git a/ci/x86_64-macos-release.sh b/ci/x86_64-macos-release.sh index a4dedb4446f1..ed61a9583938 100755 --- a/ci/x86_64-macos-release.sh +++ b/ci/x86_64-macos-release.sh @@ -62,7 +62,7 @@ stage3/bin/zig build \ --prefix stage4 \ -Denable-llvm \ -Dno-lib \ - -Drelease \ + -Doptimize=ReleaseFast \ -Dstrip \ -Dtarget=$TARGET \ -Duse-zig-libcxx \