Skip to content

Commit

Permalink
Generate new guid when building + separate logging to file from release
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Aug 21, 2021
1 parent 301078a commit 6dd47b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ZigWindowsTilingWindowManager: Tiling window manager for windows, inspired by dw
1. Clone the repository using `git clone --recurse-submodules https://github.com/Nimaoth/zwtwm.git`
2. Install zig. I developed using zig version `0.8.0-dev.1140+9270aae07`, might not build with other versions.
3. For a release build (logs to file instead of console, ReleaseFast configuration), run `zig build --prefix dist -Drelease`
4. For a debug build (logs to the console, Debug configuration), run `zig build --prefix dist`
4. For a debug build (logs to the console, Debug configuration), run `zig build --prefix dist -Dconsole`
5. Use files in `<zwtwm-repository>/dist/bin`

## Configuration
Expand Down
40 changes: 31 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
const std = @import("std");

const Guid = std.os.windows.GUID;

pub extern "RPCRT4" fn UuidCreate(
Uuid: *Guid,
) callconv(std.os.windows.WINAPI) i32;

pub extern "RPCRT4" fn UuidToStringA(
Uuid: *Guid,
StringUuid: *[*:0]u8,
) callconv(@import("std").os.windows.WINAPI) i32;

pub extern "RPCRT4" fn RpcStringFreeA(
String: *[*:0]u8,
) callconv(@import("std").os.windows.WINAPI) i32;

pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
Expand All @@ -9,23 +24,30 @@ pub fn build(b: *std.build.Builder) void {

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe
const release = b.option(bool, "release", "Optimizations on and safety on, log to file") orelse false;
const release = b.option(bool, "release", "Optimizations on and safety on.") orelse false;
const console = b.option(bool, "console", "Log to the console.") orelse false;
std.log.info("Building with release={}, console={}", .{ release, console });

var mode = if (release) std.builtin.Mode.ReleaseSafe else std.builtin.Mode.Debug;
mode = .Debug;
b.is_release = mode != .Debug;
b.release_mode = mode;

// Generate guid
var guid: Guid = undefined;
_ = UuidCreate(&guid);
var guidStringPtr: [*:0]u8 = undefined;
_ = UuidToStringA(&guid, &guidStringPtr);
const guidString = guidStringPtr[0..std.mem.len(guidStringPtr)];
std.log.info("Using tray icon guid: {s}", .{guidString});
defer _ = RpcStringFreeA(&guidStringPtr);

const exe = b.addExecutable(if (release) "zwtwm" else "zwtwm_debug", "src/main.zig");
exe.addBuildOption(bool, "RUN_IN_CONSOLE", !release);
if (release) {
exe.addBuildOption([]const u8, "TRAY_GUID", "99b74174-d3a4-48ba-a886-9af100149755");
} else {
exe.addBuildOption([]const u8, "TRAY_GUID", "b3e926bb-e7ee-4f2a-b513-0080167ec220");
}
exe.subsystem = if (release) .Windows else .Console;
exe.addBuildOption(bool, "RUN_IN_CONSOLE", console);
exe.addBuildOption([]const u8, "TRAY_GUID", guidString);
exe.addPackage(.{ .name = "zigwin32", .path = "./deps/custom_zigwin32/win32.zig" });

exe.subsystem = if (!console) .Windows else .Console;
std.log.info("Using subsystem {}", .{exe.subsystem});
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
Expand Down

0 comments on commit 6dd47b6

Please sign in to comment.