omnisharp-roslyn: build from source

- use links for internal msbuild
- add dotnet-sdk to PATH
  https://github.com/NixOS/nixpkgs/pull/98435#issuecomment-715508615
- build from source
- add myself as maintainer
This commit is contained in:
David McFarland 2020-12-30 10:21:44 -04:00
parent 06c19c70cc
commit c1d907220a
3 changed files with 2327 additions and 21 deletions

View file

@ -0,0 +1,66 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p msbuild -p jq -p xmlstarlet -p curl
set -euo pipefail
cat << EOL
{ fetchurl }: [
EOL
tmpdir="$(mktemp -d -p "$(pwd)")" # must be under source root
trap 'rm -rf "$tmpdir"' EXIT
mapfile -t repos < <(
xmlstarlet sel -t -v 'configuration/packageSources/add/@value' -n NuGet.Config |
while IFS= read index
do
curl --compressed -fsL "$index" | \
jq -r '.resources[] | select(."@type" == "PackageBaseAddress/3.0.0")."@id"'
done
)
msbuild -t:restore -p:Configuration=Release -p:RestorePackagesPath="$tmpdir" \
-p:RestoreNoCache=true -p:RestoreForce=true \
src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj >&2
cd "$tmpdir"
for package in *
do
cd "$package"
for version in *
do
found=false
for repo in "${repos[@]}"
do
url="$repo$package/$version/$package.$version.nupkg"
if curl -fsL "$url" -o /dev/null
then
found=true
break
fi
done
if ! $found
then
echo "couldn't find $package $version" >&2
exit 1
fi
sha256=$(nix-prefetch-url "$url" 2>/dev/null)
cat << EOL
{
name = "$package";
version = "$version";
src = fetchurl {
url = "$url";
sha256 = "$sha256";
};
}
EOL
done
cd ..
done
cd ..
cat << EOL
]
EOL

View file

@ -1,42 +1,104 @@
{ lib, stdenv
, fetchFromGitHub
, fetchurl
, mono
, mono6
, msbuild
, dotnet-sdk
, makeWrapper
, dotnetPackages
, unzip
, writeText
}:
stdenv.mkDerivation rec {
let
deps = map (package: stdenv.mkDerivation (with package; {
pname = name;
inherit version src;
buildInputs = [ unzip ];
unpackPhase = ''
unzip $src
chmod -R u+r .
function traverseRename () {
for e in *
do
t="$(echo "$e" | sed -e "s/%20/\ /g" -e "s/%2B/+/g")"
[ "$t" != "$e" ] && mv -vn "$e" "$t"
if [ -d "$t" ]
then
cd "$t"
traverseRename
cd ..
fi
done
}
traverseRename
'';
installPhase = ''
runHook preInstall
package=$out/lib/dotnet/${name}/${version}
mkdir -p $package
cp -r . $package
echo "{}" > $package/.nupkg.metadata
runHook postInstall
'';
dontFixup = true;
}))
(import ./deps.nix { inherit fetchurl; });
nuget-config = writeText "NuGet.Config" ''
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
</packageSources>
<fallbackPackageFolders>
${lib.concatStringsSep "\n" (map (package: "<add key=\"${package}\" value=\"${package}/lib/dotnet\"/>") deps)}
</fallbackPackageFolders>
</configuration>
'';
in stdenv.mkDerivation rec {
pname = "omnisharp-roslyn";
version = "1.37.8";
src = fetchurl {
url = "https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v${version}/omnisharp-mono.tar.gz";
sha256 = "0kgv4l15rli9a7grmcsbv72csmxi7vqa7lrrr8bd4cq9ighh54q3";
src = fetchFromGitHub {
owner = "OmniSharp";
repo = pname;
rev = "v${version}";
sha256 = "1zi31m6ngk4rm7444n6q7mim096w5h4j2biwmvwmcf5yvig845za";
};
nativeBuildInputs = [ makeWrapper dotnet-sdk dotnetPackages.Nuget ];
nativeBuildInputs = [ makeWrapper msbuild ];
preUnpack = ''
mkdir src
cd src
sourceRoot=.
buildPhase = ''
runHook preBuild
HOME=$(pwd)/fake-home msbuild -r -p:Configuration=Release -p:RestoreConfigFile=${nuget-config} src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj
runHook postBuild
'';
installPhase = ''
mkdir -p $out/bin
cd ..
cp -r src $out/
rm -r $out/src/.msbuild
cp -r ${msbuild}/lib/mono/msbuild $out/src/.msbuild
cp -r bin/Release/OmniSharp.Stdio.Driver/net472 $out/src
cp bin/Release/OmniSharp.Host/net472/SQLitePCLRaw* $out/src
mkdir $out/src/.msbuild
ln -s ${msbuild}/lib/mono/xbuild/* $out/src/.msbuild/
rm $out/src/.msbuild/Current
mkdir $out/src/.msbuild/Current
ln -s ${msbuild}/lib/mono/xbuild/Current/* $out/src/.msbuild/Current/
ln -s ${msbuild}/lib/mono/msbuild/Current/bin $out/src/.msbuild/Current/Bin
chmod -R u+w $out/src
mv $out/src/.msbuild/Current/{bin,Bin}
makeWrapper ${mono}/bin/mono $out/bin/omnisharp \
--add-flags "$out/src/OmniSharp.exe"
makeWrapper ${mono6}/bin/mono $out/bin/omnisharp \
--prefix PATH : ${dotnet-sdk}/bin \
--add-flags "$out/src/OmniSharp.exe"
'';
meta = with lib; {
@ -44,7 +106,7 @@ stdenv.mkDerivation rec {
homepage = "https://github.com/OmniSharp/omnisharp-roslyn";
platforms = platforms.linux;
license = licenses.mit;
maintainers = with maintainers; [ tesq0 ericdallo ];
maintainers = with maintainers; [ tesq0 ericdallo corngood ];
};
}

File diff suppressed because it is too large Load diff