Skip to content

Commit 6bf6c22

Browse files
Fix: always use getrandom on Linux and Android >= 28 (#16478)
Crystal < 1.7 don't support calling the `has_method?` macro from the top level. We already assume the `getrandom` libc function to be available on every Linux targets except Android 24 to 27 for which we now check the actual API version instead of the libc fun. Co-authored-by: Johannes Müller <straightshoota@gmail.com>
1 parent d348727 commit 6bf6c22

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/crystal/system/random.cr

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ end
1212

1313
{% if flag?(:wasi) %}
1414
require "./wasi/random"
15-
{% elsif flag?(:linux) %}
16-
require "c/sys/random"
17-
\{% if LibC.has_method?(:getrandom) %}
18-
require "./unix/getrandom"
19-
\{% else %}
20-
require "./unix/urandom"
21-
\{% end %}
2215
{% elsif flag?(:bsd) || flag?(:darwin) %}
2316
require "./unix/arc4random"
17+
{% elsif flag?(:linux) && (!flag?(:android) || LibC::ANDROID_API >= 28) %}
18+
require "./unix/getrandom"
2419
{% elsif flag?(:unix) %}
2520
require "./unix/urandom"
2621
{% elsif flag?(:win32) %}

0 commit comments

Comments
 (0)