From 3936b471a8a3e67573d9ad0628f98c8970f56705 Mon Sep 17 00:00:00 2001 From: Krzysztof Wolicki Date: Thu, 19 Oct 2023 09:39:20 +0200 Subject: [PATCH] Disable iconv on Windows by default (enabled via cli flag). Skip various tests not implemented on windows. --- build.zig | 2 ++ pkg/fontconfig/build.zig | 7 ++++++- src/Command.zig | 4 ++++ src/Pty.zig | 1 + src/os/desktop.zig | 1 + src/os/passwd.zig | 1 + src/os/xdg.zig | 8 +++++++- 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index a6b4f9364..4850027a5 100644 --- a/build.zig +++ b/build.zig @@ -621,9 +621,11 @@ fn addDeps( const js_dep = b.dependency("zig_js", .{ .target = step.target, .optimize = step.optimize }); const libxev_dep = b.dependency("libxev", .{ .target = step.target, .optimize = step.optimize }); const objc_dep = b.dependency("zig_objc", .{ .target = step.target, .optimize = step.optimize }); + const iconv_win_enabled = b.option(bool, "enable-iconv-win", "Build libxml2 for fontconfig with iconv on Windows") orelse false; const fontconfig_dep = b.dependency("fontconfig", .{ .target = step.target, .optimize = step.optimize, + .iconv_win_enabled = iconv_win_enabled, }); const freetype_dep = b.dependency("freetype", .{ .target = step.target, diff --git a/pkg/fontconfig/build.zig b/pkg/fontconfig/build.zig index 01eb46181..c5350235d 100644 --- a/pkg/fontconfig/build.zig +++ b/pkg/fontconfig/build.zig @@ -6,6 +6,7 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const libxml2_enabled = b.option(bool, "enable-libxml2", "Build libxml2") orelse true; + const iconv_win_enabled = b.option(bool, "enable-iconv-win", "Build libxml2 with iconv on Windows") orelse false; const freetype_enabled = b.option(bool, "enable-freetype", "Build freetype") orelse true; _ = b.addModule("fontconfig", .{ .source_file = .{ .path = "main.zig" } }); @@ -25,7 +26,11 @@ pub fn build(b: *std.Build) !void { lib.linkLibrary(freetype_dep.artifact("freetype")); } if (libxml2_enabled) { - const libxml2_dep = b.dependency("libxml2", .{ .target = target, .optimize = optimize }); + const libxml2_dep = b.dependency("libxml2", .{ + .target = target, + .optimize = optimize, + .iconv = !(target.getOsTag() == .windows) or iconv_win_enabled, + }); lib.linkLibrary(libxml2_dep.artifact("xml2")); } diff --git a/src/Command.zig b/src/Command.zig index b9d282aa7..ce606f770 100644 --- a/src/Command.zig +++ b/src/Command.zig @@ -355,6 +355,7 @@ test "createNullDelimitedEnvMap" { } test "Command: pre exec" { + if (builtin.os.tag == .windows) return error.SkipZigTest; var cmd: Command = .{ .path = "/usr/bin/env", .args = &.{ "/usr/bin/env", "-v" }, @@ -375,6 +376,7 @@ test "Command: pre exec" { } test "Command: redirect stdout to file" { + if (builtin.os.tag == .windows) return error.SkipZigTest; var td = try TempDir.init(); defer td.deinit(); var stdout = try td.dir.createFile("stdout.txt", .{ .read = true }); @@ -400,6 +402,7 @@ test "Command: redirect stdout to file" { } test "Command: custom env vars" { + if (builtin.os.tag == .windows) return error.SkipZigTest; var td = try TempDir.init(); defer td.deinit(); var stdout = try td.dir.createFile("stdout.txt", .{ .read = true }); @@ -430,6 +433,7 @@ test "Command: custom env vars" { } test "Command: custom working directory" { + if (builtin.os.tag == .windows) return error.SkipZigTest; var td = try TempDir.init(); defer td.deinit(); var stdout = try td.dir.createFile("stdout.txt", .{ .read = true }); diff --git a/src/Pty.zig b/src/Pty.zig index 3bbcb713a..c1e8efd18 100644 --- a/src/Pty.zig +++ b/src/Pty.zig @@ -128,6 +128,7 @@ pub fn childPreExec(self: Pty) !void { } test { + if (builtin.os.tag == .windows) return error.SkipZigTest; var ws: winsize = .{ .ws_row = 50, .ws_col = 80, diff --git a/src/os/desktop.zig b/src/os/desktop.zig index f7717cf65..fdc714c65 100644 --- a/src/os/desktop.zig +++ b/src/os/desktop.zig @@ -40,6 +40,7 @@ pub fn launchedFromDesktop() bool { break :linux gio_pid == pid; }, + .windows => false, else => @compileError("unsupported platform"), }; diff --git a/src/os/passwd.zig b/src/os/passwd.zig index 32d93da3b..b3e3dcc12 100644 --- a/src/os/passwd.zig +++ b/src/os/passwd.zig @@ -138,6 +138,7 @@ pub fn get(alloc: Allocator) !Entry { } test { + if (builtin.os.tag == .windows) return error.SkipZigTest; const testing = std.testing; var arena = ArenaAllocator.init(testing.allocator); defer arena.deinit(); diff --git a/src/os/xdg.zig b/src/os/xdg.zig index cab8aab3d..4c0b465db 100644 --- a/src/os/xdg.zig +++ b/src/os/xdg.zig @@ -20,7 +20,8 @@ pub const Options = struct { /// Get the XDG user config directory. The returned value is allocated. pub fn config(alloc: Allocator, opts: Options) ![]u8 { - if (std.os.getenv("XDG_CONFIG_HOME")) |env| { + if (std.process.getEnvVarOwned(alloc, "XDG_CONFIG_HOME")) |env| { + defer alloc.free(env); // If we have a subdir, then we use the env as-is to avoid a copy. if (opts.subdir) |subdir| { return try std.fs.path.join(alloc, &[_][]const u8{ @@ -30,6 +31,11 @@ pub fn config(alloc: Allocator, opts: Options) ![]u8 { } return try alloc.dupe(u8, env); + } else |err| { + switch (err) { + error.EnvironmentVariableNotFound => {}, + else => return err, + } } // If we have a cached home dir, use that.