From 77e8af36d2d227f977ef1a1fb9150647291bfaeb Mon Sep 17 00:00:00 2001 From: kasper <33230602+kasper3@users.noreply.github.com> Date: Mon, 12 Mar 2018 18:41:49 -0400 Subject: [PATCH 1/6] Add Alpine Linux support --- src/libpsl-native/src/CMakeLists.txt | 10 ++++++++++ src/libpsl-native/src/getppid.cpp | 4 ++++ src/libpsl-native/src/getuserfrompid.cpp | 4 ++++ src/libpsl-native/src/pal_config.h.in | 3 +++ 4 files changed, 21 insertions(+) create mode 100644 src/libpsl-native/src/pal_config.h.in diff --git a/src/libpsl-native/src/CMakeLists.txt b/src/libpsl-native/src/CMakeLists.txt index bb2e88e4626..b830e5d9fd0 100644 --- a/src/libpsl-native/src/CMakeLists.txt +++ b/src/libpsl-native/src/CMakeLists.txt @@ -1,3 +1,5 @@ +include(CheckIncludeFiles) + add_library(psl-native SHARED getstat.cpp getpwuid.cpp @@ -24,4 +26,12 @@ add_library(psl-native SHARED createprocess.cpp nativesyslog.cpp) +check_include_files( + "sys/types.h;sys/sysctl.h" + HAVE_SYS_SYSCTL_H) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/pal_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/pal_config.h) + target_include_directories(psl-native PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/libpsl-native/src/getppid.cpp b/src/libpsl-native/src/getppid.cpp index 824da6fce7b..7f64e285e06 100644 --- a/src/libpsl-native/src/getppid.cpp +++ b/src/libpsl-native/src/getppid.cpp @@ -1,11 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +#include "pal_config.h" #include "getppid.h" #include #include + +#if HAVE_SYS_SYSCTL_H #include +#endif //! @brief GetPPid returns the parent process id for a process //! diff --git a/src/libpsl-native/src/getuserfrompid.cpp b/src/libpsl-native/src/getuserfrompid.cpp index 871f71f86fd..fe34733a235 100644 --- a/src/libpsl-native/src/getuserfrompid.cpp +++ b/src/libpsl-native/src/getuserfrompid.cpp @@ -2,6 +2,7 @@ // Licensed under the MIT License. #include "pal.h" +#include "pal_config.h" #include "getfileowner.h" #include "getpwuid.h" #include "getuserfrompid.h" @@ -9,7 +10,10 @@ #include #include #include + +#if HAVE_SYS_SYSCTL_H #include +#endif char* GetUserFromPid(pid_t pid) { diff --git a/src/libpsl-native/src/pal_config.h.in b/src/libpsl-native/src/pal_config.h.in new file mode 100644 index 00000000000..f1d702d76b6 --- /dev/null +++ b/src/libpsl-native/src/pal_config.h.in @@ -0,0 +1,3 @@ +#pragma once + +#cmakedefine01 HAVE_SYS_SYSCTL_H From 062e05585fb16494863e4d68ceec13e23aacd94a Mon Sep 17 00:00:00 2001 From: kasper <33230602+kasper3@users.noreply.github.com> Date: Sat, 17 Mar 2018 16:42:41 -0400 Subject: [PATCH 2/6] Add a build script for Alpine Linux --- .../build-and-run-pwsh.sh | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh new file mode 100755 index 00000000000..4a49135e322 --- /dev/null +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +apk update +apk add cmake clang build-base git bash +git clone --recursive https://github.com/kasper3/powershell +cd powershell/src/libpsl-native + +cmake -DCMAKE_BUILD_TYPE=Debug . +make -j + +cd ../.. +dotnet restore +touch DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY + +cd src/ResGen +dotnet run + +cd .. +targetFile="Microsoft.PowerShell.SDK/obj/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets" +cat > $targetFile <<-"EOF" + + + + <_RefAssemblyPath Include="%(_ReferencesFromRAR.ResolvedPath)%3B" Condition=" '%(_ReferencesFromRAR.Type)' == 'assembly' And '%(_ReferencesFromRAR.PackageName)' != 'Microsoft.Management.Infrastructure' " /> + + + + +EOF +dotnet msbuild Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$(pwd)/TypeCatalogGen/powershell.inc" /nologo + +cd TypeCatalogGen +dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershell.inc + +cd ../powershell-unix +dotnet publish --configuration Linux --runtime linux-x64 +mv libpsl-native.so bin/Linux/netcoreapp2.0 +dotnet run -c Linux From 2370b4c8acaecc2b71451b953c2679ccd061a94f Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 19 Mar 2018 12:50:29 -0700 Subject: [PATCH 3/6] add dockerfile for alpine 3 build --- .../Images/microsoft_powershell_alpine3/Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile b/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile new file mode 100644 index 00000000000..feea186d5ec --- /dev/null +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile @@ -0,0 +1,10 @@ +# Docker image file that describes an Centos7 image with PowerShell installed from Microsoft YUM Repo + +FROM microsoft/dotnet:2.1-sdk-alpine +LABEL maintainer="PowerShell Team " + +# Install dependencies and clean up +RUN apk update \ + && apk add cmake clang build-base git bash + +COPY build-and-run-pwsh.sh / From 76f9ac0a65c55c5a17bc4c59e689ef9c92fb15a5 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 19 Mar 2018 12:50:47 -0700 Subject: [PATCH 4/6] update build script for docker build --- .../build-and-run-pwsh.sh | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh index 4a49135e322..64ceacf0b51 100755 --- a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh @@ -1,20 +1,27 @@ #!/bin/sh -apk update -apk add cmake clang build-base git bash -git clone --recursive https://github.com/kasper3/powershell -cd powershell/src/libpsl-native +repoRoot=$1 +destination=$2 +releaseTag=$3 + +# Build libpsl-native +cd $repoRoot/src/libpsl-native cmake -DCMAKE_BUILD_TYPE=Debug . make -j +# Restore packages cd ../.. dotnet restore + +# Add telemetry file touch DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY +# run ResGen cd src/ResGen dotnet run +# Create typeCatalog cd .. targetFile="Microsoft.PowerShell.SDK/obj/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets" cat > $targetFile <<-"EOF" @@ -28,12 +35,21 @@ cat > $targetFile <<-"EOF" EOF + dotnet msbuild Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj /t:_GetDependencies "/property:DesignTimeBuild=true;_DependencyFile=$(pwd)/TypeCatalogGen/powershell.inc" /nologo cd TypeCatalogGen dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershell.inc +# build PowerShell cd ../powershell-unix dotnet publish --configuration Linux --runtime linux-x64 -mv libpsl-native.so bin/Linux/netcoreapp2.0 -dotnet run -c Linux + +# add libpsl-native to build +mv libpsl-native.so bin/Linux/netcoreapp2.0/linux-x64 + +# tar build for output +cd bin/Linux/netcoreapp2.0/linux-x64 + +# TODO make format of file name the same as other packages +tar -czvf $destination/powershell-alpine.3.tar.gz . From 07b43ec8199a73d157588c0a6008a7dde54e4576 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 19 Mar 2018 12:51:09 -0700 Subject: [PATCH 5/6] add alpine build definition --- tools/releaseBuild/build.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/releaseBuild/build.json b/tools/releaseBuild/build.json index b7e1813a600..36b5a56674e 100644 --- a/tools/releaseBuild/build.json +++ b/tools/releaseBuild/build.json @@ -219,6 +219,15 @@ "DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_centos7/Dockerfile", "DockerImageName": "ps-centos-7", "BinaryBucket": "release" + }, + { + "Name": "alpine.3", + "RepoDestinationPath": "/PowerShell", + "BuildCommand": "/build-and-run-pwsh.sh _RepoDestinationPath_ _DockerVolume_ _ReleaseTag_", + "AdditionalContextFiles" :[ "./tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh"], + "DockerFile": "./tools/releaseBuild/Images/microsoft_powershell_alpine3/Dockerfile", + "DockerImageName": "ps-alpine-3", + "BinaryBucket": "release" } ] } From a40ed411126d854d037f06ed1ad07bee4707f9dd Mon Sep 17 00:00:00 2001 From: kasper <33230602+kasper3@users.noreply.github.com> Date: Tue, 20 Mar 2018 11:36:20 -0400 Subject: [PATCH 6/6] Use release tag and arch --- .../build-and-run-pwsh.sh | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh index 64ceacf0b51..4cc8a1c5348 100755 --- a/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh @@ -4,6 +4,45 @@ repoRoot=$1 destination=$2 releaseTag=$3 +# in Alpine, the currently supported architectures are: + +# x86_64 +# x86 +# aarch64 +# armhf +# ppc64le +# s390x + +# from https://pkgs.alpinelinux.org/packages (Arch dropdown menu) + +arch=`uname -m` + +case $arch in + x86_64) + arch=x64 + ;; + aarch64) + arch=arm64 + ;; + armhf) + arch=arm + ;; + *) + echo "Error: Unsupported OS architecture $arch detected" + exit 1 + ;; +esac + +# set variables depending on releaseTag +# remove v from release tag (v3.5 => 3.5) +if [ "${releaseTag:0:1}" = "v" ]; then + releaseTag=${releaseTag:1} + tarName=$destination/powershell-$releaseTag-alpine.3-$arch.tar.gz + dotnetArguments=/p:ReleaseTag=$releaseTag; +else + tarName=$destination/powershell-alpine.3-$arch.tar.gz +fi + # Build libpsl-native cd $repoRoot/src/libpsl-native @@ -12,7 +51,7 @@ make -j # Restore packages cd ../.. -dotnet restore +dotnet restore $dotnetArguments # Add telemetry file touch DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY @@ -43,7 +82,7 @@ dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershe # build PowerShell cd ../powershell-unix -dotnet publish --configuration Linux --runtime linux-x64 +dotnet publish --configuration Linux --runtime linux-x64 $dotnetArguments # add libpsl-native to build mv libpsl-native.so bin/Linux/netcoreapp2.0/linux-x64 @@ -51,5 +90,4 @@ mv libpsl-native.so bin/Linux/netcoreapp2.0/linux-x64 # tar build for output cd bin/Linux/netcoreapp2.0/linux-x64 -# TODO make format of file name the same as other packages -tar -czvf $destination/powershell-alpine.3.tar.gz . +tar -czvf $tarName .