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

[SR-4977] Building stdlib swiftStdlibStubs-android-armv7 FAILED #47554

Closed
swift-ci opened this issue May 23, 2017 · 15 comments
Closed

[SR-4977] Building stdlib swiftStdlibStubs-android-armv7 FAILED #47554

swift-ci opened this issue May 23, 2017 · 15 comments
Assignees
Labels
Android Platform: Android bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. build-script Area → utils: The build script

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4977
Radar None
Original Reporter amraboelela (JIRA User)
Type Bug
Status Closed
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, Android, BuildScript
Assignee @milseman
Priority Medium

md5: 0eb5fa53f558bd95b70998f9b1aae9d6

Issue Description:

[753/984] Building CXX object stdlib/public/stubs/CMakeFiles/swiftStdlibStubs-android-armv7.dir/UnicodeNormalization.cpp.o
FAILED: /home/amr/swift/build/Ninja-ReleaseAssert/llvm-linux-x86_64/./bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Istdlib/public/stubs -I/home/amr/swift/swift/stdlib/public/stubs -Iinclude -I/home/amr/swift/swift/include -I/home/amr/swift/llvm/include -I/home/amr/swift/build/Ninja-ReleaseAssert/llvm-linux-x86_64/include -I/home/amr/swift/build/Ninja-ReleaseAssert/llvm-linux-x86_64/tools/clang/include -I/home/amr/swift/llvm/tools/clang/include -I/home/amr/swift/cmark/src -I/home/amr/swift/build/Ninja-ReleaseAssert/cmark-linux-x86_64/src -isystem /home/amr/swift/libiconv-libicu-android/armeabi-v7a/icu/source/common -isystem /home/amr/swift/libiconv-libicu-android/armeabi-v7a/icu/source/i18n -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -Werror=date-time -std=c+11 -fcolor-diagnostics -ffunction-sections -fdata-sections -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -fno-sanitize=all -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 -O3 -UNDEBUG -fno-exceptions -fno-rtti -Wglobal-constructors -Wexit-time-destructors -fvisibility=hidden -DswiftCore_EXPORTS -DSWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS=1 -target armv7-none-linux-androideabi --sysroot=/home/amr/android-ndk-r14b/platforms/android-21/arch-arm --sysroot=/home/amr/android-ndk-r14b/platforms/android-21/arch-arm -B /home/amr/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ -O2 -g0 -UNDEBUG -I/home/amr/android-ndk-r14b/sources/cxx-stl/llvm-libc /include -I/home/amr/android-ndk-r14b/sources/cxx-stl/llvm-libc+abi/include -I/home/amr/android-ndk-r14b/sources/android/support/include -DSWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS=1 -MMD -MT stdlib/public/stubs/CMakeFiles/swiftStdlibStubs-android-armv7.dir/LibcShims.cpp.o -MF stdlib/public/stubs/CMakeFiles/swiftStdlibStubs-android-armv7.dir/LibcShims.cpp.o.d -o stdlib/public/stubs/CMakeFiles/swiftStdlibStubs-android-armv7.dir/LibcShims.cpp.o -c /home/amr/swift/swift/stdlib/public/stubs/LibcShims.cpp
/home/amr/swift/swift/stdlib/public/stubs/LibcShims.cpp:103:1: error: static_assert failed "This platform's pthread_key_t differs. If you hit this assert, fix __swift_pthread_key_t's typedef in LibcShims.h by adding an #if guard and definition for your platform"
static_assert(std::is_same<__swift_pthread_key_t, pthread_key_t>::value,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/amr/swift/swift/stdlib/public/stubs/LibcShims.cpp:113:10: error: no matching function for call to 'pthread_key_create'
return pthread_key_create(key, destructor);
^~~~~~~~~~~~~~~~~~
/home/amr/android-ndk-r14b/platforms/android-21/arch-arm/usr/include/pthread.h:195:5: note: candidate function not viable: no known conversion from '__swift_pthread_key_t * _Nonnull' (aka 'unsigned int *') to 'pthread_key_t *' (aka 'int *') for 1st argument
int pthread_key_create(pthread_key_t*, void ()(void)) __nonnull((1));

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

What I ran was:
./utils/build-script \
-R \
--android \
--android-ndk "${ANDROID_NDK_DIR}" \
--android-api-level 21 \
--android-icu-uc "${ANDROID_ICU_DIR}/armeabi-v7a" \
--android-icu-uc-include "${ANDROID_ICU_DIR}/armeabi-v7a/icu/source/common" \
--android-icu-i18n "${ANDROID_ICU_DIR}/armeabi-v7a" \
--android-icu-i18n-include "${ANDROID_ICU_DIR}/armeabi-v7a/icu/source/i18n"

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

// Guard compilation on the typedef for __swift_pthread_key_t in LibcShims.h
// being identical to the platform's pthread_key_t
static_assert(std::is_same<__swift_pthread_key_t, pthread_key_t>::value,
"This platform's pthread_key_t differs. If you hit this assert, "
"fix __swift_pthread_key_t's typedef in LibcShims.h by adding an "
"#if guard and definition for your platform");

SWIFT_RUNTIME_STDLIB_INTERFACE
int swift::_swift_stdlib_pthread_key_create(
__swift_pthread_key_t * _Nonnull key,
void (* _Nullable destructor)(void *)
) {
return pthread_key_create(key, destructor);
}

SWIFT_RUNTIME_STDLIB_INTERFACE
void * _Nullable swift::_swift_stdlib_pthread_getspecific(
__swift_pthread_key_t key
) {
return pthread_getspecific(key);
}

SWIFT_RUNTIME_STDLIB_INTERFACE
int swift::_swift_stdlib_pthread_setspecific(
__swift_pthread_key_t key, const void * _Nullable value
) {
return pthread_setspecific(key, value);
}

[stdlib] Shims for UBreakIterator and thread local storage.

Introduce shims for using UBreakIterators from ICU. Also introduce
shims for using thread local storage via pthreads.

We will be relying on ICU and UBreakIterators for grapheme
breaking. But, UBreakIterators are very expensive to create,
especially for the way we do grapheme breaking, which is relatively
stateless. Thus, we will stash one or more into thread local storage
and reset it as needed.

Note: Currently, pthread_key_t is hard coded for a single platform
(Darwin), but I have a static_assert alongside directions on how to
adapt it to any future platforms who differ in key type.

5eb5e34

Michael Ilseman May 16, 2017

@milseman
Copy link
Mannequin

milseman mannequin commented May 24, 2017

I don't have access to an NDK. Could you tell me what pthread_key_t is there?

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

Hi Michael,

Not sure, but I found this:

https://stackoverflow.com/questions/22164564/cannot-build-local-shared-library-in-android-ndk

@milseman
Copy link
Mannequin

milseman mannequin commented May 24, 2017

Can you try changing:

#if defined(__linux__)
typedef unsigned int __swift_pthread_key_t;
#else
typedef unsigned long __swift_pthread_key_t;
#endif

to be

#if defined(__linux__)
typedef unsigned int __swift_pthread_key_t;
#elif defined(__android__)
typedef int __swift_pthread_key_t;
#else
typedef unsigned long __swift_pthread_key_t;
#endif

Does that fix it for you? If so then I can prepare a patch (or help you do so if you're interested).

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

You are right, I checked ~/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-x86/usr/include/pthread.h
And I found:
typedef int pthread_key_t;

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

I'll try your suggestion and let you know.

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

Got the same error 🙁

/home/user/swift/swift/stdlib/public/stubs/LibcShims.cpp:103:1: error: static_assert failed "This platform's pthread_key_t differs. If you hit this assert, fix __swift_pthread_key_t's typedef in LibcShims.h by adding an #if guard and definition for your platform"
static_assert(std::is_same<__swift_pthread_key_t, pthread_key_t>::value,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/swift/swift/stdlib/public/stubs/LibcShims.cpp:113:10: error: no matching function for call to 'pthread_key_create'
return pthread_key_create(key, destructor);
^~~~~~~~~~~~~~~~~~
/home/user/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm/usr/include/pthread.h:195:5: note: candidate function not viable: no known conversion from '__swift_pthread_key_t * _Nonnull' (aka 'unsigned int *') to 'pthread_key_t *' (aka 'int *') for 1st argument
int pthread_key_create(pthread_key_t*, void ⭐(void*)) __nonnull((1));
^
/home/user/swift/swift/stdlib/public/stubs/LibcShims.cpp:158:27: warning: declaration requires a global constructor [-Wglobal-constructors]
static Lazy<std::mt19937> theGlobalMT19937;
^~~~~~~~~~~~~~~~
1 warning and 2 errors generated.
ninja: build stopped: subcommand failed.
./utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

I tried this and it worked:

#if defined(ANDROID)
typedef int __swift_pthread_key_t;
#elif defined(linux)
typedef unsigned int __swift_pthread_key_t;
#else
typedef unsigned long __swift_pthread_key_t;
#endif

@milseman
Copy link
Mannequin

milseman mannequin commented May 25, 2017

Aha, Android probably defines linux so that was hitting sooner. Could you try the following? It uses lowercase single-underscore to be consistent with other uses in the file:

#if defined(__android__)
typedef int __swift_pthread_key_t;
#elif defined(__linux__)
typedef unsigned int __swift_pthread_key_t;
#else
typedef unsigned long __swift_pthread_key_t;
#endif

If that works, would you be interested in contributing the fix (I can help walk you through it), or should I?

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

The reason I put ANDROID because I found that all the other files in swift project is using ANDROID capital letters, and only LibcShims.h is using android small letters. As seen in the attached file

![](Screen Shot 2017-05-24 at 11.41.48 PM.png)

@milseman
Copy link
Mannequin

milseman mannequin commented May 25, 2017

All caps it is!

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

do u want to change the other one to all caps too?
i can create a pull request for those changes

@milseman
Copy link
Mannequin

milseman mannequin commented May 25, 2017

Yes please! You can add me as the reviewer for that PR.

@swift-ci
Copy link
Collaborator Author

Comment by Amr Aboelela (JIRA)

Here u r 🙂

#9930

How to add u as a reviewer?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Platform: Android bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. build-script Area → utils: The build script
Projects
None yet
Development

No branches or pull requests

1 participant