Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit a8d447f

Browse files
committed
Flatten build variants to build/<variant>
Prior to this change, kernels were stored in `build/<variant>/<extname>`. However, this was fragile because the extension name had to correspond to the repository name. This change flattens kernels to be stored inside `build/<variant>`. We add a symbolic link `build/<variant>/<extname>` for compatibility with older versions of `kernels`.
1 parent 727fd6c commit a8d447f

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

lib/torch-extension/arch.nix

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,26 @@ stdenv.mkDerivation (prevAttrs: {
223223
postInstall = ''
224224
(
225225
cd ..
226-
cp -r torch-ext/${extensionName} $out/
226+
cp -r torch-ext/${extensionName}/* $out/
227227
)
228-
cp $out/_${extensionName}_*/* $out/${extensionName}
229-
rm -rf $out/_${extensionName}_*
228+
mv $out/_${extensionName}_*/* $out/
229+
rm -d $out/_${extensionName}_${rev}
230+
231+
# Set up compatibility symlink for older kernels versions, remove
232+
# the updated kernels has been around for a while. ln -r is not
233+
# supported on macOS.
234+
( cd $out ; ln -sf . $out/${extensionName} )
230235
''
231236
+ (lib.optionalString (stripRPath && stdenv.hostPlatform.isLinux)) ''
232-
find $out/${extensionName} -name '*.so' \
237+
find $out/ -name '*.so' \
233238
-exec patchelf --set-rpath "" {} \;
234239
''
235240
+ (lib.optionalString (stripRPath && stdenv.hostPlatform.isDarwin)) ''
236-
find $out/${extensionName} -name '*.so' \
241+
find $out/ -name '*.so' \
237242
-exec rewrite-nix-paths-macho {} \;
238243
239244
# Stub some rpath.
240-
find $out/${extensionName} -name '*.so' \
245+
find $out/ -name '*.so' \
241246
-exec install_name_tool -add_rpath "@loader_path/lib" {} \;
242247
'';
243248

lib/torch-extension/no-arch.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ stdenv.mkDerivation (prevAttrs: {
4646

4747
installPhase = ''
4848
mkdir -p $out
49-
cp -r torch-ext/${extensionName} $out/
49+
cp -r torch-ext/${extensionName}/* $out/
50+
( cd $out ; ln -sf . $out/${extensionName} )
5051
'';
5152

5253
doInstallCheck = true;

0 commit comments

Comments
 (0)