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

Nim fails to compile on MacOSX 10.10 because of sys/random.h header included in std/sysrand #17370

Closed
ghost opened this issue Mar 14, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 14, 2021

Got this bug report from my friend

Current Output

CC: stdlib_sysrand.nim
Error: execution of an external compiler program 'clang -c  -w -ferror-limit=3 -O3  -I/Users/vlad/projects/Nim/lib -I/Users/vlad/projects/Nim/compiler -o /Users/vlad/projects/Nim/nimcache/r_macosx_amd64/stdlib_sysrand.nim.c.o /Users/vlad/projects/Nim/nimcache/r_macosx_amd64/stdlib_sysrand.nim.c' failed with exit code: 1

In file included from /Users/vlad/projects/Nim/nimcache/r_macosx_amd64/stdlib_sysrand.nim.c:8:
/usr/include/sys/random.h:37:32: error: unknown type name 'u_int'
void read_random(void* buffer, u_int numBytes);
                               ^
/usr/include/sys/random.h:38:33: error: unknown type name 'u_int'
void read_frandom(void* buffer, u_int numBytes);
                                ^
/usr/include/sys/random.h:39:33: error: unknown type name 'u_int'
int  write_random(void* buffer, u_int numBytes);
                                ^
3 errors generated.
FAILURE

Expected Output

Successful compilation

Additional information

CPython seems to have hit the same problem before - https://bugs.python.org/issue29057.

If you check https://opensource.apple.com/source/xnu/xnu-4903.270.47/bsd/sys/random.h.auto.html you'll see that sys/random.h is available from macOS 10.12 and up.

One way to fix this would be to use the same iOS impl. for macOS (secRandomCopyBytes is available in macOS 10.10+).

Another way is to check if we have macOS 10.12 and up (via https://opensource.apple.com/source/xnu/xnu-4903.270.47/EXTERNAL_HEADERS/Availability.h.auto.html) and use generic urandom on older macOS versions.

As a temporary workaround it's possible to replace line 240 in lib/sytd/sysrand.nim with elif false and on line 61 batchImplOs = false, then the compilation succeeds (because then the generic urandom impl. is used).

Git hash - 7937aba

@ghost
Copy link
Author

ghost commented Mar 14, 2021

Rust implementation does it that way - it checks if getentropy exists (with dlsym - ), and if it doesn't - the call uses /dev/urandom instead.

rust-lang/rust#70179

https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/rand.rs#L130
https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/weak.rs#L29

@ringabout ringabout self-assigned this Mar 14, 2021
ringabout added a commit to ringabout/Nim that referenced this issue Mar 14, 2021
@ringabout
Copy link
Member

hope this issue is fixed

@ringabout
Copy link
Member

It should be fixed, feel free to reopen if not.

ringabout added a commit that referenced this issue Apr 30, 2021
macOS 10.12 was born at June 13, 2016, and the end of support date is October 2019.

This version introduces more useful features.

For example, `getentropy`, `clock_gettime` which is benefit.

However we don't have a reliable way to use different system apis for different system versions. More terribly, it makes it hard to register these apis in the VM because it causes building latest Nim to fail.

see #17370

So maybe we should increase the support version requirement for MacOS
@iffy
Copy link
Contributor

iffy commented Oct 26, 2021

I just ran into this issue trying to install 1.6.0 on macOS 10.10.5. Yes, it's an old computer, but one I'd like to still use. If 10.10 should still be supported, I can look into submitting a patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants