diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4946a11 --- /dev/null +++ b/LICENSE @@ -0,0 +1,32 @@ +Redistribution and use in source and binary forms, +with or without modification, are permitted provided +that the following conditions are met: + +1. Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials + provided with the distribution. + +3. Neither the name of the copyright holder nor the names + of any other contributors may be used to endorse or + promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGE. diff --git a/build.zig b/build.zig index 7177203..c5b7f1d 100644 --- a/build.zig +++ b/build.zig @@ -3,6 +3,7 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const version: std.SemanticVersion = .{ .major = 1, .minor = 11, .patch = 1 }; const libssh2_dep = b.dependency("libssh2", .{ .target = target, @@ -14,82 +15,111 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - const lib = b.addStaticLibrary(.{ - .name = "ssh2", + const lib_mod = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true, }); - lib.addIncludePath(libssh2_dep.path("include")); - lib.linkLibrary(mbedtls_dep.artifact("mbedtls")); - lib.addCSourceFiles(.{ + + const lib = b.addLibrary(.{ + .name = "ssh2", + .version = version, + .root_module = lib_mod, + .linkage = .static, + }); + lib_mod.addIncludePath(libssh2_dep.path("include")); + lib_mod.linkLibrary(mbedtls_dep.artifact("mbedtls")); + lib_mod.addCSourceFiles(.{ .root = libssh2_dep.path("src"), .flags = &.{}, .files = &.{ + "agent.c", + "bcrypt_pbkdf.c", + "blowfish.c", + "chacha.c", "channel.c", + "cipher-chachapoly.c", "comp.c", "crypt.c", + "global.c", "hostkey.c", + "keepalive.c", "kex.c", + "knownhost.c", + "libgcrypt.c", "mac.c", + "mbedtls.c", "misc.c", + "openssl.c", + "os400qc3.c", "packet.c", + "pem.c", + "poly1305.c", "publickey.c", "scp.c", "session.c", "sftp.c", - "userauth.c", "transport.c", + "userauth.c", + "userauth_kbd_packet.c", "version.c", - "knownhost.c", - "agent.c", - "mbedtls.c", - "pem.c", - "keepalive.c", - "global.c", - "blowfish.c", - "bcrypt_pbkdf.c", - "agent_win.c", + "wincng.c", }, }); lib.installHeader(b.path("config/libssh2_config.h"), "libssh2_config.h"); lib.installHeadersDirectory(libssh2_dep.path("include"), ".", .{}); - lib.defineCMacro("LIBSSH2_MBEDTLS", null); + lib_mod.addCMacro("LIBSSH2_MBEDTLS", ""); 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_mod.addCMacro("_CRT_SECURE_NO_DEPRECATE", "1"); + lib_mod.addCMacro("HAVE_LIBCRYPT32", ""); + lib_mod.addCMacro("HAVE_WINSOCK2_H", ""); + lib_mod.addCMacro("HAVE_IOCTLSOCKET", ""); + lib_mod.addCMacro("HAVE_SELECT", ""); + lib_mod.addCMacro("LIBSSH2_DH_GEX_NEW", "1"); - 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); + if (target.result.abi.isGnu()) { + lib_mod.addCMacro("HAVE_UNISTD_H", ""); + lib_mod.addCMacro("HAVE_INTTYPES_H", ""); + lib_mod.addCMacro("HAVE_SYS_TIME_H", ""); + lib_mod.addCMacro("HAVE_GETTIMEOFDAY", ""); } } 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); + lib_mod.addCMacro("HAVE_UNISTD_H", ""); + lib_mod.addCMacro("HAVE_INTTYPES_H", ""); + lib_mod.addCMacro("HAVE_STDLIB_H", ""); + lib_mod.addCMacro("HAVE_SYS_SELECT_H", ""); + lib_mod.addCMacro("HAVE_SYS_UIO_H", ""); + lib_mod.addCMacro("HAVE_SYS_SOCKET_H", ""); + lib_mod.addCMacro("HAVE_SYS_IOCTL_H", ""); + lib_mod.addCMacro("HAVE_SYS_TIME_H", ""); + lib_mod.addCMacro("HAVE_SYS_UN_H", ""); + lib_mod.addCMacro("HAVE_LONGLONG", ""); + lib_mod.addCMacro("HAVE_GETTIMEOFDAY", ""); + lib_mod.addCMacro("HAVE_INET_ADDR", ""); + lib_mod.addCMacro("HAVE_POLL", ""); + lib_mod.addCMacro("HAVE_SELECT", ""); + lib_mod.addCMacro("HAVE_SOCKET", ""); + lib_mod.addCMacro("HAVE_STRTOLL", ""); + lib_mod.addCMacro("HAVE_SNPRINTF", ""); + lib_mod.addCMacro("HAVE_O_NONBLOCK", ""); } b.installArtifact(lib); + + const lib_unit_tests_mod = b.createModule(.{ + .root_source_file = b.path("test/test.zig"), + .target = target, + .optimize = optimize, + }); + lib_unit_tests_mod.addImport("libssh2", lib_mod); + lib_unit_tests_mod.linkLibrary(lib); + const lib_unit_tests = b.addTest(.{ + .root_module = lib_unit_tests_mod, + }); + + 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); } diff --git a/build.zig.zon b/build.zig.zon index 8f4b862..cee4888 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -6,16 +6,18 @@ // // It is redundant to include "zig" in this name because it is already // within the Zig package namespace. - .name = "libssh2", + .name = .libssh2, // 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 = "1.11.1", + + .fingerprint = 0x57bdea04ee07dcb3, // Changing this has security and trust implications. // This field is optional. // This is currently advisory only; Zig does not yet do anything // with this value. - //.minimum_zig_version = "0.11.0", + .minimum_zig_version = "0.14.0", // This field is optional. // Each dependency must either provide a `url` and `hash`, or a `path`. @@ -24,20 +26,20 @@ // internet connectivity. .dependencies = .{ .libssh2 = .{ - .url = "https://github.com/libssh2/libssh2/archive/refs/tags/libssh2-1.11.0.tar.gz", - .hash = "1220a0863be6190270168974107d04653087aacc89e72cd81914789cb7d84b744fda", + .url = "git+https://github.com/libssh2/libssh2?ref=1.11.1#a312b43325e3383c865a87bb1d26cb52e3292641", + .hash = "N-V-__8AAATRLQBu_rNy4X2UK6RtcdYK_yAzkV6OcCqgo5aK", }, .mbedtls = .{ - .url = "git+https://github.com/allyourcodebase/mbedtls.git#e4da72f6a8bedc883e34953514a3b62cbbd4f251", - .hash = "1220ffeef9740c79b6f62f6bf350f12a7b14768acf548cb47cd56c5ca58a15af7970", + .url = "git+https://github.com/allyourcodebase/mbedtls#7d862fe61ff2eac37ee54e1e017fc287bed1cd7a", + .hash = "mbedtls-3.6.2-E4NURzYUAABWLBwHJWx_ppb_j2kDSoGfCfR2rI2zs9dz", }, }, .paths = .{ + "LICENSE", + "README.md", "build.zig", "build.zig.zon", "src", - // For example... - //"LICENSE", - //"README.md", + "config", }, } 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 deleted file mode 100644 index ecfeade..0000000 --- a/src/root.zig +++ /dev/null @@ -1,10 +0,0 @@ -const std = @import("std"); -const testing = std.testing; - -export fn add(a: i32, b: i32) i32 { - return a + b; -} - -test "basic add functionality" { - try testing.expect(add(3, 7) == 10); -} diff --git a/test/test.zig b/test/test.zig new file mode 100644 index 0000000..e6f5a0b --- /dev/null +++ b/test/test.zig @@ -0,0 +1,5 @@ +const libssh = @import("libssh2"); + +test "compiles" { + // libssh. +}