Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #50 from radical/xm-mono-port
Browse files Browse the repository at this point in the history
Add support for building on and targeting Mono
  • Loading branch information
radical authored Apr 23, 2018
2 parents 8797a94 + b83c1ab commit 4ffef71
Show file tree
Hide file tree
Showing 35 changed files with 1,146 additions and 367 deletions.
288 changes: 144 additions & 144 deletions MSBuild.sln

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
all-mono:
./cibuild.sh --scope Compile --host Mono --target Mono --config Release
./build.sh -host mono -configuration Release -skipTests

test-mono:
./cibuild.sh --scope Test --host Mono --target Mono --config Release
./build.sh -host mono -configuration Release

all-coreclr:
./cibuild.sh --scope Compile
./build.sh -host core -skipTests

test-coreclr:
./cibuild.sh --scope Test
./build.sh -host core

clean-%: clean

clean:
rm -Rf bin/ Tools/ packages/
find . -name project.lock.json -exec rm {} \;
rm -Rf artifacts
9 changes: 0 additions & 9 deletions Mono.Override.targets

This file was deleted.

14 changes: 12 additions & 2 deletions build/BootStrapMSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\*.targets" />
<InstalledVersionedExtensions Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\**\*.props" />
<SdkResolverFiles Include="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Bin\SdkResolvers\**\*.*" />
<InstalledSdks Include="$(DOTNET_INSTALL_DIR)sdk\$(DotNetCliVersion)\Sdks\**\*.*" />

<InstalledSdks Include="$(DOTNET_INSTALL_DIR)sdk\$(DotNetCliVersion)\Sdks\**\*.*" Condition="'$(MonoBuild)' != 'true'" />
<InstalledSdks Include="$(OutputPath)Sdks\**\*" Condition="'$(MonoBuild)' == 'true'" />

<InstalledStaticAnalysisTools Include="$(VsInstallRoot)\Team Tools\Static Analysis Tools\**\*.*" />

<ShimTargets Include="Microsoft.Data.Entity.targets" />
Expand All @@ -55,6 +58,7 @@
<FreshlyBuiltBinaries Include="$(OutputPath)**\*.exe" />
<FreshlyBuiltBinaries Include="$(OutputPath)**\*.pdb" />
<FreshlyBuiltBinaries Include="$(OutputPath)**\*.exe.config" />
<FreshlyBuiltBinaries Include="$(OutputPath)**\*.dll.config" />

<FreshlyBuiltProjects Include="$(OutputPath)**\*props" />
<FreshlyBuiltProjects Include="$(OutputPath)**\*targets" />
Expand All @@ -68,8 +72,14 @@
DestinationFiles="@(SdkResolverFiles->'$(BootstrapDestination)$(TargetMSBuildToolsVersion)\Bin\SdkResolvers\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(InstalledMicrosoftExtensions)"
DestinationFiles="@(InstalledMicrosoftExtensions->'$(BootstrapDestination)Microsoft\%(RecursiveDir)%(Filename)%(Extension)')" />

<Copy SourceFiles="@(InstalledSdks)"
DestinationFiles="@(InstalledSdks -> '$(BootstrapDestination)Sdks\%(RecursiveDir)%(Filename)%(Extension)')" />
DestinationFiles="@(InstalledSdks -> '$(BootstrapDestination)Sdks\%(RecursiveDir)%(Filename)%(Extension)')"
Condition="'$(MonoBuild)' != 'true'" />
<Copy SourceFiles="@(InstalledSdks)"
DestinationFiles="@(InstalledSdks -> '$(BootstrapDestination)$(TargetMSBuildToolsVersion)\Bin\Sdks\%(RecursiveDir)%(Filename)%(Extension)')"
Condition="'$(MonoBuild)' == 'true'" />

<Copy SourceFiles="@(InstalledStaticAnalysisTools)"
DestinationFiles="@(InstalledStaticAnalysisTools -> '$(BootstrapDestination)..\Team Tools\Static Analysis Tools\%(RecursiveDir)%(Filename)%(Extension)')" />

Expand Down
53 changes: 50 additions & 3 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ properties=""
function Help() {
echo "Common settings:"
echo " -configuration <value> Build configuration Debug, Release"
echo " -host <value> core (default), mono"
echo " -verbosity <value> Msbuild verbosity (q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic])"
echo " -help Print help and exit"
echo ""
Expand All @@ -41,6 +42,7 @@ function Help() {
echo " -ci Set when running on CI server"
echo " -nolog Disable logging"
echo " -prepareMachine Prepare machine for CI run"
echo " -useSystemMSBuild [mono] Use system msbuild instead of downloading a copy for use with mono"
echo ""
echo "Command line arguments not listed above are passed through to MSBuild."
}
Expand All @@ -64,6 +66,10 @@ while [[ $# > 0 ]]; do
Help
exit 0
;;
-host)
hostType=$2
shift 2
;;
-nolog)
nolog=true
shift 1
Expand Down Expand Up @@ -96,6 +102,10 @@ while [[ $# > 0 ]]; do
bootstrapOnly=true
shift 1
;;
-usesystemmsbuild)
useSystemMSBuild=true
shift 1
;;
-verbosity)
verbosity=$2
shift 2
Expand All @@ -107,6 +117,10 @@ while [[ $# > 0 ]]; do
esac
done

if [ "$hostType" = "mono" ]; then
configuration="$configuration-MONO"
fi

function CreateDirectory {
if [ ! -d "$1" ]
then
Expand Down Expand Up @@ -137,6 +151,20 @@ function GetLogCmd {
echo $logCmd
}

function downloadMSBuildForMono {
if [[ -z $useSystemMSBuild && ! -e "$MONO_MSBUILD_DIR/MSBuild.dll" ]]
then
echo "** Downloading MSBUILD from $MSBUILD_DOWNLOAD_URL"
curl -sL -o "$MSBUILD_ZIP" "$MSBUILD_DOWNLOAD_URL"

unzip -q "$MSBUILD_ZIP" -d "$ArtifactsDir"
# rename just to make it obvious when reading logs!
mv $ArtifactsDir/msbuild $ArtifactsDir/mono-msbuild
chmod +x $ArtifactsDir/mono-msbuild/MSBuild.dll
rm "$MSBUILD_ZIP"
fi
}

function CallMSBuild {
local commandLine=""

Expand Down Expand Up @@ -255,6 +283,16 @@ function Build {
if [ "$hostType" = "core" ]
then
msbuildHost=$(QQ $DOTNET_HOST_PATH)
elif [ "$hostType" = "mono" ]
then
if [ -z $useSystemMSBuild ]; then
downloadMSBuildForMono
msbuildHost=""
msbuildToUse="$MONO_MSBUILD_DIR/msbuild"
else
msbuildHost=""
msbuildToUse="msbuild"
fi
else
ErrorHostType
fi
Expand Down Expand Up @@ -289,11 +327,18 @@ function Build {
if [ $hostType = "core" ]
then
msbuildToUse=$(QQ "$bootstrapRoot/netcoreapp2.1/MSBuild/MSBuild.dll")
elif [ "$hostType" = "mono" ]
then
msbuildToUse="$bootstrapRoot/net461/MSBuild/15.0/Bin/MSBuild.dll"
msbuildHost="mono"

properties="$properties /p:MSBuildExtensionsPath=$bootstrapRoot/net461/MSBuild/"
else
ErrorHostType
fi

export ArtifactsDir="$ArtifactsDir/2"
# forcing the slashes here or they get normalized and lost later
export ArtifactsDir="$ArtifactsDir\\2\\"

local logCmd=$(GetLogCmd BuildWithBootstrap)

Expand Down Expand Up @@ -332,7 +377,9 @@ ArtifactsConfigurationDir="$ArtifactsDir/$configuration"
LogDir="$ArtifactsConfigurationDir/log"
VersionsProps="$ScriptRoot/Versions.props"

msbuildToUse="msbuild"
MONO_MSBUILD_DIR="$ArtifactsDir/mono-msbuild"
MSBUILD_DOWNLOAD_URL="https://github.com/mono/msbuild/releases/download/v0.05/mono_msbuild_port2-394a6b5e.zip"
MSBUILD_ZIP="$ArtifactsDir/msbuild.zip"

log=false
if ! $nolog
Expand All @@ -352,7 +399,7 @@ then
test=true
fi

if [ "$hostType" != "core" ]; then
if [ "$hostType" != "core" -a "$hostType" != "mono" ]; then
ErrorHostType
fi

Expand Down
103 changes: 9 additions & 94 deletions install-mono-prefix.sh
Original file line number Diff line number Diff line change
@@ -1,104 +1,19 @@
#!/bin/bash
set -e
set -x
if [ $# -ne 1 ]; then
echo "Usage: install-mono.sh </path/to/mono/installation>"
exit 1
echo "Usage: $0 </path/to/mono/installation>"
exit 1
fi

MSBUILD_TOOLSVERSION=15.0
MONO_PREFIX=$1
MSBUILD_INSTALL_BIN_DIR="$MONO_PREFIX/lib/mono/msbuild/${MSBUILD_TOOLSVERSION}/bin"
XBUILD_DIR=$MONO_PREFIX/lib/mono/xbuild

# based on the check that cibuild.sh uses
# determine OS
if [ `uname -s` = "Darwin" ]; then
OS_ARG="OSX"
else
OS_ARG="Unix"
fi

if [ -d "bin/Release-MONO" ]; then
CONFIG=Release
elif [ -d "bin/Debug-MONO" ]; then
CONFIG=Debug
if [ -d "artifacts/2/Release-MONO" ]; then
CONFIG=Release-MONO
elif [ -d "artifacts/2/Debug-MONO" ]; then
CONFIG=Debug-MONO
else
echo "Error: No bin directory 'bin/Release-MONO' or 'bin/Debug-MONO' found."
echo "Error: No build directory 'artifacts/2/Release-MONO' or 'artifacts/2/Debug-MONO' found."
exit 1
fi

MSBUILD_OUT_DIR="bin/${CONFIG}-MONO/AnyCPU/${OS_ARG}/${OS_ARG}_Deployment"

mkdir -p ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
mkdir -p ${DESTDIR}${XBUILD_DIR}/$MSBUILD_TOOLSVERSION
mkdir -p ${DESTDIR}${MONO_PREFIX}/bin

cp $MSBUILD_OUT_DIR/Microsoft.Build.* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/Microsoft.Common.* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/Microsoft.CSharp.* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/Microsoft.VisualBasic.* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/MSBuild.{dll,pdb,rsp}* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/Microsoft.NETFramework.* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/Microsoft.*.{props,targets} ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/Workflow* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp $MSBUILD_OUT_DIR/*.dll ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}

# this needs to be in extensions path only
mv ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/Mono.Build.Tasks.* ${DESTDIR}${XBUILD_DIR}

#cp -r $MSBUILD_OUT_DIR/Roslyn ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}
cp -r $MSBUILD_OUT_DIR/Extensions ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}

# Deploy files meant for the default $(MSBuildExtensionsPath)
cp -r mono/ExtensionsPath/* ${DESTDIR}${XBUILD_DIR}
cp -r mono/ExtensionsPath-ToolsVersion/* ${DESTDIR}${XBUILD_DIR}/${MSBUILD_TOOLSVERSION}

mv ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/Microsoft.Common.props ${DESTDIR}${XBUILD_DIR}/$MSBUILD_TOOLSVERSION
mv ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/Microsoft.VisualStudioVersion.v* ${DESTDIR}${XBUILD_DIR}/$MSBUILD_TOOLSVERSION

rm ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/*UnitTests*
rm ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/*xunit*
rm -f ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/System.Runtime.InteropServices.RuntimeInformation.dll
#rm ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/Roslyn/csc.exe*

FILES="\
Dependency.dll \
PortableTask.dll \
TaskWithDependency.dll \
Xunit.NetCore.Extensions.dll"

for f in $FILES; do rm ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/$f ; done

(cd ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR} && rm System.Reflection.Metadata.dll && ln -s Roslyn/System.Reflection.Metadata.dll System.Reflection.Metadata.dll)

# The directory might not exist on bockbuild when it runs this script.
# Bockbuild will handle copying these files
test -d ${DESTDIR}${XBUILD_DIR}/14.0/Imports && cp -R ${DESTDIR}${XBUILD_DIR}/14.0/Imports ${DESTDIR}${XBUILD_DIR}/${MSBUILD_TOOLSVERSION}

cp -R nuget-support/tv/* ${DESTDIR}${XBUILD_DIR}/$MSBUILD_TOOLSVERSION
cp -R nuget-support/tasks-targets/* ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}

# man page
mkdir -p ${DESTDIR}${MONO_PREFIX}/share/man/man1
cp mono/msbuild.1 ${DESTDIR}${MONO_PREFIX}/share/man/man1/

# copy SDKs
SDKS_SRC_DIR=sdks
SDKS_OUT_DIR=${MSBUILD_INSTALL_BIN_DIR}/Sdks

cp -R ${SDKS_SRC_DIR}/ ${DESTDIR}${SDKS_OUT_DIR}

SDK_RESOLVERS_OUT_DIR=${MSBUILD_INSTALL_BIN_DIR}
mkdir -p ${DESTDIR}${SDK_RESOLVERS_OUT_DIR}
cp -R mono/SdkResolvers ${DESTDIR}${SDK_RESOLVERS_OUT_DIR}

# install nuget sdk resolver
NUGET_RESOLVER_OUT_DIR=${MSBUILD_INSTALL_BIN_DIR}/SdkResolvers/NuGet.MSBuildSdkResolver
mkdir -p ${DESTDIR}${NUGET_RESOLVER_OUT_DIR}
mv ${DESTDIR}${MSBUILD_INSTALL_BIN_DIR}/NuGet.MSBuildSdkResolver* ${DESTDIR}${NUGET_RESOLVER_OUT_DIR}
MONO_PREFIX=$1

sed -e 's,@bindir@,'$MONO_PREFIX'/bin,' -e 's,@mono_instdir@,'$MONO_PREFIX/lib/mono',' msbuild-mono-deploy.in > msbuild-mono-deploy.tmp
chmod +x msbuild-mono-deploy.tmp
cp msbuild-mono-deploy.tmp ${DESTDIR}${MONO_PREFIX}/bin/msbuild
rm -f msbuild-mono-deploy.tmp
msbuild mono/build/install.proj /p:MonoInstallPrefix=$MONO_PREFIX /p:Configuration=$CONFIG
31 changes: 31 additions & 0 deletions mono/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
TODO: Ankit will fill this file with steps how to update our fork when a new msbuild version appears upstream


mono/build/install.proj:

We keep two canonical lists:

mono/build/all_files.canon.txt:
- all the files that install.proj copies to $(MonoInstallPrefix)

mono/build/remaining_files.canon.txt:
- files that were *not* copied from the bin dir in artifacts

If files get added/removed, then handle them and update these lists.

mono/create_bootstrap.sh:

Create a bootstrap msbuild zip, for use with the initial build.

This uses the msbuild in $PATH to build this bootstrap. This is mainly
to ensure that we get the corresponding Roslyn binaries too.

To create a bootstrap from the current build, install that, add to $PATH
and run the script.

Build notes:

- We download a bootstrap msbuild and use that for the initial build. `csc` used here is from the bootstrap msbuild.
- The subsequent build uses the freshly built msbuild. And `csc` used is whatever was referenced, so same as upstream.

- The installation process does not install any roslyn, instead depending on the mono prefix to have that available. And just
sets up symlinks for them.
Loading

0 comments on commit 4ffef71

Please sign in to comment.