@@ -7,17 +7,25 @@ import (
77 "path/filepath"
88)
99
10- // Based on https://github.com/NVIDIA/libnvidia-container/blob/v1.15.0/src/common.h#L29
10+ // Container runtimes like NVIDIA mount individual libraries into the container
11+ // (e.g. `<libname>.so.<driver_version>`) and create symlinks for them
12+ // (e.g. `<libname>.so.1`). This code helps with finding the right library
13+ // directory for the target Linux distribution as well as locating the symlinks.
14+ //
15+ // Please see [#143 (comment)] for further details.
16+ //
17+ // [#143 (comment)]: https://github.com/coder/envbuilder/issues/143#issuecomment-2192405828
1118
19+ // Based on https://github.com/NVIDIA/libnvidia-container/blob/v1.15.0/src/common.h#L29
1220const usrLibDir = "/usr/lib64"
1321
1422const debianVersionFile = "/etc/debian_version"
1523
16- // getLibDir returns the library directory. It returns a multiarch directory if
17- // the distribution is Debian or a derivative.
24+ // libraryDirectoryPath returns the library directory. It returns a multiarch
25+ // directory if the distribution is Debian or a derivative.
1826//
1927// Based on https://github.com/NVIDIA/libnvidia-container/blob/v1.15.0/src/nvc_container.c#L152-L165
20- func getLibDir (m mounter ) (string , error ) {
28+ func libraryDirectoryPath (m mounter ) (string , error ) {
2129 // Debian and its derivatives use a multiarch directory scheme.
2230 if _ , err := m .Stat (debianVersionFile ); err != nil && ! errors .Is (err , os .ErrNotExist ) {
2331 return "" , fmt .Errorf ("check if debian: %w" , err )
@@ -28,9 +36,10 @@ func getLibDir(m mounter) (string, error) {
2836 return usrLibDir , nil
2937}
3038
31- // getLibsSymlinks returns the stats for all library symlinks if the library
32- // directory exists.
33- func getLibsSymlinks (m mounter , libDir string ) (map [string ][]string , error ) {
39+ // libraryDirectorySymlinks returns a mapping of each library (basename) with a
40+ // list of their symlinks (basename). Libraries with no symlinks do not appear
41+ // in the mapping.
42+ func libraryDirectorySymlinks (m mounter , libDir string ) (map [string ][]string , error ) {
3443 des , err := m .ReadDir (libDir )
3544 if err != nil {
3645 return nil , fmt .Errorf ("read directory %s: %w" , libDir , err )
@@ -54,7 +63,6 @@ func getLibsSymlinks(m mounter, libDir string) (map[string][]string, error) {
5463 }
5564
5665 path = filepath .Base (path )
57-
5866 if _ , ok := libsSymlinks [path ]; ! ok {
5967 libsSymlinks [path ] = make ([]string , 0 , 1 )
6068 }
0 commit comments