1{
2 lib,
3 stdenv,
4 vscode-utils,
5 autoPatchelfHook,
6 icu,
7 openssl,
8 libz,
9 glibc,
10 libxml2,
11 libkrb5,
12 patchelf,
13}:
14let
15 extInfo = (
16 {
17 x86_64-linux = {
18 arch = "linux-x64";
19 hash = "sha256-vGHRgaqoxRU14BjmQM68SVdhe6ElvJrp6NUQXkVU5OU=";
20 };
21 aarch64-linux = {
22 arch = "linux-arm64";
23 hash = "sha256-aGRXxUpuOhsxULg7mAe1t04hfwLF5t4bSSthLlz7Mes=";
24 };
25 x86_64-darwin = {
26 arch = "darwin-x64";
27 hash = "sha256-e4+rr3k9SYIVH01wG0RxL+sush0rTuvkJu08cctXmYo=";
28 };
29 aarch64-darwin = {
30 arch = "darwin-arm64";
31 hash = "sha256-iOF9aDk9okoZsHvaW4mDOulLPGxVViAk1TQkIH0XK+A=";
32 };
33 }
34 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")
35 );
36in
37vscode-utils.buildVscodeMarketplaceExtension {
38 mktplcRef = {
39 name = "csdevkit";
40 publisher = "ms-dotnettools";
41 version = "1.30.44";
42 inherit (extInfo) hash arch;
43 };
44 sourceRoot = "extension"; # This has more than one folder.
45
46 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
47 autoPatchelfHook
48 patchelf
49 ];
50 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
51 (lib.getLib glibc) # libgcc_s.so.1
52 (lib.getLib icu) # libicui18n.so libicuuc.so
53 (lib.getLib libkrb5) # libgssapi_krb5.so
54 (lib.getLib libxml2) # libxml2.so.2
55 (lib.getLib libz) # libz.so.1
56 (lib.getLib openssl) # libopenssl.so.3
57 (lib.getLib stdenv.cc.cc) # libstdc++.so.6
58 ];
59
60 postPatch = ''
61 declare ext_unique_id
62 ext_unique_id="$(basename "$out" | head -c 32)"
63
64 substituteInPlace dist/extension.js \
65 --replace-fail 'e.extensionPath,"cache"' 'require("os").tmpdir(),"'"$ext_unique_id"'"' \
66 --replace-fail 't.setExecuteBit=async function(e){if("win32"!==process.platform){const t=i.join(e[a.SERVICEHUB_CONTROLLER_COMPONENT_NAME],"Microsoft.VisualStudio.Code.ServiceController"),r=i.join(e[a.SERVICEHUB_HOST_COMPONENT_NAME],(0,a.getServiceHubHostEntrypointName)()),n=[(0,a.getServerPath)(e),t,r,(0,c.getReliabilityMonitorPath)(e)];await Promise.all(n.map((e=>(0,o.chmod)(e,"0755"))))}}' 't.setExecuteBit=async function(e){}'
67 '';
68
69 preFixup = ''
70 (
71 set -euo pipefail
72 shopt -s globstar
73 shopt -s dotglob
74
75 # Fix all binaries.
76 for file in "$out"/**/*; do
77 if [[ ! -f "$file" || "$file" == *.so || "$file" == *.a || "$file" == *.dylib ]] ||
78 (! isELF "$file" && ! isMachO "$file"); then
79 continue
80 fi
81
82 echo Making "$file" executable...
83 chmod +x "$file"
84
85 ${lib.optionalString stdenv.hostPlatform.isLinux ''
86 # Add .NET deps if it is an apphost.
87 if grep 'You must install .NET to run this application.' "$file" > /dev/null; then
88 echo "Adding .NET needed libraries to: $file"
89 patchelf \
90 --add-needed libicui18n.so \
91 --add-needed libicuuc.so \
92 --add-needed libgssapi_krb5.so \
93 --add-needed libssl.so \
94 "$file"
95 fi
96 ''}
97 done
98
99 ${lib.optionalString stdenv.hostPlatform.isLinux ''
100 # Add the ICU libraries as needed to the globalization DLLs.
101 for file in "$out"/**/{libcoreclr.so,*System.Globalization.Native.so}; do
102 echo "Adding ICU libraries to: $file"
103 patchelf \
104 --add-needed libicui18n.so \
105 --add-needed libicuuc.so \
106 "$file"
107 done
108
109 # Add the Kerberos libraries as needed to the native security DLL.
110 for file in "$out"/**/*System.Net.Security.Native.so; do
111 echo "Adding Kerberos libraries to: $file"
112 patchelf \
113 --add-needed libgssapi_krb5.so \
114 "$file"
115 done
116
117 # Add the OpenSSL libraries as needed to the OpenSSL native security DLL.
118 for file in "$out"/**/*System.Security.Cryptography.Native.OpenSsl.so; do
119 echo "Adding OpenSSL libraries to: $file"
120 patchelf \
121 --add-needed libssl.so \
122 "$file"
123 done
124
125 # Fix libxml2 breakage. See https://github.com/NixOS/nixpkgs/pull/396195#issuecomment-2881757108
126 mkdir -p "$out/lib"
127 ln -s "${lib.getLib libxml2}/lib/libxml2.so" "$out/lib/libxml2.so.2"
128 ''}
129 )
130 '';
131
132 meta = {
133 changelog = "https://marketplace.visualstudio.com/items/ms-dotnettools.csdevkit/changelog";
134 description = "Official Visual Studio Code extension for C# from Microsoft";
135 downloadPage = "https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit";
136 license = lib.licenses.unfree;
137 maintainers = with lib.maintainers; [ ggg ];
138 platforms = [
139 "x86_64-linux"
140 "aarch64-linux"
141 "x86_64-darwin"
142 "aarch64-darwin"
143 ];
144 };
145}