-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
tvOS
/watchOS
compilation errors
#118
Comments
In principle, it should be possible to include The error you're receiving results from compiling the code in source file chacha20poly1305.c: static size_t entropy(void* buf, size_t n)
{
#if defined(__APPLE__) && defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12
if (getentropy(buf, n) == 0)
return n;
#elif defined(__linux__) && defined(SYS_getrandom)
if (syscall(SYS_getrandom, buf, n, 0) == n)
return n;
#elif defined(SYS_getentropy)
if (syscall(SYS_getentropy, buf, n) == 0)
return n;
#endif
return read_urandom(buf, n);
} Interestingly, the symbol As far as I know the function |
Could you please test to change the code for function
#if defined(__APPLE__)
#include "TargetConditionals.h"
#endif
static size_t entropy(void* buf, size_t n)
{
#if defined(__APPLE__) && ((defined(__MAC_10_12) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12) || TARGET_OS_TV || TARGET_OS_WATCH)
if (getentropy(buf, n) == 0)
return n;
#elif defined(__linux__) && defined(SYS_getrandom)
if (syscall(SYS_getrandom, buf, n, 0) == n)
return n;
#elif defined(SYS_getentropy)
if (syscall(SYS_getentropy, buf, n) == 0)
return n;
#endif
return read_urandom(buf, n);
} If that works for you please let me know. |
Had a few compilation errors
After adding the following compiler flags to suppress errors, everything built successfully for
The following Kotlin Multiplatform targets were compiled successfully:
My tests that exercised Have to figure out configuration yet to enable
Adding compiler flag |
As an alternative you may add an explicit function declaration: #if TARGET_OS_TV || TARGET_OS_WATCH
extern int getentropy(void* buffer, size_t buflen);
#endif
if (getentropy(buf, n) == 0) I will add these modifications in my SQLite3MultipleCiphers repository.
Right, the other architectures should not be affected.
Which target triple is actually defined in your build script? Maybe just specifying the target triple mentioned in the error message in your build script helps, that is:
|
That worked in that the error suppression is no-longer necessary. 👍
🥳
Yeah it's a little problematic as I'm using an older version of kotlin's llvm toolchain. It needs updating (see touchlab/cklib#11) in order to resolve this specific issue so I can add the |
In commit dd508dc I added the precompiler checks for tvOS and watchOS. I also added the explicit function declaration for #include <sys/random.h> Could you please check whether this include is available for tvOS and watchOS? That is, check for tvOS and watchOS like this: #if defined(__APPLE__) && ((defined(__MAC_10_12) && !defined(__IPHONE_OS_VERSION_MIN_REQUIRED)) || TARGET_OS_TV || TARGET_OS_WATCH)
#include <sys/random.h>
#endif You have to move the include of the target conditionals in front of the above code: #if defined(__APPLE__)
#include "TargetConditionals.h"
#endif
#if defined(__APPLE__) && ((defined(__MAC_10_12) && !defined(__IPHONE_OS_VERSION_MIN_REQUIRED)) || TARGET_OS_TV || TARGET_OS_WATCH)
#include <sys/random.h>
#endif |
TL;DR >> Was not available for
I disabled those targets (all |
According to Apple's documentation the function
Well, I found this post that indicates that the function is not considered to be part of the public Apple API (contrary to the claim in Apple's documentation). However, it would not be the first flaw in Apple's documentation. Maybe the function SecRandomCopyBytes could be used instead for
I'm unsure about which approach should be used to support |
Imo, just use |
Ok. I'd be fine with that approach. However, I don't know whether this really works for all Apple OS variants or whether checking for certain targets and/or versions is still required. Maybe you could try the following code and report the results: #if defined(__APPLE__)
#include "TargetConditionals.h"
#endif
#if defined(__APPLE__)
#include <Security/SecRandom.h>
#endif
static size_t entropy(void* buf, size_t n)
{
#if defined(__APPLE__)
if (SecRandomCopyBytes(kSecRandomDefault, n, (uint8_t*) buf) == 0)
return n;
#elif defined(__linux__) && defined(SYS_getrandom)
if (syscall(SYS_getrandom, buf, n, 0) == n)
return n;
#elif defined(SYS_getentropy)
if (syscall(SYS_getentropy, buf, n) == 0)
return n;
#endif
return read_urandom(buf, n);
} |
Oh it's available 😄 You could (if you so desired to support Rust for
Worked like a charm. Didn't even need the |
Just realized that I am able to enable the No clue what that was about, but it seems to have been something with the inclusion of Just so we are on the same page, this is what my #if defined(__APPLE__)
#include <Security/SecRandom.h>
#endif
static size_t entropy(void* buf, size_t n)
{
#if defined(__APPLE__)
if (SecRandomCopyBytes(kSecRandomDefault, n, (uint8_t*) buf) == 0)
return n;
#elif defined(__linux__) && defined(SYS_getrandom)
if (syscall(SYS_getrandom, buf, n, 0) == n)
return n;
#elif defined(SYS_getentropy)
if (syscall(SYS_getentropy, buf, n) == 0)
return n;
#endif
return read_urandom(buf, n);
} |
Another aside about the linux implementation, unless this is being compiled against https://man7.org/linux/man-pages/man2/getrandom.2.html#HISTORY Might be worth it to have an actual implementation to check for it where by |
Great. I adjusted the code accordingly in commit 21307d5.
For the time being I think the new implementation is good enough. If there are developers in need of support for older versions they can ask for it on the issue tracker.
For now, I removed the include. |
Good news.
I have no idea either. However, it would be really strange, if including
Yes, that's how the code in the SQLite3MultipleCiphers git repository now looks like, too. |
Unfortunately, the CI run fails for macOS, see GitHub CI macOS. Probably it is necessary to specify a link library, but which one? |
Need to add link flag |
Thanks. I adjusted the autoconf build files and now it works. |
Note that, that'll work for sure for For e.g. # xcrun is the CLI tool for Xcode
SDK_IOS="$(xcrun --sdk iphoneos --show-sdk-path)"
SDK_IOS_SIM="$(xcrun --sdk iphonesimulator --show-sdk-path)"
SDK_TVOS="$(xcrun --sdk appletvos --show-sdk-path)"
SDK_TVOS_SIM="$(xcrun --sdk appletvsimulator --show-sdk-path)"
SDK_WATCHOS="$(xcrun --sdk watchos --show-sdk-path)"
SDK_WATCHOS_SIM="$(xcrun --sdk watchsimulator --show-sdk-path)"
# e.g. if compiling for iOS on a macOS machine
LDFLAGS+="-isysroot $SDK_IOS" Not sure if you wanted to take it that far, but I think that's what's necessary in order for link flag |
For the current GitHub CI workflow this is good enough.
I have to admit that I'm not very familiar with all those Apple OS variants. I would certainly like to add CI runs to the GitHub workflow for these target systems. However, I have no experience in setting up macOS, iOS etc specific workflows. I would need some assistance by someone experienced.
Of course, it would be nice to be able to support Apple's OS variants right out of the box, but as said above I have only limited experience with Apple systems. |
Actually, I did not really check which source path gets compiled under Linux. The implementation of the function
I'm of course open to improve the code if necessary. |
Yeah I've had quite a few hiccups compiling it with Kotlin (not your code, just apple targets in general). Learned a lot which may be useful here if I can find the time to contribute in that area.
Ah ok. Yeah I'm definitely going to have a look at and how that is getting used. Will let ya know.
👍 |
That would be great, because from time to time developers are asking for Apple support.
TIA! |
- Fixed issue #118 - tvOS/watchOS compilation errors. On Apple platforms the function SecRandomCopyBytes() will now be used instead of getentropy(). - Fixed issue #119 - "PRAGMA mmap_size" conflicts with encrypted databases, a check has been added to allow this pragma for unencrypted databases. - Added "PRAGMA memory_security" to allow to clear memory before it is freed. This feature can have a considerable impact on performance and is therefore disabled by default.
Now, that version 1.7.0 is released, I think this issue can be closed as completed. Feel free to reopen it, if necessary. |
Trying to compile for
watchOS
andtvOS
but keep running into the following errors related to usage ofsyscall
Everything's working great though for
iOS
👍Seeing in the amalgamations that there is conditional arguments for
macOS
andiOS
only. Would it be possible to also includetvOS
andwatchOS
?The text was updated successfully, but these errors were encountered: