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
10 changes: 10 additions & 0 deletions src/libpsl-native/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(CheckIncludeFiles)

add_library(psl-native SHARED
getstat.cpp
getpwuid.cpp
Expand All @@ -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 changes: 4 additions & 0 deletions src/libpsl-native/src/getppid.cpp
Original file line number Diff line number Diff line change
@@ -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
//!
Expand Down
4 changes: 4 additions & 0 deletions src/libpsl-native/src/getuserfrompid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
// Licensed under the MIT License.

#include "pal.h"
#include "pal_config.h"
#include "getfileowner.h"
#include "getpwuid.h"
#include "getuserfrompid.h"

#include <string>
#include <sstream>
#include <errno.h>

#if HAVE_SYS_SYSCTL_H
#include <sys/sysctl.h>
#endif

char* GetUserFromPid(pid_t pid)
{
Expand Down
3 changes: 3 additions & 0 deletions src/libpsl-native/src/pal_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#cmakedefine01 HAVE_SYS_SYSCTL_H
Original file line number Diff line number Diff line change
@@ -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 /
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions tools/releaseBuild/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}