Skip to content
Open
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
96 changes: 64 additions & 32 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ pub fn build(b: *std.Build) void {
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "urcrypt",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -99,10 +102,13 @@ fn libaes_siv(
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "aes_siv",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibrary(openssl.artifact("ssl"));
Expand Down Expand Up @@ -142,10 +148,13 @@ fn libsecp256k1(
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "secp256k1",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -207,10 +216,13 @@ fn libargon2(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "argon2",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -266,10 +278,13 @@ fn libblake3(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "blake3",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -325,10 +340,13 @@ fn libed25519(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "ed25519",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -374,10 +392,13 @@ fn libge_additions(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "ge_additions",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -413,10 +434,13 @@ fn libkeccak_tiny(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "keccak_tiny",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -452,10 +476,13 @@ fn libmonocypher(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "monocypher",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -487,10 +514,13 @@ fn libscrypt(
//});
const dep_c = b;

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "scrypt",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.linkLibC();
Expand Down Expand Up @@ -537,8 +567,10 @@ fn add_test(

const test_exe = b.addExecutable(.{
.name = name,
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

// const target_output = b.addInstallArtifact(test_exe, .{
Expand Down
3 changes: 2 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.{
.name = "urcrypt",
.name = .urcrypt,
.version = "0.0.1",
.fingerprint = 0x590576be3f10afc9,
.dependencies = .{
.aes_siv = .{
.url = "https://github.com/dfoxfranke/libaes_siv/archive/9681279cfaa6e6399bb7ca3afbbc27fc2e19df4b.tar.gz",
Expand Down
62 changes: 33 additions & 29 deletions ext/openssl/build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

pub fn build(b: *std.Build) !void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

Expand All @@ -14,13 +14,13 @@ pub fn build(b: *std.Build) !void {

const linux_cflags = .{};

const crypto = try libcrypto(
const crypto = libcrypto(
b,
target,
optimize,
if (target.result.isDarwin()) &macos_cflags else &linux_cflags,
if (target.result.os.tag.isDarwin()) &macos_cflags else &linux_cflags,
);
if (target.result.isDarwin() and !target.query.isNative()) {
if (target.result.os.tag.isDarwin() and !target.query.isNative()) {
const macos_sdk = b.lazyDependency("macos_sdk", .{
.target = target,
.optimize = optimize,
Expand All @@ -37,7 +37,7 @@ pub fn build(b: *std.Build) !void {
b,
target,
optimize,
if (target.result.isDarwin()) &macos_cflags else &linux_cflags,
if (target.result.os.tag.isDarwin()) &macos_cflags else &linux_cflags,
));
}

Expand All @@ -46,18 +46,21 @@ fn libcrypto(
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
cflags: []const []const u8,
) !*std.Build.Step.Compile {
) *std.Build.Step.Compile {
const t = target.result;

const dep = b.dependency("openssl", .{
.target = target,
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "crypto",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.pie = true;
Expand Down Expand Up @@ -113,7 +116,7 @@ fn libcrypto(
// lib.root_module.addCMacro("OPENSSL_NO_STDIO", "");
// lib.root_module.addCMacro("OSSL_PKEY_PARAM_RSA_DERIVE_FROM_PQ", "1");

if (t.isDarwin() and t.cpu.arch.isAARCH64()) {
if (t.os.tag.isDarwin() and t.cpu.arch.isAARCH64()) {
lib.addIncludePath(b.path("gen/macos-aarch64/include"));
lib.addIncludePath(b.path("gen/macos-aarch64/include/crypto"));
lib.addIncludePath(b.path("gen/macos-aarch64/include/openssl"));
Expand Down Expand Up @@ -163,7 +166,7 @@ fn libcrypto(
});
}

if (t.isDarwin() and t.cpu.arch == .x86_64) {
if (t.os.tag.isDarwin() and t.cpu.arch == .x86_64) {
lib.addIncludePath(b.path("gen/macos-x86_64/include"));
lib.addIncludePath(b.path("gen/macos-x86_64/include/crypto"));
lib.addIncludePath(b.path("gen/macos-x86_64/include/openssl"));
Expand Down Expand Up @@ -247,16 +250,6 @@ fn libcrypto(
});
}

var srcs = std.ArrayList([]const u8).init(b.allocator);
defer srcs.deinit();
try srcs.appendSlice(&common_crypto_sources);

if (t.os.tag == .linux) {
try srcs.appendSlice(&.{
"engines/e_afalg.c",
});
}

lib.addCSourceFiles(.{
.root = dep.path(""),
.files = switch (t.cpu.arch) {
Expand Down Expand Up @@ -286,10 +279,18 @@ fn libcrypto(

lib.addCSourceFiles(.{
.root = dep.path(""),
.files = srcs.items,
.files = &common_crypto_sources,
.flags = cflags,
});

if (t.os.tag == .linux) {
lib.addCSourceFiles(.{
.root = dep.path(""),
.files = &.{"engines/e_afalg.c"},
.flags = cflags,
});
}

lib.installHeadersDirectory(dep.path("include/crypto"), "crypto", .{});
lib.installHeadersDirectory(dep.path("include/internal"), "internal", .{});

Expand All @@ -308,10 +309,13 @@ fn libssl(
.optimize = optimize,
});

const lib = b.addStaticLibrary(.{
const lib = b.addLibrary(.{
.linkage = .static,
.name = "ssl",
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});

lib.pie = true;
Expand All @@ -329,7 +333,7 @@ fn libssl(
lib.addIncludePath(dep.path("include/internal"));
lib.addIncludePath(dep.path("include/openssl"));

if (t.isDarwin() and t.cpu.arch.isAARCH64()) {
if (t.os.tag.isDarwin() and t.cpu.arch.isAARCH64()) {
lib.addIncludePath(b.path("gen/macos-aarch64/include"));
lib.addIncludePath(b.path("gen/macos-aarch64/include/openssl"));
lib.installHeadersDirectory(b.path("gen/macos-aarch64/include/openssl"), "openssl", .{});
Expand All @@ -341,7 +345,7 @@ fn libssl(
lib.installHeadersDirectory(b.path("gen/linux-aarch64/include/openssl"), "openssl", .{});
}

if (t.isDarwin() and t.cpu.arch == .x86_64) {
if (t.os.tag.isDarwin() and t.cpu.arch == .x86_64) {
lib.addIncludePath(b.path("gen/macos-x86_64/include"));
lib.addIncludePath(b.path("gen/macos-x86_64/include/openssl"));
lib.installHeadersDirectory(b.path("gen/macos-x86_64/include/openssl"), "openssl", .{});
Expand All @@ -353,8 +357,8 @@ fn libssl(
lib.installHeadersDirectory(b.path("gen/linux-x86_64/include/openssl"), "openssl", .{});
}

lib.defineCMacro("OPENSSLDIR", "\"\"");
lib.defineCMacro("ENGINESDIR", "\"\"");
lib.root_module.addCMacro("OPENSSLDIR", "\"\"");
lib.root_module.addCMacro("ENGINESDIR", "\"\"");

lib.addCSourceFiles(.{
.root = dep.path(""),
Expand Down