[Bug]: Enabling TLS on windows will cause non-found ssl
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.
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:
- Clone webui repo
- Build with TLS:
nmake WEBUI_USE_TLS=1 WEBUI_TLS_INCLUDE="PATH_TO_TLS_INCLUDE" WEBUI_TLS_LIB="PATH_TO_TLS_LIB" - Build your Zig program
.is_static = false, - Manually replace the
.dllwith 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.
Another thing, make sure you have OpenSSL v3.3.1+ if you still have issues, please share the compiling logs and details.
The pre-built files have the file webui-2.dll, while the program says it requires webui.dll, any idea why?
It also complains if I just rename the file.
while the program says it requires webui.dll
Which program we are talking about here?
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();
}
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);
}
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
I'll take a look, thanks for the ping.
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
After about two weeks, I have a lot of free time to deal with the deposition problem of this library.
OK,I'm back. I will try to fix it tomorrow
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
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 }
WEBUI_TLS_INCLUDE="v{}" WEBUI_TLS_LIB="v{}"
Of course those are just an example, need to be changed to -I and -L.
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.
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
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 feel free to change anything in upstream Zig build file if this may help you fixing the SSL issue for Zig.
My previous attempt is to change directly in the upstream, but I still can't find the library.
I will investigate in this, if I found a solution I will suggest it to you.