675675choose_shards (:: AnyPlatform ; kwargs... ) = choose_shards (default_host_platform; kwargs... )
676676
677677"""
678- supported_platforms(;exclude::Union{Vector{<:Platform},Function}=x-> false,
678+ supported_platforms(;exclude::Union{Vector{<:Platform},Function}=Returns( false) ,
679679 experimental::Bool=false)
680680
681681Return the list of supported platforms as an array of `Platform`s. These are the platforms we
@@ -690,7 +690,7 @@ or a function that returns true for exclusions i.e.
690690supported_platforms(exclude=Sys.islinux)
691691```
692692"""
693- function supported_platforms (;exclude:: Union{Vector{<:Platform},Function} = x -> false ,
693+ function supported_platforms (;exclude:: Union{Vector{<:Platform},Function} = Returns ( false ) ,
694694 experimental:: Bool = false )
695695 exclude_platforms! (platforms, exclude:: Function ) = filter (! exclude, platforms)
696696 exclude_platforms! (platforms, exclude:: Vector{<:Platform} ) = filter! (! in (exclude), platforms)
@@ -796,11 +796,12 @@ function expand_cxxstring_abis(ps::Vector{<:AbstractPlatform}; kwargs...)
796796end
797797
798798"""
799- expand_microarchitectures(p::AbstractPlatform)
799+ expand_microarchitectures(p::AbstractPlatform, [microarchitectures::Vector{String}] )
800800
801801Given a `Platform`, returns a vector of `Platforms` with differing `march` attributes
802802as specified by the `ARCHITECTURE_FLAGS` mapping. If the given `Platform` alread has a
803- `march` tag specified, only that platform is returned.
803+ `march` tag specified, only that platform is returned. If the `microarchitectures`
804+ argument is given, limit the expansion to the given microarchitectures.
804805
805806```jldoctest
806807julia> using BinaryBuilderBase
@@ -817,28 +818,30 @@ julia> expand_microarchitectures(Platform("armv7l", "linux"))
817818 Linux armv7l {call_abi=eabihf, libc=glibc, march=armv7l}
818819 Linux armv7l {call_abi=eabihf, libc=glibc, march=neonvfpv4}
819820
820- julia> expand_microarchitectures(Platform("aarch64", "linux"))
821- 4 -element Vector{Platform}:
821+ julia> expand_microarchitectures(Platform("aarch64", "linux"), ["armv8_0", "a64fx"] )
822+ 2 -element Vector{Platform}:
822823 Linux aarch64 {libc=glibc, march=armv8_0}
823- Linux aarch64 {libc=glibc, march=armv8_4_crypto_sve}
824- Linux aarch64 {libc=glibc, march=armv8_2_crypto}
825- Linux aarch64 {libc=glibc, march=armv8_1}
824+ Linux aarch64 {libc=glibc, march=a64fx}
826825
827826julia> expand_microarchitectures(Platform("i686", "windows"))
8288272-element Vector{Platform}:
829828 Windows i686 {march=pentium4}
830829 Windows i686 {march=prescott}
831830```
832831"""
833- function expand_microarchitectures (platform:: AbstractPlatform )
834- # If this already has a `march`, or it's an `AnyPlatform`, just return it.
835- if isa (platform, AnyPlatform) || march (platform) != = nothing
832+ function expand_microarchitectures (platform:: AbstractPlatform ,
833+ microarchitectures:: Vector{String} = get_all_march_names (arch (platform)))
834+ all_marchs = get_all_march_names (arch (platform))
835+
836+ # If this already has a `march`, or it's an `AnyPlatform`, or the microarchitectures we
837+ # want to expand aren't relative to this platform, just return it.
838+ if isa (platform, AnyPlatform) || march (platform) != = nothing ||
839+ ! any (in (all_marchs), microarchitectures)
836840 return [platform]
837841 end
838842
839- # Otherwise, return a bunch of Platform objects with appropriately-set `march` tags, but
840- # first filter out some meaningless combinations of microarchitectures.
841- all_marchs = filter (get_all_march_names (arch (platform))) do march
843+ # First, filter out some meaningless combinations of microarchitectures.
844+ marchs = filter (all_marchs) do march
842845 if (! Sys. isapple (platform) && march == " apple_m1" ) ||
843846 (Sys. isapple (platform) && arch (platform) == " aarch64" && march ∉ (" armv8_0" , " apple_m1" ))
844847 # `apple_m1` makes sense only on macOS, and the only aarch64 microarchitectures
@@ -851,39 +854,89 @@ function expand_microarchitectures(platform::AbstractPlatform)
851854 return true
852855 end
853856
854- return map (all_marchs) do march
855- p = deepcopy (platform)
856- p[ " march " ] = march
857- return p
857+ # But if none of the remaining microarchitectures are among those we want to expand,
858+ # return the given platform as is.
859+ if ! any ( in (microarchitectures), marchs)
860+ return [platform]
858861 end
862+
863+ # Otherwise, return a bunch of Platform objects with appropriately-set `march` tags
864+ return [(p = deepcopy (platform); p[" march" ] = march; p) for march in marchs if march in microarchitectures]
859865end
860866
861867"""
862- expand_microarchitectures(ps::Vector{<:Platform})
868+ expand_microarchitectures(ps::Vector{<:Platform}, [microarchitectures::Vector{String}];
869+ filter=Returns(true))
870+
871+ Expand all platforms in the vector `ps` with the supported microarchitectures.
863872
864- Expand all platforms in the given vector with the supported microarchitectures.
873+ If the `microarchitectures` argument is given, limit the expansion to the given
874+ platforms. This is useful if you do not want to expand to all available
875+ microarchitectures.
876+
877+ The expansion is applied only to the platforms matching the `filter` predicate, by
878+ default all platforms. This is useful if you want to limit the expansion to some
879+ platforms, without having to explicitly list its microarchitectures in the second
880+ argument.
865881
866882```jldoctest
867883julia> using BinaryBuilderBase
868884
869885julia> expand_microarchitectures(filter!(p -> Sys.islinux(p) && libc(p) == "glibc", supported_platforms()))
870- 13 -element Vector{Platform}:
886+ 14 -element Vector{Platform}:
871887 Linux i686 {libc=glibc, march=pentium4}
872888 Linux i686 {libc=glibc, march=prescott}
873889 Linux x86_64 {libc=glibc, march=x86_64}
874890 Linux x86_64 {libc=glibc, march=avx}
875891 Linux x86_64 {libc=glibc, march=avx2}
876892 Linux x86_64 {libc=glibc, march=avx512}
877893 Linux aarch64 {libc=glibc, march=armv8_0}
878- Linux aarch64 {libc=glibc, march=armv8_4_crypto_sve}
879- Linux aarch64 {libc=glibc, march=armv8_2_crypto}
880894 Linux aarch64 {libc=glibc, march=armv8_1}
895+ Linux aarch64 {libc=glibc, march=armv8_2_crypto}
896+ Linux aarch64 {libc=glibc, march=a64fx}
897+ Linux armv6l {call_abi=eabihf, libc=glibc, march=arm1176jzfs}
881898 Linux armv7l {call_abi=eabihf, libc=glibc, march=armv7l}
882899 Linux armv7l {call_abi=eabihf, libc=glibc, march=neonvfpv4}
883900 Linux powerpc64le {libc=glibc, march=power8}
901+
902+ julia> expand_microarchitectures(filter!(p -> Sys.islinux(p) && libc(p) == "glibc", supported_platforms()), ["x86_64", "avx2"])
903+ 7-element Vector{Platform}:
904+ Linux i686 {libc=glibc}
905+ Linux x86_64 {libc=glibc, march=x86_64}
906+ Linux x86_64 {libc=glibc, march=avx2}
907+ Linux aarch64 {libc=glibc}
908+ Linux armv6l {call_abi=eabihf, libc=glibc}
909+ Linux armv7l {call_abi=eabihf, libc=glibc}
910+ Linux powerpc64le {libc=glibc}
911+
912+ julia> expand_microarchitectures(filter!(p -> Sys.islinux(p) && libc(p) == "glibc", supported_platforms()); filter=p->arch(p)=="x86_64")
913+ 9-element Vector{Platform}:
914+ Linux i686 {libc=glibc}
915+ Linux x86_64 {libc=glibc, march=x86_64}
916+ Linux x86_64 {libc=glibc, march=avx}
917+ Linux x86_64 {libc=glibc, march=avx2}
918+ Linux x86_64 {libc=glibc, march=avx512}
919+ Linux aarch64 {libc=glibc}
920+ Linux armv6l {call_abi=eabihf, libc=glibc}
921+ Linux armv7l {call_abi=eabihf, libc=glibc}
922+ Linux powerpc64le {libc=glibc}
884923```
885924"""
886- expand_microarchitectures (ps:: Vector{<:AbstractPlatform} ) = collect (Iterators. flatten (expand_microarchitectures .(ps)))
925+ function expand_microarchitectures (ps:: Vector{<:AbstractPlatform} ,
926+ microarchitectures:: Vector{String} = collect (Iterators. flatten (get_all_march_names .(unique! (arch .(ps)))));
927+ filter= Returns (true ),
928+ )
929+ out = map (ps) do p
930+ return if filter (p)
931+ # If the platform satisfies the predicate, expand its microarchitectures
932+ expand_microarchitectures (p, microarchitectures)
933+ else
934+ # otherwise return it as-is.
935+ [p]
936+ end
937+ end
938+ return collect (Iterators. flatten (out))
939+ end
887940
888941"""
889942 preferred_libgfortran_version(platform::AbstractPlatform, shard::CompilerShard;
0 commit comments