@@ -5627,6 +5627,41 @@ pub fn addCCArgs(
5627
5627
const llvm_triple = try @import ("codegen/llvm.zig" ).targetTriple (arena , target );
5628
5628
try argv .appendSlice (&[_ ][]const u8 { "-target" , llvm_triple });
5629
5629
5630
+ switch (target .os .tag ) {
5631
+ .macos = > {
5632
+ try argv .ensureUnusedCapacity (2 );
5633
+ // Pass the proper -m<os>-version-min argument for darwin.
5634
+ const ver = target .os .version_range .semver .min ;
5635
+ argv .appendAssumeCapacity (try std .fmt .allocPrint (arena , "-mmacos-version-min={d}.{d}.{d}" , .{
5636
+ ver .major , ver .minor , ver .patch ,
5637
+ }));
5638
+ // This avoids a warning that sometimes occurs when
5639
+ // providing both a -target argument that contains a
5640
+ // version as well as the -mmacosx-version-min argument.
5641
+ // Zig provides the correct value in both places, so it
5642
+ // doesn't matter which one gets overridden.
5643
+ argv .appendAssumeCapacity ("-Wno-overriding-option" );
5644
+ },
5645
+ .ios = > switch (target .cpu .arch ) {
5646
+ // Pass the proper -m<os>-version-min argument for darwin.
5647
+ .x86 , .x86_64 = > {
5648
+ const ver = target .os .version_range .semver .min ;
5649
+ try argv .append (try std .fmt .allocPrint (
5650
+ arena ,
5651
+ "-m{s}-simulator-version-min={d}.{d}.{d}" ,
5652
+ .{ @tagName (target .os .tag ), ver .major , ver .minor , ver .patch },
5653
+ ));
5654
+ },
5655
+ else = > {
5656
+ const ver = target .os .version_range .semver .min ;
5657
+ try argv .append (try std .fmt .allocPrint (arena , "-m{s}-version-min={d}.{d}.{d}" , .{
5658
+ @tagName (target .os .tag ), ver .major , ver .minor , ver .patch ,
5659
+ }));
5660
+ },
5661
+ },
5662
+ else = > {},
5663
+ }
5664
+
5630
5665
if (target .cpu .arch .isArm ()) {
5631
5666
try argv .append (if (target .cpu .arch .isThumb ()) "-mthumb" else "-mno-thumb" );
5632
5667
}
@@ -5740,6 +5775,19 @@ pub fn addCCArgs(
5740
5775
5741
5776
// LLVM IR files don't support these flags.
5742
5777
if (ext != .ll and ext != .bc ) {
5778
+ switch (mod .optimize_mode ) {
5779
+ .Debug = > {
5780
+ // windows c runtime requires -D_DEBUG if using debug libraries
5781
+ try argv .append ("-D_DEBUG" );
5782
+ },
5783
+ .ReleaseSafe = > {
5784
+ try argv .append ("-D_FORTIFY_SOURCE=2" );
5785
+ },
5786
+ .ReleaseFast , .ReleaseSmall = > {
5787
+ try argv .append ("-DNDEBUG" );
5788
+ },
5789
+ }
5790
+
5743
5791
if (comp .config .link_libc ) {
5744
5792
if (target .isGnuLibC ()) {
5745
5793
const target_version = target .os .versionRange ().gnuLibCVersion ().? ;
@@ -5810,6 +5858,32 @@ pub fn addCCArgs(
5810
5858
}
5811
5859
}
5812
5860
5861
+ // Only C-family files support these flags.
5862
+ switch (ext ) {
5863
+ .c ,
5864
+ .h ,
5865
+ .cpp ,
5866
+ .hpp ,
5867
+ .m ,
5868
+ .hm ,
5869
+ .mm ,
5870
+ .hmm ,
5871
+ = > {
5872
+ try argv .append ("-fno-spell-checking" );
5873
+
5874
+ if (target .os .tag == .windows and target .abi .isGnu ()) {
5875
+ // windows.h has files such as pshpack1.h which do #pragma packing,
5876
+ // triggering a clang warning. So for this target, we disable this warning.
5877
+ try argv .append ("-Wno-pragma-pack" );
5878
+ }
5879
+
5880
+ if (mod .optimize_mode != .Debug ) {
5881
+ try argv .append ("-Werror=date-time" );
5882
+ }
5883
+ },
5884
+ else = > {},
5885
+ }
5886
+
5813
5887
// Only assembly files support these flags.
5814
5888
switch (ext ) {
5815
5889
.assembly ,
@@ -5884,7 +5958,7 @@ pub fn addCCArgs(
5884
5958
else = > {},
5885
5959
}
5886
5960
5887
- // Only C-family files support these flags.
5961
+ // Only compiled files support these flags.
5888
5962
switch (ext ) {
5889
5963
.c ,
5890
5964
.h ,
@@ -5894,9 +5968,9 @@ pub fn addCCArgs(
5894
5968
.hm ,
5895
5969
.mm ,
5896
5970
.hmm ,
5971
+ .ll ,
5972
+ .bc ,
5897
5973
= > {
5898
- try argv .append ("-fno-spell-checking" );
5899
-
5900
5974
if (target_util .clangSupportsTargetCpuArg (target )) {
5901
5975
if (target .cpu .model .llvm_name ) | llvm_name | {
5902
5976
try argv .appendSlice (&[_ ][]const u8 {
@@ -5925,48 +5999,6 @@ pub fn addCCArgs(
5925
5999
}
5926
6000
}
5927
6001
5928
- switch (target .os .tag ) {
5929
- .windows = > {
5930
- // windows.h has files such as pshpack1.h which do #pragma packing,
5931
- // triggering a clang warning. So for this target, we disable this warning.
5932
- if (target .abi .isGnu ()) {
5933
- try argv .append ("-Wno-pragma-pack" );
5934
- }
5935
- },
5936
- .macos = > {
5937
- try argv .ensureUnusedCapacity (2 );
5938
- // Pass the proper -m<os>-version-min argument for darwin.
5939
- const ver = target .os .version_range .semver .min ;
5940
- argv .appendAssumeCapacity (try std .fmt .allocPrint (arena , "-mmacos-version-min={d}.{d}.{d}" , .{
5941
- ver .major , ver .minor , ver .patch ,
5942
- }));
5943
- // This avoids a warning that sometimes occurs when
5944
- // providing both a -target argument that contains a
5945
- // version as well as the -mmacosx-version-min argument.
5946
- // Zig provides the correct value in both places, so it
5947
- // doesn't matter which one gets overridden.
5948
- argv .appendAssumeCapacity ("-Wno-overriding-option" );
5949
- },
5950
- .ios = > switch (target .cpu .arch ) {
5951
- // Pass the proper -m<os>-version-min argument for darwin.
5952
- .x86 , .x86_64 = > {
5953
- const ver = target .os .version_range .semver .min ;
5954
- try argv .append (try std .fmt .allocPrint (
5955
- arena ,
5956
- "-m{s}-simulator-version-min={d}.{d}.{d}" ,
5957
- .{ @tagName (target .os .tag ), ver .major , ver .minor , ver .patch },
5958
- ));
5959
- },
5960
- else = > {
5961
- const ver = target .os .version_range .semver .min ;
5962
- try argv .append (try std .fmt .allocPrint (arena , "-m{s}-version-min={d}.{d}.{d}" , .{
5963
- @tagName (target .os .tag ), ver .major , ver .minor , ver .patch ,
5964
- }));
5965
- },
5966
- },
5967
- else = > {},
5968
- }
5969
-
5970
6002
{
5971
6003
var san_arg : std .ArrayListUnmanaged (u8 ) = .empty ;
5972
6004
const prefix = "-fsanitize=" ;
@@ -6027,8 +6059,6 @@ pub fn addCCArgs(
6027
6059
6028
6060
switch (mod .optimize_mode ) {
6029
6061
.Debug = > {
6030
- // windows c runtime requires -D_DEBUG if using debug libraries
6031
- try argv .append ("-D_DEBUG" );
6032
6062
// Clang has -Og for compatibility with GCC, but currently it is just equivalent
6033
6063
// to -O1. Besides potentially impairing debugging, -O1/-Og significantly
6034
6064
// increases compile times.
@@ -6038,10 +6068,8 @@ pub fn addCCArgs(
6038
6068
// See the comment in the BuildModeFastRelease case for why we pass -O2 rather
6039
6069
// than -O3 here.
6040
6070
try argv .append ("-O2" );
6041
- try argv .append ("-D_FORTIFY_SOURCE=2" );
6042
6071
},
6043
6072
.ReleaseFast = > {
6044
- try argv .append ("-DNDEBUG" );
6045
6073
// Here we pass -O2 rather than -O3 because, although we do the equivalent of
6046
6074
// -O3 in Zig code, the justification for the difference here is that Zig
6047
6075
// has better detection and prevention of undefined behavior, so -O3 is safer for
@@ -6050,14 +6078,9 @@ pub fn addCCArgs(
6050
6078
try argv .append ("-O2" );
6051
6079
},
6052
6080
.ReleaseSmall = > {
6053
- try argv .append ("-DNDEBUG" );
6054
6081
try argv .append ("-Os" );
6055
6082
},
6056
6083
}
6057
-
6058
- if (mod .optimize_mode != .Debug ) {
6059
- try argv .append ("-Werror=date-time" );
6060
- }
6061
6084
},
6062
6085
else = > {},
6063
6086
}
0 commit comments