mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
std.Build.Step.Compile.Options: change root_module field type to *Module
This commit is contained in:
parent
faafeb51af
commit
3aa8020904
@ -719,7 +719,7 @@ pub const ExecutableOptions = struct {
|
|||||||
pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
|
pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
|
||||||
return Step.Compile.create(b, .{
|
return Step.Compile.create(b, .{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = options.root_source_file,
|
.root_source_file = options.root_source_file,
|
||||||
.target = options.target,
|
.target = options.target,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
@ -732,7 +732,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
|
|||||||
.sanitize_thread = options.sanitize_thread,
|
.sanitize_thread = options.sanitize_thread,
|
||||||
.error_tracing = options.error_tracing,
|
.error_tracing = options.error_tracing,
|
||||||
.code_model = options.code_model,
|
.code_model = options.code_model,
|
||||||
},
|
}),
|
||||||
.version = options.version,
|
.version = options.version,
|
||||||
.kind = .exe,
|
.kind = .exe,
|
||||||
.linkage = options.linkage,
|
.linkage = options.linkage,
|
||||||
@ -769,7 +769,7 @@ pub const ObjectOptions = struct {
|
|||||||
pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
|
pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
|
||||||
return Step.Compile.create(b, .{
|
return Step.Compile.create(b, .{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = options.root_source_file,
|
.root_source_file = options.root_source_file,
|
||||||
.target = options.target,
|
.target = options.target,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
@ -782,7 +782,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
|
|||||||
.sanitize_thread = options.sanitize_thread,
|
.sanitize_thread = options.sanitize_thread,
|
||||||
.error_tracing = options.error_tracing,
|
.error_tracing = options.error_tracing,
|
||||||
.code_model = options.code_model,
|
.code_model = options.code_model,
|
||||||
},
|
}),
|
||||||
.kind = .obj,
|
.kind = .obj,
|
||||||
.max_rss = options.max_rss,
|
.max_rss = options.max_rss,
|
||||||
.use_llvm = options.use_llvm,
|
.use_llvm = options.use_llvm,
|
||||||
@ -823,7 +823,7 @@ pub const SharedLibraryOptions = struct {
|
|||||||
pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
|
pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
|
||||||
return Step.Compile.create(b, .{
|
return Step.Compile.create(b, .{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.target = options.target,
|
.target = options.target,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
.root_source_file = options.root_source_file,
|
.root_source_file = options.root_source_file,
|
||||||
@ -836,7 +836,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
|
|||||||
.sanitize_thread = options.sanitize_thread,
|
.sanitize_thread = options.sanitize_thread,
|
||||||
.error_tracing = options.error_tracing,
|
.error_tracing = options.error_tracing,
|
||||||
.code_model = options.code_model,
|
.code_model = options.code_model,
|
||||||
},
|
}),
|
||||||
.kind = .lib,
|
.kind = .lib,
|
||||||
.linkage = .dynamic,
|
.linkage = .dynamic,
|
||||||
.version = options.version,
|
.version = options.version,
|
||||||
@ -874,7 +874,7 @@ pub const StaticLibraryOptions = struct {
|
|||||||
pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
|
pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
|
||||||
return Step.Compile.create(b, .{
|
return Step.Compile.create(b, .{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.target = options.target,
|
.target = options.target,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
.root_source_file = options.root_source_file,
|
.root_source_file = options.root_source_file,
|
||||||
@ -887,7 +887,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile
|
|||||||
.sanitize_thread = options.sanitize_thread,
|
.sanitize_thread = options.sanitize_thread,
|
||||||
.error_tracing = options.error_tracing,
|
.error_tracing = options.error_tracing,
|
||||||
.code_model = options.code_model,
|
.code_model = options.code_model,
|
||||||
},
|
}),
|
||||||
.kind = .lib,
|
.kind = .lib,
|
||||||
.linkage = .static,
|
.linkage = .static,
|
||||||
.version = options.version,
|
.version = options.version,
|
||||||
@ -935,7 +935,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
|
|||||||
return Step.Compile.create(b, .{
|
return Step.Compile.create(b, .{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.kind = .@"test",
|
.kind = .@"test",
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.root_source_file = options.root_source_file,
|
.root_source_file = options.root_source_file,
|
||||||
.target = options.target orelse b.graph.host,
|
.target = options.target orelse b.graph.host,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
@ -948,7 +948,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
|
|||||||
.omit_frame_pointer = options.omit_frame_pointer,
|
.omit_frame_pointer = options.omit_frame_pointer,
|
||||||
.sanitize_thread = options.sanitize_thread,
|
.sanitize_thread = options.sanitize_thread,
|
||||||
.error_tracing = options.error_tracing,
|
.error_tracing = options.error_tracing,
|
||||||
},
|
}),
|
||||||
.max_rss = options.max_rss,
|
.max_rss = options.max_rss,
|
||||||
.filters = if (options.filter != null and options.filters.len > 0) filters: {
|
.filters = if (options.filter != null and options.filters.len > 0) filters: {
|
||||||
const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM");
|
const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM");
|
||||||
@ -978,10 +978,10 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
|
|||||||
const obj_step = Step.Compile.create(b, .{
|
const obj_step = Step.Compile.create(b, .{
|
||||||
.name = options.name,
|
.name = options.name,
|
||||||
.kind = .obj,
|
.kind = .obj,
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.target = options.target,
|
.target = options.target,
|
||||||
.optimize = options.optimize,
|
.optimize = options.optimize,
|
||||||
},
|
}),
|
||||||
.max_rss = options.max_rss,
|
.max_rss = options.max_rss,
|
||||||
.zig_lib_dir = options.zig_lib_dir,
|
.zig_lib_dir = options.zig_lib_dir,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -242,45 +242,57 @@ pub const Import = struct {
|
|||||||
module: *Module,
|
module: *Module,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void {
|
pub fn init(
|
||||||
|
m: *Module,
|
||||||
|
owner: *std.Build,
|
||||||
|
value: union(enum) { options: CreateOptions, existing: *const Module },
|
||||||
|
compile: ?*Step.Compile,
|
||||||
|
) void {
|
||||||
const allocator = owner.allocator;
|
const allocator = owner.allocator;
|
||||||
|
|
||||||
m.* = .{
|
switch (value) {
|
||||||
.owner = owner,
|
.options => |options| {
|
||||||
.depending_steps = .{},
|
m.* = .{
|
||||||
.root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
|
.owner = owner,
|
||||||
.import_table = .{},
|
.depending_steps = .{},
|
||||||
.resolved_target = options.target,
|
.root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null,
|
||||||
.optimize = options.optimize,
|
.import_table = .{},
|
||||||
.link_libc = options.link_libc,
|
.resolved_target = options.target,
|
||||||
.link_libcpp = options.link_libcpp,
|
.optimize = options.optimize,
|
||||||
.dwarf_format = options.dwarf_format,
|
.link_libc = options.link_libc,
|
||||||
.c_macros = .{},
|
.link_libcpp = options.link_libcpp,
|
||||||
.include_dirs = .{},
|
.dwarf_format = options.dwarf_format,
|
||||||
.lib_paths = .{},
|
.c_macros = .{},
|
||||||
.rpaths = .{},
|
.include_dirs = .{},
|
||||||
.frameworks = .{},
|
.lib_paths = .{},
|
||||||
.link_objects = .{},
|
.rpaths = .{},
|
||||||
.strip = options.strip,
|
.frameworks = .{},
|
||||||
.unwind_tables = options.unwind_tables,
|
.link_objects = .{},
|
||||||
.single_threaded = options.single_threaded,
|
.strip = options.strip,
|
||||||
.stack_protector = options.stack_protector,
|
.unwind_tables = options.unwind_tables,
|
||||||
.stack_check = options.stack_check,
|
.single_threaded = options.single_threaded,
|
||||||
.sanitize_c = options.sanitize_c,
|
.stack_protector = options.stack_protector,
|
||||||
.sanitize_thread = options.sanitize_thread,
|
.stack_check = options.stack_check,
|
||||||
.fuzz = options.fuzz,
|
.sanitize_c = options.sanitize_c,
|
||||||
.code_model = options.code_model,
|
.sanitize_thread = options.sanitize_thread,
|
||||||
.valgrind = options.valgrind,
|
.fuzz = options.fuzz,
|
||||||
.pic = options.pic,
|
.code_model = options.code_model,
|
||||||
.red_zone = options.red_zone,
|
.valgrind = options.valgrind,
|
||||||
.omit_frame_pointer = options.omit_frame_pointer,
|
.pic = options.pic,
|
||||||
.error_tracing = options.error_tracing,
|
.red_zone = options.red_zone,
|
||||||
.export_symbol_names = &.{},
|
.omit_frame_pointer = options.omit_frame_pointer,
|
||||||
};
|
.error_tracing = options.error_tracing,
|
||||||
|
.export_symbol_names = &.{},
|
||||||
|
};
|
||||||
|
|
||||||
m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
|
m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
|
||||||
for (options.imports) |dep| {
|
for (options.imports) |dep| {
|
||||||
m.import_table.putAssumeCapacity(dep.name, dep.module);
|
m.import_table.putAssumeCapacity(dep.name, dep.module);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.existing => |existing| {
|
||||||
|
m.* = existing.*;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compile) |c| {
|
if (compile) |c| {
|
||||||
@ -294,7 +306,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St
|
|||||||
|
|
||||||
pub fn create(owner: *std.Build, options: CreateOptions) *Module {
|
pub fn create(owner: *std.Build, options: CreateOptions) *Module {
|
||||||
const m = owner.allocator.create(Module) catch @panic("OOM");
|
const m = owner.allocator.create(Module) catch @panic("OOM");
|
||||||
m.init(owner, options, null);
|
m.init(owner, .{ .options = options }, null);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -262,7 +262,7 @@ pub const Entry = union(enum) {
|
|||||||
|
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
root_module: Module.CreateOptions,
|
root_module: *Module,
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
linkage: ?std.builtin.LinkMode = null,
|
linkage: ?std.builtin.LinkMode = null,
|
||||||
version: ?std.SemanticVersion = null,
|
version: ?std.SemanticVersion = null,
|
||||||
@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
|
|||||||
else
|
else
|
||||||
owner.fmt("{s} ", .{name});
|
owner.fmt("{s} ", .{name});
|
||||||
|
|
||||||
const resolved_target = options.root_module.target.?;
|
const resolved_target = options.root_module.resolved_target orelse
|
||||||
|
@panic("the root Module of a Compile step must be created with a known 'target' field");
|
||||||
const target = resolved_target.result;
|
const target = resolved_target.result;
|
||||||
|
|
||||||
const step_name = owner.fmt("{s} {s}{s} {s}", .{
|
const step_name = owner.fmt("{s} {s}{s} {s}", .{
|
||||||
@ -431,10 +432,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
|
|||||||
|
|
||||||
.zig_process = null,
|
.zig_process = null,
|
||||||
};
|
};
|
||||||
|
options.root_module.init(owner, .{ .existing = options.root_module }, compile);
|
||||||
const root_module = owner.allocator.create(Module) catch @panic("OOM");
|
compile.root_module = options.root_module;
|
||||||
root_module.init(owner, options.root_module, compile);
|
|
||||||
compile.root_module = root_module;
|
|
||||||
|
|
||||||
if (options.zig_lib_dir) |lp| {
|
if (options.zig_lib_dir) |lp| {
|
||||||
compile.zig_lib_dir = lp.dupe(compile.step.owner);
|
compile.zig_lib_dir = lp.dupe(compile.step.owner);
|
||||||
|
|||||||
@ -70,7 +70,7 @@ fn addCompileStep(
|
|||||||
) *Compile {
|
) *Compile {
|
||||||
const compile_step = Compile.create(b, .{
|
const compile_step = Compile.create(b, .{
|
||||||
.name = overlay.name,
|
.name = overlay.name,
|
||||||
.root_module = .{
|
.root_module = b.createModule(.{
|
||||||
.target = base.target,
|
.target = base.target,
|
||||||
.optimize = base.optimize,
|
.optimize = base.optimize,
|
||||||
.root_source_file = rsf: {
|
.root_source_file = rsf: {
|
||||||
@ -80,7 +80,7 @@ fn addCompileStep(
|
|||||||
},
|
},
|
||||||
.pic = overlay.pic,
|
.pic = overlay.pic,
|
||||||
.strip = if (base.strip) |s| s else overlay.strip,
|
.strip = if (base.strip) |s| s else overlay.strip,
|
||||||
},
|
}),
|
||||||
.use_llvm = base.use_llvm,
|
.use_llvm = base.use_llvm,
|
||||||
.use_lld = base.use_lld,
|
.use_lld = base.use_lld,
|
||||||
.kind = switch (kind) {
|
.kind = switch (kind) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user