mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Update for Zig-current
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const fmt = std.fmt;
|
||||
const fs = std.fs;
|
||||
const Io = std.Io;
|
||||
const Dir = Io.Dir;
|
||||
const heap = std.heap;
|
||||
const mem = std.mem;
|
||||
const Compile = std.Build.Step.Compile;
|
||||
@@ -140,15 +141,15 @@ fn initLibConfig(b: *std.Build, target: std.Build.ResolvedTarget, lib: *Compile)
|
||||
}
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
var threaded: Io.Threaded = .init_single_threaded;
|
||||
const io = threaded.io();
|
||||
|
||||
const root_path = b.pathFromRoot(".");
|
||||
var cwd = try fs.openDirAbsolute(root_path, .{});
|
||||
defer cwd.close();
|
||||
var cwd = try Dir.openDirAbsolute(io, root_path, .{});
|
||||
defer cwd.close(io);
|
||||
|
||||
const src_path = "src/libsodium";
|
||||
const src_dir = if (@hasField(fs.Dir.OpenOptions, "follow_symlinks"))
|
||||
try fs.Dir.openDir(cwd, src_path, .{ .iterate = true, .follow_symlinks = false })
|
||||
else
|
||||
try fs.Dir.openDir(cwd, src_path, .{ .iterate = true, .no_follow = true });
|
||||
const src_dir = try cwd.openDir(io, src_path, .{ .iterate = true });
|
||||
|
||||
var target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
@@ -209,14 +210,9 @@ pub fn build(b: *std.Build) !void {
|
||||
const prebuilt_version_file_path = "builds/msvc/version.h";
|
||||
const version_file_path = "include/sodium/version.h";
|
||||
|
||||
if (@hasField(fs.Dir.OpenOptions, "follow_symlinks"))
|
||||
src_dir.access(version_file_path, .{ .read = true }) catch {
|
||||
try cwd.copyFile(prebuilt_version_file_path, src_dir, version_file_path, .{});
|
||||
}
|
||||
else
|
||||
src_dir.access(version_file_path, .{ .mode = .read_only }) catch {
|
||||
try cwd.copyFile(prebuilt_version_file_path, src_dir, version_file_path, .{});
|
||||
};
|
||||
src_dir.access(io, version_file_path, .{ .read = true }) catch {
|
||||
try Dir.copyFile(cwd, prebuilt_version_file_path, src_dir, version_file_path, io, .{});
|
||||
};
|
||||
|
||||
for (libs.items) |lib| {
|
||||
b.installArtifact(lib);
|
||||
@@ -237,7 +233,7 @@ pub fn build(b: *std.Build) !void {
|
||||
const allocator = heap.page_allocator;
|
||||
|
||||
var walker = try src_dir.walk(allocator);
|
||||
while (try walker.next()) |entry| {
|
||||
while (try walker.next(io)) |entry| {
|
||||
const name = entry.basename;
|
||||
if (mem.endsWith(u8, name, ".c")) {
|
||||
const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ src_path, entry.path });
|
||||
@@ -255,20 +251,17 @@ pub fn build(b: *std.Build) !void {
|
||||
|
||||
const test_path = "test/default";
|
||||
const out_bin_path = "zig-out/bin";
|
||||
const test_dir = if (@hasField(fs.Dir.OpenOptions, "follow_symlinks"))
|
||||
try fs.Dir.openDir(cwd, test_path, .{ .iterate = true, .follow_symlinks = false })
|
||||
else
|
||||
try fs.Dir.openDir(cwd, test_path, .{ .iterate = true, .no_follow = true });
|
||||
fs.Dir.makePath(cwd, out_bin_path) catch {};
|
||||
const out_bin_dir = try fs.Dir.openDir(cwd, out_bin_path, .{});
|
||||
try test_dir.copyFile("run.sh", out_bin_dir, "run.sh", .{});
|
||||
const test_dir = try cwd.openDir(io, test_path, .{ .iterate = true });
|
||||
cwd.createDirPath(io, out_bin_path) catch {};
|
||||
const out_bin_dir = try cwd.openDir(io, out_bin_path, .{});
|
||||
try Dir.copyFile(test_dir, "run.sh", out_bin_dir, "run.sh", io, .{});
|
||||
const allocator = heap.page_allocator;
|
||||
var walker = try test_dir.walk(allocator);
|
||||
if (build_tests) {
|
||||
while (try walker.next()) |entry| {
|
||||
while (try walker.next(io)) |entry| {
|
||||
const name = entry.basename;
|
||||
if (mem.endsWith(u8, name, ".exp")) {
|
||||
try test_dir.copyFile(name, out_bin_dir, name, .{});
|
||||
try Dir.copyFile(test_dir, name, out_bin_dir, name, io, .{});
|
||||
continue;
|
||||
}
|
||||
if (!mem.endsWith(u8, name, ".c")) {
|
||||
|
||||
Reference in New Issue
Block a user