From 8635e1e68a4ddc134ee06c2f11aa12fcc341f4eb Mon Sep 17 00:00:00 2001 From: Elliot Huang Date: Wed, 25 Dec 2024 12:23:59 +0800 Subject: [PATCH] fix config directory not included in zon --- build.zig | 152 +++++++++++++++++++++------------------- build.zig.zon | 14 ++-- config/libssh2_config.h | 10 --- src/main.zig | 24 ------- src/root.zig | 3 + 5 files changed, 90 insertions(+), 113 deletions(-) delete mode 100644 config/libssh2_config.h delete mode 100644 src/main.zig diff --git a/build.zig b/build.zig index 7177203..5537bdf 100644 --- a/build.zig +++ b/build.zig @@ -4,92 +4,100 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const libssh2_dep = b.dependency("libssh2", .{ + const ssh2_dep = b.dependency("libssh2", .{}); + + const openssl_dep = b.dependency("openssl", .{ .target = target, .optimize = optimize, }); - const mbedtls_dep = b.dependency("mbedtls", .{ - .target = target, - .optimize = optimize, + const config_h = b.addConfigHeader(.{ + .style = .{ .cmake = ssh2_dep.path("src/libssh2_config_cmake.h.in") }, + .include_path = "libssh2_config.h", + }, .{ + .HAVE_UNISTD_H = 1, + .HAVE_INTTYPES_H = 1, + .HAVE_SYS_SELECT_H = 1, + .HAVE_SYS_UIO_H = 1, + .HAVE_SYS_SOCKET_H = 1, + .HAVE_SYS_IOCTL_H = 1, + .HAVE_SYS_TIME_H = 1, + .HAVE_SYS_UN_H = 1, + .HAVE_SYS_PARAM_H = 1, + .HAVE_ARPA_INET_H = 1, + .HAVE_NETINET_IN_H = 1, + .HAVE_GETTIMEOFDAY = 1, + .HAVE_STRTOLL = 1, + .HAVE_STRTOI64 = null, + .HAVE_SNPRINTF = 1, + .HAVE_EXPLICIT_BZERO = 1, + .HAVE_EXPLICIT_MEMSET = null, + .HAVE_MEMSET_S = null, + .HAVE_POLL = 1, + .HAVE_SELECT = 1, + .HAVE_O_NONBLOCK = 1, + .HAVE_FIONBIO = null, + .HAVE_IOCTLSOCKET_CASE = null, + .HAVE_SO_NONBLOCK = null, + .LIBSSH2_API = "__attribute__ ((__visibility__ (\"default\")))", }); const lib = b.addStaticLibrary(.{ .name = "ssh2", .target = target, .optimize = optimize, - .link_libc = true, }); - lib.addIncludePath(libssh2_dep.path("include")); - lib.linkLibrary(mbedtls_dep.artifact("mbedtls")); + lib.linkLibrary(openssl_dep.artifact("openssl")); + lib.defineCMacro("HAVE_CONFIG_H", null); + lib.defineCMacro("LIBSSH2_OPENSSL", null); + lib.addConfigHeader(config_h); lib.addCSourceFiles(.{ - .root = libssh2_dep.path("src"), + .root = ssh2_dep.path("src"), + .files = &ssh_src, .flags = &.{}, - .files = &.{ - "channel.c", - "comp.c", - "crypt.c", - "hostkey.c", - "kex.c", - "mac.c", - "misc.c", - "packet.c", - "publickey.c", - "scp.c", - "session.c", - "sftp.c", - "userauth.c", - "transport.c", - "version.c", - "knownhost.c", - "agent.c", - "mbedtls.c", - "pem.c", - "keepalive.c", - "global.c", - "blowfish.c", - "bcrypt_pbkdf.c", - "agent_win.c", - }, }); - lib.installHeader(b.path("config/libssh2_config.h"), "libssh2_config.h"); - lib.installHeadersDirectory(libssh2_dep.path("include"), ".", .{}); - lib.defineCMacro("LIBSSH2_MBEDTLS", null); - - if (target.result.os.tag == .windows) { - lib.defineCMacro("_CRT_SECURE_NO_DEPRECATE", "1"); - lib.defineCMacro("HAVE_LIBCRYPT32", null); - lib.defineCMacro("HAVE_WINSOCK2_H", null); - lib.defineCMacro("HAVE_IOCTLSOCKET", null); - lib.defineCMacro("HAVE_SELECT", null); - lib.defineCMacro("LIBSSH2_DH_GEX_NEW", "1"); + lib.addIncludePath(ssh2_dep.path("src")); + lib.addIncludePath(ssh2_dep.path("include")); + lib.installHeadersDirectory(ssh2_dep.path("include"), "", .{}); + lib.installConfigHeader(config_h); + b.installArtifact(lib); - if (target.result.isGnu()) { - lib.defineCMacro("HAVE_UNISTD_H", null); - lib.defineCMacro("HAVE_INTTYPES_H", null); - lib.defineCMacro("HAVE_SYS_TIME_H", null); - lib.defineCMacro("HAVE_GETTIMEOFDAY", null); - } - } else { - lib.defineCMacro("HAVE_UNISTD_H", null); - lib.defineCMacro("HAVE_INTTYPES_H", null); - lib.defineCMacro("HAVE_STDLIB_H", null); - lib.defineCMacro("HAVE_SYS_SELECT_H", null); - lib.defineCMacro("HAVE_SYS_UIO_H", null); - lib.defineCMacro("HAVE_SYS_SOCKET_H", null); - lib.defineCMacro("HAVE_SYS_IOCTL_H", null); - lib.defineCMacro("HAVE_SYS_TIME_H", null); - lib.defineCMacro("HAVE_SYS_UN_H", null); - lib.defineCMacro("HAVE_LONGLONG", null); - lib.defineCMacro("HAVE_GETTIMEOFDAY", null); - lib.defineCMacro("HAVE_INET_ADDR", null); - lib.defineCMacro("HAVE_POLL", null); - lib.defineCMacro("HAVE_SELECT", null); - lib.defineCMacro("HAVE_SOCKET", null); - lib.defineCMacro("HAVE_STRTOLL", null); - lib.defineCMacro("HAVE_SNPRINTF", null); - lib.defineCMacro("HAVE_O_NONBLOCK", null); - } + const lib_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); - b.installArtifact(lib); + const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_lib_unit_tests.step); } + +const ssh_src = [_][]const u8{ + "agent.c", + "bcrypt_pbkdf.c", + "chacha.c", + "channel.c", + "cipher-chachapoly.c", + "comp.c", + "crypt.c", + "crypto.c", + "global.c", + "hostkey.c", + "keepalive.c", + "kex.c", + "knownhost.c", + "mac.c", + "misc.c", + "packet.c", + "pem.c", + "poly1305.c", + "publickey.c", + "scp.c", + "session.c", + "sftp.c", + "transport.c", + "userauth.c", + "userauth_kbd_packet.c", + "version.c", +}; diff --git a/build.zig.zon b/build.zig.zon index 8f4b862..54b5bbd 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -6,11 +6,11 @@ // // It is redundant to include "zig" in this name because it is already // within the Zig package namespace. - .name = "libssh2", + .name = "libssh2-1.11.0", // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. - .version = "1.11.0", + .version = "0.0.0", // This field is optional. // This is currently advisory only; Zig does not yet do anything @@ -24,12 +24,12 @@ // internet connectivity. .dependencies = .{ .libssh2 = .{ - .url = "https://github.com/libssh2/libssh2/archive/refs/tags/libssh2-1.11.0.tar.gz", - .hash = "1220a0863be6190270168974107d04653087aacc89e72cd81914789cb7d84b744fda", + .url = "https://github.com/libssh2/libssh2/releases/download/libssh2-1.11.1/libssh2-1.11.1.tar.gz", + .hash = "12207b71b0f7f0ecd3dcc0cb0959eb75d697f34904fe65b2adf5dffba48800d34ce8", }, - .mbedtls = .{ - .url = "git+https://github.com/allyourcodebase/mbedtls.git#e4da72f6a8bedc883e34953514a3b62cbbd4f251", - .hash = "1220ffeef9740c79b6f62f6bf350f12a7b14768acf548cb47cd56c5ca58a15af7970", + .openssl = .{ + .url = "https://github.com/allyourcodebase/openssl/archive/refs/tags/3.3.1-1.tar.gz", + .hash = "12207c40cefa38fe90e4230dfba2e5c76b37e1ee36602512cad8ff0501f892002a65", }, }, .paths = .{ diff --git a/config/libssh2_config.h b/config/libssh2_config.h deleted file mode 100644 index eb30d10..0000000 --- a/config/libssh2_config.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LIBSSH2_CONFIG_H -#define LIBSSH2_CONFIG_H - -#ifdef WIN32 -#include -#include -#include -#endif - -#endif diff --git a/src/main.zig b/src/main.zig deleted file mode 100644 index c8a3f67..0000000 --- a/src/main.zig +++ /dev/null @@ -1,24 +0,0 @@ -const std = @import("std"); - -pub fn main() !void { - // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) - std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); - - // stdout is for the actual output of your application, for example if you - // are implementing gzip, then only the compressed bytes should be sent to - // stdout, not any debugging messages. - const stdout_file = std.io.getStdOut().writer(); - var bw = std.io.bufferedWriter(stdout_file); - const stdout = bw.writer(); - - try stdout.print("Run `zig build test` to run the tests.\n", .{}); - - try bw.flush(); // don't forget to flush! -} - -test "simple test" { - var list = std.ArrayList(i32).init(std.testing.allocator); - defer list.deinit(); // try commenting this out and see if zig detects the memory leak! - try list.append(42); - try std.testing.expectEqual(@as(i32, 42), list.pop()); -} diff --git a/src/root.zig b/src/root.zig index ecfeade..f034ca3 100644 --- a/src/root.zig +++ b/src/root.zig @@ -1,3 +1,6 @@ +//! By convention, root.zig is the root source file when making a library. If +//! you are making an executable, the convention is to delete this file and +//! start with main.zig instead. const std = @import("std"); const testing = std.testing;