zig-webui icon indicating copy to clipboard operation
zig-webui copied to clipboard

[Bug]: Enabling TLS on windows will cause non-found ssl

Open avalyn0x45 opened this issue 1 year ago • 21 comments

On my windows machine, whenever i try to compile with TLS enabled, zig says that it cannot find SSL or crypto, and that it has searched no paths. I have OpenSSL installed, an it is in path, and i have even tried directly linking libssl.

avalyn0x45 avatar Dec 03 '24 16:12 avalyn0x45

I'm not sure how to use TLS with Zig build ! @jinzhongjia, I guess we should add an option for TLS include and lib paths.

.enable_tls = false,
.tls_include = "PATH_TO_TLS_INCLUDE",
.tls_lib = "PATH_TO_TLS_LIB",

However, a workaround for now, is to you can manually build a dynamic version of webui + TLS using any C compiler:

  1. Clone webui repo
  2. Build with TLS: nmake WEBUI_USE_TLS=1 WEBUI_TLS_INCLUDE="PATH_TO_TLS_INCLUDE" WEBUI_TLS_LIB="PATH_TO_TLS_LIB"
  3. Build your Zig program .is_static = false,
  4. Manually replace the .dll with the one that have TLS

Note:

  • You can also download a trusted secure pre-compiled DLL + TLS (compiled by GitHub Workflow)
  • Zig build does not support cross-compiling, or Musl, when using TLS build.

AlbertShown avatar Dec 03 '24 17:12 AlbertShown

Another thing, make sure you have OpenSSL v3.3.1+ if you still have issues, please share the compiling logs and details.

AlbertShown avatar Dec 03 '24 17:12 AlbertShown

The pre-built files have the file webui-2.dll, while the program says it requires webui.dll, any idea why?

avalyn0x45 avatar Dec 03 '24 19:12 avalyn0x45

It also complains if I just rename the file.

avalyn0x45 avatar Dec 03 '24 19:12 avalyn0x45

while the program says it requires webui.dll

Which program we are talking about here?

AlbertShown avatar Dec 03 '24 21:12 AlbertShown

The program that utilizes zig-webui, which is currently just

const os = std.os;
const webui = @import("webui");

const main = @embedFile("main.html");

pub fn main() !void {
    var nwin = webui.newWindow();
    _ = nwin.show(main);
    webui.wait();
}

avalyn0x45 avatar Dec 03 '24 23:12 avalyn0x45

In case it matters, the build.zig is

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const exe = b.addExecutable(.{
        .name = "main",
        .root_source_file = b.path("src/main.zig"),
        .target = b.host,
    });
    const zig_webui = b.dependency("zig-webui", .{
        .target = target,
        .optimize = optimize,
        .is_static = false,
    });
    exe.subsystem = .Windows;
    exe.root_module.addImport("webui", zig_webui.module("webui"));
    b.installArtifact(exe);
}

avalyn0x45 avatar Dec 03 '24 23:12 avalyn0x45

Yes, the problem does exist on Windows, but the root cause of the problem is in the upstream webui. The build of webui cannot correctly find system libraries on windows I won't be able to deal with this issue for a short time, but maybe I can let him take a look. @mochalins

jinzhongjia avatar Dec 04 '24 02:12 jinzhongjia

I'll take a look, thanks for the ping.

mochalins avatar Dec 04 '24 02:12 mochalins

Past CI tests did not have tls testing. At least in the 0.11 period, tls was running normally. After the issue is resolved, you need to add the CI test of tls

jinzhongjia avatar Dec 04 '24 02:12 jinzhongjia

After about two weeks, I have a lot of free time to deal with the deposition problem of this library.

jinzhongjia avatar Dec 04 '24 02:12 jinzhongjia

OK,I'm back. I will try to fix it tomorrow

jinzhongjia avatar Dec 22 '24 15:12 jinzhongjia

Well, I tried for a few hours and still didn't find the perfect solution. The zig compiler never found the ssl library correctly, even if the path was specified. I will make additional attempts when I have time

jinzhongjia avatar Dec 23 '24 11:12 jinzhongjia

I guess the solution may look something like this:

.enable_tls = true,
.tls_include = "PATH_TO_TLS_INCLUDE", // Example: C:\Program Files\OpenSSL-xxx\include
.tls_lib = "PATH_TO_TLS_LIB", // Example: C:\Program Files\OpenSSL-xxx\lib

Compiling webui with TLS on Windows:

...... WEBUI_USE_TLS=1 WEBUI_TLS_INCLUDE="v{}" WEBUI_TLS_LIB="v{}", .{ tls_include, tls_lib }

AlbertShown avatar Dec 23 '24 18:12 AlbertShown

WEBUI_TLS_INCLUDE="v{}" WEBUI_TLS_LIB="v{}"

Of course those are just an example, need to be changed to -I and -L.

AlbertShown avatar Dec 23 '24 18:12 AlbertShown

tls_include = "PATH_TO_TLS_INCLUDE", // Example: C:\Program Files\OpenSSL-xxx\include
.tls_lib = "PATH_TO_TLS_LIB", // Example: C:\Program Files\OpenSSL-xxx\lib

Those options need to be added, I guess.

AlbertShown avatar Dec 23 '24 18:12 AlbertShown

Good idea, I will initiate a PR to the upstream and let webui's build.zig expose the option to set the location of the library

jinzhongjia avatar Jan 11 '25 14:01 jinzhongjia

A very strange problem, the Zig's construction system cannot find a package in the LIB and INCLUDE directory I specified, but GCC can

jinzhongjia avatar Jan 24 '25 06:01 jinzhongjia

@jinzhongjia feel free to change anything in upstream Zig build file if this may help you fixing the SSL issue for Zig.

AlbertShown avatar Jan 24 '25 14:01 AlbertShown

My previous attempt is to change directly in the upstream, but I still can't find the library.

jinzhongjia avatar Jan 24 '25 16:01 jinzhongjia

I will investigate in this, if I found a solution I will suggest it to you.

AlbertShown avatar Jan 24 '25 16:01 AlbertShown