Coder Social home page Coder Social logo

vgorloff / swift-everywhere-toolchain Goto Github PK

View Code? Open in Web Editor NEW
85.0 7.0 25.0 1.54 MB

Automated workflow to compile Swift Toolchain, for making Android apps with Swift.

License: MIT License

Ruby 42.36% Shell 8.22% Swift 2.99% JavaScript 45.86% C 0.34% C++ 0.23%
swift android android-ndk icu swift-corelibs-foundation swift-corelibs-dispatch

swift-everywhere-toolchain's Introduction

swift-everywhere-toolchain

My Town

This Open source project won't be updated until Kremlin will stop war in Ukraine and repair damages made in towns: Irpin, Bucha, Gostomel. If this won't happen during next 6 months (until 1 September 2022), then this project will be removed from public space.

Town of Irpin after Airstrike

See also:

Requirements

  • macOS 12
  • Xcode 13
  • Android Studio 2020.3.1
  • Android NDK (See version number in file NDK_VERSION in the root of this repository)
  • Node 14.17.3 (node -v). Newer versions may also work, but not tested.
  • CMake 3.21.2 (cmake --version)
  • Ninja 1.10.2 (ninja --version)
  • autoconf 2.71 (autoconf --version)
  • aclocal 1.16.4 (aclocal --version)
  • glibtool 2.4.6 (glibtool --version)
  • pkg-config 0.29.2 (pkg-config --version)

Important

Keep tools like CMake and ninja up to date.

Using pre-built toolchain

Build of complete toolchain takes ~1.5h. Instead of building it you can just download and use already pre-built package from Releases page.

Setup and Build

  1. Install CMake, Ninja, Autotools and git-lfs. Check that all requirements are installed.

    brew install cmake ninja autoconf automake libtool pkg-config git-lfs
    which cmake
    which ninja
    which autoconf
    which aclocal
    which glibtool
    which pkg-config
    which git-lfs
  2. Make sure that Xcode Build Tools properly configured.

    xcode-select --print-path
  3. Clone this repository.

    git clone https://github.com/vgorloff/swift-everywhere-toolchain.git
    cd swift-everywhere-toolchain
  4. Create a symbolic link to NDK installation directory.

    sudo mkdir -p /usr/local/ndk
    sudo ln -vsi ~/Library/Android/sdk/ndk/$VERSION /usr/local/ndk/$VERSION

    The placeholder $VERSION needs to be replaced with a version mentioned in file NDK_VERSION at the root of cloned repository.

  5. Start a build.

    node main.js
  6. Once the build completed, toolchain will be saved to folder ToolChain/swift-android-toolchain and compressed into archive ToolChain/swift-android-toolchain.tar.gz.

Usage

Please refer file Assets/Readme.md to see how to compile Swift files or build Swift packages using Toolchain.

Sample Projects

Sample projects can be found in a separate swift-everywhere-samples repository. Please look into Readme.md in that repository to get information about how to configure and build sample projects.

swift-everywhere-toolchain's People

Contributors

jt9897253 avatar maxdesiatov avatar michalsrutek avatar molanda avatar vgorloff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-everywhere-toolchain's Issues

CMath build errors

/usr/local/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace; did you mean 'sigwait'?
using ::signbit;
~~^
/usr/local/ndk/21.4.7075529/sysroot/usr/include/signal.h:129:5: note: 'sigwait' declared here
int sigwait(const sigset_t* __set, int* __signal);

I forget, how do we solve these when building with the toolchain.

swift package build fail

kmi@Murodjons-MacBook-Pro ncp-core % /Users/kmi/Desktop/android/build-ev/swift-everywhere-toolchain/ToolChain/swift-android-toolchain/usr/bin/swift-build-arm-linux-androideabi
'NCPSocket' /Users/kmi/ncp-core: warning: in tools version 5.4.0 and later, use 'executableTarget()' to declare executable targets
/Users/kmi/ncp-core/.build/checkouts/swift-log/Sources/Logging/Logging.swift:806:45: error: cannot find type 'FILE' in scope
    internal let file: UnsafeMutablePointer<FILE>
                                            ^~~~
/Users/kmi/ncp-core/.build/checkouts/swift-log/Sources/Logging/Logging.swift:841:84: error: cannot infer contextual base in reference to member 'always'
    internal static let stderr = StdioOutputStream(file: systemStderr, flushMode: .always)
                                                                                  ~^~~~~~
/Users/kmi/ncp-core/.build/checkouts/swift-log/Sources/Logging/Logging.swift:842:84: error: cannot infer contextual base in reference to member 'always'
    internal static let stdout = StdioOutputStream(file: systemStdout, flushMode: .always)
                                                                                  ~^~~~~~
[42/868] Compiling ssl_aead_ctx.cc
// swift-tools-version:5.4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "NCPSocket",
    platforms: [
        .macOS(.v10_15), .iOS(.v13)
       ],
    products: [
        .library(name: "NCPSocket", type: .dynamic, targets: ["App"]),
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
        .package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0"),
        .package(url: "https://github.com/apple/swift-nio-ssl", from: "2.14.0"),
        .package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.0.0"),
        .package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.0.0"),
        .package(url: "https://github.com/swift-server/async-http-client.git", from: "1.2.2"),
        .package(url: "https://github.com/swift-server/swift-backtrace.git", from: "1.2.1"),
        .package(url: "https://github.com/vapor/multipart-kit.git", from: "4.0.0"),
        .package(url: "https://github.com/vapor/console-kit.git", from: "4.0.0"),
        .package(url: "https://github.com/apple/swift-crypto.git", from: "1.0.0"),
        .package(url: "https://github.com/vapor/websocket-kit.git", from: "2.0.0"),
    ],
    targets: [
        .target(name: "CBase32"),
        .target(name: "CBcrypt"),
        .target(name: "COperatingSystem"),
        .target(name: "CURLParser"),
        .target( name: "App", dependencies: [
            .product(name: "NIO", package: "swift-nio"),
            .product(name: "AsyncHTTPClient", package: "async-http-client"),
            .product(name: "AsyncKit", package: "async-kit"),
            .product(name: "Backtrace", package: "swift-backtrace"),
            .product(name: "NIOSSL", package: "swift-nio-ssl"),
            .product(name: "NIOHTTP1", package: "swift-nio"),
            .product(name: "NIOWebSocket", package: "swift-nio"),
            .product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
            .target(name: "CBase32"),
            .target(name: "CBcrypt"),
            .target(name: "COperatingSystem"),
            .target(name: "CURLParser"),
            .product(name: "NIOFoundationCompat", package: "swift-nio"),
            .product(name: "NIOExtras", package: "swift-nio-extras"),
            .product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
            .product(name: "MultipartKit", package: "multipart-kit"),
            .product(name: "ConsoleKit", package: "console-kit"),
            .product(name: "Crypto", package: "swift-crypto"),
            .product(name: "WebSocketKit", package: "websocket-kit"),
            ]
        ),
        .target(name: "NCPSocketBenchmark", dependencies: ["App"]),
        .testTarget(name: "socket-libTests", dependencies: ["App"]),
    ]
)

rpath ?

dyld: Library not loaded: @rpath/libCommands.dylib
Referenced from: /Users/johnburkey/brightenTools/swift-android-toolchain/usr/bin/swift-build
Reason: image not found

Build on Apple Silicon fails

Using NDK 21.3.6528147
Branch 1.0.66 or develop

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"swift" Build [host] is started.
mkdir -p "/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift"
cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7
[20/802] Generating ../../../lib/swift/macosx/libswiftCompatibility50.a
FAILED: lib/swift/macosx/libswiftCompatibility50.a 
cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/stdlib/toolchain/Compatibility50 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo -create -output /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/./lib/swift/macosx/libswiftCompatibility50.a /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64e/libswiftCompatibility50.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (arm64) and can't be in the same fat output file
[22/802] Linking CXX static library lib/swift/macosx/arm64e/libswiftCompatibility51.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: lib/swift/macosx/arm64e/libswiftCompatibility51.a will be fat and ar(1) will not be able to operate on it
[26/802] Generating SyntaxNodes.cpp from SyntaxNodes.cpp.gyb with ptr size = 8
ninja: build stopped: subcommand failed.
Execution of command is failed:
cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7

If error was due Memory, CPU, or Disk peak resource usage (i.e. missed file while file exists),
then try to run previous command again. Build process will perform "configure" step again,
but most of compilation steps will be skipped.

/swift-everywhere-toolchain/lib/Tool.js:82
      throw error;
      ^

Error: Command failed: cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7
    at checkExecSyncError (node:child_process:682:11)
    at Object.execSync (node:child_process:719:15)
    at SwiftBuilder.execute (/swift-everywhere-toolchain/lib/Tool.js:72:10)
    at SwiftBuilder.executeBuild (/swift-everywhere-toolchain/lib/Builders/SwiftBuilder.js:159:10)
    at SwiftBuilder.build (/swift-everywhere-toolchain/lib/Builder.js:86:10)
    at SwiftBuilder.make (/swift-everywhere-toolchain/lib/Builder.js:97:10)
    at SwiftBuilder.runAction (/swift-everywhere-toolchain/lib/Builder.js:62:12)
    at Automation.runComponentAction (/swift-everywhere-toolchain/Automation.js:117:26)
    at Automation.stage3 (/swift-everywhere-toolchain/Automation.js:161:10)
    at Automation.build (/swift-everywhere-toolchain/Automation.js:142:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 63481,
  stdout: null,
  stderr: null
}

Looks like lipo is trying to add the same architecture twice in this command:

lipo: /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (arm64) and can't be in the same fat output file

The file libswiftCompatibility50.a already contains intel and arm64 slices:

% file /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a

/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a: Mach-O universal binary with 2 architectures: [x86_64:current ar archive random library] [arm64:current ar archive random library]
/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a (for architecture x86_64):	current ar archive random library
/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a (for architecture arm64):	current ar archive random library

Runtime crash when using Android SDK Version 30

Hello! I'm running into this crash when setting our project to use compileSdkVersion and targetSdkVersion 30. This can also be reproduced by using the sample project (at https://github.com/vgorloff/swift-everywhere-samples/tree/55797008c69382f74e0fa492d2917a93c06852e4) and changing build.gradle to sdk 30.

Crash that occurs:

2020-12-07 12:47:10.266 4318-4318/? A/SwiftRuntime: Fatal error: No foreign strings on Linux in this version of Swift: file Swift/UnicodeHelpers.swift, line 266
2020-12-07 12:47:10.269 4318-4318/? A/libc: Fatal signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x73262eec38 in tid 4318 (.home.hello_ndk), pid 4318 (.home.hello_ndk)
2020-12-07 12:47:10.312 4390-4390/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2020-12-07 12:47:10.312 4390-4390/? A/DEBUG: Build fingerprint: 'google/flame/flame:11/RP1A.201005.004/6782484:user/release-keys'
2020-12-07 12:47:10.312 4390-4390/? A/DEBUG: Revision: 'MP1.0'
2020-12-07 12:47:10.312 4390-4390/? A/DEBUG: ABI: 'arm64'
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG: Timestamp: 2020-12-07 12:47:10-0800
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG: pid: 4318, tid: 4318, name: .home.hello_ndk  >>> com.home.hello_ndk <<<
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG: uid: 10264
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG: signal 5 (SIGTRAP), code 1 (TRAP_BRKPT), fault addr 0x73262eec38
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG: Abort message: 'Fatal error: No foreign strings on Linux in this version of Swift: file Swift/UnicodeHelpers.swift, line 266
    '
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x0  80000073265dacc0  x1  0000007326558f60  x2  0000007fd7608fe8  x3  0000000000000042
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x4  0000000000000010  x5  b400007407253cf1  x6  6965726f66206f4e  x7  6e69727473206e67
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x8  0000007326558f60  x9  addce693f77b2657  x10 0000000000000009  x11 0000000000000090
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x12 0000000000000000  x13 c886000000042107  x14 0000000000000107  x15 0000000000000000
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x16 0000007326681a58  x17 0000007629e9ead4  x18 000000762d13e000  x19 00000073265df5a0
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x20 0000000000000001  x21 0000000000000000  x22 000000000000010a  x23 00000073265dad20
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x24 80000073265dacc0  x25 d000000000000034  x26 000000000000000b  x27 0000000000000002
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     x28 0000007fd7609710  x29 0000007fd7609160
2020-12-07 12:47:10.313 4390-4390/? A/DEBUG:     lr  00000073262eec38  sp  0000007fd7609120  pc  00000073262eec38  pst 00000000a0000000
2020-12-07 12:47:10.400 4390-4390/? A/DEBUG: backtrace:
2020-12-07 12:47:10.400 4390-4390/? A/DEBUG:       #00 pc 000000000016ec38  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) ($ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF+464) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.400 4390-4390/? A/DEBUG:       #01 pc 00000000002b7218  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) ($sSS8UTF8ViewV13_foreignIndex5afterSS0D0VAF_tF+100) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #02 pc 0000000000173884  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #03 pc 00000000002a49e4  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #04 pc 00000000002582f0  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #05 pc 000000000025818c  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) ($sSS5write2toyxz_ts16TextOutputStreamRzlF+36) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #06 pc 0000000000421184  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libFoundation.so (offset 0x6bc000) ($s10Foundation14OperationQueueCACycfc+644)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #07 pc 0000000000420ef0  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libFoundation.so (offset 0x6bc000) ($s10Foundation14OperationQueueCACycfC+32)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #08 pc 0000000000006018  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk (offset 0xe81000)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #09 pc 0000000000092220  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libc++_shared.so (offset 0x223000) (std::__ndk1::__call_once(unsigned long volatile&, void*, void (*)(void*))+156) (BuildId: 0075e78523040db11292a281c23d268c33bbc8e5)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #10 pc 00000000003f8154  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!libswiftCore.so (offset 0xe8d000) (swift_once+68) (BuildId: b675f3bdf87ce6bbd5f501895dea482bce59b5fb)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #11 pc 000000000000604c  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk (offset 0xe81000)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #12 pc 00000000000059c4  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk (offset 0xe81000) ($s12HelloJNICore14probeOperationyyF+88)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #13 pc 0000000000005564  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk (offset 0xe81000) ($s12HelloJNICore03sayA0SiyF+68)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #14 pc 0000000000005514  /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk (offset 0xe81000) (Java_com_home_helloNDK_SwiftLib_sayHello+8)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #15 pc 000000000013ced4  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+148) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #16 pc 0000000000133564  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #17 pc 00000000001a8a78  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #18 pc 000000000031830c  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+376) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #19 pc 000000000030e638  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+996) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #20 pc 00000000001489d0  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+28080) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #21 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #22 pc 0000000000019408  [anon:dalvik-classes2.dex extracted in memory from /data/app/~~easO8X0C3Cv7ineZXMOkqw==/com.home.hello_ndk-SB3Mbo_6XLjJ5KAZGQ-RUA==/base.apk!classes2.dex] (com.home.helloNDK.MainActivity$1.onClick)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #23 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #24 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #25 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #26 pc 000000000014846c  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+26700) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #27 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #28 pc 00000000002508c8  /system/framework/framework.jar (offset 0x125d000) (android.view.View.performClick)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #29 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #30 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #31 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #32 pc 00000000001489d0  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+28080) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #33 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #34 pc 0000000000250918  /system/framework/framework.jar (offset 0x125d000) (android.view.View.performClickInternal)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #35 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #36 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #37 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #38 pc 00000000001489d0  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+28080) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #39 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #40 pc 000000000024c05c  /system/framework/framework.jar (offset 0x125d000) (android.view.View.access$3600)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #41 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #42 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #43 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #44 pc 000000000014a0c8  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+33960) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #45 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #46 pc 000000000022ac4c  /system/framework/framework.jar (offset 0x125d000) (android.view.View$PerformClick.run)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #47 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #48 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #49 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #50 pc 000000000014846c  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+26700) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #51 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #52 pc 000000000036f420  /system/framework/framework.jar (offset 0x92b000) (android.os.Handler.handleCallback)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #53 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #54 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #55 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #56 pc 000000000014a0c8  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+33960) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #57 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #58 pc 000000000036f288  /system/framework/framework.jar (offset 0x92b000) (android.os.Handler.dispatchMessage)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #59 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #60 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #61 pc 000000000030e61c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #62 pc 00000000001489d0  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false, false>(art::interpreter::SwitchImplContext*)+28080) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #63 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #64 pc 00000000003968c8  /system/framework/framework.jar (offset 0x92b000) (android.os.Looper.loop)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #65 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #66 pc 000000000030dc24  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #67 pc 000000000030f00c  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, true>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1772) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #68 pc 0000000000177f40  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<true, false>(art::interpreter::SwitchImplContext*)+57848) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #69 pc 000000000013f7d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #70 pc 00000000001a1698  /system/framework/framework.jar (android.app.ActivityThread.main)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #71 pc 0000000000305d3c  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.16249794272548105830)+532) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #72 pc 0000000000669e20  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+780) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #73 pc 000000000013cff8  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.401 4390-4390/? A/DEBUG:       #74 pc 000000000013d20c  /apex/com.android.art/lib64/libart.so (BuildId: 0252adff22f4c0297f97cb35735c7649)
2020-12-07 12:47:10.556 864-864/? E/tombstoned: Tombstone written to: /data/tombstones/tombstone_01

Note that the crash does not occur in an emulator only when running on device (Pixel 4).

which xcode12 version are you using?

Hello @vgorloff

I compile the swift-5.3-Release today, but got the error:

$  node main.js swift:make

output:

# ... other log

/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:318:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
      ~~^
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:319:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
      ~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)

# ... other log

so i think my xcode 12 version is different from your's.

Could you give me your xcode 12 version's detail info?

Here is my xcode12 snapshot:

image

Does the build work right now?

I get this:

/Users/johnburkey/Library/Android/sdk/ndk/21.4.7075529/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld.gold: error: symbol __aeabi_atexit has undefined version LIBC_PRIVATE
/Users/johnburkey/Library/Android/sdk/ndk/21.4.7075529/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld.gold: error: symbol __aeabi_atexit has undefined version LIBC_N
external/jemalloc_new/src/android_je_iterate.c:91: error: undefined reference to 'pthread_atfork'
external/jemalloc_new/src/jemalloc.c:1367: error: undefined reference to 'pthread_atfork'
bionic/libc/bionic/libc_init_common.cpp:105: error: undefined reference to 'pthread_atfork'

SIGSEGV when calling print()

Hi @vgorloff,

I upgraded to the Swift 5.4.1 toolchain and I've encountered an issue. As soon as I call print() in Swift, the Android app crashes with the following error:

A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 15101 (.home.hello_ndk), pid 15101 (.home.hello_ndk)

Some observations:

  • It happens in both my own project and your swift-everywhere-samples. Try it by calling print("Hello") in the initialize() function.
  • It doesn't matter what I print.
  • It happens regardless of whether I build the toolchain myself or use your prebuilt one.

I'm aware it's not necessarily an issue with your toolchain but I was wondering if you've encountered the same thing. I suppose a workaround is to remove all print statements but since my Swift framework is also used on other platforms, I'd rather not do that.

__aarch64_ldadd1_relax

dlopen failed: cannot locate symbol "__aarch64_ldadd1_relax" referenced by

Getting this error on launch on droid with new libs. Have you seen this?
Also have you built your tree with apple silicon yet?

Possible for sayHello() to return String ?

Hi !
I tried the toolchain and it works well. I'm even surprised how easy it is to set up. So thanks a ton ! :)
I am now learning how to work with JNI and I've had a problem from the beginning.
When i take the sample project and I modify the sayHello() method to return a String instead of an Int, it crashes instantly without any error message. I changed the type on the Kotlin side as well. It seemed to be a simple change so I must have misunderstood something. I
Is this possible to pass a String from Swift to JNI ?

Thanks

`null pointer dereference` crash on armeabi-v7a

after updating to the latest version of the toolchain I noticed that app apks built for arm32 now crash on arm64 devices. This seems to happen since the swift 5.4 update in 4a27bac. I am guessing this is not the expected behaviour. I can't reproduce these crashes when using this release of the toolchain 2b0e328 so I seems not to be related to the ndk update.

Do you have any ideas where this is coming from? I mean, ideally the apks are used on the architecture where they are compiled for, but unfortunately this does not always reflect the reality. In our bugtracking tools we see that sometimes people use 32bit apks even when the arch of their device would be capable of running 64bit. We still don't understand why this happens. Maybe people manually install apks on their devices, maybe this happens when migrating the data from old phones to new ones or maybe there is even a bug in the play store.

edit: maybe arm32 libs are generally broken and it has nothing to do with executing them on arm64. I'll try to test the behaviour on an arm32 device.

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1
Cause: null pointer dereference
    r0  00000000  r1  00000001  r2  00000203  r3  00000000
    r4  b086802c  r5  b08350d4  r6  b083518c  r7  ffa0c090
    r8  b08351d8  r9  00000004  r10 b086802c  r11 00000000
    ip  00000000  sp  ffa0c088  lr  b07a4b91  pc  b07915d4
backtrace:
    #00 pc 004115d4  /data/app/com.flowkey.app-l5bhdCK6OXt5wZje6DjubQ==/lib/arm/libswiftCore.so
    #01 pc 00424b8d  /data/app/com.flowkey.app-l5bhdCK6OXt5wZje6DjubQ==/lib/arm/libswiftCore.so
    #02 pc 0005e6ab  /data/app/com.flowkey.app-l5bhdCK6OXt5wZje6DjubQ==/lib/arm/libc++_shared.so (std::__ndk1::__call_once(unsigned long volatile&, void*, void (*)(void*))+74)
    #03 pc 00437fd5  /data/app/com.flowkey.app-l5bhdCK6OXt5wZje6DjubQ==/lib/arm/libswiftCore.so (swift_once+44)
    #04 pc 0041c82d  /data/app/com.flowkey.app-l5bhdCK6OXt5wZje6DjubQ==/lib/arm/libswiftCore.so (swift_getCanonicalPrespecializedGenericMetadata+20)
    #05 pc 00401430  /data/app/com.flowkey.app-l5bhdCK6OXt5wZje6DjubQ==/lib/arm/libswiftCore.so

Swift package using C sources fail to link

Hey @vgorloff thanks for all the great work here!

I am running into a linker error when importing a swift package that wraps a C library.
Package being imported: https://github.com/gshahbazian/SwiftGumbo

Exports.swift:

...
import SwiftGumbo

@_cdecl("Java_com_home_helloNDK_SwiftLib_sayHello")
public func sayHello() {
   let g = SwiftGumbo(html: #"<html><body><h1>HEY <span>WHATS</span> UP</h1><p>Nothing</p></body></html>"#)
   let text = g.root.textContent

   AndroidLogger.info("SA - SwiftCore: Works! \(text)")
   probeDispatch()
   probeOperation()
   probeSerialization()
   tester.test()
}
...

Package.swift:

// swift-tools-version:5.0

import PackageDescription

let package = Package(
   name: "HelloJNI",
   products: [
      .library(name: "HelloJNICore", type: .dynamic, targets: ["HelloJNICore"]),
      .library(name: "NDKLog", targets: ["NDKLog"])
   ],
   dependencies: [
      .package(url: "https://github.com/gshahbazian/SwiftGumbo", .exact("1.0.0")),
   ],
   targets: [
      .target(name: "HelloJNICore", dependencies: ["NDKLog", "SwiftGumbo"]),
      .target(name: "NDKLog", dependencies: ["sysNDKLog"]),
      .systemLibrary(name: "sysNDKLog"),
   ]
)

Compile error:

...
[18/19] Compiling HelloJNICore Exports.swift
<unknown>:0: error: error opening input file '/Users/gabepop/Downloads/swift-everywhere-samples-master/Android/app/build/swift-x86_64/x86_64-apple-macosx/release/CGumboParser.build/ascii.c.o' (Don't know how to extract from object fileformat)
<unknown>:0: error: swift-autolink-extract command failed with exit code 1 (use -v to see invocation)
[18/19] Linking libHelloJNICore.dylib

build toolchain for linux host machines

Do you know of any major blockers that are keeping us from building an android toolchain which can be used on linux host machines? Did you ever try? If you think this is something the project can benefit from i would like to take a look at. @vgorloff

SPM support?

Hey, it looks like you have SPM support pretty close- im able to build our SPM projects with a --destination param and this JSON. But you can't build SwiftNIO because it has a module map to define c functions to call directly from swift. Any idea if anyone knows how to fix that?

{
"version": 1,
"sdk": "/Users/johnburkey/Library/Developer/Platforms/Android.platform/Developer/SDKs/Android.sdk",
"toolchain-bin-dir": "/Users/johnburkey/Downloads/swift-android-toolchain/usr/bin",
"target": "aarch64-unknown-linux-android",
"dynamic-library-extension": "so",
"extra-cc-flags": [
"-fPIC",
],
"extra-swiftc-flags": [
"-use-ld=gold"
],
"extra-cpp-flags": ["-lstdc++"]
}

Include Clang into Toolchain

  • Build all components using clang built during building toolchain.
  • Make clang compiler part of Toolchain distribution.

Question about build process

I'm new to build swift on android and only started to checking how it works
I have a few questions about the way you build your toolchain.

  1. I saw that swift repo has 2 instructions - windows and linux. And looks like they didn't add most obv how build swift for android from macOS. Did you try replicate same instructions as they provide and may be add it to repo?
  2. I see that you use node for automation. While scripts in swift repo are python. Any reason why js? Asking because I was interested in check how it works and gives me problem to find all needed information in scripts, becasue I simple can't find some ๐Ÿ™ˆ
  3. How often you do releases? I see that 5.5.1 is out, but latest is 5.5.0
    Thank you for your help

building llvm fails on intel mac

I followed the readme and tried to execute node main.js bootstrap, but the build fails early with the following error. @vgorloff any ideas how I can workaround that?

macos 11.3 with intel arch
node 12
xcode 12.5
cmake 3.19.4
ninja 1.10.2
ndk 21.3.6528147 properly linked to /usr/local/ndk

-- clang project is enabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- debuginfo-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- libcxx project is disabled
-- libcxxabi project is disabled
-- libunwind project is disabled
-- lld project is disabled
-- lldb project is disabled
-- llgo project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- parallel-libs project is disabled
-- polly project is disabled
-- pstl project is disabled
-- Could NOT find Z3: Found unsuitable version "0.0.0", but required is at least "4.7.1" (found Z3_LIBRARIES-NOTFOUND)
-- Found libtool - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
CMake Error at cmake/modules/CheckAtomic.cmake:53 (message):
Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
cmake/config-ix.cmake:334 (include)
CMakeLists.txt:629 (include)

I guess thats the error:

CMake Error at cmake/modules/CheckAtomic.cmake:53 (message):
Host compiler appears to require libatomic, but cannot find it.

Does toolchain support `Core-Foundation`?

@vgorloff

It can not found symbol the kCFRunLoopRunFinished in the CoreFoundation.CFRunLoop when building the RxSwift throught the lastest release toolchain with spm.

https://github.com/Guang1234567/RxSwift/blob/8557039b880bafd53307e2198d0051a303f03ae8/RxBlocking/RunLoopLock.swift#L70

Does toolchain not support to import CoreFoundation and then use it? Thanks.

error log:

/Users/xxxx/dev_kit/sdk/swift_source/readdle/RxSwift/Sources/RxBlocking/RunLoopLock.swift:69:24: error: initializer 'init(_:)' requires that 'CFRunLoopRunResult' conform to 'BinaryInteger'
                switch Int(CFRunLoopRunInMode(runLoopModeRaw, timeout, false)) {
                       ^
Swift.SignedInteger:2:23: note: where 'T' = 'CFRunLoopRunResult'
    @inlinable public init<T>(_ source: T) where T : BinaryInteger
                      ^
/Users/xxxxx/dev_kit/sdk/swift_source/readdle/RxSwift/Sources/RxBlocking/RunLoopLock.swift:70:22: error: cannot find 'kCFRunLoopRunFinished' in scope
                case kCFRunLoopRunFinished:
                     ^~~~~~~~~~~~~~~~~~~~~
/Users/xxxx/dev_kit/sdk/swift_source/readdle/RxSwift/Sources/RxBlocking/RunLoopLock.swift:72:22: error: cannot find 'kCFRunLoopRunHandledSource' in scope
                case kCFRunLoopRunHandledSource:
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/xxx/dev_kit/sdk/swift_source/readdle/RxSwift/Sources/RxBlocking/RunLoopLock.swift:74:22: error: cannot find 'kCFRunLoopRunStopped' in scope
                case kCFRunLoopRunStopped:
                     ^~~~~~~~~~~~~~~~~~~~
/Users/xxxx/dev_kit/sdk/swift_source/readdle/RxSwift/Sources/RxBlocking/RunLoopLock.swift:76:22: error: cannot find 'kCFRunLoopRunTimedOut' in scope
                case kCFRunLoopRunTimedOut:

[Q] How to change the build-dir of cross-compile?

Hello vgorloff:

I create a HelloSwift_Lib swift project to attempt this project recently.

Everything is good, but has anyway to chang the build-dir like below:

# compile swift project
~/dev_kit/src_code/HelloSwift_Lib  $  ~/dev_kit/sdk/swift_source/swift-android-toolchain/usr/bin/android-swift-build --android-target x86_64-unknown-linux-android

~/dev_kit/src_code/HelloSwift_Lib   $   tree -a -L 5                                                                                                  
.
โ”œโ”€โ”€ .build
โ”‚ย ย  โ””โ”€โ”€ x86_64-apple-macosx

to

~/dev_kit/src_code/HelloSwift_Lib   $   tree -a -L 5                                                                                                  
.
โ”œโ”€โ”€ .build
โ”‚ย ย  โ””โ”€โ”€  x86_64-unknown-linux-android
โ”‚ย ย  โ””โ”€โ”€  aarch64-unknown-linux-android
โ”‚ย ย  โ””โ”€โ”€  armv7-none-linux-androideabi

Could you give me some suggestion? Thanks a lot.

Toolchain for Apple Silicon

Seems that toolchain should be built for Apple Silicon architecture separately cause toolchain from releases won't build anything on M1.

I have built it on M1 from sources and it works well. I can't attach it here seems cause the archive is too large.

@vgorloff do you have plans to build it for M1 as well?

host MacOS failed build for android NDK arm-linux-androideabi-gcc on $PATH at (eval 10) line 124.

my build script

export ANDROID_NDK_HOME=../NDK/android-ndk-r21e
OPENSSL_CONFIG=android-arm
OPEN_SSL_INSTALL_PATH=../armeabi-v7a
ANDROID_API=16
UNAME=uname

ANDROID_TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$UNAME-x86_64/bin
export PATH=$PATH:$ANDROID_TOOLCHAIN

echo $PATH

./Configure ${OPENSSL_CONFIG} -D__ANDROID_API__=$ANDROID_API no-ui-console no-zlib no-psk no-asm no-shared no-tests --prefix=${OPEN_SSL_INSTALL_PATH}

make

result:
Configuring OpenSSL version 1.1.1j (0x101010afL) for android-arm
Using os-specific seed configuration

Failure! build file wasn't produced.
Please read INSTALL and associated NOTES files. You may also have to look over
your available compiler tool chain or change your configuration.

no NDK arm-linux-androideabi-gcc on $PATH at (eval 10) line 124.
make: *** No targets specified and no makefile found. Stop.

perl configdata.pm --dump Can't open perl script "configdata.pm": No such file or directory

in Linux the same script works fine

no NDK arm-linux-androideabi-gcc on $PATH at (eval 10) line 124.

@vgorloff
Thanks for your job.

When running "node main.js bootstrap", I met error here:

cd /Users/kylewong/Codes/Swift/swift-everywhere-toolchain/ToolChain/Sources/ssl && \
   ANDROID_NDK=/usr/local/ndk/21.3.6528147 PATH=/usr/local/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH \
   ./Configure \
   -D__ANDROID_API__=21 \
   --prefix=/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/ToolChain/Install/darwin-armv7a/ssl \
   android-arm
Configuring OpenSSL version 1.1.1d (0x1010104fL) for android-arm
Using os-specific seed configuration

Failure!  build file wasn't produced.
Please read INSTALL and associated NOTES files.  You may also have to look over
your available compiler tool chain or change your configuration.

no NDK arm-linux-androideabi-gcc on $PATH at (eval 10) line 124.
Execution of command is failed:
cd /Users/kylewong/Codes/Swift/swift-everywhere-toolchain/ToolChain/Sources/ssl && \
   ANDROID_NDK=/usr/local/ndk/21.3.6528147 PATH=/usr/local/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH \
   ./Configure \
   -D__ANDROID_API__=21 \
   --prefix=/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/ToolChain/Install/darwin-armv7a/ssl \
   android-arm

If error was due Memory, CPU, or Disk peak resource usage (i.e. missed file while file exists),
then try to run previous command again. Build process will perform "configure" step again,
but most of compilation steps will be skipped.

/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Tool.js:82
      throw error;
      ^

Error: Command failed: cd /Users/kylewong/Codes/Swift/swift-everywhere-toolchain/ToolChain/Sources/ssl && \
   ANDROID_NDK=/usr/local/ndk/21.3.6528147 PATH=/usr/local/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH \
   ./Configure \
   -D__ANDROID_API__=21 \
   --prefix=/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/ToolChain/Install/darwin-armv7a/ssl \
   android-arm
    at checkExecSyncError (child_process.js:630:11)
    at Object.execSync (child_process.js:666:15)
    at SSLBuilder.execute (/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Tool.js:72:10)
    at SSLBuilder.executeCommands (/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Tool.js:89:10)
    at SSLBuilder.executeConfigure (/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Builders/SSLBuilder.js:62:10)
    at SSLBuilder.configure (/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Builder.js:79:10)
    at SSLBuilder.make (/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Builder.js:96:10)
    at SSLBuilder.runAction (/Users/kylewong/Codes/Swift/swift-everywhere-toolchain/lib/Builder.js:62:12)
    at /Users/kylewong/Codes/Swift/swift-everywhere-toolchain/Automation.js:123:57
    at Array.forEach (<anonymous>) {
  status: 2,
  signal: null,
  output: [ null, null, null ],
  pid: 22798,
  stdout: null,
  stderr: null
}

arm-linux-androideabi-gcc indeed doesn't exist in the ndk.

kylewong@KyleWongs-MacBook-Pro swift-everywhere-toolchain % ls ~/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin | grep gcc

How to resolve this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.