Skip to content

Commit

Permalink
Merge pull request #16 from akash-akya/mac-arm64-bin
Browse files Browse the repository at this point in the history
Add pre-built binary for macos arm64
  • Loading branch information
akash-akya authored Jun 23, 2022
2 parents 2646b2b + f6533e8 commit 92fa6fe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions lib/mix/compile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule Mix.Tasks.Compile.Odu do
{"windows", "amd64"} -> "odu_windows_amd64.exe"
{"linux", "amd64"} -> "odu_linux_amd64"
{"darwin", "amd64"} -> "odu_darwin_amd64"
{"darwin", "arm64"} -> "odu_darwin_arm64"
# generic name for all other platform
_ -> "odu"
end
Expand Down Expand Up @@ -60,7 +61,7 @@ defmodule Mix.Tasks.Compile.Odu do
result =
System.cmd(
"go",
~w/build -o #{executable_path}/,
~w/build -ldflags -w -o #{executable_path}/,
cd: "go_src",
stderr_to_stdout: true,
env: env
Expand Down Expand Up @@ -95,21 +96,45 @@ defmodule Mix.Tasks.Compile.Odu do
end

defp current_platform do
is_amd64 = String.starts_with?(@system_arch, "x86_64")
{osfamily, osname} = :os.type()
arch = system_arch(osfamily)

case :os.type() do
{:win32, _} ->
# FIXME: determine architecture properly
case {osfamily, osname, arch} do
{:win32, _, "amd64"} ->
{"windows", "amd64"}

{:unix, :linux} when is_amd64 ->
{:unix, :linux, "amd64"} ->
{"linux", "amd64"}

{:unix, :darwin} when is_amd64 ->
{:unix, :darwin, "amd64"} ->
{"darwin", "amd64"}

{:unix, os_name} ->
{:unix, :darwin, "aarch64"} ->
{"darwin", "arm64"}

{:unix, os_name, _} ->
{to_string(os_name), nil}
end
end

defp system_arch(osfamily) do
arch =
:erlang.system_info(:system_architecture)
|> List.to_string()
|> String.split("-")
|> List.first()

# normalize
arch =
if osfamily == :win32 && :erlang.system_info(:wordsize) == 8 do
"amd64"
else
arch
end

case arch do
"x86_64" -> "amd64"
arch -> arch
end
end
end
Binary file modified priv/odu_darwin_amd64
Binary file not shown.
Binary file added priv/odu_darwin_arm64
Binary file not shown.
Binary file modified priv/odu_linux_amd64
Binary file not shown.
Binary file modified priv/odu_windows_amd64.exe
Binary file not shown.

0 comments on commit 92fa6fe

Please sign in to comment.