zap icon indicating copy to clipboard operation
zap copied to clipboard

Find libopenssl instead of libssl

Open joeypas opened this issue 1 year ago • 1 comments

I don't know if this is an issue on all platforms, and might require some editing if it's not, but on MacOS building fails when trying to link openssl.

zig build-lib facil.io Debug native: error: error: unable to find Dynamic system library 'ssl' using strategy 'paths_first'. searched paths:
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libssl.tbd
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libssl.dylib
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libssl.so
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libssl.a
error: unable to find Dynamic system library 'crypto' using strategy 'paths_first'. searched paths:
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libcrypto.tbd
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libcrypto.dylib
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libcrypto.so
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/libcrypto.a

Changing the one line fixes the issue.

joeypas avatar Apr 12 '24 17:04 joeypas

Thx for this. Not sure this is the correct solution, tho. I think it used to work on my mac as is. I would at least make the change platform dependent. You can see it in build.zig: if (target.result.os.tag == .windows) { ...

renerocksai avatar Apr 19 '24 08:04 renerocksai

This is the change we made in our repo to support building on macOS. Unfortunately the way macOS / Xcode links these libraries is a bit of a mess.

    // link in libopenssl and libcrypto on demand
    if (use_openssl) {
        switch (@import("builtin").os.tag) {
            .linux => {
                lib.linkSystemLibrary("ssl");
                lib.linkSystemLibrary("crypto");
            },
            else => {
                lib.linkSystemLibrary2("libssl", .{ .use_pkg_config = .force });
                lib.linkSystemLibrary2("libcrypto", .{ .use_pkg_config = .force });
            },
        }
    }

dwolrdcojp avatar May 30 '24 15:05 dwolrdcojp