@@ -7,17 +7,25 @@ import (
7
7
"path/filepath"
8
8
)
9
9
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
11
18
19
+ // Based on https://github.com/NVIDIA/libnvidia-container/blob/v1.15.0/src/common.h#L29
12
20
const usrLibDir = "/usr/lib64"
13
21
14
22
const debianVersionFile = "/etc/debian_version"
15
23
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.
18
26
//
19
27
// 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 ) {
21
29
// Debian and its derivatives use a multiarch directory scheme.
22
30
if _ , err := m .Stat (debianVersionFile ); err != nil && ! errors .Is (err , os .ErrNotExist ) {
23
31
return "" , fmt .Errorf ("check if debian: %w" , err )
@@ -28,9 +36,10 @@ func getLibDir(m mounter) (string, error) {
28
36
return usrLibDir , nil
29
37
}
30
38
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 ) {
34
43
des , err := m .ReadDir (libDir )
35
44
if err != nil {
36
45
return nil , fmt .Errorf ("read directory %s: %w" , libDir , err )
@@ -54,7 +63,6 @@ func getLibsSymlinks(m mounter, libDir string) (map[string][]string, error) {
54
63
}
55
64
56
65
path = filepath .Base (path )
57
-
58
66
if _ , ok := libsSymlinks [path ]; ! ok {
59
67
libsSymlinks [path ] = make ([]string , 0 , 1 )
60
68
}
0 commit comments