Skip to content

Commit 2db48d7

Browse files
committed
Auto merge of #44979 - hinaria:master, r=dtolnay
make `backtrace = false` compile for windows targets. when building for windows with `backtrace = false`, `libstd` fails to compile because some modules that use items from `sys_common::backtrace::*` are still included, even though those modules aren't used or referenced by anything. `sys_common::backtrace` doesn't exist when the backtrace feature is turned off. -- i've also added `#[cfg(feature = "backtrace")]` to various items that exist exclusively to support `mod backtrace` since the compilation would fail since they would be unused in a configuration with backtraces turned off.
2 parents bd90aa6 + a5296a5 commit 2db48d7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/libstd/sys/windows/c.rs

+11
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,13 @@ pub const WAIT_TIMEOUT: DWORD = 258;
279279
pub const WAIT_FAILED: DWORD = 0xFFFFFFFF;
280280

281281
#[cfg(target_env = "msvc")]
282+
#[cfg(feature = "backtrace")]
282283
pub const MAX_SYM_NAME: usize = 2000;
283284
#[cfg(target_arch = "x86")]
285+
#[cfg(feature = "backtrace")]
284286
pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
285287
#[cfg(target_arch = "x86_64")]
288+
#[cfg(feature = "backtrace")]
286289
pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;
287290

288291
pub const PROV_RSA_FULL: DWORD = 1;
@@ -575,6 +578,7 @@ pub struct OVERLAPPED {
575578

576579
#[repr(C)]
577580
#[cfg(target_env = "msvc")]
581+
#[cfg(feature = "backtrace")]
578582
pub struct SYMBOL_INFO {
579583
pub SizeOfStruct: c_ulong,
580584
pub TypeIndex: c_ulong,
@@ -598,6 +602,7 @@ pub struct SYMBOL_INFO {
598602

599603
#[repr(C)]
600604
#[cfg(target_env = "msvc")]
605+
#[cfg(feature = "backtrace")]
601606
pub struct IMAGEHLP_LINE64 {
602607
pub SizeOfStruct: u32,
603608
pub Key: *const c_void,
@@ -616,13 +621,15 @@ pub enum ADDRESS_MODE {
616621
}
617622

618623
#[repr(C)]
624+
#[cfg(feature = "backtrace")]
619625
pub struct ADDRESS64 {
620626
pub Offset: u64,
621627
pub Segment: u16,
622628
pub Mode: ADDRESS_MODE,
623629
}
624630

625631
#[repr(C)]
632+
#[cfg(feature = "backtrace")]
626633
pub struct STACKFRAME64 {
627634
pub AddrPC: ADDRESS64,
628635
pub AddrReturn: ADDRESS64,
@@ -638,6 +645,7 @@ pub struct STACKFRAME64 {
638645
}
639646

640647
#[repr(C)]
648+
#[cfg(feature = "backtrace")]
641649
pub struct KDHELP64 {
642650
pub Thread: u64,
643651
pub ThCallbackStack: DWORD,
@@ -1089,6 +1097,7 @@ extern "system" {
10891097
pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
10901098
-> BOOL;
10911099
pub fn FindClose(findFile: HANDLE) -> BOOL;
1100+
#[cfg(feature = "backtrace")]
10921101
pub fn RtlCaptureContext(ctx: *mut CONTEXT);
10931102
pub fn getsockopt(s: SOCKET,
10941103
level: c_int,
@@ -1120,7 +1129,9 @@ extern "system" {
11201129
res: *mut *mut ADDRINFOA) -> c_int;
11211130
pub fn freeaddrinfo(res: *mut ADDRINFOA);
11221131

1132+
#[cfg(feature = "backtrace")]
11231133
pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
1134+
#[cfg(feature = "backtrace")]
11241135
pub fn FreeLibrary(handle: HMODULE) -> BOOL;
11251136
pub fn GetProcAddress(handle: HMODULE,
11261137
name: LPCSTR) -> *mut c_void;

src/libstd/sys/windows/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ use time::Duration;
2020
#[macro_use] pub mod compat;
2121

2222
pub mod args;
23+
#[cfg(feature = "backtrace")]
2324
pub mod backtrace;
2425
pub mod c;
2526
pub mod condvar;
27+
#[cfg(feature = "backtrace")]
2628
pub mod dynamic_lib;
2729
pub mod env;
2830
pub mod ext;

0 commit comments

Comments
 (0)