Skip to content

Commit

Permalink
Auto merge of #44979 - hinaria:master, r=dtolnay
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Oct 4, 2017
2 parents bd90aa6 + a5296a5 commit 2db48d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libstd/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,13 @@ pub const WAIT_TIMEOUT: DWORD = 258;
pub const WAIT_FAILED: DWORD = 0xFFFFFFFF;

#[cfg(target_env = "msvc")]
#[cfg(feature = "backtrace")]
pub const MAX_SYM_NAME: usize = 2000;
#[cfg(target_arch = "x86")]
#[cfg(feature = "backtrace")]
pub const IMAGE_FILE_MACHINE_I386: DWORD = 0x014c;
#[cfg(target_arch = "x86_64")]
#[cfg(feature = "backtrace")]
pub const IMAGE_FILE_MACHINE_AMD64: DWORD = 0x8664;

pub const PROV_RSA_FULL: DWORD = 1;
Expand Down Expand Up @@ -575,6 +578,7 @@ pub struct OVERLAPPED {

#[repr(C)]
#[cfg(target_env = "msvc")]
#[cfg(feature = "backtrace")]
pub struct SYMBOL_INFO {
pub SizeOfStruct: c_ulong,
pub TypeIndex: c_ulong,
Expand All @@ -598,6 +602,7 @@ pub struct SYMBOL_INFO {

#[repr(C)]
#[cfg(target_env = "msvc")]
#[cfg(feature = "backtrace")]
pub struct IMAGEHLP_LINE64 {
pub SizeOfStruct: u32,
pub Key: *const c_void,
Expand All @@ -616,13 +621,15 @@ pub enum ADDRESS_MODE {
}

#[repr(C)]
#[cfg(feature = "backtrace")]
pub struct ADDRESS64 {
pub Offset: u64,
pub Segment: u16,
pub Mode: ADDRESS_MODE,
}

#[repr(C)]
#[cfg(feature = "backtrace")]
pub struct STACKFRAME64 {
pub AddrPC: ADDRESS64,
pub AddrReturn: ADDRESS64,
Expand All @@ -638,6 +645,7 @@ pub struct STACKFRAME64 {
}

#[repr(C)]
#[cfg(feature = "backtrace")]
pub struct KDHELP64 {
pub Thread: u64,
pub ThCallbackStack: DWORD,
Expand Down Expand Up @@ -1089,6 +1097,7 @@ extern "system" {
pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
-> BOOL;
pub fn FindClose(findFile: HANDLE) -> BOOL;
#[cfg(feature = "backtrace")]
pub fn RtlCaptureContext(ctx: *mut CONTEXT);
pub fn getsockopt(s: SOCKET,
level: c_int,
Expand Down Expand Up @@ -1120,7 +1129,9 @@ extern "system" {
res: *mut *mut ADDRINFOA) -> c_int;
pub fn freeaddrinfo(res: *mut ADDRINFOA);

#[cfg(feature = "backtrace")]
pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE;
#[cfg(feature = "backtrace")]
pub fn FreeLibrary(handle: HMODULE) -> BOOL;
pub fn GetProcAddress(handle: HMODULE,
name: LPCSTR) -> *mut c_void;
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ use time::Duration;
#[macro_use] pub mod compat;

pub mod args;
#[cfg(feature = "backtrace")]
pub mod backtrace;
pub mod c;
pub mod condvar;
#[cfg(feature = "backtrace")]
pub mod dynamic_lib;
pub mod env;
pub mod ext;
Expand Down

0 comments on commit 2db48d7

Please sign in to comment.