Skip to content

Commit

Permalink
Make erlang ffi code work on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DitherWither committed Aug 22, 2024
1 parent a88a833 commit cb16004
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/platform.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ pub fn runtime() -> Runtime {

pub fn os() -> Os {
case os_() {
"aix" | "aix" <> _ -> Aix
"darwin" | "darwin" <> _ -> Darwin
"freebsd" | "freebsd" <> _ -> FreeBsd
"linux" | "linux" <> _ -> Linux
"openbsd" | "openbsd" <> _ -> OpenBsd
"sunos" | "sunos" <> _ -> SunOs
"win" | "win" <> _ -> Win32
"aix" -> Aix
"darwin" -> Darwin
"freebsd" -> FreeBsd
"linux" -> Linux
"openbsd" -> OpenBsd
"sunos" -> SunOs
"win" -> Win32
os -> OtherOs(os)
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/platform_ffi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
runtime() -> unicode:characters_to_binary("erlang").

os() ->
ArchitectureString = erlang:system_info(system_architecture),
Tokens = string:tokens(ArchitectureString, "-"),
unicode:characters_to_binary(
case length(Tokens) of
4 -> lists:nth(3, Tokens);
3 -> lists:nth(3, Tokens);
2 -> lists:nth(2, Tokens)
end
).
Platform =
case os:type() of
{win32, nt} ->
"win32";
{unix, Os} ->
erlang:atom_to_list(Os);
{_, _} ->
"unknown"
end,
list_to_binary(Platform).

arch() ->
ArchitectureString = erlang:system_info(system_architecture),
[CpuArch | _] = string:tokens(ArchitectureString, "-"),
unicode:characters_to_binary(CpuArch).
case erlang:system_info(os_type) of
{unix, _} ->
[Arch, _] = string:split(erlang:system_info(system_architecture), "-"),
unicode:characters_to_binary(Arch);
{win32, _} ->
case erlang:system_info(wordsize) of
4 -> <<"ia32">>;
8 -> <<"x64">>
end
end.

0 comments on commit cb16004

Please sign in to comment.