0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00

SERVER-8969 Support specifying minimum windows version to build

This commit is contained in:
Andrew Morrow 2013-04-02 17:15:13 -04:00
parent ad60f1bdac
commit 53d7bcd4ed
9 changed files with 120 additions and 64 deletions

View File

@ -197,7 +197,9 @@ add_option( "libc++", "use libc++ (experimental, requires clang)", 0, True )
# mongo feature options
add_option( "noshell", "don't build shell" , 0 , True )
add_option( "safeshell", "don't let shell scripts run programs (still, don't run untrusted scripts)" , 0 , True )
add_option( "win2008plus", "use newer operating system API features" , 0 , False )
add_option( "win2008plus",
"use newer operating system API features (deprecated, use win-version-min instead)" ,
0 , False )
# dev options
add_option( "d", "debug build no optimization, etc..." , 0 , True , "debugBuild" )
@ -591,8 +593,21 @@ elif "win32" == os.sys.platform:
env['DIST_ARCHIVE_SUFFIX'] = '.zip'
if has_option( "win2008plus" ):
env.Append( CPPDEFINES=[ "MONGO_USE_SRW_ON_WINDOWS" ] )
win_version_min_choices = {
'xpsp3' : ('0501', '0300'),
'vista' : ('0600', '0000'),
'ws08r2' : ('0601', '0000'),
'win7' : ('0601', '0000'),
'win8' : ('0602', '0000'),
}
add_option("win-version-min", "minimum Windows version to support", 1, False,
type = 'choice', default = None,
choices = win_version_min_choices.keys())
if has_option('win-version-min') and has_option('win2008plus'):
print("Can't specify both 'win-version-min' and 'win2008plus'")
Exit(1)
for pathdir in env['ENV']['PATH'].split(os.pathsep):
if os.path.exists(os.path.join(pathdir, 'cl.exe')):
@ -630,9 +645,7 @@ elif "win32" == os.sys.platform:
# 'conversion' conversion from 'type1' to 'type2', possible loss of data
# An integer type is converted to a smaller integer type.
env.Append( CCFLAGS=["/wd4355", "/wd4800", "/wd4267", "/wd4244"] )
# PSAPI_VERSION relates to process api dll Psapi.dll.
env.Append( CPPDEFINES=["_CONSOLE","_CRT_SECURE_NO_WARNINGS","PSAPI_VERSION=1" ] )
env.Append( CPPDEFINES=["_CONSOLE","_CRT_SECURE_NO_WARNINGS"] )
# this would be for pre-compiled headers, could play with it later
#env.Append( CCFLAGS=['/Yu"pch.h"'] )
@ -670,31 +683,11 @@ elif "win32" == os.sys.platform:
# This gives 32-bit programs 4 GB of user address space in WOW64, ignored in 64-bit builds
env.Append( LINKFLAGS=" /LARGEADDRESSAWARE " )
if force64:
env.Append( EXTRALIBPATH=[ winSDKHome + "/Lib/x64" ] )
else:
env.Append( EXTRALIBPATH=[ winSDKHome + "/Lib" ] )
if release:
env.Append( LINKFLAGS=" /NODEFAULTLIB:MSVCPRT " )
else:
env.Append( LINKFLAGS=" /NODEFAULTLIB:MSVCPRT /NODEFAULTLIB:MSVCRT " )
winLibString = "ws2_32.lib kernel32.lib advapi32.lib Psapi.lib DbgHelp.lib"
if force64:
winLibString += ""
else:
winLibString += " user32.lib gdi32.lib winspool.lib comdlg32.lib shell32.lib ole32.lib oleaut32.lib "
winLibString += " odbc32.lib odbccp32.lib uuid.lib "
env.Append(LIBS=['ws2_32.lib', 'kernel32.lib', 'advapi32.lib', 'Psapi.lib', 'DbgHelp.lib'])
# v8 calls timeGetTime()
if usev8:
winLibString += " winmm.lib "
env.Append( LIBS=Split(winLibString) )
env.Append(LIBS=['winmm.lib'])
env.Append( EXTRACPPPATH=["#/../winpcap/Include"] )
env.Append( EXTRALIBPATH=["#/../winpcap/Lib"] )
@ -898,6 +891,51 @@ def doConfigure(myenv):
myenv = conf.Finish()
# Figure out what our minimum windows version is. If the user has specified, then use
# that. Otherwise, if they have explicitly selected between 32 bit or 64 bit, choose XP or
# Vista respectively. Finally, if they haven't done either of these, try invoking the
# compiler to figure out whether we are doing a 32 or 64 bit build and select as
# appropriate.
if windows:
win_version_min = None
default_32_bit_min = 'xpsp3'
default_64_bit_min = 'vista'
if has_option('win-version-min'):
win_version_min = get_option('win-version-min')
elif has_option('win2008plus'):
win_version_min = 'win7'
else:
if force32:
win_version_min = default_32_bit_min
elif force64:
win_version_min = default_64_bit_min
else:
def CheckFor64Bit(context):
win64_test_body = textwrap.dedent(
"""
#if !defined(_WIN64)
#error
#endif
"""
)
context.Message('Checking if toolchain is in 64-bit mode... ')
result = context.TryCompile(win64_test_body, ".c")
context.Result(result)
return result
conf = Configure(myenv, clean=False, help=False, custom_tests = {
'CheckFor64Bit' : CheckFor64Bit
})
if conf.CheckFor64Bit():
win_version_min = default_64_bit_min
else:
win_version_min = default_32_bit_min
conf.Finish();
win_version_min = win_version_min_choices[win_version_min]
env.Append( CPPDEFINES=[("_WIN32_WINNT", "0x" + win_version_min[0])] )
env.Append( CPPDEFINES=[("NTDDI_VERSION", "0x" + win_version_min[0] + win_version_min[1])] )
# Enable PCH if we are on using gcc or clang and the 'Gch' tool is enabled. Otherwise,
# remove any pre-compiled header since the compiler may try to use it if it exists.
if usePCH and (using_gcc() or using_clang()):

View File

@ -637,7 +637,7 @@ namespace ThreadedTests {
RWLock::Upgradable u(m);
LOG(Z) << x << ' ' << ch << " got" << endl;
if( ch == 'U' ) {
#ifdef MONGO_USE_SRW_ON_WINDOWS
#if defined(NTDDI_VERSION) && defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
// SRW locks are neither fair nor FIFO, as per docs
if( t.millis() > 2000 ) {
#else

View File

@ -87,7 +87,12 @@ namespace mongo {
template <typename T>
class AtomicIntrinsics<T, typename boost::enable_if_c<sizeof(T) == sizeof(LONGLONG)>::type> {
public:
static const bool kHaveInterlocked64 = (_WIN32_WINNT >= _WIN32_WINNT_VISTA);
#if defined(NTDDI_VERSION) && defined(NTDDI_VISTA) && (NTDDI_VERSION >= NTDDI_VISTA)
static const bool kHaveInterlocked64 = true;
#else
static const bool kHaveInterlocked64 = false;
#endif
static T compareAndSwap(volatile T* dest, T expected, T newValue) {
return InterlockedImpl<kHaveInterlocked64>::compareAndSwap(dest, expected, newValue);

View File

@ -18,7 +18,26 @@
#pragma once
#if defined(_WIN32)
#if !defined(_WIN32)
#error "windows_basic included but _WIN32 is not defined"
#endif
// Ensure that _WIN32_WINNT is set to something before we include windows.h. For server builds
// both _WIN32_WINNT and NTDDI_VERSION are set as defines on the command line, but we need
// these here for things like client driver builds, where they may not already be set.
#if !defined(_WIN32_WINNT)
// Can't use symbolic versions here, since we may not have seen sdkddkver.h yet.
#if defined(_WIN64)
// 64-bit builds default to Windows Vista support.
#define _WIN32_WINNT 0x0600
#else
// 32-bit builds default to Windows XP support.
#define _WIN32_WINNT 0x0501
#endif
#endif
// No need to set WINVER, SdkDdkVer.h does that for us, we double check this below.
// for rand_s() usage:
# define _CRT_RAND_S
# ifndef NOMINMAX
@ -26,10 +45,28 @@
# endif
// tell windows.h not to include a bunch of headers we don't need:
# define WIN32_LEAN_AND_MEAN
# include "mongo/targetver.h"
# include <winsock2.h> //this must be included before the first windows.h include
# include <ws2tcpip.h>
# include <wspiapi.h>
# include <windows.h>
// Should come either from the command line, or if not set there, the inclusion of sdkddkver.h
// via windows.h above should set it based in _WIN32_WINNT, which is assuredly set by now.
#if !defined(NTDDI_VERSION)
#error "NTDDI_VERSION is not defined"
#endif
#if !defined(WINVER) || (WINVER != _WIN32_WINNT)
#error "Expected WINVER to have been defined and to equal _WIN32_WINNT"
#endif
#if defined(_WIN64)
#if !defined(NTDDI_VISTA) || (NTDDI_VERSION < NTDDI_VISTA)
#error "64 bit mongo does not support Windows versions older than Vista"
#endif
#else
#if !defined(NTDDI_WINXPSP3) || (NTDDI_VERSION < NTDDI_WINXPSP3)
#error "32 bit mongo does not support Windows versions older than XP Service Pack 3"
#endif
#endif

View File

@ -1,29 +0,0 @@
/**
* Copyright (C) 2008 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef _WIN32
#ifndef _WIN32_WINNT
#if defined _WIN64
// For 64 bit Windows we require at least Windows Vista or Windows Server 2008.
#define _WIN32_WINNT 0x0600
#else
// For 32 bit Windows we allow Windows XP as well. See platform/atomic_intrinsics_win32.h for
// an example of where this makes a difference.
#define _WIN32_WINNT 0x0502
#endif
#endif
#endif

View File

@ -39,7 +39,7 @@ using namespace std;
namespace mongo {
#if defined(_WIN32) && defined(MONGO_USE_SRW_ON_WINDOWS)
#if defined(NTDDI_VERSION) && defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
SimpleRWLock::SimpleRWLock(const StringData& p) : name(p.toString()) {
InitializeSRWLock(&_lock);
}

View File

@ -24,7 +24,7 @@
namespace mongo {
typedef RWLockBase1 RWLockBase;
}
#elif defined(MONGO_USE_SRW_ON_WINDOWS) && defined(_WIN32)
#elif defined(NTDDI_VERSION) && defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
// windows slimreaderwriter version. newer windows versions only

View File

@ -25,7 +25,7 @@ namespace mongo {
depending on OS, as there is no upgrade etc. facility herein.
*/
class SimpleRWLock : boost::noncopyable {
#if defined(_WIN32) && defined(MONGO_USE_SRW_ON_WINDOWS)
#if defined(NTDDI_VERSION) && defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
SRWLOCK _lock;
#else
RWLockBase m;

View File

@ -4,8 +4,13 @@
// (C) Copyright 2007 Anthony Williams
// (C) Copyright 2007 David Deakins
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x400
#endif
#ifndef WINVER
#define WINVER 0x400
#endif
#include <boost/thread/thread.hpp>
#include <algorithm>