Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Pkg.BinaryPlatforms compat, fix invalidations #3736

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 14 additions & 34 deletions src/BinaryPlatforms_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ export platform_key_abi, platform_dlext, valid_dl_path, arch, libc,
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()
function UnknownPlatform(args...; kwargs...)
p = Platform("unknown", "unknown")
delete!(p.tags, "arch")
return p
end
tags(::UnknownPlatform) = Dict{String,String}("os"=>"unknown")


struct CompilerABI
Expand Down Expand Up @@ -46,29 +43,24 @@ 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))
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 Platform(string(arch), $(string(T)); kwargs..., validate_strict=true)
end
end
end

const PlatformUnion = Union{Linux,MacOS,Windows,FreeBSD}

# 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::PlatformUnion)
str = $(f)(p.p)
function $(f)(p::AbstractPlatform)
str = Base.BinaryPlatforms.$(f)(p)
if str === nothing
return nothing
end
Expand All @@ -77,18 +69,6 @@ for f in (:arch, :libc, :call_abi, :cxxstring_abi)
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::PlatformUnion) = $(f)(p.p)
end
end

# Finally, add equality testing between these wrapper types and other AbstractPlatforms
@eval begin
Base.:(==)(a::PlatformUnion, b::AbstractPlatform) = b == a.p
end

# Add one-off functions
MacOS(; kwargs...) = MacOS(:x86_64; kwargs...)
FreeBSD(; kwargs...) = FreeBSD(:x86_64; kwargs...)
Expand Down