python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / development / tools / omnisharp-roslyn / default.nix
blobbd1d80ef88f78881fa618809a6793d127d04bca6
1 { buildDotnetModule
2 , dotnetCorePackages
3 , fetchFromGitHub
4 , icu
5 , lib
6 , patchelf
7 , stdenv
8 , runCommand
9 , expect
11 let
12   inherit (dotnetCorePackages) sdk_6_0 runtime_6_0;
14 let finalPackage = buildDotnetModule rec {
15   pname = "omnisharp-roslyn";
16   version = "1.39.1";
18   src = fetchFromGitHub {
19     owner = "OmniSharp";
20     repo = pname;
21     rev = "v${version}";
22     sha256 = "Fd9fS5iSEynZfRwZexDlVndE/zSZdUdugR0VgXXAdmI=";
23   };
25   projectFile = "src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj";
26   nugetDeps = ./deps.nix;
28   nativeBuildInputs = [
29     patchelf
30   ];
32   dotnetInstallFlags = [ "--framework net6.0" ];
33   dotnetBuildFlags = [ "--framework net6.0" ];
34   dotnetFlags = [
35     # These flags are set by the cake build.
36     "-property:PackageVersion=${version}"
37     "-property:AssemblyVersion=${version}.0"
38     "-property:FileVersion=${version}.0"
39     "-property:InformationalVersion=${version}"
40     "-property:RuntimeFrameworkVersion=${runtime_6_0.version}"
41     "-property:RollForward=LatestMajor"
42   ];
44   postPatch = ''
45     # Relax the version requirement
46     substituteInPlace global.json \
47       --replace '7.0.100-preview.4.22252.9' '${sdk_6_0.version}'
48     # Patch the project files so we can compile them properly
49     for project in src/OmniSharp.Http.Driver/OmniSharp.Http.Driver.csproj src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj; do
50       substituteInPlace $project \
51         --replace '<RuntimeIdentifiers>win7-x64;win7-x86;win10-arm64</RuntimeIdentifiers>' '<RuntimeIdentifiers>linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>'
52     done
53   '';
55   dontDotnetFixup = true; # we'll fix it ourselves
56   postFixup = lib.optionalString stdenv.isLinux ''
57     # Emulate what .NET 7 does to its binaries while a fix doesn't land in buildDotnetModule
58     patchelf --set-interpreter $(patchelf --print-interpreter ${sdk_6_0}/dotnet) \
59       --set-rpath $(patchelf --print-rpath ${sdk_6_0}/dotnet) \
60       $out/lib/omnisharp-roslyn/OmniSharp
62   '' + ''
63     # Now create a wrapper without DOTNET_ROOT
64     # we explicitly don't set DOTNET_ROOT as it should get the one from PATH
65     # as you can use any .NET SDK higher than 6 to run OmniSharp and you most
66     # likely will NOT want the .NET 6 runtime running it (as it'll use that to
67     # detect the SDKs for its own use, so it's better to let it find it in PATH).
68     makeWrapper $out/lib/omnisharp-roslyn/OmniSharp $out/bin/OmniSharp \
69       --prefix LD_LIBRARY_PATH : ${sdk_6_0.icu}/lib \
70       --set-default DOTNET_ROOT ${sdk_6_0}
72     # Delete files to mimick hacks in https://github.com/OmniSharp/omnisharp-roslyn/blob/bdc14ca/build.cake#L594
73     rm $out/lib/omnisharp-roslyn/NuGet.*.dll
74     rm $out/lib/omnisharp-roslyn/System.Configuration.ConfigurationManager.dll
75   '';
77   passthru.tests = {
78     no-sdk = runCommand "no-sdk" { nativeBuildInputs = [ finalPackage expect ]; meta.timeout = 60; } ''
79       HOME=$TMPDIR
80       expect <<"EOF"
81         spawn OmniSharp
82         expect_before timeout {
83           send_error "timeout!\n"
84           exit 1
85         }
86         expect "\"ERROR\",\"Name\":\"OmniSharp.MSBuild.Discovery.Providers.SdkInstanceProvider\""
87         expect eof
88         catch wait result
89         if { [lindex $result 3] == 0 } {
90           exit 1
91         }
92       EOF
93       touch $out
94     '';
96     with-sdk = runCommand "with-sdk" { nativeBuildInputs = [ finalPackage sdk_6_0 expect ]; meta.timeout = 60; } ''
97       HOME=$TMPDIR
98       expect <<"EOF"
99         spawn OmniSharp
100         expect_before timeout {
101           send_error "timeout!\n"
102           exit 1
103         }
104         expect "{\"Event\":\"started\","
105         send \x03
106         expect eof
107         catch wait result
108         exit [lindex $result 3]
109       EOF
110       touch $out
111     '';
112   };
114   meta = with lib; {
115     description = "OmniSharp based on roslyn workspaces";
116     homepage = "https://github.com/OmniSharp/omnisharp-roslyn";
117     sourceProvenance = with sourceTypes; [
118       fromSource
119       binaryNativeCode # dependencies
120     ];
121     license = licenses.mit;
122     maintainers = with maintainers; [ tesq0 ericdallo corngood mdarocha ];
123     mainProgram = "OmniSharp";
124   };
125 }; in finalPackage