Skip to content

Commit e76eb7a

Browse files
committed
Replace Pkg.build with runtime initialization.
1 parent 3753780 commit e76eb7a

File tree

4 files changed

+63
-113
lines changed

4 files changed

+63
-113
lines changed

deps/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

deps/build.jl

Lines changed: 0 additions & 105 deletions
This file was deleted.
File renamed without changes.

src/LLVM.jl

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,63 @@ using Printf
55
using Libdl
66

77

8-
const ext = joinpath(@__DIR__, "..", "deps", "ext.jl")
9-
isfile(ext) || error("LLVM.jl has not been built, please run Pkg.build(\"LLVM\").")
10-
include(ext)
11-
const libllvm = libllvm_path
8+
## discovery
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+
# figure out the path to libLLVM by looking at the libraries loaded by Julia
15+
const libllvm_paths = filter(Libdl.dllist()) do lib
16+
occursin("LLVM", basename(lib))
17+
end
18+
if isempty(libllvm_paths)
19+
error("""
20+
Cannot find the LLVM library loaded by Julia.
21+
Please use a version of Julia that has been built with USE_LLVM_SHLIB=1 (like the official binaries).
22+
If you are, please file an issue and attach the output of `Libdl.dllist()`.""")
23+
end
24+
if length(libllvm_paths) > 1
25+
error("""
26+
Multiple LLVM libraries loaded by Julia.
27+
Please file an issue and attach the output of `Libdl.dllist()`.""")
28+
end
29+
const libllvm = first(libllvm_paths)
30+
const libllvm_version = Base.libllvm_version::VersionNumber
31+
@debug "Discovered LLVM v$libllvm_version at $libllvm"
32+
33+
vercmp_match(a,b) = a.major==b.major && a.minor==b.minor
34+
vercmp_compat(a,b) = a.major>b.major || (a.major==b.major && a.minor>=b.minor)
35+
36+
const llvmjl_wrappers = filter(path->isdir(joinpath(@__DIR__, "..", "lib", path)),
37+
readdir(joinpath(@__DIR__, "..", "lib")))
38+
@assert !isempty(llvmjl_wrappers)
39+
40+
# figure out which wrapper to use
41+
const matching_wrappers = filter(wrapper->vercmp_match(libllvm_version,
42+
VersionNumber(wrapper)),
43+
llvmjl_wrappers)
44+
const llvmjl_wrapper = if !isempty(matching_wrappers)
45+
@assert length(matching_wrappers) == 1
46+
matching_wrappers[1]
47+
else
48+
compatible_wrappers = filter(wrapper->vercmp_compat(libllvm_version,
49+
VersionNumber(wrapper)),
50+
llvmjl_wrappers)
51+
isempty(compatible_wrappers) && error("Could not find any compatible wrapper for LLVM $(libllvm_version)")
52+
last(compatible_wrappers)
53+
end
54+
@debug "Using LLVM.jl wrapper for v$llvmjl_wrapper"
55+
56+
# TODO: figure out the name of the native target
57+
const libllvm_targets = [:NVPTX, :AMDGPU]
58+
59+
# backwards-compatible flags
60+
const libllvm_system = false
61+
const configured = true
62+
63+
64+
## source code includes
1265

1366
include("util/types.jl")
1467

@@ -49,14 +102,19 @@ include("interop.jl")
49102

50103
include("deprecated.jl")
51104

105+
106+
## initialization
107+
52108
function __init__()
53109
libllvm_paths = filter(Libdl.dllist()) do lib
54110
occursin("LLVM", basename(lib))
55111
end
56112
if length(libllvm_paths) > 1
57113
# NOTE: this still allows switching to a non-USE_LLVM_SHLIB version, but
58114
# there's no way to detect that since the new libLLVM is loaded before this...
59-
error("LLVM.jl and Julia are using different LLVM libraries, please re-run Pkg.build(\"LLVM\").")
115+
cachefile = Base.compilecache(Base.PkgId(LLVM))
116+
rm(cachefile)
117+
error("Your set-up changed, and LLVM.jl needs to be reconfigured. Please load the package again.")
60118
end
61119

62120
_install_handlers()

0 commit comments

Comments
 (0)