#Can I make `zig build run` run the program with Wine when I cross-compile Linux -> Windows?

1 messages · Page 1 of 1 (latest)

broken isle
#

Here is my build.zig :

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{
        .whitelist = &.{.{
            .cpu_arch = .x86_64,
            .os_tag = .windows,
        }},
        .default_target = .{
            .cpu_arch = .x86_64,
            .os_tag = .windows,
        },
    });

    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "zig_test",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    const zigwin32 = b.dependency("zigwin32", .{});
    exe.root_module.addImport("zigwin32", zigwin32.module("zigwin32"));

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);
    if (b.host.result.os.tag != .windows) {
        // TODO Make the windows .exe file run with Wine.
    }

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

If its possible. How do I change it to make it run under Wine?

final rune
#

youd use b.addRunSystemCommand() instead of b.addRunArtifact
and then youd use run_cmd.addArgs(“wine”) and run_cmd.addArtifactArg(exe)

#

(and ofc pass it any options you want alongisde that)

indigo pebble
#

the build system actually supports this natively

final rune
#

oh it does?

indigo pebble
#

in zig build -h

#

ime just zig build run works but you may need -fwine, im not sure why it might not be needed sometimes

final rune
#

thats awesome

indigo pebble
#

indeed

#

zigs text matrix heavily relies on this i believe, the linux hosts test basically everything

broken isle
#

Yea -fwine works. Now i guess ill figure it out how to edit the build script to include that option by default.

indigo pebble
#

theres b.enable_wine but this doesnt feel like something you should be putting in the build script

#

although the field is documented so maybe its meant to be 🤷‍♂️

#

its not a function

final rune
#

another code base destroyed by lazy analysis 😔

broken isle
#

Hmm.

final rune
#

iif youre not on windows, it should fail to compile

#

since it would be analyzed

indigo pebble
#

b.host isnt even comptime known

#

this should be unconditionally analyzed

final rune
#

oh right, good point
hmm

broken isle
#

Ok I went abit fast there:

    if (b.host.result.os.tag != .windows) {
        b.enable_wine = true;
    }

Fixes the error.

austere glen
#
    b.enable_wine = target.result.os.tag == .windows and target.result.cpu.arch == .x86_64;
    b.enable_rosetta = target.result.os.tag == .macos and target.result.cpu.arch == .x86_64;
broken isle
#

Yea i guess your version is better for projects that can compile to multiple targets. Mine depends on WIN32 API so yea.