Add Alpine Linux support (#6367)

sys/sysctl header is not available in musl-libc based systems and system calls are available without any header inclusion. I have ported the cmake test from CoreFX repo (https://github.com/dotnet/corefx/blob/431475b8/src/Native/Unix/configure.cmake#L560).

Progress towards: #4605
This commit is contained in:
kasper3 authored and Travis Plunk committed 2018-03-20 13:34:18 -07:00
1 parent 1b3c8aca50
commit 271dd50df2
7 files changed
+133

No files matched your search

+10
View File
@@ -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})
+4
View File
@@ -1,11 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "pal_config.h"
#include "getppid.h"
#include <sys/user.h>
#include <sys/param.h>
#if HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
//! @brief GetPPid returns the parent process id for a process
//!
+4
View File
@@ -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 <string>
#include <sstream>
#include <errno.h>
#if HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif
char* GetUserFromPid(pid_t pid)
{
+3
View File
@@ -0,0 +1,3 @@
#pragma once
#cmakedefine01 HAVE_SYS_SYSCTL_H
@@ -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 <powershellteam@hotmail.com>"
# Install dependencies and clean up
RUN apk update \
&& apk add cmake clang build-base git bash
COPY 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"
<Project>
<Target Name="_GetDependencies"
DependsOnTargets="ResolveAssemblyReferencesDesignTime">
<ItemGroup>
<_RefAssemblyPath Include="%(_ReferencesFromRAR.ResolvedPath)%3B" Condition=" '%(_ReferencesFromRAR.Type)' == 'assembly' And '%(_ReferencesFromRAR.PackageName)' != 'Microsoft.Management.Infrastructure' " />
</ItemGroup>
<WriteLinesToFile File="$(_DependencyFile)" Lines="@(_RefAssemblyPath)" Overwrite="true" />
</Target>
</Project>
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 .
+9
View File
@@ -228,6 +228,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"
}
]
}