Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Where is concurrency lib? #138

Open
johnburkey opened this issue Dec 29, 2021 · 57 comments
Open

Where is concurrency lib? #138

johnburkey opened this issue Dec 29, 2021 · 57 comments

Comments

@johnburkey
Copy link

Where is _concurrency lib :-)

See discussion section!

Happy Holidays!

@vgorloff
Copy link
Owner

I wasn't used "new concurrency" on Android yet. For example, in this project - https://github.com/vgorloff/swift-everywhere-samples.
I conducted few examples on macOS 12 / Xcode 13.1, but not yet used "new concurrency" in production or commercial apps.

Will try to use few "new concurrency" examples on Android.

@johnburkey
Copy link
Author

johnburkey commented Dec 29, 2021 via email

@johnburkey
Copy link
Author

johnburkey commented Dec 29, 2021 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 1, 2022

Building Concurrency example (645e75d) gives me the following error:

{0}vova@MacBook-Pro:sample-package$ swift-build-arm-linux-androideabi
<unknown>:0: warning: unable to perform implicit import of "_Concurrency" module: no such module found
<unknown>:0: warning: unable to perform implicit import of "_Concurrency" module: no such module found
<unknown>:0: warning: unable to perform implicit import of "_Concurrency" module: no such module found
/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/Tests/sample-package/Sources/SAConcurrency/SAConcurrencyMain.swift:18:7: error: cannot find 'Task' in scope
      Task {
      ^~~~

Seems the Concurrencyfeature wasn't build when building Android toolchain.

@vgorloff
Copy link
Owner

vgorloff commented Jan 1, 2022

The Concurrency feature wasn't enabled during build.

# File CMakeCache.txt
//Enable build of the Swift concurrency module
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY:BOOL=OFF

@vgorloff
Copy link
Owner

vgorloff commented Jan 1, 2022

There is a chicken-egg problem "dispatch needs stdlib" and, at the same time, "stdlib needs dispatch".

# File: stdlib/public/Concurrency/CMakeLists.txt

if(SWIFT_CONCURRENCY_USES_DISPATCH)
  if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
    include_directories(AFTER
                          ${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})

    # FIXME: we can't rely on libdispatch having been built for the
    # target at this point in the process.  Currently, we're relying
    # on soft-linking.
    list(APPEND swift_concurrency_link_libraries
      dispatch)
  endif()
endif()

@vgorloff
Copy link
Owner

vgorloff commented Jan 1, 2022

To build Concurrency feature the Dispatch subproject needs to be build during stdlib build. It is configured via cmake/modules/Libdispatch.cmake.

@vgorloff
Copy link
Owner

vgorloff commented Jan 1, 2022

Dispatch subproject fails to build due compiler flag -Werror :)

@johnburkey
Copy link
Author

johnburkey commented Jan 1, 2022 via email

@johnburkey
Copy link
Author

does it build?

@vgorloff
Copy link
Owner

vgorloff commented Jan 5, 2022

I will try to figure out in coming days how to pass arguments to external project (dispatch in our case). After quick search I didn't managed to find "who" is passing that -Werror flag. Maybe it is a CMake default.

@johnburkey
Copy link
Author

johnburkey commented Jan 5, 2022 via email

@johnburkey
Copy link
Author

@johnburkey
Copy link
Author

Sounds like they want to do a strategy discussion with you too - Nice folks .

@vgorloff
Copy link
Owner

vgorloff commented Jan 5, 2022

Building of "libdispatch" is not a problem. There is already builder for it (https://github.com/vgorloff/swift-everywhere-toolchain/blob/master/lib/Builders/DispatchBuilder.js). Issue that CMake is a functional-programming thing which consumes time to figure out needed options to pass :)

@johnburkey
Copy link
Author

johnburkey commented Jan 5, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 5, 2022

Seems "libDispatch" itself defined compiler flags here: https://github.com/apple/swift-corelibs-libdispatch/blob/swift-5.5.2-RELEASE/cmake/modules/DispatchCompilerWarnings.cmake

Strange why I don't have this issue when building libdispatch standalone. Maybe because i am passing C/CXX flags explicitly.

@vgorloff
Copy link
Owner

vgorloff commented Jan 5, 2022

The issue with -Werror is fixed by adding code below:

    if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
      add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Wno-unused-command-line-argument>)
    endif()

The next error seems due minSDKVersion 21 (https://stackoverflow.com/a/53217341/1418981):

/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Sources/swift-corelibs-libdispatch/src/event/event_epoll.c:460:33: error: use of undeclared identifier 'EPOLL_CLOEXEC'
        _dispatch_epfd = epoll_create1(EPOLL_CLOEXEC);
                                       ^
1 error generated.

Cmake uses SDK 16 by default:

-- ANDROID_PLATFORM not set. Defaulting to minimum supported version
16.

@vgorloff
Copy link
Owner

vgorloff commented Jan 5, 2022

Passing -DANDROID_PLATFORM=${ANDROID_PLATFORM} in cmake/modules/Libdispatch.cmake helped to build libswift_Concurrency.so for armv7.

Next error when building for aarch64:

-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
-- Check for working C compiler: /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - broken
CMake Error at /usr/local/Cellar/cmake/3.22.0/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang"

  is not able to compile a simple test program.

Configure is not finished successfully :0

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

When I am building libdispatch as standalone, the CMAKE_C_FLAGS defined as empty string. When building libdispatch via stdlib, then CMAKE_C_FLAGS defined as CMAKE_C_FLAGS:STRING=-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -Wno-comment -fdiagnostics-color

Thus the following configure error seems due unneeded flag -L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21

-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
-- Check for working C compiler: /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - broken
CMake Error at /usr/local/Cellar/cmake/3.22.0/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/libdispatch-android-aarch64-prefix/src/libdispatch-android-aarch64-build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/local/bin/ninja cmTC_06ead && [1/2] Building C object CMakeFiles/cmTC_06ead.dir/testCCompiler.c.o
    clang: warning: argument unused during compilation: '-L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21' [-Wunused-command-line-argument]
    [2/2] Linking C executable cmTC_06ead
    FAILED: cmTC_06ead
    : && /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=armv7-none-linux-androideabi21 --gcc-toolchain=/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -L`/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21` -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -Wno-comment -fdiagnostics-color -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,--gc-sections CMakeFiles/cmTC_06ead.dir/testCCompiler.c.o -o cmTC_06ead  -latomic -lm && :
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libm.so while searching for m
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libdl.so while searching for dl
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libdl.so while searching for dl
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libc.so while searching for c
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libdl.so while searching for dl
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21/libdl.so while searching for dl
    /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: treating warnings as errors

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

When building stdlib, I am passing manually the C flag -L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21. And then Cmake picks it and passes to the libdispatch subproject. Maybe I just need not to pass it.

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

Next error:

FAILED: lib/swift/android/aarch64/libswift_Concurrency.so
: && /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=aarch64-none-linux-android21 --gcc-toolchain=/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/21 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -Wno-comment -fdiagnostics-color -O2  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments     -shared -Wl,-soname,libswift_Concurrency.so -target aarch64-unknown-linux-android21 --sysroot=/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -B /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin -lm -fuse-ld=gold -shared  -o lib/swift/android/aarch64/libswift_Concurrency.so stdlib/public/Concurrency/ANDROID/aarch64/_Concurrency.o lib/swift/android/aarch64/swiftrt.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/__/CompatibilityOverride/CompatibilityOverride.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/Actor.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/AsyncLet.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/Error.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/LinkCompatibilityShims.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/Task.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/TaskAlloc.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/TaskStatus.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/TaskGroup.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/TaskLocal.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/ThreadSanitizer.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/Mutex.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/AsyncStream.cpp.o stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/linker-support/magic-symbols-for-install-name.c.o -L/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llvm-project/./lib   -L/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/./lib/swift/android/aarch64   -L/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/bin/../lib/swift/android/aarch64   -L/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/bin/../lib/swift/android   -L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/swift   -L/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/../lib/gcc/aarch64-linux-android/4.9.x   -L/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Install/darwin-aarch64/icu/lib   -L/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/libdispatch-android-aarch64-prefix/lib -ldispatch  -ldl  -llog  /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++abi.a  /Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so  /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Install/darwin-aarch64/icu/lib/libicui18nswift.so  /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Install/darwin-aarch64/icu/lib/libicuucswift.so  lib/swift/android/aarch64/libswiftGlibc.so  lib/swift/android/aarch64/libswiftCore.so  -latomic -lm && :
/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.gold: warning: skipping incompatible /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/./lib/swift/android/aarch64/libdispatch.so while searching for dispatch
/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.gold: warning: skipping incompatible /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/libdispatch-android-aarch64-prefix/lib/libdispatch.so while searching for dispatch
/Volumes/Shared/Data/Android/sdk/ndk/21.4.7075529/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.gold: error: cannot find -ldispatch
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to 'dispatch_queue_attr_make_with_qos_class'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to 'dispatch_queue_create'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to 'dispatch_queue_set_width'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalImpl(swift::Job*): error: undefined reference to 'dispatch_release'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to 'dispatch_time'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to 'dispatch_after_f'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to '_dispatch_queue_attr_concurrent'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to 'dispatch_queue_attr_make_with_qos_class'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to 'dispatch_queue_create'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to 'dispatch_queue_set_width'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueGlobalWithDelayImpl(unsigned long long, swift::Job*): error: undefined reference to 'dispatch_release'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueMainExecutor: error: undefined reference to '_dispatch_main_q'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueMainExecutor: error: undefined reference to '_dispatch_main_q'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueMainExecutorImpl(swift::Job*): error: undefined reference to '_dispatch_main_q'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function swift_task_enqueueMainExecutorImpl(swift::Job*): error: undefined reference to '_dispatch_main_q'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/GlobalExecutor.cpp.o:GlobalExecutor.cpp:function dispatchEnqueueDispatchAsync(dispatch_queue_s*, void*, unsigned int): error: undefined reference to 'dispatch_async_f'
stdlib/public/Concurrency/CMakeFiles/swift_Concurrency-android-aarch64.dir/Task.cpp.o:Task.cpp:function swift_task_asyncMainDrainQueueImpl(): error: undefined reference to 'dispatch_main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Obviously because libdispatch for some reason was built for armv7 instead for aarch64 :)

{0}vova@MacBook-Pro:swift-everywhere-toolchain$ file /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/lib/swift/android/aarch64/libswiftCore.so
/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/lib/swift/android/aarch64/libswiftCore.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=994cfd8863a2c520eb9e21ff8538133e63c478ca, with debug_info, not stripped
{0}vova@MacBook-Pro:swift-everywhere-toolchain$ file /Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/lib/swift/android/aarch64/libdispatch.so
/Volumes/Shared/Git/MyProjects/swift-everywhere-toolchain/ToolChain/Build/darwin-aarch64/swift-stdlib/lib/swift/android/aarch64/libdispatch.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=b8dfcdb8a04a347ce81569ad7dcec4457acf3e8f, with debug_info, not stripped
{0}vova@MacBook-Pro:swift-everywhere-toolchain$

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

For some reason the option CMAKE_SYSTEM_PROCESSOR set as armv7-a in file /.../CMakeFiles/3.22.0/CMakeSystem.cmake for libdispatch subproject. At the same time stdlib itself has value for the same option set as aarch64. Which is correct one.

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

The above issue fixed by passing Cmake flag -DANDROID_ABI=${ANDROID_ABI} to the libdispatch subproject.

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

Ok. I am able to build stdlib with libswift_Concurrency.so for all 4 Android archs: arm 32/64 bit and x86 32/64 bit.

Now it is time to make clean rebuild of Swift, stdlib, libDispatch, libFoundation and then try Async/Await example again.

@johnburkey
Copy link
Author

johnburkey commented Jan 6, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

But sample code which works on macOS crashes with Segmentation fault on Android :0

@johnburkey
Copy link
Author

johnburkey commented Jan 6, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

I will try one idea, but if it won't work, then I will come back to troubleshooting after next major release of Swift - Swift 5.5.3 or Swift 5.6.0.

The Swift Concurrency is experimental thing.
Even Cmake option, which is used to activate this feature, defined as following -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=TRUE/FALSE

@johnburkey
Copy link
Author

johnburkey commented Jan 6, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

The release which builds concurrency is ready https://github.com/vgorloff/swift-everywhere-toolchain/releases/tag/1.0.78
But on runtime new Swift concurrency seems will alway crash.

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

Here is what adb logcat shows me:

01-06 19:52:55.058  4489  4497 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x18 in tid 4497 (Exe), pid 4489 (Exe)
01-06 19:52:55.097  4501  4501 W crash_dump32: type=1400 audit(0.0:2863): avc: denied { search } for name="tmp" dev="dm-2" ino=130818 scontext=u:r:crash_dump:s0 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
01-06 19:52:55.100  4501  4501 I chatty  : uid=10110(com.whatsapp) crash_dump32 identical 14 lines
01-06 19:52:55.100  4501  4501 W crash_dump32: type=1400 audit(0.0:2878): avc: denied { search } for name="tmp" dev="dm-2" ino=130818 scontext=u:r:crash_dump:s0 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
01-06 19:52:55.107  4501  4501 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
01-06 19:52:55.108   587   587 I /system/bin/tombstoned: received crash request for pid 4489
01-06 19:52:55.110  4501  4501 I crash_dump32: performing dump of process 4489 (target tid = 4497)
01-06 19:52:55.110  4501  4501 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-06 19:52:55.110  4501  4501 W crash_dump32: type=1400 audit(0.0:2879): avc: denied { search } for name="tmp" dev="dm-2" ino=130818 scontext=u:r:crash_dump:s0 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
01-06 19:52:55.111  4501  4501 F DEBUG   : Build fingerprint: 'google/bullhead/bullhead:8.1.0/OPM7.181205.001/5080180:user/release-keys'
01-06 19:52:55.111  4501  4501 F DEBUG   : Revision: 'rev_1.0'
01-06 19:52:55.111  4501  4501 F DEBUG   : ABI: 'arm'
01-06 19:52:55.111  4501  4501 F DEBUG   : pid: 4489, tid: 4497, name: Exe  >>> /data/local/tmp/sample-Exe/Exe <<<
01-06 19:52:55.111  4501  4501 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x18
01-06 19:52:55.111  4501  4501 F DEBUG   : Cause: null pointer dereference
01-06 19:52:55.111  4501  4501 F DEBUG   :     r0 00000000  r1 6a205680  r2 00000019  r3 80000000
01-06 19:52:55.111  4501  4501 F DEBUG   :     r4 00000000  r5 00000000  r6 f4f8b1cb  r7 00000000
01-06 19:52:55.111  4501  4501 F DEBUG   :     r8 f38a2aa0  r9 02001900  sl f34400f0  fp f38bd740
01-06 19:52:55.111  4501  4501 F DEBUG   :     ip f4fa6fbc  sp f327f838  lr f4f8a51b  pc 00000018  cpsr 80070030
01-06 19:52:55.113  4501  4501 F DEBUG   : 
01-06 19:52:55.113  4501  4501 F DEBUG   : backtrace:
01-06 19:52:55.114  4501  4501 F DEBUG   :     #00 pc 00000018  <unknown>
01-06 19:52:55.115  4501  4501 F DEBUG   :     #01 pc 00043517  /data/local/tmp/sample-Exe/libswift_Concurrency.so
01-06 19:52:55.115  4501  4501 F DEBUG   :     #02 pc fffffffd  <unknown>
01-06 19:52:55.186   763  1089 W NativeCrashListener: Couldn't find ProcessRecord for pid 4489
01-06 19:52:55.143  4501  4501 I chatty  : uid=10110(com.whatsapp) identical 3 lines
01-06 19:52:55.180  4501  4501 W crash_dump32: type=1400 audit(0.0:2883): avc: denied { search } for name="tmp" dev="dm-2" ino=130818 scontext=u:r:crash_dump:s0 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
01-06 19:52:55.188   587   587 W /system/bin/tombstoned: crash socket received short read of length 0 (expected 12)
01-06 19:52:55.190   763   784 I BootReceiver: Copying /data/tombstones/tombstone_06 to DropBox (SYSTEM_TOMBSTONE)
01-06 19:52:55.216   763   777 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
01-06 19:52:55.216   763   777 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver

The issue is null pointer dereference.

@johnburkey
Copy link
Author

Got symbols ?

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

Not too much: <anonymous:f1d90000> instead of <unknown> :)

01-06 20:29:25.735  5762  5762 F DEBUG   : backtrace:
01-06 20:29:25.735  5762  5762 F DEBUG   :     #00 pc 000fb970  <anonymous:f1d90000>
01-06 20:29:25.735  5762  5762 F DEBUG   :     #01 pc 000834c7  /data/local/tmp/sample-Exe/libswift_Concurrency.so
01-06 20:29:25.735  5762  5762 F DEBUG   :     #02 pc 219021ac  <unknown>

@vgorloff
Copy link
Owner

vgorloff commented Jan 6, 2022

The Concurrency actually working with latest toolchain, but for macOS and Android it works differently.

public class SAConcurrencyMain {

   private var task: Task<Void, Error>?

   public init() {
      print("[SAC] Concurrency: Init")
   }

   public func execute(completion: @escaping () -> Void) {
      print("[SAC] Concurrency: Start")
#if !false
      task = Task.detached(priority: .high) {
         let urls = await self.getURLs()
         print("[SAC] Concurrency: Got \(urls.count) urls.")
         print("[SAC] Concurrency: End")
         completion()
      }
#else // Below works on macOS but crashes on Android. See: https://github.com/vgorloff/swift-everywhere-toolchain/issues/138
      Task {
         let task = Task.detached(priority: .userInitiated) { () -> Int in
            let urls = await self.getURLs()
            return urls.count
         }
         let value = await task.value
         print("[SAC] Concurrency: Got \(value) urls.")
         print("[SAC] Concurrency: End")
         completion()
      }
#endif
   }

   private func getURLs() async -> [String] {
      Thread.sleep(forTimeInterval: 1)
      return ["https://docs.swift.org/", "https://google.com/", "https://ibm.com/"]
   }

}

The Task inside a Task not working on Android, but works on macOS:

Task {
         let task = Task.detached(priority: .userInitiated) { () -> Int in
             ...
         }
         let value = await task.value
        ...
}

@johnburkey
Copy link
Author

johnburkey commented Jan 6, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 7, 2022

True. Some pieces of Concurrency seems working on Android as on macOS. Others seems not.
Maybe some kind of execution environment on Android is not fully initialised/configured (e.g. MainActor or similar).

@johnburkey
Copy link
Author

johnburkey commented Jan 7, 2022 via email

@finagolfin
Copy link

Hmm, looks like you're building the stdlib with the NDK clang, you have to make sure the Concurrency files are built with Apple's fork of clang.

@johnburkey
Copy link
Author

Hey! Thanks for this ! Can we jump on that slack channel on swift for android for higher bandwidth? Gorloff you game? I think Vlad is in Europe somewhere, so hoping to catch this "everyone is awake" window.. You don't really need me, i'm merely the pot stirrer. :-)

@johnburkey
Copy link
Author

Buttaface, any stability issues once you had it running? Saleem mentioned to me that he had to work over the libdispatch on windows stuff to get things stable.

@finagolfin
Copy link

finagolfin commented Jan 7, 2022

I'm not sure he's awake. 😉 I don't think there will be much to discuss, that is the only issue I've had with getting it working.

I can't really speak to stability, as I don't use the new Concurrency runtime on Android much. However, I run the full compiler validation testsuite on Android with the latest trunk tag once a month, and all the Concurrency tests pass.

@johnburkey
Copy link
Author

johnburkey commented Jan 7, 2022 via email

@finagolfin
Copy link

I think the issue is only because he doesn't use the official build-script, whereas I'm now down to a couple small patches since I use that. There's not much left to upstream for me, just submitting the last handful of patches.

If you run into any issues with Concurrency on Android, just post it in the forums or the bug tracker and we'll take a look.

@johnburkey
Copy link
Author

johnburkey commented Jan 7, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 7, 2022

Interesting. I didn't know that LLVM has a new flag, which seems emits something into binary which seems is needed to support Concurrency feature.

@johnburkey
Copy link
Author

johnburkey commented Jan 7, 2022 via email

@finagolfin
Copy link

I didn't know about that one. Vlad and I occasionally chat on another Slack: he can find me on there now if he wants.

@johnburkey
Copy link
Author

johnburkey commented Jan 7, 2022 via email

@finagolfin
Copy link

I don't think we have invites or are even supposed to publicly talk about it yet. As you said, it's mostly me and him that might need to talk, so we'll get to it whenever. If you want us to look at something in particular, just post it here.

@johnburkey
Copy link
Author

johnburkey commented Jan 7, 2022 via email

@vgorloff
Copy link
Owner

vgorloff commented Jan 7, 2022

Seems like I have to research first which NDK contains clang with Swift concurrency support. It seems easier way than building stdlib with system provided clang and then linking with NDK clang/linker.

@finagolfin
Copy link

No, you can just use the forked Swift clang to both build and link the Swift stdlib, that works fine. That is what it does by default when you build the full Swift toolchain, so you must be overriding the stdlib build to use the NDK clang. Turn off that override and it should work fine.

@vgorloff
Copy link
Owner

vgorloff commented Jan 8, 2022

Ok. Then I have to look closer which clang used where.

I past there were some build issues (in this not official toolchain) when building some components using clang built from fork (https://github.com/apple/llvm-project).

I even have an issue for this #101

@finagolfin
Copy link

OK, I didn't know you had issues with the Swift-forked clang before. The problem is this line, where you pass in the NDK clang to build the stdlib instead. I used to do that too, but switched to the Swift-forked clang a couple months ago to fix this issue with building the Concurrency library.

@johnburkey
Copy link
Author

How’s it going Vlad?

@johnburkey
Copy link
Author

Can we jump on slack for a few minutes ? I would like to help with this effort.

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

No branches or pull requests

3 participants