@@ -209,7 +209,7 @@ impl ToolFamily {
209
209
fn add_debug_flags ( & self , cmd : & mut Tool ) {
210
210
match * self {
211
211
ToolFamily :: Msvc { .. } => {
212
- cmd. push_cc_arg ( "/ Z7" . into ( ) ) ;
212
+ cmd. push_cc_arg ( "- Z7" . into ( ) ) ;
213
213
}
214
214
ToolFamily :: Gnu | ToolFamily :: Clang => {
215
215
cmd. push_cc_arg ( "-g" . into ( ) ) ;
@@ -218,26 +218,10 @@ impl ToolFamily {
218
218
}
219
219
}
220
220
221
- /// What the flag to include directories into header search path looks like
222
- fn include_flag ( & self ) -> & ' static str {
223
- match * self {
224
- ToolFamily :: Msvc { .. } => "/I" ,
225
- ToolFamily :: Gnu | ToolFamily :: Clang => "-I" ,
226
- }
227
- }
228
-
229
- /// What the flag to request macro-expanded source output looks like
230
- fn expand_flag ( & self ) -> & ' static str {
231
- match * self {
232
- ToolFamily :: Msvc { .. } => "/E" ,
233
- ToolFamily :: Gnu | ToolFamily :: Clang => "-E" ,
234
- }
235
- }
236
-
237
221
/// What the flags to enable all warnings
238
222
fn warnings_flags ( & self ) -> & ' static str {
239
223
match * self {
240
- ToolFamily :: Msvc { .. } => "/ W4" ,
224
+ ToolFamily :: Msvc { .. } => "- W4" ,
241
225
ToolFamily :: Gnu | ToolFamily :: Clang => "-Wall" ,
242
226
}
243
227
}
@@ -253,29 +237,11 @@ impl ToolFamily {
253
237
/// What the flag to turn warning into errors
254
238
fn warnings_to_errors_flag ( & self ) -> & ' static str {
255
239
match * self {
256
- ToolFamily :: Msvc { .. } => "/ WX" ,
240
+ ToolFamily :: Msvc { .. } => "- WX" ,
257
241
ToolFamily :: Gnu | ToolFamily :: Clang => "-Werror" ,
258
242
}
259
243
}
260
244
261
- /// NVCC-specific. Device code debug info flag. This is separate from the
262
- /// debug info flag passed to the C++ compiler.
263
- fn nvcc_debug_flag ( & self ) -> & ' static str {
264
- match * self {
265
- ToolFamily :: Msvc { .. } => unimplemented ! ( ) ,
266
- ToolFamily :: Gnu | ToolFamily :: Clang => "-G" ,
267
- }
268
- }
269
-
270
- /// NVCC-specific. Redirect the following flag to the underlying C++
271
- /// compiler.
272
- fn nvcc_redirect_flag ( & self ) -> & ' static str {
273
- match * self {
274
- ToolFamily :: Msvc { .. } => unimplemented ! ( ) ,
275
- ToolFamily :: Gnu | ToolFamily :: Clang => "-Xcompiler" ,
276
- }
277
- }
278
-
279
245
fn verbose_stderr ( & self ) -> bool {
280
246
* self == ToolFamily :: Clang
281
247
}
@@ -454,12 +420,19 @@ impl Build {
454
420
455
421
let mut cmd = compiler. to_command ( ) ;
456
422
let is_arm = target. contains ( "aarch64" ) || target. contains ( "arm" ) ;
457
- command_add_output_file ( & mut cmd, & obj, target. contains ( "msvc" ) , false , is_arm) ;
423
+ command_add_output_file (
424
+ & mut cmd,
425
+ & obj,
426
+ self . cuda ,
427
+ target. contains ( "msvc" ) ,
428
+ false ,
429
+ is_arm,
430
+ ) ;
458
431
459
432
// We need to explicitly tell msvc not to link and create an exe
460
433
// in the root directory of the crate
461
- if target. contains ( "msvc" ) {
462
- cmd. arg ( "/ c" ) ;
434
+ if target. contains ( "msvc" ) && ! self . cuda {
435
+ cmd. arg ( "- c" ) ;
463
436
}
464
437
465
438
cmd. arg ( & src) ;
@@ -500,7 +473,6 @@ impl Build {
500
473
/// .shared_flag(true)
501
474
/// .compile("libfoo.so");
502
475
/// ```
503
-
504
476
pub fn shared_flag ( & mut self , shared_flag : bool ) -> & mut Build {
505
477
self . shared_flag = Some ( shared_flag) ;
506
478
self
@@ -595,7 +567,7 @@ impl Build {
595
567
/// Set warnings flags.
596
568
///
597
569
/// Adds some flags:
598
- /// - "/ Wall" for MSVC.
570
+ /// - "- Wall" for MSVC.
599
571
/// - "-Wall", "-Wextra" for GNU and Clang.
600
572
///
601
573
/// Enabled by default.
@@ -1008,10 +980,10 @@ impl Build {
1008
980
)
1009
981
} ;
1010
982
let is_arm = target. contains ( "aarch64" ) || target. contains ( "arm" ) ;
1011
- command_add_output_file ( & mut cmd, & obj. dst , msvc, is_asm, is_arm) ;
983
+ command_add_output_file ( & mut cmd, & obj. dst , self . cuda , msvc, is_asm, is_arm) ;
1012
984
// armasm and armasm64 don't requrie -c option
1013
985
if !msvc || !is_asm || !is_arm {
1014
- cmd. arg ( if msvc { "/c" } else { " -c" } ) ;
986
+ cmd. arg ( " -c") ;
1015
987
}
1016
988
cmd. arg ( & obj. src ) ;
1017
989
@@ -1026,7 +998,7 @@ impl Build {
1026
998
for & ( ref a, ref b) in self . env . iter ( ) {
1027
999
cmd. env ( a, b) ;
1028
1000
}
1029
- cmd. arg ( compiler . family . expand_flag ( ) ) ;
1001
+ cmd. arg ( "-E" ) ;
1030
1002
1031
1003
assert ! (
1032
1004
self . files. len( ) <= 1 ,
@@ -1116,7 +1088,7 @@ impl Build {
1116
1088
}
1117
1089
1118
1090
for directory in self . include_directories . iter ( ) {
1119
- cmd. args . push ( cmd . family . include_flag ( ) . into ( ) ) ;
1091
+ cmd. args . push ( "-I" . into ( ) ) ;
1120
1092
cmd. args . push ( directory. into ( ) ) ;
1121
1093
}
1122
1094
@@ -1153,15 +1125,10 @@ impl Build {
1153
1125
}
1154
1126
1155
1127
for & ( ref key, ref value) in self . definitions . iter ( ) {
1156
- let lead = if let ToolFamily :: Msvc { .. } = cmd. family {
1157
- "/"
1158
- } else {
1159
- "-"
1160
- } ;
1161
1128
if let Some ( ref value) = * value {
1162
- cmd. args . push ( format ! ( "{} D{}={}" , lead , key, value) . into ( ) ) ;
1129
+ cmd. args . push ( format ! ( "- D{}={}" , key, value) . into ( ) ) ;
1163
1130
} else {
1164
- cmd. args . push ( format ! ( "{} D{}" , lead , key) . into ( ) ) ;
1131
+ cmd. args . push ( format ! ( "- D{}" , key) . into ( ) ) ;
1165
1132
}
1166
1133
}
1167
1134
@@ -1183,32 +1150,29 @@ impl Build {
1183
1150
// If the flag is not conditioned on target variable, it belongs here :)
1184
1151
match cmd. family {
1185
1152
ToolFamily :: Msvc { .. } => {
1186
- assert ! ( !self . cuda,
1187
- "CUDA C++ compilation not supported for MSVC, yet... but you are welcome to implement it :)" ) ;
1188
-
1189
- cmd. args . push ( "/nologo" . into ( ) ) ;
1153
+ cmd. push_cc_arg ( "-nologo" . into ( ) ) ;
1190
1154
1191
1155
let crt_flag = match self . static_crt {
1192
- Some ( true ) => "/ MT" ,
1193
- Some ( false ) => "/ MD" ,
1156
+ Some ( true ) => "- MT" ,
1157
+ Some ( false ) => "- MD" ,
1194
1158
None => {
1195
1159
let features = self
1196
1160
. getenv ( "CARGO_CFG_TARGET_FEATURE" )
1197
1161
. unwrap_or ( String :: new ( ) ) ;
1198
1162
if features. contains ( "crt-static" ) {
1199
- "/ MT"
1163
+ "- MT"
1200
1164
} else {
1201
- "/ MD"
1165
+ "- MD"
1202
1166
}
1203
1167
}
1204
1168
} ;
1205
- cmd. args . push ( crt_flag. into ( ) ) ;
1169
+ cmd. push_cc_arg ( crt_flag. into ( ) ) ;
1206
1170
1207
1171
match & opt_level[ ..] {
1208
1172
// Msvc uses /O1 to enable all optimizations that minimize code size.
1209
- "z" | "s" | "1" => cmd. push_opt_unless_duplicate ( "/ O1" . into ( ) ) ,
1173
+ "z" | "s" | "1" => cmd. push_opt_unless_duplicate ( "- O1" . into ( ) ) ,
1210
1174
// -O3 is a valid value for gcc and clang compilers, but not msvc. Cap to /O2.
1211
- "2" | "3" => cmd. push_opt_unless_duplicate ( "/ O2" . into ( ) ) ,
1175
+ "2" | "3" => cmd. push_opt_unless_duplicate ( "- O2" . into ( ) ) ,
1212
1176
_ => { }
1213
1177
}
1214
1178
}
@@ -1226,7 +1190,10 @@ impl Build {
1226
1190
cmd. push_cc_arg ( "-fdata-sections" . into ( ) ) ;
1227
1191
}
1228
1192
// Disable generation of PIC on RISC-V for now: rust-lld doesn't support this yet
1229
- if self . pic . unwrap_or ( !target. contains ( "windows-gnu" ) && !target. contains ( "riscv" ) ) {
1193
+ if self
1194
+ . pic
1195
+ . unwrap_or ( !target. contains ( "windows-gnu" ) && !target. contains ( "riscv" ) )
1196
+ {
1230
1197
cmd. push_cc_arg ( "-fPIC" . into ( ) ) ;
1231
1198
// PLT only applies if code is compiled with PIC support,
1232
1199
// and only for ELF targets.
@@ -1239,8 +1206,8 @@ impl Build {
1239
1206
1240
1207
if self . get_debug ( ) {
1241
1208
if self . cuda {
1242
- let nvcc_debug_flag = cmd . family . nvcc_debug_flag ( ) . into ( ) ;
1243
- cmd. args . push ( nvcc_debug_flag ) ;
1209
+ // NVCC debug flag
1210
+ cmd. args . push ( "-G" . into ( ) ) ;
1244
1211
}
1245
1212
let family = cmd. family ;
1246
1213
family. add_debug_flags ( cmd) ;
@@ -1257,13 +1224,13 @@ impl Build {
1257
1224
cmd. args . push ( "-m64" . into ( ) ) ;
1258
1225
} else if target. contains ( "86" ) {
1259
1226
cmd. args . push ( "-m32" . into ( ) ) ;
1260
- cmd. args . push ( "/ arch:IA32". into ( ) ) ;
1227
+ cmd. push_cc_arg ( "- arch:IA32". into ( ) ) ;
1261
1228
} else {
1262
- cmd. args . push ( format ! ( "--target={}" , target) . into ( ) ) ;
1229
+ cmd. push_cc_arg ( format ! ( "--target={}" , target) . into ( ) ) ;
1263
1230
}
1264
1231
} else {
1265
1232
if target. contains ( "i586" ) {
1266
- cmd. args . push ( "/ARCH :IA32". into ( ) ) ;
1233
+ cmd. push_cc_arg ( "-arch :IA32". into ( ) ) ;
1267
1234
}
1268
1235
}
1269
1236
@@ -1278,7 +1245,7 @@ impl Build {
1278
1245
// Windows SDK it is required.
1279
1246
if target. contains ( "arm" ) || target. contains ( "thumb" ) {
1280
1247
cmd. args
1281
- . push ( "/ D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1" . into ( ) ) ;
1248
+ . push ( "- D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1" . into ( ) ) ;
1282
1249
}
1283
1250
}
1284
1251
ToolFamily :: Gnu => {
@@ -1502,18 +1469,18 @@ impl Build {
1502
1469
} ;
1503
1470
let mut cmd = windows_registry:: find ( & target, tool) . unwrap_or_else ( || self . cmd ( tool) ) ;
1504
1471
for directory in self . include_directories . iter ( ) {
1505
- cmd. arg ( "/ I" ) . arg ( directory) ;
1472
+ cmd. arg ( "- I" ) . arg ( directory) ;
1506
1473
}
1507
1474
for & ( ref key, ref value) in self . definitions . iter ( ) {
1508
1475
if let Some ( ref value) = * value {
1509
- cmd. arg ( & format ! ( "/ D{}={}" , key, value) ) ;
1476
+ cmd. arg ( & format ! ( "- D{}={}" , key, value) ) ;
1510
1477
} else {
1511
- cmd. arg ( & format ! ( "/ D{}" , key) ) ;
1478
+ cmd. arg ( & format ! ( "- D{}" , key) ) ;
1512
1479
}
1513
1480
}
1514
1481
1515
1482
if target. contains ( "i686" ) || target. contains ( "i586" ) {
1516
- cmd. arg ( "/ safeseh" ) ;
1483
+ cmd. arg ( "- safeseh" ) ;
1517
1484
}
1518
1485
for flag in self . flags . iter ( ) {
1519
1486
cmd. arg ( flag) ;
@@ -1531,9 +1498,9 @@ impl Build {
1531
1498
let target = self . get_target ( ) ?;
1532
1499
if target. contains ( "msvc" ) {
1533
1500
let ( mut cmd, program) = self . get_ar ( ) ?;
1534
- let mut out = OsString :: from ( "/OUT :" ) ;
1501
+ let mut out = OsString :: from ( "-out :" ) ;
1535
1502
out. push ( dst) ;
1536
- cmd. arg ( out) . arg ( "/ nologo" ) ;
1503
+ cmd. arg ( out) . arg ( "- nologo" ) ;
1537
1504
1538
1505
// Similar to https://github.com/rust-lang/rust/pull/47507
1539
1506
// and https://github.com/rust-lang/rust/pull/48548
@@ -1632,19 +1599,21 @@ impl Build {
1632
1599
}
1633
1600
} ;
1634
1601
1635
- let min_version = std :: env :: var ( "IPHONEOS_DEPLOYMENT_TARGET" )
1636
- . unwrap_or_else ( |_| "7.0" . into ( ) ) ;
1602
+ let min_version =
1603
+ std :: env :: var ( "IPHONEOS_DEPLOYMENT_TARGET" ) . unwrap_or_else ( |_| "7.0" . into ( ) ) ;
1637
1604
1638
1605
let sdk = match arch {
1639
1606
ArchSpec :: Device ( arch) => {
1640
1607
cmd. args . push ( "-arch" . into ( ) ) ;
1641
1608
cmd. args . push ( arch. into ( ) ) ;
1642
- cmd. args . push ( format ! ( "-miphoneos-version-min={}" , min_version) . into ( ) ) ;
1609
+ cmd. args
1610
+ . push ( format ! ( "-miphoneos-version-min={}" , min_version) . into ( ) ) ;
1643
1611
"iphoneos"
1644
1612
}
1645
1613
ArchSpec :: Simulator ( arch) => {
1646
1614
cmd. args . push ( arch. into ( ) ) ;
1647
- cmd. args . push ( format ! ( "-mios-simulator-version-min={}" , min_version) . into ( ) ) ;
1615
+ cmd. args
1616
+ . push ( format ! ( "-mios-simulator-version-min={}" , min_version) . into ( ) ) ;
1648
1617
"iphonesimulator"
1649
1618
}
1650
1619
} ;
@@ -1776,13 +1745,14 @@ impl Build {
1776
1745
}
1777
1746
} else if target. contains ( "cloudabi" ) {
1778
1747
format ! ( "{}-{}" , target, traditional)
1779
- } else if target == "wasm32-wasi" ||
1780
- target == "wasm32-unknown-wasi" ||
1781
- target == "wasm32-unknown-unknown" {
1748
+ } else if target == "wasm32-wasi"
1749
+ || target == "wasm32-unknown-wasi"
1750
+ || target == "wasm32-unknown-unknown"
1751
+ {
1782
1752
"clang" . to_string ( )
1783
1753
} else if target. contains ( "vxworks" ) {
1784
- "wr- c++" . to_string ( )
1785
- } else if self . get_host ( ) ? != target {
1754
+ "wr= c++" . to_string ( )
1755
+ } else if self . get_host ( ) ? != target {
1786
1756
// CROSS_COMPILE is of the form: "arm-linux-gnueabi-"
1787
1757
let cc_env = self . getenv ( "CROSS_COMPILE" ) ;
1788
1758
let cross_compile = cc_env. as_ref ( ) . map ( |s| s. trim_right_matches ( '-' ) ) ;
@@ -1880,6 +1850,7 @@ impl Build {
1880
1850
nvcc_tool
1881
1851
. args
1882
1852
. push ( format ! ( "-ccbin={}" , tool. path. display( ) ) . into ( ) ) ;
1853
+ nvcc_tool. family = tool. family ;
1883
1854
nvcc_tool
1884
1855
} else {
1885
1856
tool
@@ -2185,7 +2156,7 @@ impl Tool {
2185
2156
/// with a "-Xcompiler" flag to get passed to the underlying C++ compiler.
2186
2157
fn push_cc_arg ( & mut self , flag : OsString ) {
2187
2158
if self . cuda {
2188
- self . args . push ( self . family . nvcc_redirect_flag ( ) . into ( ) ) ;
2159
+ self . args . push ( "-Xcompiler" . into ( ) ) ;
2189
2160
}
2190
2161
self . args . push ( flag) ;
2191
2162
}
@@ -2441,13 +2412,16 @@ fn fail(s: &str) -> ! {
2441
2412
std:: process:: exit ( 1 ) ;
2442
2413
}
2443
2414
2444
- fn command_add_output_file ( cmd : & mut Command , dst : & Path , msvc : bool , is_asm : bool , is_arm : bool ) {
2445
- if msvc && is_asm && is_arm {
2446
- cmd. arg ( "-o" ) . arg ( & dst) ;
2447
- } else if msvc && is_asm {
2448
- cmd. arg ( "/Fo" ) . arg ( dst) ;
2449
- } else if msvc {
2450
- let mut s = OsString :: from ( "/Fo" ) ;
2415
+ fn command_add_output_file (
2416
+ cmd : & mut Command ,
2417
+ dst : & Path ,
2418
+ cuda : bool ,
2419
+ msvc : bool ,
2420
+ is_asm : bool ,
2421
+ is_arm : bool ,
2422
+ ) {
2423
+ if msvc && !cuda && !( is_asm && is_arm) {
2424
+ let mut s = OsString :: from ( "-Fo" ) ;
2451
2425
s. push ( & dst) ;
2452
2426
cmd. arg ( s) ;
2453
2427
} else {
0 commit comments