Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions LICENSE
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically illegal for me to add this.

Therefore:
I license my additions made in this PR under the BSD 3-clause license. Existing code remains under a proprietary license.

See #3.

(And yes, I know that's not how that works)

Original file line number Diff line number Diff line change
@@ -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.
120 changes: 75 additions & 45 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
22 changes: 12 additions & 10 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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",
},
}
24 changes: 0 additions & 24 deletions src/main.zig

This file was deleted.

10 changes: 0 additions & 10 deletions src/root.zig

This file was deleted.

5 changes: 5 additions & 0 deletions test/test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const libssh = @import("libssh2");

test "compiles" {
// libssh.
}