Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "src/libpsl-native/test/googletest"]
path = src/libpsl-native/test/googletest
url = https://github.com/google/googletest.git
ignore = dirty
284 changes: 0 additions & 284 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -177,220 +177,6 @@ if ( -not $env:PSModulePath.Contains($TestModulePath) ) {
$env:PSModulePath = $TestModulePath+$TestModulePathSeparator+$($env:PSModulePath)
}

function Test-Win10SDK {
# The Windows 10 SDK is installed to "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64",
# but the directory may exist even if the SDK has not been installed.
#
# A slightly more robust check is for the mc.exe binary within that directory.
# It is only present if the SDK is installed.
return (Test-Path "${env:ProgramFiles(x86)}\Windows Kits\10\bin\x64\mc.exe")
}

function Start-BuildNativeWindowsBinaries {
param(
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Release',

# The `x64_arm` syntax is the build environment for VS2017, `x64` means the host is an x64 machine and will use
# the x64 built tool. The `arm` refers to the target architecture when doing cross compilation.
[ValidateSet('x64', 'x86', 'x64_arm64', 'x64_arm')]
[string]$Arch = 'x64',

[switch]$Clean
)

if (-not $Environment.IsWindows) {
Write-Warning -Message "'Start-BuildNativeWindowsBinaries' is only supported on Windows platforms"
return
}

# cmake is needed to build pwsh.exe
if (-not (precheck 'cmake' $null)) {
throw 'cmake not found. Run "Start-PSBootstrap -BuildWindowsNative". You can also install it from https://chocolatey.org/packages/cmake'
}

Use-MSBuild

# mc.exe is Message Compiler for native resources
if (-Not (Test-Win10SDK)) {
throw 'Win 10 SDK not found. Run "Start-PSBootstrap -BuildWindowsNative" or install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk'
}

if ($env:VS140COMNTOOLS -ne $null) {
$vcPath = (Get-Item(Join-Path -Path "$env:VS140COMNTOOLS" -ChildPath '../../vc')).FullName
} else {
$vcPath = (Get-ChildItem "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017" -Filter "VC" -Directory -Recurse | Select-Object -First 1).FullName
}

$atlMfcIncludePath = Join-Path -Path $vcPath -ChildPath 'atlmfc/include'
if (!(Test-Path $atlMfcIncludePath)) { # for VS2017, need to search for it
$atlMfcIncludePath = (Get-ChildItem $vcPath -Filter AtlBase.h -Recurse -File | Select-Object -First 1).DirectoryName
}

# atlbase.h is included in the pwrshplugin project
if ((Test-Path -Path $atlMfcIncludePath\atlbase.h) -eq $false) {
throw "Could not find Visual Studio include file atlbase.h at $atlMfcIncludePath. Please ensure the optional feature 'Microsoft Foundation Classes for C++' is installed."
}

# vcvarsall.bat is used to setup environment variables
$vcvarsallbatPath = "$vcPath\vcvarsall.bat"
if (!(Test-Path -Path $vcvarsallbatPath)) { # for VS2017, need to search for it
$vcvarsallbatPath = (Get-ChildItem $vcPath -Filter vcvarsall.bat -Recurse -File | Select-Object -First 1).FullName
}

if ([string]::IsNullOrEmpty($vcvarsallbatPath) -or (Test-Path -Path $vcvarsallbatPath) -eq $false) {
throw "Could not find Visual Studio vcvarsall.bat at $vcvarsallbatPath. Please ensure the optional feature 'Common Tools for Visual C++' is installed."
}

Write-Log "Start building native Windows binaries"

if ($Clean) {
git clean -fdx
Remove-Item $HOME\source\cmakecache.txt -ErrorAction SilentlyContinue
}

try {
Push-Location "$PSScriptRoot\src\powershell-native"

# setup cmakeGenerator
$cmakeGeneratorPlatform = ""
if ($Arch -eq 'x86') {
$cmakeGenerator = 'Visual Studio 15 2017'
$cmakeArch = 'x86'
} elseif ($Arch -eq 'x64_arm') {
$cmakeGenerator = 'Visual Studio 15 2017 ARM'
$cmakeArch = 'arm'
} elseif ($Arch -eq 'x64_arm64') {
$cmakeGenerator = 'Visual Studio 15 2017'
$cmakeArch = 'arm64'
$cmakeGeneratorPlatform = "-A ARM64"
} else {
$cmakeGenerator = 'Visual Studio 15 2017 Win64'
$cmakeArch = 'x64'
}

# Compile native resources
$currentLocation = Get-Location
@("nativemsh\pwrshplugin") | ForEach-Object {
$nativeResourcesFolder = $_
Get-ChildItem $nativeResourcesFolder -Filter "*.mc" | ForEach-Object {
$command = @"
cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" mc.exe -o -d -c -U "$($_.FullName)" -h "$currentLocation\$nativeResourcesFolder" -r "$currentLocation\$nativeResourcesFolder"
"@
Write-Log " Executing mc.exe Command: $command"
Start-NativeExecution { Invoke-Expression -Command:$command }
}
}

# make sure we use version we installed and not from VS
$cmakePath = (Get-Command cmake).Source
# Disabling until I figure out if it is necessary
# $overrideFlags = "-DCMAKE_USER_MAKE_RULES_OVERRIDE=$PSScriptRoot\src\powershell-native\windows-compiler-override.txt"
$overrideFlags = ""
$command = @"
cmd.exe /C cd /d "$currentLocation" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$cmakeArch -G "$cmakeGenerator" $cmakeGeneratorPlatform "$currentLocation" "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration"
"@
Write-Log " Executing Build Command: $command"
Start-NativeExecution { Invoke-Expression -Command:$command }

# Copy the binaries from the local build directory to the packaging directory
$FilesToCopy = @('pwrshplugin.dll', 'pwrshplugin.pdb')
$dstPath = "$PSScriptRoot\src\powershell-win-core"
$FilesToCopy | ForEach-Object {
$srcPath = [IO.Path]::Combine($PWD.Path, "bin", $Configuration, "CoreClr/$_")

Write-Log " Copying $srcPath to $dstPath"
Copy-Item $srcPath $dstPath
}

#
# Build the ETW manifest resource-only binary
#
$location = "$PSScriptRoot\src\PowerShell.Core.Instrumentation"
Set-Location -Path $location

Remove-Item $HOME\source\cmakecache.txt -ErrorAction SilentlyContinue

$command = @"
cmd.exe /C cd /d "$location" "&" "$vcvarsallbatPath" "$Arch" "&" "$cmakePath" "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$cmakeArch -G "$cmakeGenerator" $cmakeGeneratorPlatform "$location" "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration"
"@
Write-Log " Executing Build Command for PowerShell.Core.Instrumentation: $command"
Start-NativeExecution { Invoke-Expression -Command:$command }

# Copy the binary to the packaging directory
# NOTE: No PDB file; it's a resource-only DLL.
$srcPath = [IO.Path]::Combine($PWD.Path, $Configuration, 'PowerShell.Core.Instrumentation.dll')
Copy-Item -Path $srcPath -Destination $dstPath

} finally {
Pop-Location
}
}

function Start-BuildNativeUnixBinaries {
param (
[switch] $BuildLinuxArm
)

if (-not $Environment.IsLinux -and -not $Environment.IsMacOS) {
Write-Warning -Message "'Start-BuildNativeUnixBinaries' is only supported on Linux/macOS platforms"
return
}

if ($BuildLinuxArm -and -not $Environment.IsUbuntu) {
throw "Cross compiling for linux-arm is only supported on Ubuntu environment"
}

# Verify we have all tools in place to do the build
$precheck = $true
foreach ($Dependency in 'cmake', 'make', 'g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}

if ($BuildLinuxArm) {
foreach ($Dependency in 'arm-linux-gnueabihf-gcc', 'arm-linux-gnueabihf-g++') {
$precheck = $precheck -and (precheck $Dependency "Build dependency '$Dependency' not found. Run 'Start-PSBootstrap'.")
}
}

# Abort if any precheck failed
if (-not $precheck) {
return
}

# Build native components
$Ext = if ($Environment.IsLinux) {
"so"
} elseif ($Environment.IsMacOS) {
"dylib"
}

$Native = "$PSScriptRoot/src/libpsl-native"
$Lib = "$PSScriptRoot/src/powershell-unix/libpsl-native.$Ext"
Write-Log "Start building $Lib"

git clean -qfdX $Native

try {
Push-Location $Native
if ($BuildLinuxArm) {
Start-NativeExecution { cmake -DCMAKE_TOOLCHAIN_FILE="./arm.toolchain.cmake" . }
Start-NativeExecution { make -j }
}
else {
Start-NativeExecution { cmake -DCMAKE_BUILD_TYPE=Debug . }
Start-NativeExecution { make -j }
Start-NativeExecution { ctest --verbose }
}
} finally {
Pop-Location
}

if (-not (Test-Path $Lib)) {
throw "Compilation of $Lib failed"
}
}

<#
.Synopsis
Tests if a version is preview
Expand Down Expand Up @@ -1719,7 +1505,6 @@ function Start-PSBootstrap {
[string]$Version = $dotnetCLIRequiredVersion,
[switch]$Package,
[switch]$NoSudo,
[switch]$BuildWindowsNative,
[switch]$BuildLinuxArm,
[switch]$Force
)
Expand Down Expand Up @@ -1909,75 +1694,6 @@ function Start-PSBootstrap {

Invoke-WebRequest -OutFile "~/.rcedit/rcedit-x64.exe" -Uri $rceditUrl
}

if ($BuildWindowsNative) {
Write-Log "Install Windows dependencies for building PSRP plugin"

$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
$newMachineEnvironmentPath = $machinePath

$cmakePresent = precheck 'cmake' $null
$sdkPresent = Test-Win10SDK

# Install chocolatey
$chocolateyPath = "$env:AllUsersProfile\chocolatey\bin"

if(precheck 'choco' $null) {
Write-Log "Chocolatey is already installed. Skipping installation."
}
elseif(($cmakePresent -eq $false) -or ($sdkPresent -eq $false)) {
Write-Log "Chocolatey not present. Installing chocolatey."
if ($Force -or $PSCmdlet.ShouldProcess("Install chocolatey via https://chocolatey.org/install.ps1")) {
Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) {
Write-Log "Adding $chocolateyPath to Path environment variable"
$env:Path += ";$chocolateyPath"
$newMachineEnvironmentPath += ";$chocolateyPath"
} else {
Write-Log "$chocolateyPath already present in Path environment variable"
}
} else {
Write-Error "Chocolatey is required to install missing dependencies. Please install it from https://chocolatey.org/ manually. Alternatively, install cmake and Windows 10 SDK."
return
}
} else {
Write-Log "Skipping installation of chocolatey, cause both cmake and Win 10 SDK are present."
}

# Install cmake
$cmakePath = "${env:ProgramFiles}\CMake\bin"
if($cmakePresent -and !($force.IsPresent)) {
Write-Log "Cmake is already installed. Skipping installation."
} else {
Write-Log "Cmake not present or -Force used. Installing cmake."
Start-NativeExecution { choco install cmake -y --version 3.10.0 }
if (-not ($machinePath.ToLower().Contains($cmakePath.ToLower()))) {
Write-Log "Adding $cmakePath to Path environment variable"
$env:Path += ";$cmakePath"
$newMachineEnvironmentPath = "$cmakePath;$newMachineEnvironmentPath"
} else {
Write-Log "$cmakePath already present in Path environment variable"
}
}

# Install Windows 10 SDK
$packageName = "windows-sdk-10.0"

if (-not $sdkPresent) {
Write-Log "Windows 10 SDK not present. Installing $packageName."
Start-NativeExecution { choco install windows-sdk-10.0 -y }
} else {
Write-Log "Windows 10 SDK present. Skipping installation."
}

# Update path machine environment variable
if ($newMachineEnvironmentPath -ne $machinePath) {
Write-Log "Updating Path machine environment variable"
if ($Force -or $PSCmdlet.ShouldProcess("Update Path machine environment variable to $newMachineEnvironmentPath")) {
[Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE')
}
}
}
}
} finally {
Pop-Location
Expand Down
75 changes: 0 additions & 75 deletions src/PowerShell.Core.Instrumentation/CMakeLists.txt

This file was deleted.

This file was deleted.

Loading