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 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 / 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..4cc8a1c5348 --- /dev/null +++ b/tools/releaseBuild/Images/microsoft_powershell_alpine3/build-and-run-pwsh.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +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 + +cmake -DCMAKE_BUILD_TYPE=Debug . +make -j + +# Restore packages +cd ../.. +dotnet restore $dotnetArguments + +# 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" + + + + <_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 + +# build PowerShell +cd ../powershell-unix +dotnet publish --configuration Linux --runtime linux-x64 $dotnetArguments + +# 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 + +tar -czvf $tarName . 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" } ] }