Current section

Files

Jump to
mdex lib mdex comptime_utils.ex
Raw

lib/mdex/comptime_utils.ex

# Original https://github.com/elixir-explorer/explorer/blob/a96052dd2cc967d362a06d208fd3cc7dc64cead1/lib/explorer/comptime_utils.ex
defmodule MDEx.ComptimeUtils do
@moduledoc false
def cpu_with_all_caps?(needed_flags, opts \\ []) do
opts = Keyword.validate!(opts, cpu_info_file_path: "/proc/cpuinfo", target: nil)
case File.read(opts[:cpu_info_file_path]) do
{:ok, contents} ->
flags =
contents
|> String.split("\n")
|> Stream.filter(&String.starts_with?(&1, "flags"))
|> Stream.map(fn line ->
[_, flags] = String.split(line, ": ")
String.split(flags)
end)
|> Stream.uniq()
|> Enum.to_list()
|> List.flatten()
Enum.all?(needed_flags, fn flag -> flag in flags end)
{:error, _} ->
false
end
end
end