@@ -3,15 +3,8 @@ module Linking
3
3
4
4
import Base. Libc: Libdl
5
5
6
- # inlined LLD_jll
7
- # These get calculated in __init__()
8
- const PATH = Ref (" " )
9
- const LIBPATH = Ref (" " )
10
- const PATH_list = String[]
11
- const LIBPATH_list = String[]
12
- const lld_path = Ref {String} ()
6
+ # from LLD_jll
13
7
const lld_exe = Sys. iswindows () ? " lld.exe" : " lld"
14
- const dsymutil_path = Ref {String} ()
15
8
const dsymutil_exe = Sys. iswindows () ? " dsymutil.exe" : " dsymutil"
16
9
17
10
if Sys. iswindows ()
@@ -47,61 +40,51 @@ function adjust_ENV!(env::Dict, PATH::String, LIBPATH::String, adjust_PATH::Bool
47
40
return env
48
41
end
49
42
50
- function __init_lld_path ()
43
+ const lld_path = OncePerProcess {String} () do
51
44
# Prefer our own bundled lld, but if we don't have one, pick it up off of the PATH
52
45
# If this is an in-tree build, `lld` will live in `tools`. Otherwise, it'll be in `private_libexecdir`
53
46
for bundled_lld_path in (joinpath (Sys. BINDIR, Base. PRIVATE_LIBEXECDIR, lld_exe),
54
47
joinpath (Sys. BINDIR, " .." , " tools" , lld_exe),
55
48
joinpath (Sys. BINDIR, lld_exe))
56
49
if isfile (bundled_lld_path)
57
- lld_path[] = abspath (bundled_lld_path)
58
- return
50
+ return abspath (bundled_lld_path)
59
51
end
60
52
end
61
- lld_path[] = something (Sys. which (lld_exe), lld_exe)
62
- return
53
+ return something (Sys. which (lld_exe), lld_exe)
63
54
end
64
55
65
- function __init_dsymutil_path ()
66
- # Same as with lld but for dsymutil
56
+ const dsymutil_path = OncePerProcess {String} () do
57
+ # Same as with lld but for dsymutil
67
58
for bundled_dsymutil_path in (joinpath (Sys. BINDIR, Base. PRIVATE_LIBEXECDIR, dsymutil_exe),
68
59
joinpath (Sys. BINDIR, " .." , " tools" , dsymutil_exe),
69
60
joinpath (Sys. BINDIR, dsymutil_exe))
70
61
if isfile (bundled_dsymutil_path)
71
- dsymutil_path[] = abspath (bundled_dsymutil_path)
72
- return
62
+ return abspath (bundled_dsymutil_path)
73
63
end
74
64
end
75
- dsymutil_path[] = something (Sys. which (dsymutil_exe), dsymutil_exe)
76
- return
65
+ return something (Sys. which (dsymutil_exe), dsymutil_exe)
77
66
end
78
67
79
- const VERBOSE = Ref {Bool} ( false )
68
+ PATH () = dirname ( lld_path () )
80
69
81
- function __init__ ()
82
- VERBOSE[] = something (Base. get_bool_env (" JULIA_VERBOSE_LINKING" , false ), false )
83
-
84
- __init_lld_path ()
85
- __init_dsymutil_path ()
86
- PATH[] = dirname (lld_path[])
70
+ const LIBPATH = OncePerProcess {String} () do
87
71
if Sys. iswindows ()
88
72
# On windows, the dynamic libraries (.dll) are in Sys.BINDIR ("usr\\bin")
89
- append! ( LIBPATH_list, [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), Sys. BINDIR])
73
+ LIBPATH_list = [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), Sys. BINDIR]
90
74
else
91
- append! ( LIBPATH_list, [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), abspath (Sys. BINDIR, Base. LIBDIR)])
75
+ LIBPATH_list = [abspath (Sys. BINDIR, Base. LIBDIR, " julia" ), abspath (Sys. BINDIR, Base. LIBDIR)]
92
76
end
93
- LIBPATH[] = join (LIBPATH_list, pathsep)
94
- return
77
+ return join (LIBPATH_list, pathsep)
95
78
end
96
79
97
80
function lld (; adjust_PATH:: Bool = true , adjust_LIBPATH:: Bool = true )
98
- env = adjust_ENV! (copy (ENV ), PATH[] , LIBPATH[] , adjust_PATH, adjust_LIBPATH)
99
- return Cmd (Cmd ([lld_path[] ]); env)
81
+ env = adjust_ENV! (copy (ENV ), PATH () , LIBPATH () , adjust_PATH, adjust_LIBPATH)
82
+ return Cmd (Cmd ([lld_path () ]); env)
100
83
end
101
84
102
85
function dsymutil (; adjust_PATH:: Bool = true , adjust_LIBPATH:: Bool = true )
103
- env = adjust_ENV! (copy (ENV ), PATH[] , LIBPATH[] , adjust_PATH, adjust_LIBPATH)
104
- return Cmd (Cmd ([dsymutil_path[] ]); env)
86
+ env = adjust_ENV! (copy (ENV ), PATH () , LIBPATH () , adjust_PATH, adjust_LIBPATH)
87
+ return Cmd (Cmd ([dsymutil_path () ]); env)
105
88
end
106
89
107
90
function ld ()
149
132
shlibdir () = libdir ()
150
133
end
151
134
135
+ verbose_linking () = something (Base. get_bool_env (" JULIA_VERBOSE_LINKING" , false ), false )
136
+
152
137
function link_image_cmd (path, out)
153
138
PRIVATE_LIBDIR = " -L$(private_libdir ()) "
154
139
SHLIBDIR = " -L$(shlibdir ()) "
@@ -158,7 +143,7 @@ function link_image_cmd(path, out)
158
143
LIBS = (LIBS... , " -lopenlibm" , " -lssp" , " -lgcc_s" , " -lgcc" , " -lmsvcrt" )
159
144
end
160
145
161
- V = VERBOSE[] ? " --verbose" : " "
146
+ V = verbose_linking () ? " --verbose" : " "
162
147
` $(ld ()) $V $SHARED -o $out $WHOLE_ARCHIVE $path $NO_WHOLE_ARCHIVE $PRIVATE_LIBDIR $SHLIBDIR $LIBS `
163
148
end
164
149
0 commit comments