Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jackedak opened this issue Dec 3, 2024 · 21 comments
Open

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

jackedak opened this issue Dec 3, 2024 · 21 comments
Labels
bug Something isn't working

Comments

@jackedak
Copy link

jackedak commented Dec 3, 2024

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.

@AlbertShown
Copy link
Contributor

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
Copy link
Contributor

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

@jackedak
Copy link
Author

jackedak commented Dec 3, 2024

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

@jackedak
Copy link
Author

jackedak commented Dec 3, 2024

It also complains if I just rename the file.

@AlbertShown
Copy link
Contributor

while the program says it requires webui.dll

Which program we are talking about here?

@jackedak
Copy link
Author

jackedak commented Dec 3, 2024

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();
}

@jackedak
Copy link
Author

jackedak commented Dec 3, 2024

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);
}

@jinzhongjia
Copy link
Collaborator

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

@mochalins
Copy link
Contributor

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

@jinzhongjia
Copy link
Collaborator

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
Copy link
Collaborator

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

@jinzhongjia jinzhongjia added the bug Something isn't working label Dec 4, 2024
@jinzhongjia
Copy link
Collaborator

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

@jinzhongjia
Copy link
Collaborator

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 jinzhongjia changed the title Cannot enable TLS on windows. [Bug]: Enabling TLS on windows will cause non-found ssl Dec 23, 2024
@AlbertShown
Copy link
Contributor

AlbertShown commented Dec 23, 2024

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
Copy link
Contributor

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

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

@AlbertShown
Copy link
Contributor

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.

@jinzhongjia
Copy link
Collaborator

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
Copy link
Collaborator

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

@AlbertShown
Copy link
Contributor

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

@jinzhongjia
Copy link
Collaborator

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

@AlbertShown
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants