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

Add -d:nimNoGetEntropy to allow running on macOS earlier than 10.12 #20460

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
8 changes: 6 additions & 2 deletions lib/std/sysrand.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
## for targets running kernel version < 3.17) by passing a compile flag of
## `-d:nimNoGetRandom`. If this flag is passed, sysrand will use `/dev/urandom`
## as with any other POSIX compliant OS.
##
## On a macOS target, you can choose to use `/dev/urandom` instead of
## the one from `sys/random.h` by passing `-d:nimNoGetEntropy`. This is
## useful if you are running macOS prior to 10.12.
##

runnableExamples:
Expand All @@ -66,7 +70,7 @@ when defined(nimPreviewSlimSystem):
import std/assertions

const
batchImplOS = defined(freebsd) or defined(openbsd) or defined(zephyr) or (defined(macosx) and not defined(ios))
batchImplOS = defined(freebsd) or defined(openbsd) or defined(zephyr) or (defined(macosx) and not defined(nimNoGetEntropy) and not defined(ios))
batchSize {.used.} = 256

when batchImplOS:
Expand Down Expand Up @@ -254,7 +258,7 @@ elif defined(ios):

result = secRandomCopyBytes(nil, csize_t(size), addr dest[0])

elif defined(macosx):
elif defined(macosx) and not defined(nimNoGetEntropy):
const sysrandomHeader = """#include <Availability.h>
#include <sys/random.h>
"""
Expand Down