|
| 1 | +const std = @import("std"); |
| 2 | + |
| 3 | +pub fn build(b: *std.Build) void { |
| 4 | + const target = b.standardTargetOptions(.{}); |
| 5 | + const optimize = b.standardOptimizeOption(.{}); |
| 6 | + |
| 7 | + const libssh2_dep = b.dependency("libssh2", .{ |
| 8 | + .target = target, |
| 9 | + .optimize = optimize, |
| 10 | + }); |
| 11 | + |
| 12 | + const mbedtls_dep = b.dependency("mbedtls", .{ |
| 13 | + .target = target, |
| 14 | + .optimize = optimize, |
| 15 | + }); |
| 16 | + |
| 17 | + const lib = b.addStaticLibrary(.{ |
| 18 | + .name = "ssh2", |
| 19 | + .target = target, |
| 20 | + .optimize = optimize, |
| 21 | + .link_libc = true, |
| 22 | + }); |
| 23 | + lib.addIncludePath(libssh2_dep.path("include")); |
| 24 | + lib.linkLibrary(mbedtls_dep.artifact("mbedtls")); |
| 25 | + lib.addCSourceFiles(.{ |
| 26 | + .root = libssh2_dep.path("src"), |
| 27 | + .flags = &.{}, |
| 28 | + .files = &.{ |
| 29 | + "channel.c", |
| 30 | + "comp.c", |
| 31 | + "crypt.c", |
| 32 | + "hostkey.c", |
| 33 | + "kex.c", |
| 34 | + "mac.c", |
| 35 | + "misc.c", |
| 36 | + "packet.c", |
| 37 | + "publickey.c", |
| 38 | + "scp.c", |
| 39 | + "session.c", |
| 40 | + "sftp.c", |
| 41 | + "userauth.c", |
| 42 | + "transport.c", |
| 43 | + "version.c", |
| 44 | + "knownhost.c", |
| 45 | + "agent.c", |
| 46 | + "mbedtls.c", |
| 47 | + "pem.c", |
| 48 | + "keepalive.c", |
| 49 | + "global.c", |
| 50 | + "blowfish.c", |
| 51 | + "bcrypt_pbkdf.c", |
| 52 | + "agent_win.c", |
| 53 | + }, |
| 54 | + }); |
| 55 | + lib.installHeader(b.path("config/libssh2_config.h"), "libssh2_config.h"); |
| 56 | + lib.installHeadersDirectory(libssh2_dep.path("include"), ".", .{}); |
| 57 | + lib.defineCMacro("LIBSSH2_MBEDTLS", null); |
| 58 | + |
| 59 | + if (target.result.os.tag == .windows) { |
| 60 | + lib.defineCMacro("_CRT_SECURE_NO_DEPRECATE", "1"); |
| 61 | + lib.defineCMacro("HAVE_LIBCRYPT32", null); |
| 62 | + lib.defineCMacro("HAVE_WINSOCK2_H", null); |
| 63 | + lib.defineCMacro("HAVE_IOCTLSOCKET", null); |
| 64 | + lib.defineCMacro("HAVE_SELECT", null); |
| 65 | + lib.defineCMacro("LIBSSH2_DH_GEX_NEW", "1"); |
| 66 | + |
| 67 | + if (target.result.isGnu()) { |
| 68 | + lib.defineCMacro("HAVE_UNISTD_H", null); |
| 69 | + lib.defineCMacro("HAVE_INTTYPES_H", null); |
| 70 | + lib.defineCMacro("HAVE_SYS_TIME_H", null); |
| 71 | + lib.defineCMacro("HAVE_GETTIMEOFDAY", null); |
| 72 | + } |
| 73 | + } else { |
| 74 | + lib.defineCMacro("HAVE_UNISTD_H", null); |
| 75 | + lib.defineCMacro("HAVE_INTTYPES_H", null); |
| 76 | + lib.defineCMacro("HAVE_STDLIB_H", null); |
| 77 | + lib.defineCMacro("HAVE_SYS_SELECT_H", null); |
| 78 | + lib.defineCMacro("HAVE_SYS_UIO_H", null); |
| 79 | + lib.defineCMacro("HAVE_SYS_SOCKET_H", null); |
| 80 | + lib.defineCMacro("HAVE_SYS_IOCTL_H", null); |
| 81 | + lib.defineCMacro("HAVE_SYS_TIME_H", null); |
| 82 | + lib.defineCMacro("HAVE_SYS_UN_H", null); |
| 83 | + lib.defineCMacro("HAVE_LONGLONG", null); |
| 84 | + lib.defineCMacro("HAVE_GETTIMEOFDAY", null); |
| 85 | + lib.defineCMacro("HAVE_INET_ADDR", null); |
| 86 | + lib.defineCMacro("HAVE_POLL", null); |
| 87 | + lib.defineCMacro("HAVE_SELECT", null); |
| 88 | + lib.defineCMacro("HAVE_SOCKET", null); |
| 89 | + lib.defineCMacro("HAVE_STRTOLL", null); |
| 90 | + lib.defineCMacro("HAVE_SNPRINTF", null); |
| 91 | + lib.defineCMacro("HAVE_O_NONBLOCK", null); |
| 92 | + } |
| 93 | + |
| 94 | + b.installArtifact(lib); |
| 95 | +} |
0 commit comments