Skip to content

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

Open

Description

@avalyn0x45

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.

Activity

  1. AlbertShown commented on Dec 3, 2024

    @AlbertShown
    Member

    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.
  2. AlbertShown commented on Dec 3, 2024

    @AlbertShown
    Member

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

  3. avalyn0x45 commented on Dec 3, 2024

    @avalyn0x45
    Author

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

  4. avalyn0x45 commented on Dec 3, 2024

    @avalyn0x45
    Author

    It also complains if I just rename the file.

  5. AlbertShown commented on Dec 3, 2024

    @AlbertShown
    Member

    while the program says it requires webui.dll

    Which program we are talking about here?

  6. avalyn0x45 commented on Dec 3, 2024

    @avalyn0x45
    Author

    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();
    }
    
  7. avalyn0x45 commented on Dec 3, 2024

    @avalyn0x45
    Author

    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);
    }
    
  8. jinzhongjia commented on Dec 4, 2024

    @jinzhongjia
    Member

    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

  9. mochalins commented on Dec 4, 2024

    @mochalins
    Contributor

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

  10. jinzhongjia commented on Dec 4, 2024

    @jinzhongjia
    Member

    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

  11. jinzhongjia commented on Dec 4, 2024

    @jinzhongjia
    Member

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

  12. jinzhongjia commented on Dec 22, 2024

    @jinzhongjia
    Member

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

  13. jinzhongjia commented on Dec 23, 2024

    @jinzhongjia
    Member

    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

  14. changed the title [-]Cannot enable TLS on windows.[/-] [+][Bug]: Enabling TLS on windows will cause non-found ssl[/+] on Dec 23, 2024
  15. AlbertShown commented on Dec 23, 2024

    @AlbertShown
    Member

    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 }
  16. AlbertShown commented on Dec 23, 2024

    @AlbertShown
    Member
    WEBUI_TLS_INCLUDE="v{}" WEBUI_TLS_LIB="v{}"

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

  17. AlbertShown commented on Dec 23, 2024

    @AlbertShown
    Member
    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.

  18. jinzhongjia commented on Jan 11, 2025

    @jinzhongjia
    Member

    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

  19. jinzhongjia commented on Jan 24, 2025

    @jinzhongjia
    Member

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

  20. AlbertShown commented on Jan 24, 2025

    @AlbertShown
    Member

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

  21. jinzhongjia commented on Jan 24, 2025

    @jinzhongjia
    Member

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

  22. AlbertShown commented on Jan 24, 2025

    @AlbertShown
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions