@@ -7,79 +7,29 @@ using Libdl
7
7
8
8
# # discovery
9
9
10
- using Libdl
11
-
12
- VERSION >= v " 0.7.0-DEV.2576" || error (" This version of LLVM.jl requires Julia 0.7" )
13
-
14
- let
15
- # find LLVM library
16
-
17
- libllvm_paths = filter (Libdl. dllist ()) do lib
18
- occursin (r" LLVM\b " , basename (lib))
19
- end
20
- if isempty (libllvm_paths)
21
- error ("""
22
- Cannot find the LLVM library loaded by Julia.
23
- Please use a version of Julia that has been built with USE_LLVM_SHLIB=1 (like the official binaries).
24
- If you are, please file an issue and attach the output of `Libdl.dllist()`.""" )
25
- end
26
- if length (libllvm_paths) > 1
27
- error ("""
28
- Multiple LLVM libraries loaded by Julia.
29
- Please file an issue and attach the output of `Libdl.dllist()`.""" )
30
- end
31
- global const libllvm = first (libllvm_paths)
32
- Base. include_dependency (libllvm)
33
-
34
- global const libllvm_version = Base. libllvm_version:: VersionNumber
35
-
36
- # figure out the supported targets by looking at initialization routines
37
- lib = Libdl. dlopen (libllvm)
38
- llvm_targets = [:AArch64 , :AMDGPU , :ARC , :ARM , :AVR , :BPF , :Hexagon , :Lanai , :MSP430 ,
39
- :Mips , :NVPTX , :PowerPC , :RISCV , :Sparc , :SystemZ , :WebAssembly , :X86 ,
40
- :XCore ]
41
- global const libllvm_targets = filter (llvm_targets) do target
42
- sym = Libdl. dlsym_e (lib, Symbol (" LLVMInitialize$(target) Target" ))
43
- sym != = nothing
44
- end
45
- # TODO : figure out the name of the native target
46
-
47
- @debug " Found LLVM v$libllvm_version at $libllvm with support for $(join (libllvm_targets, " , " )) "
48
-
49
-
50
- # find appropriate LLVM.jl wrapper
51
-
52
- vercmp_match (a,b) = a. major== b. major && a. minor== b. minor
53
- vercmp_compat (a,b) = a. major> b. major || (a. major== b. major && a. minor>= b. minor)
54
-
55
- llvmjl_wrappers_path = joinpath (@__DIR__ , " .." , " lib" )
56
-
57
- llvmjl_wrappers = filter (path-> isdir (joinpath (llvmjl_wrappers_path, path)),
58
- readdir (llvmjl_wrappers_path))
59
- @assert ! isempty (llvmjl_wrappers)
60
-
61
- matching_wrappers = filter (wrapper-> vercmp_match (libllvm_version,
62
- VersionNumber (wrapper)),
63
- llvmjl_wrappers)
64
- global const llvmjl_wrapper = if ! isempty (matching_wrappers)
65
- @assert length (matching_wrappers) == 1
66
- matching_wrappers[1 ]
67
- else
68
- compatible_wrappers = filter (wrapper-> vercmp_compat (libllvm_version,
69
- VersionNumber (wrapper)),
70
- llvmjl_wrappers)
71
- isempty (compatible_wrappers) && error (" Could not find any compatible wrapper for LLVM $(libllvm_version) " )
72
- last (compatible_wrappers)
10
+ export version
11
+
12
+ # make sure we precompile again when LLVM changes (some definitions are version-dependent)
13
+ global const libllvm = Sys. iswindows () ? :LLVM : :libLLVM
14
+ Base. include_dependency (Libdl. dlpath (libllvm))
15
+
16
+ const libllvm_version = Ref {VersionNumber} ()
17
+ function version ()
18
+ if ! isassigned (libllvm_version)
19
+ # FIXME : add a proper C API to LLVM
20
+ version_print = unsafe_string (
21
+ ccall ((:_ZN4llvm16LTOCodeGenerator16getVersionStringEv , libllvm), Cstring, ()))
22
+ m = match (r" LLVM version (?<version>.+)" , version_print)
23
+ m === nothing && error (" Unrecognized version string: '$version_print '" )
24
+ libllvm_version[] = if endswith (m[:version ], " jl" )
25
+ # strip the "jl" SONAME suffix (JuliaLang/julia#33058)
26
+ # (LLVM does never report a prerelease version anyway)
27
+ VersionNumber (m[:version ][1 : end - 2 ])
28
+ else
29
+ VersionNumber (m[:version ])
30
+ end
73
31
end
74
-
75
- @debug " Using LLVM.jl wrapper for LLVM v$llvmjl_wrapper "
76
-
77
-
78
- # backwards-compatible flags
79
-
80
- global const libllvm_system = false
81
-
82
- global const configured = true
32
+ return libllvm_version[]
83
33
end
84
34
85
35
@@ -92,12 +42,12 @@ include("base.jl")
92
42
module API
93
43
using CEnum
94
44
using .. LLVM
95
- using .. LLVM: @apicall , libllvm_version
45
+ using .. LLVM: @apicall
96
46
const off_t = Csize_t
97
- libdir = joinpath (@__DIR__ , " .." , " lib" , LLVM . llvmjl_wrapper )
47
+ libdir = joinpath (@__DIR__ , " .." , " lib" )
98
48
include (joinpath (libdir, " libLLVM_common.jl" ))
99
49
include (joinpath (libdir, " libLLVM_h.jl" ))
100
- include (joinpath (libdir, " .. " , " libLLVM_extra.jl" ))
50
+ include (joinpath (libdir, " libLLVM_extra.jl" ))
101
51
end
102
52
103
53
# LLVM API wrappers
@@ -130,19 +80,10 @@ include("deprecated.jl")
130
80
# # initialization
131
81
132
82
function __init__ ()
133
- libllvm_paths = filter (Libdl. dllist ()) do lib
134
- occursin (r" LLVM\b " , basename (lib))
135
- end
136
- if length (libllvm_paths) > 1
137
- # NOTE: this still allows switching to a non-USE_LLVM_SHLIB version, but
138
- # there's no way to detect that since the new libLLVM is loaded before this...
139
- cachefile = if VERSION >= v " 1.3-"
140
- Base. compilecache_path (Base. PkgId (LLVM))
141
- else
142
- abspath (DEPOT_PATH [1 ], Base. cache_file_entry (Base. PkgId (LLVM)))
143
- end
144
- rm (cachefile)
145
- error (" Your set-up changed, and LLVM.jl needs to be reconfigured. Please load the package again." )
83
+ libllvm_version = version ()
84
+ @debug " Using LLVM $libllvm_version at $(Libdl. dlpath (libllvm)) "
85
+ if libllvm_version != Base. libllvm_version
86
+ @warn " Using a different version of LLVM ($libllvm_version ) than the one shipped with Julia ($(Base. libllvm_version) ); this is unsupported"
146
87
end
147
88
148
89
_install_handlers ()
0 commit comments