|
| 1 | + |
| 2 | +# This file is a part of Julia. License is MIT: https://julialang.org/license |
| 3 | + |
| 4 | +## dummy stub for https://github.com/JuliaBinaryWrappers/LLD_jll.jl |
| 5 | + |
| 6 | +baremodule LLD_jll |
| 7 | +using Base, Libdl |
| 8 | +Base.Experimental.@compiler_options compile=min optimize=0 infer=false |
| 9 | + |
| 10 | +const PATH_list = String[] |
| 11 | +const LIBPATH_list = String[] |
| 12 | + |
| 13 | +export lld |
| 14 | + |
| 15 | +# These get calculated in __init__() |
| 16 | +const PATH = Ref("") |
| 17 | +const LIBPATH = Ref("") |
| 18 | +artifact_dir = "" |
| 19 | +lld_path = "" |
| 20 | +if Sys.iswindows() |
| 21 | + const lld_exe = "lld.exe" |
| 22 | +else |
| 23 | + const lld_exe = "lld" |
| 24 | +end |
| 25 | + |
| 26 | +if Sys.iswindows() |
| 27 | + const LIBPATH_env = "PATH" |
| 28 | + const LIBPATH_default = "" |
| 29 | + const pathsep = ';' |
| 30 | +elseif Sys.isapple() |
| 31 | + const LIBPATH_env = "DYLD_FALLBACK_LIBRARY_PATH" |
| 32 | + const LIBPATH_default = "~/lib:/usr/local/lib:/lib:/usr/lib" |
| 33 | + const pathsep = ':' |
| 34 | +else |
| 35 | + const LIBPATH_env = "LD_LIBRARY_PATH" |
| 36 | + const LIBPATH_default = "" |
| 37 | + const pathsep = ':' |
| 38 | +end |
| 39 | + |
| 40 | +function adjust_ENV!(env::Dict, PATH::String, LIBPATH::String, adjust_PATH::Bool, adjust_LIBPATH::Bool) |
| 41 | + if adjust_LIBPATH |
| 42 | + LIBPATH_base = get(env, LIBPATH_env, expanduser(LIBPATH_default)) |
| 43 | + if !isempty(LIBPATH_base) |
| 44 | + env[LIBPATH_env] = string(LIBPATH, pathsep, LIBPATH_base) |
| 45 | + else |
| 46 | + env[LIBPATH_env] = LIBPATH |
| 47 | + end |
| 48 | + end |
| 49 | + if adjust_PATH && (LIBPATH_env != "PATH" || !adjust_LIBPATH) |
| 50 | + if adjust_PATH |
| 51 | + if !isempty(get(env, "PATH", "")) |
| 52 | + env["PATH"] = string(PATH, pathsep, env["PATH"]) |
| 53 | + else |
| 54 | + env["PATH"] = PATH |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | + return env |
| 59 | +end |
| 60 | + |
| 61 | +function lld(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) |
| 62 | + env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH) |
| 63 | + withenv(env...) do |
| 64 | + return f(lld_path) |
| 65 | + end |
| 66 | +end |
| 67 | +function lld(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) |
| 68 | + env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH) |
| 69 | + return Cmd(Cmd([lld_path]); env) |
| 70 | +end |
| 71 | + |
| 72 | +function init_lld_path() |
| 73 | + # Prefer our own bundled lld, but if we don't have one, pick it up off of the PATH |
| 74 | + # If this is an in-tree build, `lld` will live in `tools`. Otherwise, it'll be in `libexec` |
| 75 | + for bundled_lld_path in (joinpath(Sys.BINDIR, Base.LIBEXECDIR, lld_exe), |
| 76 | + joinpath(Sys.BINDIR, "..", "tools", lld_exe), |
| 77 | + joinpath(Sys.BINDIR, lld_exe)) |
| 78 | + if isfile(bundled_lld_path) |
| 79 | + global lld_path = abspath(bundled_lld_path) |
| 80 | + return |
| 81 | + end |
| 82 | + end |
| 83 | + global lld_path = something(Sys.which(lld_exe), lld_exe) |
| 84 | +end |
| 85 | + |
| 86 | +function __init__() |
| 87 | + global artifact_dir = dirname(Sys.BINDIR) |
| 88 | + init_lld_path() |
| 89 | + PATH[] = dirname(lld_path) |
| 90 | + push!(PATH_list, PATH[]) |
| 91 | + if Sys.iswindows() |
| 92 | + # On windows, the dynamic libraries (.dll) are in Sys.BINDIR ("usr\\bin") |
| 93 | + append!(LIBPATH_list, [joinpath(Sys.BINDIR, Base.LIBDIR, "julia"), Sys.BINDIR]) |
| 94 | + else |
| 95 | + append!(LIBPATH_list, [joinpath(Sys.BINDIR, Base.LIBDIR, "julia"), joinpath(Sys.BINDIR, Base.LIBDIR)]) |
| 96 | + end |
| 97 | + LIBPATH[] = join(LIBPATH_list, pathsep) |
| 98 | +end |
| 99 | + |
| 100 | +# JLLWrappers API compatibility shims. Note that not all of these will really make sense. |
| 101 | +# For instance, `find_artifact_dir()` won't actually be the artifact directory, because |
| 102 | +# there isn't one. It instead returns the overall Julia prefix. |
| 103 | +is_available() = true |
| 104 | +find_artifact_dir() = artifact_dir |
| 105 | +dev_jll() = error("stdlib JLLs cannot be dev'ed") |
| 106 | +best_wrapper = nothing |
| 107 | + |
| 108 | +end # module libLLD_jll |
0 commit comments