mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Merge pull request #13865 from ziglang/std-build-reorg
std.build: extract steps to separate files
This commit is contained in:
commit
5238f9c409
2318
lib/std/build.zig
2318
lib/std/build.zig
File diff suppressed because it is too large
Load Diff
88
lib/std/build/InstallArtifactStep.zig
Normal file
88
lib/std/build/InstallArtifactStep.zig
Normal file
@ -0,0 +1,88 @@
|
||||
const std = @import("../std.zig");
|
||||
const build = @import("../build.zig");
|
||||
const Step = build.Step;
|
||||
const Builder = build.Builder;
|
||||
const LibExeObjStep = std.build.LibExeObjStep;
|
||||
const InstallDir = std.build.InstallDir;
|
||||
|
||||
pub const base_id = .install_artifact;
|
||||
|
||||
step: Step,
|
||||
builder: *Builder,
|
||||
artifact: *LibExeObjStep,
|
||||
dest_dir: InstallDir,
|
||||
pdb_dir: ?InstallDir,
|
||||
h_dir: ?InstallDir,
|
||||
|
||||
const Self = @This();
|
||||
|
||||
pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self {
|
||||
if (artifact.install_step) |s| return s;
|
||||
|
||||
const self = builder.allocator.create(Self) catch unreachable;
|
||||
self.* = Self{
|
||||
.builder = builder,
|
||||
.step = Step.init(.install_artifact, builder.fmt("install {s}", .{artifact.step.name}), builder.allocator, make),
|
||||
.artifact = artifact,
|
||||
.dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
|
||||
.obj => @panic("Cannot install a .obj build artifact."),
|
||||
.@"test" => @panic("Cannot install a test build artifact, use addTestExe instead."),
|
||||
.exe, .test_exe => InstallDir{ .bin = {} },
|
||||
.lib => InstallDir{ .lib = {} },
|
||||
},
|
||||
.pdb_dir = if (artifact.producesPdbFile()) blk: {
|
||||
if (artifact.kind == .exe or artifact.kind == .test_exe) {
|
||||
break :blk InstallDir{ .bin = {} };
|
||||
} else {
|
||||
break :blk InstallDir{ .lib = {} };
|
||||
}
|
||||
} else null,
|
||||
.h_dir = if (artifact.kind == .lib and artifact.emit_h) .header else null,
|
||||
};
|
||||
self.step.dependOn(&artifact.step);
|
||||
artifact.install_step = self;
|
||||
|
||||
builder.pushInstalledFile(self.dest_dir, artifact.out_filename);
|
||||
if (self.artifact.isDynamicLibrary()) {
|
||||
if (artifact.major_only_filename) |name| {
|
||||
builder.pushInstalledFile(.lib, name);
|
||||
}
|
||||
if (artifact.name_only_filename) |name| {
|
||||
builder.pushInstalledFile(.lib, name);
|
||||
}
|
||||
if (self.artifact.target.isWindows()) {
|
||||
builder.pushInstalledFile(.lib, artifact.out_lib_filename);
|
||||
}
|
||||
}
|
||||
if (self.pdb_dir) |pdb_dir| {
|
||||
builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
|
||||
}
|
||||
if (self.h_dir) |h_dir| {
|
||||
builder.pushInstalledFile(h_dir, artifact.out_h_filename);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step) !void {
|
||||
const self = @fieldParentPtr(Self, "step", step);
|
||||
const builder = self.builder;
|
||||
|
||||
const full_dest_path = builder.getInstallPath(self.dest_dir, self.artifact.out_filename);
|
||||
try builder.updateFile(self.artifact.getOutputSource().getPath(builder), full_dest_path);
|
||||
if (self.artifact.isDynamicLibrary() and self.artifact.version != null and self.artifact.target.wantSharedLibSymLinks()) {
|
||||
try LibExeObjStep.doAtomicSymLinks(builder.allocator, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
|
||||
}
|
||||
if (self.artifact.isDynamicLibrary() and self.artifact.target.isWindows() and self.artifact.emit_implib != .no_emit) {
|
||||
const full_implib_path = builder.getInstallPath(self.dest_dir, self.artifact.out_lib_filename);
|
||||
try builder.updateFile(self.artifact.getOutputLibSource().getPath(builder), full_implib_path);
|
||||
}
|
||||
if (self.pdb_dir) |pdb_dir| {
|
||||
const full_pdb_path = builder.getInstallPath(pdb_dir, self.artifact.out_pdb_filename);
|
||||
try builder.updateFile(self.artifact.getOutputPdbSource().getPath(builder), full_pdb_path);
|
||||
}
|
||||
if (self.h_dir) |h_dir| {
|
||||
const full_pdb_path = builder.getInstallPath(h_dir, self.artifact.out_h_filename);
|
||||
try builder.updateFile(self.artifact.getOutputHSource().getPath(builder), full_pdb_path);
|
||||
}
|
||||
self.artifact.installed_path = full_dest_path;
|
||||
}
|
||||
90
lib/std/build/InstallDirStep.zig
Normal file
90
lib/std/build/InstallDirStep.zig
Normal file
@ -0,0 +1,90 @@
|
||||
const std = @import("../std.zig");
|
||||
const mem = std.mem;
|
||||
const fs = std.fs;
|
||||
const build = @import("../build.zig");
|
||||
const Step = build.Step;
|
||||
const Builder = build.Builder;
|
||||
const InstallDir = std.build.InstallDir;
|
||||
const InstallDirStep = @This();
|
||||
|
||||
step: Step,
|
||||
builder: *Builder,
|
||||
options: Options,
|
||||
|
||||
pub const base_id = .install_dir;
|
||||
|
||||
pub const Options = struct {
|
||||
source_dir: []const u8,
|
||||
install_dir: InstallDir,
|
||||
install_subdir: []const u8,
|
||||
/// File paths which end in any of these suffixes will be excluded
|
||||
/// from being installed.
|
||||
exclude_extensions: []const []const u8 = &.{},
|
||||
/// File paths which end in any of these suffixes will result in
|
||||
/// empty files being installed. This is mainly intended for large
|
||||
/// test.zig files in order to prevent needless installation bloat.
|
||||
/// However if the files were not present at all, then
|
||||
/// `@import("test.zig")` would be a compile error.
|
||||
blank_extensions: []const []const u8 = &.{},
|
||||
|
||||
fn dupe(self: Options, b: *Builder) Options {
|
||||
return .{
|
||||
.source_dir = b.dupe(self.source_dir),
|
||||
.install_dir = self.install_dir.dupe(b),
|
||||
.install_subdir = b.dupe(self.install_subdir),
|
||||
.exclude_extensions = b.dupeStrings(self.exclude_extensions),
|
||||
.blank_extensions = b.dupeStrings(self.blank_extensions),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub fn init(
|
||||
builder: *Builder,
|
||||
options: Options,
|
||||
) InstallDirStep {
|
||||
builder.pushInstalledFile(options.install_dir, options.install_subdir);
|
||||
return InstallDirStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(.install_dir, builder.fmt("install {s}/", .{options.source_dir}), builder.allocator, make),
|
||||
.options = options.dupe(builder),
|
||||
};
|
||||
}
|
||||
|
||||
fn make(step: *Step) !void {
|
||||
const self = @fieldParentPtr(InstallDirStep, "step", step);
|
||||
const dest_prefix = self.builder.getInstallPath(self.options.install_dir, self.options.install_subdir);
|
||||
const full_src_dir = self.builder.pathFromRoot(self.options.source_dir);
|
||||
var src_dir = try std.fs.cwd().openIterableDir(full_src_dir, .{});
|
||||
defer src_dir.close();
|
||||
var it = try src_dir.walk(self.builder.allocator);
|
||||
next_entry: while (try it.next()) |entry| {
|
||||
for (self.options.exclude_extensions) |ext| {
|
||||
if (mem.endsWith(u8, entry.path, ext)) {
|
||||
continue :next_entry;
|
||||
}
|
||||
}
|
||||
|
||||
const full_path = self.builder.pathJoin(&.{
|
||||
full_src_dir, entry.path,
|
||||
});
|
||||
|
||||
const dest_path = self.builder.pathJoin(&.{
|
||||
dest_prefix, entry.path,
|
||||
});
|
||||
|
||||
switch (entry.kind) {
|
||||
.Directory => try fs.cwd().makePath(dest_path),
|
||||
.File => {
|
||||
for (self.options.blank_extensions) |ext| {
|
||||
if (mem.endsWith(u8, entry.path, ext)) {
|
||||
try self.builder.truncateFile(dest_path);
|
||||
continue :next_entry;
|
||||
}
|
||||
}
|
||||
|
||||
try self.builder.updateFile(full_path, dest_path);
|
||||
},
|
||||
else => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
38
lib/std/build/InstallFileStep.zig
Normal file
38
lib/std/build/InstallFileStep.zig
Normal file
@ -0,0 +1,38 @@
|
||||
const std = @import("../std.zig");
|
||||
const build = @import("../build.zig");
|
||||
const Step = build.Step;
|
||||
const Builder = build.Builder;
|
||||
const FileSource = std.build.FileSource;
|
||||
const InstallDir = std.build.InstallDir;
|
||||
const InstallFileStep = @This();
|
||||
|
||||
pub const base_id = .install_file;
|
||||
|
||||
step: Step,
|
||||
builder: *Builder,
|
||||
source: FileSource,
|
||||
dir: InstallDir,
|
||||
dest_rel_path: []const u8,
|
||||
|
||||
pub fn init(
|
||||
builder: *Builder,
|
||||
source: FileSource,
|
||||
dir: InstallDir,
|
||||
dest_rel_path: []const u8,
|
||||
) InstallFileStep {
|
||||
builder.pushInstalledFile(dir, dest_rel_path);
|
||||
return InstallFileStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(.install_file, builder.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }), builder.allocator, make),
|
||||
.source = source.dupe(builder),
|
||||
.dir = dir.dupe(builder),
|
||||
.dest_rel_path = builder.dupePath(dest_rel_path),
|
||||
};
|
||||
}
|
||||
|
||||
fn make(step: *Step) !void {
|
||||
const self = @fieldParentPtr(InstallFileStep, "step", step);
|
||||
const full_dest_path = self.builder.getInstallPath(self.dir, self.dest_rel_path);
|
||||
const full_src_path = self.source.getPath(self.builder);
|
||||
try self.builder.updateFile(full_src_path, full_dest_path);
|
||||
}
|
||||
@ -26,7 +26,7 @@ const BinaryElfSegment = struct {
|
||||
virtualAddress: u64,
|
||||
elfOffset: u64,
|
||||
binaryOffset: u64,
|
||||
fileSize: usize,
|
||||
fileSize: u64,
|
||||
firstSection: ?*BinaryElfSection,
|
||||
};
|
||||
|
||||
@ -69,7 +69,7 @@ const BinaryElfOutput = struct {
|
||||
|
||||
const shstrtab_shdr = (try section_headers.next()).?;
|
||||
|
||||
const buffer = try allocator.alloc(u8, shstrtab_shdr.sh_size);
|
||||
const buffer = try allocator.alloc(u8, @intCast(usize, shstrtab_shdr.sh_size));
|
||||
errdefer allocator.free(buffer);
|
||||
|
||||
const num_read = try elf_file.preadAll(buffer, shstrtab_shdr.sh_offset);
|
||||
@ -301,7 +301,7 @@ const HexWriter = struct {
|
||||
const row_address = @intCast(u32, segment.physicalAddress + bytes_read);
|
||||
|
||||
const remaining = segment.fileSize - bytes_read;
|
||||
const to_read = @min(remaining, MAX_PAYLOAD_LEN);
|
||||
const to_read = @intCast(usize, @min(remaining, MAX_PAYLOAD_LEN));
|
||||
const did_read = try elf_file.preadAll(buf[0..to_read], segment.elfOffset + bytes_read);
|
||||
if (did_read < to_read) return error.UnexpectedEOF;
|
||||
|
||||
|
||||
2062
lib/std/build/LibExeObjStep.zig
Normal file
2062
lib/std/build/LibExeObjStep.zig
Normal file
File diff suppressed because it is too large
Load Diff
25
lib/std/build/LogStep.zig
Normal file
25
lib/std/build/LogStep.zig
Normal file
@ -0,0 +1,25 @@
|
||||
const std = @import("../std.zig");
|
||||
const log = std.log;
|
||||
const build = @import("../build.zig");
|
||||
const Step = build.Step;
|
||||
const Builder = build.Builder;
|
||||
const LogStep = @This();
|
||||
|
||||
pub const base_id = .log;
|
||||
|
||||
step: Step,
|
||||
builder: *Builder,
|
||||
data: []const u8,
|
||||
|
||||
pub fn init(builder: *Builder, data: []const u8) LogStep {
|
||||
return LogStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(.log, builder.fmt("log {s}", .{data}), builder.allocator, make),
|
||||
.data = builder.dupe(data),
|
||||
};
|
||||
}
|
||||
|
||||
fn make(step: *Step) anyerror!void {
|
||||
const self = @fieldParentPtr(LogStep, "step", step);
|
||||
log.info("{s}", .{self.data});
|
||||
}
|
||||
@ -131,7 +131,7 @@ pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value:
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
out.print("pub const {}: {s} = ", .{ std.zig.fmtId(name), std.zig.fmtId(@typeName(T)) }) catch unreachable;
|
||||
out.print("pub const {}: {s} = ", .{ std.zig.fmtId(name), @typeName(T) }) catch unreachable;
|
||||
printLiteral(out, value, 0) catch unreachable;
|
||||
out.writeAll(";\n") catch unreachable;
|
||||
}
|
||||
@ -292,9 +292,10 @@ test "OptionsStep" {
|
||||
|
||||
const options = builder.addOptions();
|
||||
|
||||
const KeywordEnum = enum {
|
||||
@"0.8.1",
|
||||
};
|
||||
// TODO this regressed at some point
|
||||
//const KeywordEnum = enum {
|
||||
// @"0.8.1",
|
||||
//};
|
||||
|
||||
const nested_array = [2][2]u16{
|
||||
[2]u16{ 300, 200 },
|
||||
@ -310,7 +311,7 @@ test "OptionsStep" {
|
||||
options.addOption(?[]const u8, "optional_string", null);
|
||||
options.addOption([2][2]u16, "nested_array", nested_array);
|
||||
options.addOption([]const []const u16, "nested_slice", nested_slice);
|
||||
options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1");
|
||||
//options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1");
|
||||
options.addOption(std.builtin.Version, "version", try std.builtin.Version.parse("0.1.2"));
|
||||
options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
|
||||
|
||||
@ -341,10 +342,10 @@ test "OptionsStep" {
|
||||
\\ 200,
|
||||
\\ },
|
||||
\\};
|
||||
\\pub const KeywordEnum = enum {
|
||||
\\ @"0.8.1",
|
||||
\\};
|
||||
\\pub const keyword_enum: KeywordEnum = KeywordEnum.@"0.8.1";
|
||||
//\\pub const KeywordEnum = enum {
|
||||
//\\ @"0.8.1",
|
||||
//\\};
|
||||
//\\pub const keyword_enum: KeywordEnum = KeywordEnum.@"0.8.1";
|
||||
\\pub const version: @import("std").builtin.Version = .{
|
||||
\\ .major = 0,
|
||||
\\ .minor = 1,
|
||||
|
||||
31
lib/std/build/RemoveDirStep.zig
Normal file
31
lib/std/build/RemoveDirStep.zig
Normal file
@ -0,0 +1,31 @@
|
||||
const std = @import("../std.zig");
|
||||
const log = std.log;
|
||||
const fs = std.fs;
|
||||
const build = @import("../build.zig");
|
||||
const Step = build.Step;
|
||||
const Builder = build.Builder;
|
||||
const RemoveDirStep = @This();
|
||||
|
||||
pub const base_id = .remove_dir;
|
||||
|
||||
step: Step,
|
||||
builder: *Builder,
|
||||
dir_path: []const u8,
|
||||
|
||||
pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
|
||||
return RemoveDirStep{
|
||||
.builder = builder,
|
||||
.step = Step.init(.remove_dir, builder.fmt("RemoveDir {s}", .{dir_path}), builder.allocator, make),
|
||||
.dir_path = builder.dupePath(dir_path),
|
||||
};
|
||||
}
|
||||
|
||||
fn make(step: *Step) !void {
|
||||
const self = @fieldParentPtr(RemoveDirStep, "step", step);
|
||||
|
||||
const full_path = self.builder.pathFromRoot(self.dir_path);
|
||||
fs.cwd().deleteTree(full_path) catch |err| {
|
||||
log.err("Unable to remove {s}: {s}", .{ full_path, @errorName(err) });
|
||||
return err;
|
||||
};
|
||||
}
|
||||
@ -848,6 +848,11 @@ test "writeBlockHuff" {
|
||||
// Tests huffman encoding against reference files to detect possible regressions.
|
||||
// If encoding/bit allocation changes you can regenerate these files
|
||||
|
||||
if (builtin.os.tag == .windows) {
|
||||
// https://github.com/ziglang/zig/issues/13892
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
try testBlockHuff(
|
||||
"huffman-null-max.input",
|
||||
"huffman-null-max.golden",
|
||||
|
||||
@ -1983,7 +1983,7 @@ pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid:
|
||||
ws2_32.SIO_GET_EXTENSION_FUNCTION_POINTER,
|
||||
@ptrCast(*const anyopaque, &guid),
|
||||
@sizeOf(GUID),
|
||||
&function,
|
||||
@intToPtr(?*anyopaque, @ptrToInt(function)),
|
||||
@sizeOf(T),
|
||||
&num_bytes,
|
||||
null,
|
||||
|
||||
@ -2344,6 +2344,6 @@ pub extern "ws2_32" fn getnameinfo(
|
||||
Flags: i32,
|
||||
) callconv(WINAPI) i32;
|
||||
|
||||
pub extern "IPHLPAPI" fn if_nametoindex(
|
||||
pub extern "iphlpapi" fn if_nametoindex(
|
||||
InterfaceName: [*:0]const u8,
|
||||
) callconv(WINAPI) u32;
|
||||
|
||||
@ -100,36 +100,5 @@ comptime {
|
||||
}
|
||||
|
||||
test {
|
||||
if (@import("builtin").os.tag == .windows) {
|
||||
// We only test the Windows-relevant stuff to save memory because the CI
|
||||
// server is hitting OOM. TODO revert this after stage2 arrives.
|
||||
_ = ChildProcess;
|
||||
_ = DynLib;
|
||||
_ = Progress;
|
||||
_ = Target;
|
||||
_ = Thread;
|
||||
|
||||
_ = atomic;
|
||||
_ = build;
|
||||
_ = builtin;
|
||||
_ = debug;
|
||||
_ = event;
|
||||
_ = fs;
|
||||
_ = heap;
|
||||
_ = io;
|
||||
_ = log;
|
||||
_ = macho;
|
||||
_ = net;
|
||||
_ = os;
|
||||
_ = once;
|
||||
_ = pdb;
|
||||
_ = process;
|
||||
_ = testing;
|
||||
_ = time;
|
||||
_ = unicode;
|
||||
_ = zig;
|
||||
_ = start;
|
||||
} else {
|
||||
testing.refAllDecls(@This());
|
||||
}
|
||||
testing.refAllDecls(@This());
|
||||
}
|
||||
|
||||
@ -374,6 +374,11 @@ test "tcp/client: 1ms read timeout" {
|
||||
test "tcp/client: read and write multiple vectors" {
|
||||
if (native_os.tag == .wasi) return error.SkipZigTest;
|
||||
|
||||
if (builtin.os.tag == .windows) {
|
||||
// https://github.com/ziglang/zig/issues/13893
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
const listener = try tcp.Listener.init(.ip, .{ .close_on_exec = true });
|
||||
defer listener.deinit();
|
||||
|
||||
@ -426,6 +431,11 @@ test "tcp/listener: bind to unspecified ipv4 address" {
|
||||
test "tcp/listener: bind to unspecified ipv6 address" {
|
||||
if (native_os.tag == .wasi) return error.SkipZigTest;
|
||||
|
||||
if (builtin.os.tag == .windows) {
|
||||
// https://github.com/ziglang/zig/issues/13893
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
const listener = try tcp.Listener.init(.ipv6, .{ .close_on_exec = true });
|
||||
defer listener.deinit();
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ pub fn Mixin(comptime Socket: type) type {
|
||||
return switch (ws2_32.WSAGetLastError()) {
|
||||
.WSANOTINITIALISED => {
|
||||
_ = try windows.WSAStartup(2, 2);
|
||||
return Socket.init(domain, socket_type, protocol, flags);
|
||||
return init(domain, socket_type, protocol, flags);
|
||||
},
|
||||
.WSAEAFNOSUPPORT => error.AddressFamilyNotSupported,
|
||||
.WSAEMFILE => error.ProcessFdQuotaExceeded,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user