Skip to content

Commit 762bfbd

Browse files
committed
Allow xcframework generation to skip xcarchive recompilation.
1 parent af40bec commit 762bfbd

9 files changed

+171
-99
lines changed
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
name: Archive Framework
22
inputs:
3-
scheme:
4-
description: Scheme
5-
required: true
6-
destination:
7-
description: Destination
8-
required: true
9-
platform:
10-
description: Platform Name
11-
required: true
12-
project:
13-
description: Project directory, relative to the xcode folder
14-
required: true
3+
destination:
4+
description: Destination platform/architecture details. Typically looks like "generic/platform=iOS" or "platform=macOS,variant=Mac Catalyst,arch=x86_64"
5+
required: true
6+
human_readable_platform:
7+
description: Human-readable platform name, used for directory naming
8+
required: true
9+
description: Framework archivation description.
1510
runs:
16-
using: composite
17-
steps:
18-
- shell: bash
19-
working-directory: .
20-
run: |
21-
cd xcode
11+
using: composite
12+
steps:
13+
- shell: bash
14+
working-directory: .
15+
run: |
16+
cd xcode
2217
23-
xcodebuild archive \
24-
-scheme '${{ inputs.scheme }}' \
25-
-project '${{ inputs.project }}' \
26-
-destination '${{ inputs.destination }}' \
27-
-archivePath "$BUILD_DIR/LDKFramework-${{ inputs.platform }}" \
28-
ENABLE_BITCODE=NO \
29-
CLANG_ADDRESS_SANITIZER=NO CLANG_ADDRESS_SANITIZER_ALLOW_ERROR_RECOVERY=NO CLANG_ADDRESS_SANITIZER_USE_AFTER_SCOPE=NO \
30-
SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
18+
LDK_C_BINDINGS_BINARY_DIRECTORY="" \
19+
xcodebuild archive \
20+
-scheme 'LDKFramework' \
21+
-project 'LDKFramework/LDKFramework.xcodeproj' \
22+
-destination '${{ inputs.destination }}' \
23+
-archivePath "/Users/runner/work/ldk-swift/ldk-swift/bindings/bin/release/${{ inputs.human_readable_platform }}/${{ inputs.human_readable_platform }}" \
24+
ENABLE_BITCODE=NO \
25+
CLANG_ADDRESS_SANITIZER=NO CLANG_ADDRESS_SANITIZER_ALLOW_ERROR_RECOVERY=NO CLANG_ADDRESS_SANITIZER_USE_AFTER_SCOPE=NO \
26+
SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
27+
LDK_C_BINDINGS_BASE="${LDK_C_BINDINGS_BASE}" \
28+
LDK_C_BINDINGS_BINARY_DIRECTORY="" \
29+
LDK_C_BINDINGS_BINARY_FORCED_REBUILD_OUTPUT_DIRECTORY="${LDK_C_BINDINGS_BINARY_DIRECTORY}"
Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate XCFramework from parallel XCArchive builds
1+
name: XCFramework from XCArchives
22
permissions:
33
contents: read
44
statuses: read
@@ -14,29 +14,21 @@ on:
1414
- "*"
1515

1616
jobs:
17-
build:
18-
name: Build XCArchive for ${{ matrix.configuration['platform'] }}
17+
build-xcarchives:
18+
name: Build xcarchive for ${{ matrix.configuration['human_readable_platform'] }}
1919
runs-on: macos-12
2020
strategy:
2121
fail-fast: false
2222
matrix:
2323
configuration:
24-
- scheme: LDKFramework
25-
destination: generic/platform=iOS
26-
platform: iOS
27-
project: LDKFramework/LDKFramework.xcodeproj
28-
- scheme: LDKFramework
29-
destination: platform=iOS Simulator,OS=15.2,name=iPhone 13 Pro
30-
platform: iOS Simulator
31-
project: LDKFramework/LDKFramework.xcodeproj
32-
- scheme: LDKFramework
33-
destination: generic/platform=OS X
34-
platform: OS X
35-
project: LDKFramework/LDKFramework.xcodeproj
36-
- scheme: LDKFramework
37-
destination: platform=macOS,variant=Mac Catalyst,arch=x86_64
38-
platform: Mac Catalyst
39-
project: LDKFramework/LDKFramework.xcodeproj
24+
- destination: generic/platform=iOS
25+
human_readable_platform: 'iphoneos'
26+
- destination: platform=iOS Simulator,OS=15.2,name=iPhone 13 Pro
27+
human_readable_platform: 'iphonesimulator'
28+
- destination: generic/platform=OS X
29+
human_readable_platform: 'macosx'
30+
- destination: platform=macOS,variant=Mac Catalyst,arch=x86_64
31+
human_readable_platform: 'catalyst'
4032
env:
4133
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
4234
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
@@ -52,34 +44,37 @@ jobs:
5244
uses: ./.github/actions/install-dependencies
5345
- name: Build
5446
id: build
55-
uses: ./.github/actions/build-for-testing
47+
uses: ./.github/actions/archive-framework
5648
with:
57-
project: ${{ matrix.configuration['project'] }}
58-
scheme: ${{ matrix.configuration['scheme'] }}
5949
destination: ${{ matrix.configuration['destination'] }}
50+
human_readable_platform: ${{ matrix.configuration['human_readable_platform'] }}
51+
- name: Xcarchive hack
52+
run: touch ./bindings_root.txt
53+
- name: Upload xcarchive
54+
uses: actions/upload-artifact@v3
55+
with:
56+
name: bindings
57+
path: ./bindings/**/bin/release/${{ matrix.configuration['human_readable_platform'] }}/${{ matrix.configuration['human_readable_platform'] }}.xcarchive
6058

61-
# generate:
62-
# name: Generate XCFramework
63-
# runs-on: macos-12
64-
# env:
65-
# DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
66-
# LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
67-
# steps:
68-
# - name: Configure Xcode
69-
# uses: maxim-lobanov/setup-xcode@v1
70-
# with:
71-
# xcode-version: latest
72-
# - name: Checkout
73-
# uses: actions/checkout@v2
74-
# - name: Install Dependencies
75-
# uses: ./.github/actions/install-dependencies
76-
# - name: Generate XCFramework
77-
# uses: ./.github/actions/generate-xcframework
78-
# - name: Zip Xcframework (remove before merging!)
79-
# run: |
80-
# ditto -c -k --sequesterRsrc /Users/runner/work/ldk-swift/ldk-swift/bindings/bin/release/LDKFramework.xcframework LDKFramework.xcframework.zip
81-
# - name: Upload Framework Artifact (remove before merging!)
82-
# uses: actions/upload-artifact@v3
83-
# with:
84-
# name: LDKFramework.xcframework.zip
85-
# path: LDKFramework.xcframework.zip
59+
generate:
60+
name: Combine xcarchives into xcframework
61+
runs-on: macos-12
62+
needs: [ build-xcarchives ]
63+
env:
64+
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
65+
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
66+
steps:
67+
- name: Configure Xcode
68+
uses: maxim-lobanov/setup-xcode@v1
69+
with:
70+
xcode-version: latest
71+
- name: Checkout
72+
uses: actions/checkout@v2
73+
- name: Download xcarchives
74+
uses: actions/download-artifact@v3
75+
- name: Generate xcframework
76+
shell: bash
77+
run:
78+
python3 ./src/scripts/generate_xcframework.py
79+
env:
80+
PRESERVE_XCARCHIVES: true

.github/workflows/build-xcframework-parallel-libldk.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate XCframework from parallel libldk.a builds
1+
name: XCframework from libldks
22
permissions:
33
contents: read
44
statuses: read
@@ -15,9 +15,10 @@ on:
1515

1616
jobs:
1717
build-libldks:
18-
name: Build lipo libldk.a for ${{ matrix.configuration['human_readable_platform'] }}
18+
name: Build & lipo libldk.a for ${{ matrix.configuration['human_readable_platform'] }}
1919
runs-on: macos-12
2020
env:
21+
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
2122
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
2223
strategy:
2324
fail-fast: true
@@ -60,11 +61,13 @@ jobs:
6061
- name: Upload binary
6162
uses: actions/upload-artifact@v3
6263
with:
63-
name: libldk-${{ matrix.configuration['human_readable_platform'] }}.a
64+
name: bindings
6465
path: |
65-
/Users/runner/work/ldk-swift/ldk-swift/bindings/bin/release/${{ matrix.configuration['human_readable_platform'] }}/libldk.a
66+
./bindings/**/artifacts/ldk-c-bindings/lightning-c-bindings/include/*.h
67+
./bindings/**/artifacts/ldk-c-bindings/ldk-net/ldk_net.*
68+
./bindings/**/bin/release/${{ matrix.configuration['human_readable_platform'] }}/libldk.a
6669
generate-parallel:
67-
name: Generate XCarchives and XCFramework based on parallelized libldk builds
70+
name: Build xcarchives and generate xcframework
6871
needs: [ build-libldks ]
6972
runs-on: macos-12
7073
env:
@@ -77,7 +80,7 @@ jobs:
7780
xcode-version: latest
7881
- name: Checkout
7982
uses: actions/checkout@v2
80-
- name: Download xcarchives
83+
- name: Download libldks
8184
uses: actions/download-artifact@v3
8285
- name: Generate Swift Bindings
8386
shell: bash

.github/workflows/build-xcframework-sequential.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate XCFramework from sequential bulk build script
1+
name: XCFramework from sequential Python script
22
permissions:
33
contents: read
44
statuses: read
@@ -15,7 +15,7 @@ on:
1515

1616
jobs:
1717
generate-sequential:
18-
name: Generate XCFramework
18+
name: Build libldks, xcarchives, and combine into xcframework
1919
runs-on: macos-12
2020
env:
2121
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer

.github/workflows/test-artifacts.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test Artifacts
2+
permissions:
3+
contents: read
4+
statuses: read
5+
pull-requests: read
6+
actions: read
7+
checks: write
8+
on:
9+
workflow_dispatch:
10+
11+
jobs:
12+
create-artifact:
13+
name: Add ${{ matrix.configuration['human_readable_platform'] }} to artifact
14+
runs-on: macos-12
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
configuration:
19+
- destination: generic/platform=iOS
20+
human_readable_platform: 'iphoneos'
21+
- destination: platform=iOS Simulator,OS=15.2,name=iPhone 13 Pro
22+
human_readable_platform: 'iphonesimulator'
23+
- destination: generic/platform=OS X
24+
human_readable_platform: 'macosx'
25+
- destination: platform=macOS,variant=Mac Catalyst,arch=x86_64
26+
human_readable_platform: 'catalyst'
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
- name: Xcarchive emulation
31+
run: |
32+
mkdir -p ./bindings/bin/release/${{ matrix.configuration['human_readable_platform'] }}
33+
touch ./bindings/bin/release/${{ matrix.configuration['human_readable_platform'] }}/${{ matrix.configuration['human_readable_platform'] }}.xcarchive
34+
- name: Upload emulated xcarchive
35+
uses: actions/upload-artifact@v3
36+
with:
37+
name: uploaded-artifact-name
38+
path: ./bindings/**/bin/release/${{ matrix.configuration['human_readable_platform'] }}/${{ matrix.configuration['human_readable_platform'] }}.xcarchive
39+
40+
download-artifact:
41+
name: Download artifact
42+
runs-on: macos-12
43+
needs: [ create-artifact ]
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v2
47+
- name: Download emulated xcarchives
48+
uses: actions/download-artifact@v3
49+
with:
50+
path: ./downloaded-artifact-name
51+
- name: Preview download result
52+
run: |
53+
ls -ll -R
54+

src/scripts/build_individual_libldk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def run(config: ScriptConfig):
1313
if len(config.LIBLDK_BUILD_CONFIGURATIONS) != 1:
14-
print('Individual libldk build must have exactly 1 build configuration.')
14+
print('Individual libldk build must have exactly 1 build configuration.', file=sys.stderr)
1515
sys.exit(1)
1616

1717
ldkBuildConfig = config.LIBLDK_BUILD_CONFIGURATIONS[0]

src/scripts/generate_xcframework.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def parse_config() -> ScriptConfig:
9-
config = ScriptConfig.parse(allow_ldk_argument=True, parse_configuration=True)
9+
config = ScriptConfig.parse(allow_ldk_argument=True, parse_configuration=True, parse_xcarchive_preservation=True)
1010

1111
individual_configurations: [ArchiveConfig] = [
1212
ArchiveConfig('iOS Simulator', 'iphonesimulator'),
@@ -57,6 +57,16 @@ def run(config: ScriptConfig):
5757
current_human_readable_platform # the last component is the filename excluding .xcarchive
5858
)
5959

60+
# XCFRAMEWORK_INPUT_FLAGS="${XCFRAMEWORK_INPUT_FLAGS}-framework ${CURRENT_ARCHIVE_PATH}.xcarchive/Products/Library/Frameworks/LDKFramework.framework "
61+
framework_input_flags += [
62+
'-framework',
63+
f'{xcarchive_output_path}.xcarchive/Products/Library/Frameworks/LDKFramework.framework'
64+
]
65+
66+
if config.PRESERVE_XCARCHIVES:
67+
# we don't regenerate any new xcarchives, and simply reuse the existing ones
68+
break
69+
6070
# create clean derived data directory
6171
if os.path.exists(derived_data_directory):
6272
shutil.rmtree(derived_data_directory, ignore_errors=True)
@@ -88,12 +98,6 @@ def run(config: ScriptConfig):
8898
# clean up the derived data
8999
shutil.rmtree(derived_data_directory, ignore_errors=True)
90100

91-
# XCFRAMEWORK_INPUT_FLAGS="${XCFRAMEWORK_INPUT_FLAGS}-framework ${CURRENT_ARCHIVE_PATH}.xcarchive/Products/Library/Frameworks/LDKFramework.framework "
92-
framework_input_flags += [
93-
'-framework',
94-
f'{xcarchive_output_path}.xcarchive/Products/Library/Frameworks/LDKFramework.framework'
95-
]
96-
97101
# xcodebuild -create-xcframework ${XCFRAMEWORK_INPUT_FLAGS} -output ${XCFRAMEWORK_OUTPUT_PATH}"
98102
if os.path.exists(xcframework_output_path):
99103
shutil.rmtree(xcframework_output_path, ignore_errors=True)

src/scripts/prepare_xcode_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def run(config: ScriptConfig):
2222
copy_c_files.run(config)
2323

2424
if bindings_binary_directory and forced_rebuild_override_directory:
25-
print('LDK_C_BINDINGS_BINARY_DIRECTORY and LDK_C_BINDINGS_BINARY_FORCED_REBUILD_OUTPUT_DIRECTORY may not both be set at the same time!')
25+
print('LDK_C_BINDINGS_BINARY_DIRECTORY and LDK_C_BINDINGS_BINARY_FORCED_REBUILD_OUTPUT_DIRECTORY may not both be set at the same time!', file=sys.stderr)
2626
sys.exit(1)
2727

2828
if not bindings_binary_directory and not forced_rebuild_override_directory:
29-
print('One of LDK_C_BINDINGS_BINARY_DIRECTORY and LDK_C_BINDINGS_BINARY_FORCED_REBUILD_OUTPUT_DIRECTORY must be set!')
29+
print('One of LDK_C_BINDINGS_BINARY_DIRECTORY and LDK_C_BINDINGS_BINARY_FORCED_REBUILD_OUTPUT_DIRECTORY must be set!', file=sys.stderr)
3030
sys.exit(1)
3131

3232
if not forced_rebuild_override_directory:

0 commit comments

Comments
 (0)