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

Expand get_target to include crosscompilation #123

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions lib/bundlex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,41 @@ defmodule Bundlex do
* architecture - e.g. `x86_64` or `arm64`
* vendor - e.g. `pc`
* os - operating system, e.g. `linux` or `darwin20.6.0`
* abi - application binary interface, e.g. `musl` or `gnu` (nil if unknown / non-existent)
* abi - application binary interface, e.g. `musl` or `gnu`
"""
@type target ::
%{architecture: String.t(), vendor: String.t(), os: String.t(), abi: String.t() | nil}
%{
architecture: String.t() | :unknown,
vendor: String.t() | :unknown,
os: String.t() | :unknown,
abi: String.t() | :unknown
}

@doc """
A function returning a target triplet for the environment on which it is run.
A function returning information about the target platform (unknown in case of crosscompilation).
"""
@spec get_target() :: target()
def get_target() do
[architecture, vendor, os | maybe_abi] =
:erlang.system_info(:system_architecture) |> List.to_string() |> String.split("-")

%{
architecture: architecture,
vendor: vendor,
os: os,
abi: List.first(maybe_abi)
}
if Mix.target() == :host do
def get_target() do
[architecture, vendor, os | maybe_abi] =
:erlang.system_info(:system_architecture) |> List.to_string() |> String.split("-")

%{
architecture: architecture,
vendor: vendor,
os: os,
abi: List.first(maybe_abi) || :unknown
}
end
else
def get_target() do
%{
architecture: :unknown,
vendor: :unknown,
os: :unknown,
abi: :unknown
}
end
end

@doc """
Expand Down
Loading