Skip to content

Commit 684d95c

Browse files
Build PowerShell native assemblies and Publish NuGet package (#6)
* Fix AdditionalChildPath issue * Fix build script for VS 2017 * Dockerfiles for building native binaries * Fix linux build * Create infrastructure for docker based build * Add NuGet packaging function Add function to consume zip files for all architectures and then produce a NuGet package for Microsoft.PowerShell.Native * Address code review comments and updated copyright message
1 parent 98599da commit 684d95c

File tree

9 files changed

+549
-55
lines changed

9 files changed

+549
-55
lines changed

build.psm1

Lines changed: 236 additions & 55 deletions
Large diffs are not rendered by default.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
[CmdletBinding()]
5+
6+
param (
7+
8+
[Parameter(Mandatory, ParameterSetName = 'Build')]
9+
[ValidateSet('x64', 'x86', 'x64_arm', 'x64_arm64', 'linux-x64', 'osx', 'linux-arm')]
10+
[string]
11+
$Arch,
12+
13+
[Parameter(Mandatory, ParameterSetName = 'Build')]
14+
[ValidateSet('Release', 'Debug')]
15+
[string]
16+
$Configuration,
17+
18+
[switch] $Symbols,
19+
20+
[Parameter(Mandatory, ParameterSetName = 'Build')]
21+
$RepoRoot,
22+
23+
[Parameter(Mandatory, ParameterSetName = 'Build')]
24+
$TargetLocation
25+
)
26+
27+
end {
28+
29+
Import-Module $RepoRoot/build.psm1 -Force
30+
#$binOut = New-Item -Path $TargetLocation/$Arch -ItemType Directory -Force
31+
$binOut = New-Item -Path $TargetLocation -ItemType Directory -Force
32+
Write-Verbose "Created output directory: $binOut" -Verbose
33+
34+
if ($Arch -eq 'linux-x64' -or $Arch -eq 'osx') {
35+
Start-PSBootstrap
36+
Start-BuildNativeUnixBinaries
37+
38+
$buildOutputPath = Join-Path $RepoRoot "src/powershell-unix"
39+
Compress-Archive -Path $buildOutputPath/libpsl-native.* -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
40+
}
41+
elseif ($Arch -eq 'linux-arm') {
42+
Start-PSBootstrap -BuildLinuxArm
43+
Start-BuildNativeUnixBinaries -BuildLinuxArm
44+
45+
$buildOutputPath = Join-Path $RepoRoot "src/powershell-unix"
46+
Compress-Archive -Path $buildOutputPath/libpsl-native.* -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
47+
}
48+
else {
49+
Start-PSBootstrap -BuildWindowsNative
50+
Start-BuildNativeWindowsBinaries -Configuration $Configuration -Arch $Arch -Clean
51+
52+
$buildOutputPath = Join-Path $RepoRoot "src/powershell-win-core"
53+
Compress-Archive -Path "$buildOutputPath/*.dll" -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Verbose
54+
55+
if ($Symbols.IsPresent) {
56+
Compress-Archive -Path "$buildOutputPath/*.pdb" -DestinationPath "$TargetLocation/$Arch-symbols.zip" -Update -Verbose
57+
}
58+
}
59+
}
60+

tools/releaseBuild/build.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"Windows": [
3+
{
4+
"Name": "win-x64-symbols",
5+
"RepoDestinationPath": "C:\\PowerShellNative",
6+
"BuildCommand": "C:\\powershellnative\\tools\\releasebuild\\PowerShellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch x64 -Configuration Release -Symbols",
7+
"BuildDockerOptions": [
8+
"-m",
9+
"3968m"
10+
],
11+
"DockerFile": ".\\tools\\releaseBuild\\Images\\Windows\\DockerFile",
12+
"AdditionalContextFiles": [
13+
".\\tools\\releaseBuild\\PowerShellNative.ps1"
14+
],
15+
"DockerImageName": "ps-winsrvcore",
16+
"BinaryBucket": "release",
17+
"ArtifactsExpected": 1,
18+
"VariableForExtractedBinariesPath": "Symbols_x64",
19+
"EnableFeature": [ "ArtifactAsFolder" ]
20+
},
21+
{
22+
"Name": "win-x86-symbols",
23+
"RepoDestinationPath": "C:\\PowerShellNative",
24+
"BuildCommand": "C:\\powershellnative\\tools\\releasebuild\\PowerShellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch x86 -Configuration Release -Symbols",
25+
"BuildDockerOptions": [
26+
"-m",
27+
"3968m"
28+
],
29+
"DockerFile": ".\\tools\\releaseBuild\\Images\\Windows\\DockerFile",
30+
"AdditionalContextFiles": [
31+
".\\tools\\releaseBuild\\PowerShellNative.ps1"
32+
],
33+
"DockerImageName": "ps-winsrvcore",
34+
"BinaryBucket": "release",
35+
"ArtifactsExpected": 1,
36+
"VariableForExtractedBinariesPath": "Symbols_x86",
37+
"EnableFeature": [ "ArtifactAsFolder" ]
38+
},
39+
{
40+
"Name": "win-x64_arm-symbols",
41+
"RepoDestinationPath": "C:\\PowerShellNative",
42+
"BuildCommand": "C:\\powershellnative\\tools\\releasebuild\\PowerShellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch x64_arm -Configuration Release -Symbols",
43+
"BuildDockerOptions": [
44+
"-m",
45+
"3968m"
46+
],
47+
"DockerFile": ".\\tools\\releaseBuild\\Images\\Windows\\DockerFile",
48+
"AdditionalContextFiles": [
49+
".\\tools\\releaseBuild\\PowerShellNative.ps1"
50+
],
51+
"DockerImageName": "ps-winsrvcore",
52+
"BinaryBucket": "release",
53+
"ArtifactsExpected": 1,
54+
"VariableForExtractedBinariesPath": "Symbols_x64_arm",
55+
"EnableFeature": [ "ArtifactAsFolder" ]
56+
},
57+
{
58+
"Name": "win-x64_arm64-symbols",
59+
"RepoDestinationPath": "C:\\PowerShellNative",
60+
"BuildCommand": "C:\\powershellnative\\tools\\releasebuild\\PowerShellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch x64_arm64 -Configuration Release -Symbols",
61+
"BuildDockerOptions": [
62+
"-m",
63+
"3968m"
64+
],
65+
"DockerFile": ".\\tools\\releaseBuild\\Images\\Windows\\DockerFile",
66+
"AdditionalContextFiles": [
67+
".\\tools\\releaseBuild\\PowerShellNative.ps1"
68+
],
69+
"DockerImageName": "ps-winsrvcore",
70+
"BinaryBucket": "release",
71+
"ArtifactsExpected": 1,
72+
"VariableForExtractedBinariesPath": "Symbols_x64_arm64",
73+
"EnableFeature": [ "ArtifactAsFolder" ]
74+
}
75+
],
76+
"Linux": [
77+
{
78+
"Name": "ubuntu.16.04",
79+
"RepoDestinationPath": "/PowerShellNative",
80+
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-arm -Configuration Release",
81+
"AdditionalContextFiles": [
82+
"./tools/releaseBuild/PowershellNative.ps1"
83+
],
84+
"DockerFile": "./tools/releaseBuild/images/Ubuntu16.04/Dockerfile",
85+
"DockerImageName": "ps-ubunutu-16-04",
86+
"BinaryBucket": "release",
87+
"EnableFeature": [ "ArtifactAsFolder" ]
88+
},
89+
{
90+
"Name": "centos.7",
91+
"RepoDestinationPath": "/PowerShellNative",
92+
"BuildCommand": "/PowerShellNative/tools/releaseBuild/PowershellNative.ps1 -RepoRoot _RepoDestinationPath_ -TargetLocation _DockerVolume_ -Arch linux-x64 -Configuration Release",
93+
"AdditionalContextFiles": [
94+
"./tools/releaseBuild/PowershellNative.ps1"
95+
],
96+
"DockerFile": "./tools/releaseBuild/images/CentOS/Dockerfile",
97+
"DockerImageName": "ps-centos-7",
98+
"BinaryBucket": "release",
99+
"EnableFeature": [ "ArtifactAsFolder" ]
100+
}
101+
]
102+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM microsoft/powershell:centos-7
2+
3+
LABEL maintainer="PowerShell Team <[email protected]>"
4+
5+
RUN yum install -y \
6+
which \
7+
git \
8+
sudo \
9+
&& yum clean all
10+
11+
ENTRYPOINT [ "pwsh" ]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM microsoft/powershell:ubuntu16.04
2+
3+
LABEL maintainer="PowerShell Team <[email protected]>"
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends \
7+
git \
8+
sudo \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
ENTRYPOINT [ "pwsh" ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM arpatwar/microsoft.windowsservercore_build-tools:latest
2+
3+
LABEL maintainer="PowerShell Team <[email protected]>"

tools/releaseBuild/signing.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<SignConfigXML>
3+
<!-- ****Begin**** Authenticode - Authenticode SHA256 ******** -->
4+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Core" approvers="vigarg;gstolt">
5+
<file src="__INPATHROOT__\PowerShell.Core.Instrumentation.dll" signType="Authenticode" dest="__OUTPATHROOT__\PowerShell.Core.Instrumentation.dll" />
6+
<file src="__INPATHROOT__\pwrshplugin.dll" signType="Authenticode" dest="__OUTPATHROOT__\pwrshplugin.dll" />
7+
</job>
8+
</SignConfigXML>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
param(
4+
[string] $SigningXmlPath = (Join-Path -Path $PSScriptRoot -ChildPath 'signing.xml')
5+
)
6+
# Script for use in VSTS to update signing.xml
7+
8+
# Parse the signing xml
9+
$signingXml = [xml](Get-Content $signingXmlPath)
10+
11+
# Get any variables to updating 'signType' in the XML
12+
# Define a varabile named `<signTypeInXml>SignType' in VSTS to updating that signing type
13+
# Example: $env:AuthenticodeSignType='newvalue'
14+
# will cause all files with the 'Authenticode' signtype to be updated with the 'newvalue' signtype
15+
$signTypes = @{}
16+
Get-ChildItem -Path env:/*SignType | ForEach-Object -Process {
17+
$signType = $_.Name.ToUpperInvariant().Replace('SIGNTYPE','')
18+
Write-Host "Found SigningType $signType with value $($_.value)"
19+
$signTypes[$signType] = $_.Value
20+
}
21+
22+
# examine each job in the xml
23+
$signingXml.SignConfigXML.job | ForEach-Object -Process {
24+
# examine each file in the job
25+
$_.file | ForEach-Object -Process {
26+
# if the sign type is one of the variables we found, update it to the new value
27+
$signType = $_.SignType.ToUpperInvariant()
28+
if($signTypes.ContainsKey($signType))
29+
{
30+
$newSignType = $signTypes[$signType]
31+
Write-Host "Updating $($_.src) to $newSignType"
32+
$_.signType = $newSignType
33+
}
34+
}
35+
}
36+
37+
$signingXml.Save($signingXmlPath)

tools/releaseBuild/vstsBuild.ps1

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
[cmdletbinding(DefaultParameterSetName = 'Build')]
5+
param(
6+
)
7+
8+
DynamicParam {
9+
# Add a dynamic parameter '-Name' which specifies the name of the build to run
10+
11+
# Get the names of the builds.
12+
$buildJsonPath = (Join-Path -path $PSScriptRoot -ChildPath 'build.json')
13+
$build = Get-Content -Path $buildJsonPath | ConvertFrom-Json
14+
$names = @($build.Windows.Name)
15+
foreach ($name in $build.Linux.Name) {
16+
$names += $name
17+
}
18+
19+
# Create the parameter attributes
20+
$ParameterAttr = New-Object "System.Management.Automation.ParameterAttribute"
21+
$ValidateSetAttr = New-Object "System.Management.Automation.ValidateSetAttribute" -ArgumentList $names
22+
$Attributes = New-Object "System.Collections.ObjectModel.Collection``1[System.Attribute]"
23+
$Attributes.Add($ParameterAttr) > $null
24+
$Attributes.Add($ValidateSetAttr) > $null
25+
26+
# Create the parameter
27+
$Parameter = New-Object "System.Management.Automation.RuntimeDefinedParameter" -ArgumentList ("Name", [string], $Attributes)
28+
$Dict = New-Object "System.Management.Automation.RuntimeDefinedParameterDictionary"
29+
$Dict.Add("Name", $Parameter) > $null
30+
return $Dict
31+
}
32+
33+
begin {
34+
$Name = $PSBoundParameters['Name']
35+
}
36+
37+
end {
38+
39+
$psReleaseBranch = 'master'
40+
$psReleaseFork = 'PowerShell'
41+
$psReleaseLocation = Join-Path -Path $PSScriptRoot -ChildPath 'PSRelease'
42+
if (Test-Path $psReleaseLocation) {
43+
Remove-Item -Path $psReleaseLocation -Recurse -Force
44+
}
45+
46+
$gitBinFullPath = (Get-Command -Name git).Source
47+
if (-not $gitBinFullPath) {
48+
throw "Git is required to proceed. Install from 'https://git-scm.com/download/win'"
49+
}
50+
51+
Write-Verbose "cloning -b $psReleaseBranch --quiet https://github.com/$psReleaseFork/PSRelease.git" -verbose
52+
& $gitBinFullPath clone -b $psReleaseBranch --quiet https://github.com/$psReleaseFork/PSRelease.git $psReleaseLocation
53+
54+
Push-Location -Path $PWD.Path
55+
try {
56+
Set-Location $psReleaseLocation
57+
& $gitBinFullPath submodule update --init --recursive --quiet
58+
}
59+
finally {
60+
Pop-Location
61+
}
62+
63+
$unresolvedRepoRoot = Join-Path -Path $PSScriptRoot '../..'
64+
$resolvedRepoRoot = (Resolve-Path -Path $unresolvedRepoRoot).ProviderPath
65+
66+
try {
67+
Write-Verbose "Starting build at $resolvedRepoRoot ..." -Verbose
68+
Import-Module "$psReleaseLocation/vstsBuild" -Force
69+
Import-Module "$psReleaseLocation/dockerBasedBuild" -Force
70+
Clear-VstsTaskState
71+
72+
Invoke-Build -RepoPath $resolvedRepoRoot -BuildJsonPath "tools/releaseBuild/build.json" -Name $Name
73+
}
74+
catch {
75+
Write-VstsError -Error $_
76+
}
77+
finally {
78+
Write-VstsTaskState
79+
exit 0
80+
}
81+
}

0 commit comments

Comments
 (0)