Skip to content

Commit

Permalink
Improve command line script with hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
florentmorin committed Aug 10, 2022
1 parent 830d828 commit 3055319
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 6 deletions.
116 changes: 111 additions & 5 deletions CommandLineApp/compile.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,117 @@
#!/bin/sh

SDK_PATH=$(xcrun --show-sdk-path)
SDK_VERSION=$(xcrun --show-sdk-version)
BUILD_PATH="./build"
LIB_BUILD_PATH="${BUILD_PATH}/lib"
ARCH="arm64"
TARGET="${ARCH}-apple-macosx12.0"
TARGET_SDK_VERSION="${SDK_VERSION}.0"
DEVELOPER_DIR=$(xcode-select -p)
SWIFT_FRONTEND_PATH="${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend"
LIBTOOL_PATH="${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool"
LD_PATH="${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
DSYMUTIL_PATH="${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil"

if [[ -d "build" ]]; then
rm -rf build
rm -rf "${BUILD_PATH}"
fi

mkdir build
mkdir build/lib
mkdir "${BUILD_PATH}"
mkdir "${LIB_BUILD_PATH}"

# libHello

$SWIFT_FRONTEND_PATH \
-frontend \
-c \
-primary-file Hello.swift \
-emit-module-path "${LIB_BUILD_PATH}/Hello-1.swiftmodule" \
-emit-module-doc-path "${LIB_BUILD_PATH}/Hello-1.swiftdoc" \
-emit-module-source-info-path "${LIB_BUILD_PATH}/Hello-1.swiftsourceinfo" \
-target "${TARGET}" \
-Xllvm -aarch64-use-tbi \
-enable-objc-interop \
-stack-check \
-sdk "${SDK_PATH}" \
-color-diagnostics \
-g -static -Onone \
-new-driver-path "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" \
-resource-dir "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift" \
-enable-anonymous-context-mangled-names \
-module-name Hello \
-target-sdk-version "${TARGET_SDK_VERSION}" \
-parse-as-library -o "${LIB_BUILD_PATH}/Hello-1.o"

$SWIFT_FRONTEND_PATH \
-frontend -merge-modules \
-emit-module "${LIB_BUILD_PATH}/Hello-1.swiftmodule" \
-parse-as-library -disable-diagnostic-passes -disable-sil-perf-optzns \
-target "${TARGET}" \
-Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check \
-sdk "${SDK_PATH}" \
-color-diagnostics -g -static -Onone \
-new-driver-path "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" \
-resource-dir "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift" \
-enable-anonymous-context-mangled-names \
-module-name Hello \
-target-sdk-version "${TARGET_SDK_VERSION}" \
-emit-module-doc-path "${LIB_BUILD_PATH}/Hello.swiftdoc" \
-emit-module-source-info-path "${LIB_BUILD_PATH}/Hello.swiftsourceinfo" \
-o "${LIB_BUILD_PATH}/Hello.swiftmodule" \
-emit-abi-descriptor-path "${LIB_BUILD_PATH}/Hello.abi.json"

$LIBTOOL_PATH \
-static "${LIB_BUILD_PATH}/Hello-1.o" \
-o "${LIB_BUILD_PATH}/libHello.a"


# app

$SWIFT_FRONTEND_PATH \
-frontend -c \
-primary-file main.swift \
-emit-module-path "${BUILD_PATH}/main-1.swiftmodule" \
-emit-module-doc-path "${BUILD_PATH}/main-1.swiftdoc" \
-emit-module-source-info-path "${BUILD_PATH}/main-1.swiftsourceinfo" \
-target "${TARGET}" \
-Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check \
-sdk "${SDK_PATH}" -I "${LIB_BUILD_PATH}" \
-color-diagnostics -g -Onone \
-new-driver-path "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" \
-resource-dir "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift" \
-enable-anonymous-context-mangled-names \
-module-name app \
-target-sdk-version "${TARGET_SDK_VERSION}" \
-o "${BUILD_PATH}/main-1.o"

$SWIFT_FRONTEND_PATH \
-frontend -merge-modules \
-emit-module "${BUILD_PATH}/main-1.swiftmodule" -parse-as-library \
-disable-diagnostic-passes -disable-sil-perf-optzns \
-target "${TARGET}" \
-Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check \
-sdk "${SDK_PATH}" -I "${LIB_BUILD_PATH}" \
-color-diagnostics -g -Onone \
-new-driver-path "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver" \
-resource-dir "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift" \
-enable-anonymous-context-mangled-names \
-module-name app \
-target-sdk-version "${TARGET_SDK_VERSION}" \
-emit-module-doc-path "${BUILD_PATH}/app-1.swiftdoc" \
-emit-module-source-info-path "${BUILD_PATH}/app-1.swiftsourceinfo" \
-o "${BUILD_PATH}/app-1.swiftmodule" \
-emit-abi-descriptor-path "${BUILD_PATH}/app-1.abi.json"
$LD_PATH \
"${BUILD_PATH}/main-1.o" \
-add_ast_path "${LIB_BUILD_PATH}/Hello.swiftmodule" \
-add_ast_path "${BUILD_PATH}/app-1.swiftmodule" \
"${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/lib/darwin/libclang_rt.osx.a" \
-syslibroot "${SDK_PATH}" \
-lobjc -lSystem -arch "${ARCH}" \
-L "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx" \
-L "${SDK_PATH}/usr/lib/swift" \
-platform_version macos 12.0.0 12.1.0 -no_objc_category_merging -L "${LIB_BUILD_PATH}" -lHello \
-o "${BUILD_PATH}/app"

swiftc Hello.swift -g -Onone -emit-module -emit-library -static -o build/lib/libHello.a
swiftc main.swift -g -Onone -L ./build/lib/ -I ./build/lib/ -lHello -o build/app
$DSYMUTIL_PATH "${BUILD_PATH}/app" -o "${BUILD_PATH}/app.dSYM"
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The project can be tested by opening `AppWithInternalFramework/AppWithInternalFr

If you run the app on a simulator, a shared breakpoint will be triggered.

### In command line
### In command line (hotfixed)

In a Terminal:

Expand Down Expand Up @@ -57,6 +57,10 @@ Wait for breakpoint to be called...
(lldb) po name
```

#### The hotfix

I had to append `-add_ast_path "${LIB_BUILD_PATH}/Hello.swiftmodule"` with Xcode 13.4.1. (not required with Xcode 13.2.1 or Xcode 14+)


## Tests results

Expand Down

0 comments on commit 3055319

Please sign in to comment.