diff --git a/src/powershell-native/CMakeLists.txt b/src/powershell-native/CMakeLists.txt index dd039341f..0bad92878 100644 --- a/src/powershell-native/CMakeLists.txt +++ b/src/powershell-native/CMakeLists.txt @@ -18,12 +18,16 @@ endif () # # Normalize the platform name # -# TODO: Only x64 and x86 are supported right now. This needs to be expanded to arm as well +# TODO: Only x64 and x86 are supported right now. This needs to be expanded to arm and arm64 to match CoreCLR # +SET(BUILD_ARCH_ARM 0) +SET(BUILD_ARCH_ARM64 0) if (WindowsSDKPlatform STREQUAL "x64" OR WindowsSDKPlatform STREQUAL "X64" OR WindowsSDKPlatform STREQUAL "amd64" OR WindowsSDKPlatform STREQUAL "AMD64") SET(WindowsSDKPlatform "x64") + SET(BUILD_ARCH_AMD64 1) elseif (WindowsSDKPlatform STREQUAL "x86" OR WindowsSDKPlatform STREQUAL "X86") SET(WindowsSDKPlatform "x86") + SET(BUILD_ARCH_X86 1) else() message(FATAL_ERROR "Unsupported WindowsSDKPlatform ${WindowsSDKPlatform}") endif () @@ -60,16 +64,10 @@ SET (WIN_VERSION_LONGHORN 0x0600) SET (WIN_VERSION_WS03 0x0502) SET (WIN_VERSION_WINXP 0x0501) -#include(dsc_defs.cmake) -if (BUILD_ONECORE) - include(nano_defs.cmake) -else () - include(coreclr_defs.cmake) -endif (BUILD_ONECORE) +include(coreclr_defs.cmake) # Default of BUILD_ONECORE should be ON once it is supported option(BUILD_ONECORE "Compile the OneCore version of the binaries" ON) -option(BUILD_DOWNLEVEL "Compile the downlevel version of the binaries" OFF) # Build the common library that powershell.exe and pwrshplugin.dll depend on add_subdirectory(nativemsh/pwrshcommon) diff --git a/src/powershell-native/Install-PowerShellRemoting.ps1 b/src/powershell-native/Install-PowerShellRemoting.ps1 index 9ef4224e3..bc3896374 100644 --- a/src/powershell-native/Install-PowerShellRemoting.ps1 +++ b/src/powershell-native/Install-PowerShellRemoting.ps1 @@ -13,7 +13,15 @@ param ( - [Switch]$Verbose + [parameter(ParameterSetName = "ByPath")] + [ValidateNotNullOrEmpty()] + [string] + $PowerShellHome, + + [parameter(ParameterSetName = "ByPath")] + [ValidateNotNullOrEmpty()] + [string] + $PowerShellVersion ) function Register-WinRmPlugin @@ -74,13 +82,18 @@ function Generate-PluginConfigFile [string] [parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] - $pluginFile + $pluginFile, + + [string] + [parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + $powershellHomeDir ) # This always overwrites the file with a new version of it if the # script is invoked multiple times. - Set-Content -Path $pluginFile -Value "PSHOMEDIR=$PSHOME" - Add-Content -Path $pluginFile -Value "CORECLRDIR=$PSHOME" + Set-Content -Path $pluginFile -Value "PSHOMEDIR=$powershellHomeDir" + Add-Content -Path $pluginFile -Value "CORECLRDIR=$powershellHomeDir" Write-Verbose "Created Plugin Config File: $pluginFile" } @@ -103,7 +116,9 @@ if ($Verbose) $VerbosePreference = "Continue" } -$powershellVersion = $PSVersionTable.PSVersion +$powershellVersion = $PowershellVersion +$powershellHome = $PowerShellHome + $pluginBasePath = Join-Path "$env:WINDIR\System32\PowerShell" $powerShellVersion $resolvedPluginAbsolutePath = "" @@ -122,10 +137,10 @@ $pluginRawPath = Join-Path $resolvedPluginAbsolutePath "pwrshplugin.dll" $fixedPluginPath = $pluginRawPath -replace '\\','\\' # This is forced to ensure the the file is placed correctly -Copy-Item $PSHOME\pwrshplugin.dll $resolvedPluginAbsolutePath -Force -Verbose +Copy-Item $powershellHome\pwrshplugin.dll $resolvedPluginAbsolutePath -Force -Verbose $pluginFile = Join-Path $resolvedPluginAbsolutePath "RemotePowerShellConfig.txt" -Generate-PluginConfigFile $pluginFile +Generate-PluginConfigFile $pluginFile $powershellHome $pluginEndpointName = "powershell.$powershellVersion" @@ -163,3 +178,6 @@ catch [Microsoft.PowerShell.Commands.WriteErrorException] Write-Error "No remoting session configuration matches the name $pluginEndpointName." } +Write-Host "Restarting WinRM to ensure that the plugin configuration change takes effect. This is required in WinRM pre-Windows 10" +Restart-Service winrm + diff --git a/src/powershell-native/coreclr_defs.cmake b/src/powershell-native/coreclr_defs.cmake index 1b4071895..5468843e2 100644 --- a/src/powershell-native/coreclr_defs.cmake +++ b/src/powershell-native/coreclr_defs.cmake @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 2.8.4) set(CMAKE_CXX_STANDARD_LIBRARIES "") # do not link against standard win32 libs i.e. kernel32, uuid, user32, etc. -#if(NOT CLR_CMAKE_PLATFORM_ARCH_ARM64) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf") -#endif (NOT CLR_CMAKE_PLATFORM_ARCH_ARM64) +if(NOT BUILD_ARCH_ARM64) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf") +endif (NOT BUILD_ARCH_ARM64) # Incremental linking with CFG is broken until next VS release. # This needs to be appended to the last for each build type to override the default flag. @@ -24,12 +24,6 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUGTYPE:cv,fixup" set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /PDBCOMPRESS") #shrink pdb size set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG") -# -# TODO: Should these be ignored???? -# -#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /IGNORE:4197,4013,4254,4070,4221") -#set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /PDBCOMPRESS") #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:1572864") @@ -53,13 +47,6 @@ set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWIT set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG /OPT:REF /OPT:ICF ${NO_INCREMENTAL_LINKER_FLAGS}") -# Temporary until cmake has VS generators for arm64 -#if(CLR_CMAKE_PLATFORM_ARCH_ARM64) -# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /machine:arm64") -# set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /machine:arm64") -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /machine:arm64") -#endif(CLR_CMAKE_PLATFORM_ARCH_ARM64) - # Force uCRT to be dynamically linked for Release build set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:ucrt.lib") @@ -69,24 +56,22 @@ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBIN #------------------------------------ # Definitions (for platform) #----------------------------------- -#if (CLR_CMAKE_PLATFORM_ARCH_AMD64) - add_definitions(-D_AMD64_) - add_definitions(-D_WIN64) - add_definitions(-DAMD64) - add_definitions(-DBIT64=1) -#elseif (CLR_CMAKE_PLATFORM_ARCH_I386) -# add_definitions(-D_X86_) -#elseif (CLR_CMAKE_PLATFORM_ARCH_ARM) -# add_definitions(-D_ARM_) -# add_definitions(-DARM) -#elseif (CLR_CMAKE_PLATFORM_ARCH_ARM64) -# add_definitions(-D_ARM64_) -# add_definitions(-DARM64) -# add_definitions(-D_WIN64) -# add_definitions(-DBIT64=1) -#else () -# clr_unknown_arch() -#endif () +if (BUILD_ARCH_AMD64) + add_definitions(-D_AMD64_) + add_definitions(-D_WIN64) + add_definitions(-DAMD64) + add_definitions(-DBIT64=1) +elseif (BUILD_ARCH_I386) + add_definitions(-D_X86_) +elseif (BUILD_ARCH_ARM) + add_definitions(-D_ARM_) + add_definitions(-DARM) +elseif (BUILD_ARCH_ARM64) + add_definitions(-D_ARM64_) + add_definitions(-DARM64) + add_definitions(-D_WIN64) + add_definitions(-DBIT64=1) +endif () # Define the CRT lib references that link into Desktop imports set(STATIC_MT_CRT_LIB "libcmt$<$,$>:d>.lib") @@ -111,7 +96,7 @@ add_compile_options(/W3) # set warning level to 3 #add_compile_options(/WX) # treat warnings as errors add_compile_options(/Oi) # enable intrinsics add_compile_options(/Oy-) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls -#add_compile_options(/U_MT) # undefine the predefined _MT macro +add_compile_options(/U_MT) # undefine the predefined _MT macro add_compile_options(/GF) # enable read-only string pooling add_compile_options(/Gm-) # disable minimal rebuild add_compile_options(/EHa) # enable C++ EH (w/ SEH exceptions) @@ -121,24 +106,27 @@ add_compile_options(/Zc:wchar_t-) # C++ language conformance: wchar_t is NOT the add_compile_options(/Zc:forScope) # C++ language conformance: enforce Standard C++ for scoping rules add_compile_options(/GR-) # disable C++ RTTI add_compile_options(/FC) # use full pathnames in diagnostics -#add_compile_options(/MP) # Build with Multiple Processes (number of processes equal to the number of processors) +if (BUILD_CORECLR) + # This option is not supported for "FullClr" because it triggers: error C2813: #import is not supported with /MP + add_compile_options(/MP) # Build with Multiple Processes (number of processes equal to the number of processors) +endif (BUILD_CORECLR) add_compile_options(/GS) # Buffer Security Check add_compile_options(/Zm200) # Specify Precompiled Header Memory Allocation Limit of 150MB -add_compile_options(/wd4960 /wd4961 /wd4603 /wd4627 /wd4838 /wd4456 /wd4457 /wd4458 /wd4459 /wd4091 /we4640) +#add_compile_options(/wd4960 /wd4961 /wd4603 /wd4627 /wd4838 /wd4456 /wd4457 /wd4458 /wd4459 /wd4091 /we4640) add_compile_options(/Zi) # enable debugging information add_compile_options(/ZH:SHA_256) # use SHA256 for generating hashes of compiler processed source files. -#if (CLR_CMAKE_PLATFORM_ARCH_I386) -# add_compile_options(/Gz) -#endif (CLR_CMAKE_PLATFORM_ARCH_I386) +if (BUILD_ARCH_I386) + add_compile_options(/Gz) +endif (BUILD_ARCH_I386) add_compile_options($<$,$>:/GL>) add_compile_options($<$,$>,$>:/O1>) -#if (CLR_CMAKE_PLATFORM_ARCH_AMD64) +if (BUILD_ARCH_AMD64) # The generator expression in the following command means that the /homeparams option is added only for debug builds add_compile_options($<$:/homeparams>) # Force parameters passed in registers to be written to the stack -#endif (CLR_CMAKE_PLATFORM_ARCH_AMD64) +endif (BUILD_ARCH_AMD64) # enable control-flow-guard support for native components for non-Arm64 builds add_compile_options(/guard:cf) @@ -154,41 +142,26 @@ add_compile_options($<$,$>:/MTd>) #set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /ZH:SHA_256") -#if (CLR_CMAKE_TARGET_ARCH_AMD64) +if (BUILD_ARCH_AMD64) add_definitions(-D_TARGET_AMD64_=1) - add_definitions(-DDBG_TARGET_64BIT=1) - add_definitions(-DDBG_TARGET_AMD64=1) - add_definitions(-DDBG_TARGET_WIN64=1) -#elseif (CLR_CMAKE_TARGET_ARCH_ARM) -# add_definitions(-D_TARGET_ARM_=1) -# add_definitions(-DDBG_TARGET_32BIT=1) -# add_definitions(-DDBG_TARGET_ARM=1) -#elseif (CLR_CMAKE_TARGET_ARCH_I386) -# add_definitions(-D_TARGET_X86_=1) -# add_definitions(-DDBG_TARGET_32BIT=1) -# add_definitions(-DDBG_TARGET_X86=1) -#else () -# clr_unknown_arch() -#endif (CLR_CMAKE_TARGET_ARCH_AMD64) - -# -# TODO: Are these needed??????????? -# -#add_definitions(-D_BLD_CLR) -#add_definitions(-DDEBUGGING_SUPPORTED) -#add_definitions(-DPROFILING_SUPPORTED) +elseif (BUILD_ARCH_ARM) + add_definitions(-D_TARGET_ARM_=1) +elseif (BUILD_ARCH_I386) + add_definitions(-D_TARGET_X86_=1) +endif (BUILD_ARCH_AMD64) add_definitions(-DWIN32) add_definitions(-D_WIN32) -add_definitions(-DWINVER=${WIN_VERSION_WIN8})# 0x0601 for Win7, was 0x0602 -add_definitions(-D_WIN32_WINNT=${WIN_VERSION_WIN8}) # 0x0601 for Win7 +add_definitions(-DWINVER=${WIN_VERSION_WIN8}) +add_definitions(-D_WIN32_WINNT=${WIN_VERSION_WIN8}) add_definitions(-DWIN32_LEAN_AND_MEAN=1) add_definitions(-D_CRT_SECURE_NO_WARNINGS) -#if(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386) - # Only enable edit and continue on windows x86 and x64 - # exclude Linux, arm & arm64 + +if(BUILD_ARCH_AMD64 OR BUILD_ARCH_I386) + # Only enable edit and continue on windows x86 and x64. + # Exclude arm & arm64 add_definitions(-DEnC_SUPPORTED) -#endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386) +endif(BUILD_ARCH_AMD64 OR BUILD_ARCH_I386) add_definitions(-DUNICODE) add_definitions(-D_UNICODE) diff --git a/src/powershell-native/nativemsh/pwrshcommon/CMakeLists.txt b/src/powershell-native/nativemsh/pwrshcommon/CMakeLists.txt index d8170fa41..29b0b6c92 100644 --- a/src/powershell-native/nativemsh/pwrshcommon/CMakeLists.txt +++ b/src/powershell-native/nativemsh/pwrshcommon/CMakeLists.txt @@ -13,25 +13,12 @@ target_include_directories(pwrshcommon PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) if (BUILD_ONECORE) # Libraries to use when creating this binary for Windows on OneCore-based SKUs set(PWRSHCOMMON_WINDOWS_LIBS - # onecore.lib ) set_target_properties(pwrshcommon PROPERTIES COMPILE_DEFINITIONS "CORECLR") else () # NOT BUILD_ONECORE # Libraries to use when creating this binary for Windows on full SKUs # Note: The appropriate libs get added automatically by VS set(PWRSHCOMMON_WINDOWS_LIBS - # CoreCLR libs -### ${STATIC_MT_CRT_LIB} -### ${STATIC_MT_VCRT_LIB} -### ${STATIC_UCRT_LIB} - # - # ole32.lib - # oleaut32.lib - # uuid.lib - # user32.lib - # MUILoad.lib - # msxml6.lib - # mscoree.lib) ) endif (BUILD_ONECORE) diff --git a/src/powershell-native/nativemsh/pwrshexe/CMakeLists.txt b/src/powershell-native/nativemsh/pwrshexe/CMakeLists.txt index e0f8ada21..149f1048e 100644 --- a/src/powershell-native/nativemsh/pwrshexe/CMakeLists.txt +++ b/src/powershell-native/nativemsh/pwrshexe/CMakeLists.txt @@ -8,22 +8,29 @@ if (BUILD_ONECORE) CssMainEntry.cpp ) set(PWRSHEXE_WINDOWS_LIBS -### ${STATIC_MT_CRT_LIB} -### ${STATIC_MT_VCRT_LIB} -### ${STATIC_UCRT_LIB} onecore.lib - vcruntime.lib - ucrtd.lib - msvcrt.lib - msvcrt.lib - msvcprtd.lib - user32.lib - atls.lib + ${STATIC_MT_CRT_LIB} + ${STATIC_MT_VCRT_LIB} ) - set(powershell_definitions - _CONSOLE - CORECLR - ) + set(powershell_definitions + _CONSOLE + CORECLR + ) + + # + # Configure lib directories so that CI picks up onecore.lib + # + SET (WindowsSdkDir $ENV{WindowsSdkDir}) + SET (WindowsSDKVersion $ENV{WindowsSDKVersion}) + SET (WindowsSDKLibBase "${WindowsSdkDir}/Lib/${WindowsSDKVersion}") + SET (OneCoreLibBase "$ENV{VCInstallDir}lib/onecore/amd64") + + SET (LibraryPath) + list (APPEND LibraryPath "${OneCoreLibBase}") + list (APPEND LibraryPath "${WindowsSDKLibBase}ucrt/${WindowsSDKPlatform}") + list (APPEND LibraryPath "${WindowsSDKLibBase}um/${WindowsSDKPlatform}" ) + link_directories(${LibraryPath}) + else () # Settings to use when creating PowerShell.exe for Windows on full SKUs or downlevel platforms set(PWRSHEXE_WINDOWS_SOURCES @@ -34,11 +41,6 @@ else () # CoreCLR libs ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB} - # ${STATIC_UCRT_LIB} -# ole32.lib -# oleaut32.lib -# uuid.lib -# user32.lib MUILoad.lib msxml6.lib mscoree.lib diff --git a/src/powershell-native/nativemsh/pwrshplugin/CMakeLists.txt b/src/powershell-native/nativemsh/pwrshplugin/CMakeLists.txt index 981d69d82..2090d7de2 100644 --- a/src/powershell-native/nativemsh/pwrshplugin/CMakeLists.txt +++ b/src/powershell-native/nativemsh/pwrshplugin/CMakeLists.txt @@ -13,35 +13,23 @@ add_library(pwrshplugin SHARED if (BUILD_ONECORE) # Libraries to use when creating this binary for Windows on OneCore-based SKUs set(PWRSHPLUGIN_WINDOWS_LIBS -### ${STATIC_MT_CRT_LIB} -### ${STATIC_MT_VCRT_LIB} -### ${STATIC_UCRT_LIB} - onecore.lib - vcruntime.lib - ucrtd.lib - msvcrt.lib - msvcprtd.lib - user32.lib - atls.lib + ${STATIC_MT_CRT_LIB} + ${STATIC_MT_VCRT_LIB} + kernel32.lib + advapi32.lib + ole32.lib wsmsvc.lib ) set_target_properties(pwrshplugin PROPERTIES COMPILE_DEFINITIONS "CORECLR") else () # Libraries to use when creating this binary for Windows on full SKUs set(PWRSHPLUGIN_WINDOWS_LIBS -# ntdll.lib -# kernel32.lib -# advapi32.lib -# ole32.lib -# oleaut32.lib -# uuid.lib MUILoad.lib mscoree.lib wsmsvc.lib # CoreCLR lib ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB} - # ${STATIC_UCRT_LIB} legacy_stdio_definitions.lib # Resolves: LNK2019: unresolved external symbol _vsnwprintf ) set(pwrshplugin_definitions ${common_pwrsh_definitions}) diff --git a/src/powershell-win-core/.gitignore b/src/powershell-win-core/.gitignore new file mode 100644 index 000000000..8aa2b4e44 --- /dev/null +++ b/src/powershell-win-core/.gitignore @@ -0,0 +1 @@ +Install-PowerShellRemoting.ps1 diff --git a/src/powershell-win-full/.gitignore b/src/powershell-win-full/.gitignore new file mode 100644 index 000000000..8aa2b4e44 --- /dev/null +++ b/src/powershell-win-full/.gitignore @@ -0,0 +1 @@ +Install-PowerShellRemoting.ps1