-
-
Notifications
You must be signed in to change notification settings - Fork 265
/
BinaryPlatforms_compat.jl
142 lines (121 loc) · 5.09 KB
/
BinaryPlatforms_compat.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
module BinaryPlatforms
using Base.BinaryPlatforms
export platform_key_abi, platform_dlext, valid_dl_path, arch, libc,
libgfortran_version, libstdcxx_version, cxxstring_abi, parse_dl_name_version,
detect_libgfortran_version, detect_libstdcxx_version, detect_cxxstring_abi,
call_abi, wordsize, triplet, select_platform, platforms_match,
CompilerABI, Platform, UnknownPlatform, Linux, MacOS, Windows, FreeBSD
import Base.BinaryPlatforms: libgfortran_version, libstdcxx_version, platform_name,
wordsize, platform_dlext, tags, arch, libc, call_abi,
cxxstring_abi
struct UnknownPlatform <: AbstractPlatform
UnknownPlatform(args...; kwargs...) = new()
end
tags(::UnknownPlatform) = Dict{String,String}("os"=>"unknown")
struct CompilerABI
libgfortran_version::Union{Nothing,VersionNumber}
libstdcxx_version::Union{Nothing,VersionNumber}
cxxstring_abi::Union{Nothing,Symbol}
function CompilerABI(;libgfortran_version::Union{Nothing, VersionNumber} = nothing,
libstdcxx_version::Union{Nothing, VersionNumber} = nothing,
cxxstring_abi::Union{Nothing, Symbol} = nothing)
return new(libgfortran_version, libstdcxx_version, cxxstring_abi)
end
end
# Easy replacement constructor
function CompilerABI(cabi::CompilerABI; libgfortran_version=nothing,
libstdcxx_version=nothing,
cxxstring_abi=nothing)
return CompilerABI(;
libgfortran_version=something(libgfortran_version, Some(cabi.libgfortran_version)),
libstdcxx_version=something(libstdcxx_version, Some(cabi.libstdcxx_version)),
cxxstring_abi=something(cxxstring_abi, Some(cabi.cxxstring_abi)),
)
end
libgfortran_version(cabi::CompilerABI) = cabi.libgfortran_version
libstdcxx_version(cabi::CompilerABI) = cabi.libstdcxx_version
cxxstring_abi(cabi::CompilerABI) = cabi.cxxstring_abi
for T in (:Linux, :Windows, :MacOS, :FreeBSD)
@eval begin
struct $(T) <: AbstractPlatform
p::Platform
function $(T)(arch::Symbol; compiler_abi=nothing, kwargs...)
if compiler_abi !== nothing
kwargs = (; kwargs...,
:libgfortran_version => libgfortran_version(compiler_abi),
:libstdcxx_version => libstdcxx_version(compiler_abi),
:cxxstring_abi => cxxstring_abi(compiler_abi)
)
end
return new(Platform(string(arch), $(string(T)); kwargs..., validate_strict=true))
end
end
end
# First, methods we need to coerce to Symbol for backwards-compatibility
for f in (:arch, :libc, :call_abi, :cxxstring_abi)
@eval begin
function $(f)(p::$(T))
str = $(f)(p.p)
if str === nothing
return nothing
end
return Symbol(str)
end
end
end
# Next, things we don't need to coerce
for f in (:libgfortran_version, :libstdcxx_version, :platform_name, :wordsize, :platform_dlext, :tags, :triplet)
@eval begin
$(f)(p::$(T)) = $(f)(p.p)
end
end
# Finally, add equality testing between these wrapper types and other AbstractPlatforms
@eval begin
Base.:(==)(a::$(T), b::AbstractPlatform) = b == a.p
end
end
# Add one-off functions
MacOS(; kwargs...) = MacOS(:x86_64; kwargs...)
FreeBSD(; kwargs...) = FreeBSD(:x86_64; kwargs...)
function triplet(p::AbstractPlatform)
# We are going to sub off to `Base.BinaryPlatforms.triplet()` here,
# with the important exception that we override `os_version` to better
# mimic the old behavior of `triplet()`
if Sys.isfreebsd(p)
p = deepcopy(p)
p["os_version"] = "11.1.0"
elseif Sys.isapple(p)
p = deepcopy(p)
p["os_version"] = "14.0.0"
end
return Base.BinaryPlatforms.triplet(p)
end
"""
platform_key_abi(machine::AbstractString)
Returns the platform key for the current platform, or any other though the
the use of the `machine` parameter.
This method is deprecated, import `Base.BinaryPlatforms` and use either `HostPlatform()`
to get the current host platform, or `parse(Base.BinaryPlatforms.Platform, triplet)`
to parse the triplet for some other platform instead.
"""
platform_key_abi() = HostPlatform()
platform_key_abi(triplet::AbstractString) = parse(Platform, triplet)
"""
valid_dl_path(path::AbstractString, platform::Platform)
Return `true` if the given `path` ends in a valid dynamic library filename.
E.g. returns `true` for a path like `"usr/lib/libfoo.so.3.5"`, but returns
`false` for a path like `"libbar.so.f.a"`.
This method is deprecated and will be removed in Julia 2.0.
"""
function valid_dl_path(path::AbstractString, platform::AbstractPlatform)
try
parse_dl_name_version(path, string(os(platform))::String)
return true
catch e
if isa(e, ArgumentError)
return false
end
rethrow(e)
end
end
end # module BinaryPlatforms