vgorloff / swift-everywhere-toolchain

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Guang1234567 opened this issue · comments

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.

The folder layout, shown below, with the target build subfolder x86_64-apple-macosx is produced by "Swift Package Manager" (https://github.com/apple/swift-package-manager).

At the moment "Swift Package Manager" officially not supporting Android targets. Thats why subfolder name is x86_64-apple-macosx.

Maybe later we will also provide embedded "Swift Package Manager" which will produce directory structure with appropriate Android target names.

├── .build
│   └── x86_64-apple-macosx

@vgorloff

Thanks your reply.

I find the other solution without provide embedded spm accidentally.

https://github.com/readdle/swift-android-buildtools/blob/4c13ae4768606992ab6e83f2415d8f3d39e1b362/src/bash/swift-build.sh#L54

$SWIFT_ANDROID_HOME/toolchain/usr/bin/swift-build --destination=<($SELF_DIR/generate-destination-json.sh) $flags "$@"

Just pass —destination to spm, and the generate-destination-json.sh should be like below:

#!/bin/bash
: "${SWIFT_ANDROID_HOME:?$SWIFT_ANDROID_HOME should be set}"
: "${ANDROID_NDK_HOME:?$ANDROID_NDK_HOME should be set}"

EXTERNAL_TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/$TOOLCHAIN_ROOT-4.9/prebuilt/darwin-x86_64"

cat <<JSON
{
    "version": 1,
    "dynamic-library-extension": "so",
    "target": "$TARGET",
    
    #  …….
}
JSON

"target": "$TARGET" is the point. And the $TARGET is a env var.

export TARGET = x86_64-unknown-linux-android
export TARGET = aarch64-unknown-linux-android
export TARGET = armv7-none-linux-androideabi

In addition, swift-everywhere-toolchain can be wrapped by readdle/swift-android-gradle and readdle/swift-android-toolchain.

But readdle/swift-android-toolchain is 5.0-r9, so i use swift-everywhere-toolchain to instead it today and success.