@@ -810,7 +810,6 @@ pub const InitOptions = struct {
810
810
/// this flag would be set to disable this machinery to avoid false positives.
811
811
disable_lld_caching : bool = false ,
812
812
cache_mode : CacheMode = .incremental ,
813
- object_format : ? std.Target.ObjectFormat = null ,
814
813
optimize_mode : std.builtin.Mode = .Debug ,
815
814
keep_source_files_loaded : bool = false ,
816
815
clang_argv : []const []const u8 = &[0 ][]const u8 {},
@@ -1027,8 +1026,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1027
1026
const comp = try arena .create (Compilation );
1028
1027
const root_name = try arena .dupeZ (u8 , options .root_name );
1029
1028
1030
- const ofmt = options .object_format orelse options .target .getObjectFormat ();
1031
-
1032
1029
const use_stage1 = options .use_stage1 orelse blk : {
1033
1030
// Even though we may have no Zig code to compile (depending on `options.main_pkg`),
1034
1031
// we may need to use stage1 for building compiler-rt and other dependencies.
@@ -1042,7 +1039,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1042
1039
}
1043
1040
1044
1041
// If LLVM does not support the target, then we can't use it.
1045
- if (! target_util .hasLlvmSupport (options .target , ofmt ))
1042
+ if (! target_util .hasLlvmSupport (options .target , options . target . ofmt ))
1046
1043
break :blk false ;
1047
1044
1048
1045
break :blk build_options .is_stage1 ;
@@ -1072,7 +1069,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1072
1069
break :blk true ;
1073
1070
1074
1071
// If LLVM does not support the target, then we can't use it.
1075
- if (! target_util .hasLlvmSupport (options .target , ofmt ))
1072
+ if (! target_util .hasLlvmSupport (options .target , options . target . ofmt ))
1076
1073
break :blk false ;
1077
1074
1078
1075
// Prefer LLVM for release builds.
@@ -1115,7 +1112,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1115
1112
if (! build_options .have_llvm )
1116
1113
break :blk false ;
1117
1114
1118
- if (ofmt == .c )
1115
+ if (options . target . ofmt == .c )
1119
1116
break :blk false ;
1120
1117
1121
1118
if (options .want_lto ) | lto | {
@@ -1374,7 +1371,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1374
1371
cache .hash .add (options .target .os .getVersionRange ());
1375
1372
cache .hash .add (options .is_native_os );
1376
1373
cache .hash .add (options .target .abi );
1377
- cache .hash .add (ofmt );
1374
+ cache .hash .add (options . target . ofmt );
1378
1375
cache .hash .add (pic );
1379
1376
cache .hash .add (pie );
1380
1377
cache .hash .add (lto );
@@ -1682,7 +1679,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1682
1679
.sysroot = sysroot ,
1683
1680
.output_mode = options .output_mode ,
1684
1681
.link_mode = link_mode ,
1685
- .object_format = ofmt ,
1686
1682
.optimize_mode = options .optimize_mode ,
1687
1683
.use_lld = use_lld ,
1688
1684
.use_llvm = use_llvm ,
@@ -1841,7 +1837,9 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1841
1837
1842
1838
const have_bin_emit = comp .bin_file .options .emit != null or comp .whole_bin_sub_path != null ;
1843
1839
1844
- if (have_bin_emit and ! comp .bin_file .options .skip_linker_dependencies ) {
1840
+ if (have_bin_emit and ! comp .bin_file .options .skip_linker_dependencies and
1841
+ options .target .ofmt != .c )
1842
+ {
1845
1843
if (comp .getTarget ().isDarwin ()) {
1846
1844
switch (comp .getTarget ().abi ) {
1847
1845
.none ,
@@ -3739,7 +3737,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
3739
3737
else
3740
3738
c_source_basename [0 .. c_source_basename .len - std .fs .path .extension (c_source_basename ).len ];
3741
3739
3742
- const o_ext = comp .bin_file .options .object_format .fileExt (comp .bin_file .options .target .cpu .arch );
3740
+ const target = comp .getTarget ();
3741
+ const o_ext = target .ofmt .fileExt (target .cpu .arch );
3743
3742
const digest = if (! comp .disable_c_depfile and try man .hit ()) man .final () else blk : {
3744
3743
var argv = std .ArrayList ([]const u8 ).init (comp .gpa );
3745
3744
defer argv .deinit ();
@@ -4092,7 +4091,7 @@ pub fn addCCArgs(
4092
4091
4093
4092
if (! comp .bin_file .options .strip ) {
4094
4093
try argv .append ("-g" );
4095
- switch (comp . bin_file . options . object_format ) {
4094
+ switch (target . ofmt ) {
4096
4095
.coff = > try argv .append ("-gcodeview" ),
4097
4096
else = > {},
4098
4097
}
@@ -4660,7 +4659,7 @@ fn wantBuildLibCFromSource(comp: Compilation) bool {
4660
4659
};
4661
4660
return comp .bin_file .options .link_libc and is_exe_or_dyn_lib and
4662
4661
comp .bin_file .options .libc_installation == null and
4663
- comp .bin_file .options .object_format != .c ;
4662
+ comp .bin_file .options .target . ofmt != .c ;
4664
4663
}
4665
4664
4666
4665
fn wantBuildGLibCFromSource (comp : Compilation ) bool {
@@ -4688,7 +4687,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool {
4688
4687
.Exe = > true ,
4689
4688
};
4690
4689
return is_exe_or_dyn_lib and comp .bin_file .options .link_libunwind and
4691
- comp .bin_file .options .object_format != .c ;
4690
+ comp .bin_file .options .target . ofmt != .c ;
4692
4691
}
4693
4692
4694
4693
fn setAllocFailure (comp : * Compilation ) void {
@@ -4747,7 +4746,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
4747
4746
const zig_backend : std.builtin.CompilerBackend = blk : {
4748
4747
if (use_stage1 ) break :blk .stage1 ;
4749
4748
if (build_options .have_llvm and comp .bin_file .options .use_llvm ) break :blk .stage2_llvm ;
4750
- if (comp . bin_file . options . object_format == .c ) break :blk .stage2_c ;
4749
+ if (target . ofmt == .c ) break :blk .stage2_c ;
4751
4750
break :blk switch (target .cpu .arch ) {
4752
4751
.wasm32 , .wasm64 = > std .builtin .CompilerBackend .stage2_wasm ,
4753
4752
.arm , .armeb , .thumb , .thumbeb = > .stage2_arm ,
@@ -4895,6 +4894,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
4895
4894
\\ .cpu = cpu,
4896
4895
\\ .os = os,
4897
4896
\\ .abi = abi,
4897
+ \\ .ofmt = object_format,
4898
4898
\\}};
4899
4899
\\pub const object_format = std.Target.ObjectFormat.{};
4900
4900
\\pub const mode = std.builtin.Mode.{};
@@ -4909,7 +4909,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
4909
4909
\\pub const code_model = std.builtin.CodeModel.{};
4910
4910
\\
4911
4911
, .{
4912
- std .zig .fmtId (@tagName (comp . bin_file . options . object_format )),
4912
+ std .zig .fmtId (@tagName (target . ofmt )),
4913
4913
std .zig .fmtId (@tagName (comp .bin_file .options .optimize_mode )),
4914
4914
link_libc ,
4915
4915
comp .bin_file .options .link_libcpp ,
0 commit comments