2021-10-17 09:34:42 +00:00
|
|
|
{ lib, stdenv, fetchurl, fetchpatch, makeWrapper, glibcLocales, mono, dotnetPackages, unzip, dotnetCorePackages, writeText, roslyn }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2022-11-27 09:42:12 +00:00
|
|
|
dotnet-sdk = dotnetCorePackages.sdk_6_0;
|
2021-10-17 09:34:42 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
xplat = fetchurl {
|
2021-08-08 23:34:03 +00:00
|
|
|
url = "https://github.com/mono/msbuild/releases/download/v16.9.0/mono_msbuild_6.12.0.137.zip";
|
|
|
|
sha256 = "1wnzbdpk4s9bmawlh359ak2b8zi0sgx1qvcjnvfncr1wsck53v7q";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
deps = map (package: package.src)
|
|
|
|
(import ./deps.nix { inherit fetchurl; });
|
|
|
|
|
|
|
|
nuget-config = writeText "NuGet.config" ''
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<configuration>
|
|
|
|
<packageSources>
|
|
|
|
<clear />
|
|
|
|
</packageSources>
|
|
|
|
</configuration>
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "msbuild";
|
2021-08-08 23:34:03 +00:00
|
|
|
version = "16.10.1+xamarinxplat.2021.05.26.14.00";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://download.mono-project.com/sources/msbuild/msbuild-${version}.tar.xz";
|
2021-08-08 23:34:03 +00:00
|
|
|
sha256 = "05ghqqkdj4s3d0xkp7mkdzjig5zj3k6ajx71j0g2wv6rdbvg6899";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
dotnet-sdk
|
|
|
|
mono
|
2021-03-19 17:17:44 +00:00
|
|
|
unzip
|
2022-09-09 14:08:57 +00:00
|
|
|
makeWrapper
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
dotnetPackages.Nuget
|
|
|
|
glibcLocales
|
|
|
|
];
|
|
|
|
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/38991
|
|
|
|
# bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
|
2021-02-05 17:12:51 +00:00
|
|
|
LOCALE_ARCHIVE = lib.optionalString stdenv.isLinux
|
2020-04-24 23:36:52 +00:00
|
|
|
"${glibcLocales}/lib/locale/locale-archive";
|
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
postPatch = ''
|
2021-08-08 23:34:03 +00:00
|
|
|
# not patchShebangs, there is /bin/bash in the body of the script as well
|
|
|
|
substituteInPlace ./eng/cibuild_bootstrapped_msbuild.sh --replace /bin/bash ${stdenv.shell}
|
|
|
|
|
|
|
|
patchShebangs eng/*.sh mono/build/*.sh
|
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
sed -i -e "/<\/projectImportSearchPaths>/a <property name=\"MSBuildExtensionsPath\" value=\"$out/lib/mono/xbuild\"/>" \
|
|
|
|
src/MSBuild/app.config
|
2021-08-08 23:34:03 +00:00
|
|
|
|
|
|
|
# license check is case sensitive
|
|
|
|
mv LICENSE license.bak && mv license.bak license
|
2021-04-12 18:23:04 +00:00
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPhase = ''
|
|
|
|
# nuget would otherwise try to base itself in /homeless-shelter
|
|
|
|
export HOME=$(pwd)/fake-home
|
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
cp ${nuget-config} NuGet.config
|
|
|
|
nuget sources Add -Name nixos -Source $(pwd)/nixos
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
for package in ${toString deps}; do
|
|
|
|
nuget add $package -Source nixos
|
|
|
|
done
|
|
|
|
|
|
|
|
mkdir -p artifacts
|
|
|
|
unzip ${xplat} -d artifacts
|
|
|
|
mv artifacts/msbuild artifacts/mono-msbuild
|
|
|
|
chmod +x artifacts/mono-msbuild/MSBuild.dll
|
|
|
|
|
|
|
|
ln -s $(find ${dotnet-sdk} -name libhostfxr.so) artifacts/mono-msbuild/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/
|
|
|
|
|
|
|
|
# overwrite the file
|
|
|
|
echo "#!${stdenv.shell}" > eng/common/dotnet-install.sh
|
2021-08-08 23:34:03 +00:00
|
|
|
echo "#!${stdenv.shell}" > mono/build/get_sdk_files.sh
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-08-08 23:34:03 +00:00
|
|
|
mkdir -p mono/dotnet-overlay/msbuild-bin
|
|
|
|
cp ${dotnet-sdk}/sdk/*/{Microsoft.NETCoreSdk.BundledVersions.props,RuntimeIdentifierGraph.json} mono/dotnet-overlay/msbuild-bin
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# DisableNerdbankVersioning https://gitter.im/Microsoft/msbuild/archives/2018/06/27?at=5b33dbc4ce3b0f268d489bfa
|
|
|
|
# TODO there are some (many?) failing tests
|
|
|
|
./eng/cibuild_bootstrapped_msbuild.sh --host_type mono --configuration Release --skip_tests /p:DisableNerdbankVersioning=true
|
2021-04-12 18:23:04 +00:00
|
|
|
patchShebangs stage1/mono-msbuild/msbuild
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2021-04-12 18:23:04 +00:00
|
|
|
stage1/mono-msbuild/msbuild mono/build/install.proj /p:MonoInstallPrefix="$out" /p:Configuration=Release-MONO
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
ln -s ${roslyn}/lib/dotnet/microsoft.net.compilers.toolset/*/tasks/net472 $out/lib/mono/msbuild/Current/bin/Roslyn
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
makeWrapper ${mono}/bin/mono $out/bin/msbuild \
|
|
|
|
--set-default MONO_GC_PARAMS "nursery-size=64m" \
|
|
|
|
--add-flags "$out/lib/mono/msbuild/15.0/bin/MSBuild.dll"
|
2021-04-12 18:23:04 +00:00
|
|
|
|
|
|
|
ln -s $(find ${dotnet-sdk} -name libhostfxr.so) $out/lib/mono/msbuild/Current/bin/SdkResolvers/Microsoft.DotNet.MSBuildSdkResolver/
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
doInstallCheck = true;
|
|
|
|
|
|
|
|
# https://docs.microsoft.com/cs-cz/visualstudio/msbuild/walkthrough-creating-an-msbuild-project-file-from-scratch?view=vs-2019
|
|
|
|
installCheckPhase = ''
|
|
|
|
cat > Helloworld.cs <<EOF
|
|
|
|
using System;
|
|
|
|
|
|
|
|
class HelloWorld
|
|
|
|
{
|
|
|
|
static void Main()
|
|
|
|
{
|
|
|
|
#if DebugConfig
|
|
|
|
Console.WriteLine("WE ARE IN THE DEBUG CONFIGURATION");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Console.WriteLine("Hello, world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > Helloworld.csproj <<EOF
|
|
|
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
|
|
<ItemGroup>
|
|
|
|
<Compile Include="Helloworld.cs" />
|
|
|
|
</ItemGroup>
|
|
|
|
<Target Name="Build">
|
|
|
|
<Csc Sources="@(Compile)"/>
|
|
|
|
</Target>
|
|
|
|
</Project>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
$out/bin/msbuild Helloworld.csproj -t:Build
|
|
|
|
${mono}/bin/mono Helloworld.exe | grep "Hello, world!"
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Mono version of Microsoft Build Engine, the build platform for .NET, and Visual Studio";
|
|
|
|
homepage = "https://github.com/mono/msbuild";
|
2022-06-26 10:26:21 +00:00
|
|
|
sourceProvenance = with sourceTypes; [
|
|
|
|
fromSource
|
|
|
|
binaryNativeCode # dependencies
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.mit;
|
|
|
|
maintainers = with maintainers; [ jdanek ];
|
|
|
|
platforms = platforms.unix;
|
|
|
|
};
|
|
|
|
}
|