Skip to content

Commit 2ca0b8e

Browse files
authored
Introduce deterministic formatting (#111)
* Create swift formatter accessor and runner. * Generate version file differently if formatting is available. * Remove Valgrind to accelerate dependency installation process. * Use main branch of swift formatter * Verify that generated output matches the formatter expectations. * fail if formatting failed when it was supposed to run * Use custom ldk-c-bindings clone with debug lines * Switch to tag-based checkouts of custom debugging ldk-c-bindings fork. * Only use self-compiled swift-format version, and never use swiftformat. Given install dependency already automatically generates bindings files, just use those. * Move Swift file generation outside of dependency installation step. * Check in deterministically formatted Swift files. * Experiment with combined sleep/yield while loops in C++. * Use published 115 version of ldk-c-bindings. * Update Swift code to reflect updated dependencies.
1 parent a1fa39c commit 2ca0b8e

File tree

521 files changed

+152744
-145537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

521 files changed

+152744
-145537
lines changed

.github/actions/install-dependencies/action.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ runs:
2323
echo `pwd`
2424
mkdir -p ${{ inputs.destination }}/bin
2525
git clone --branch 2023-04-0.0.115-java-bindings https://github.com/TheBlueMatt/rust-lightning ${{ inputs.destination }}/rust-lightning
26-
git clone --branch v0.0.115.0 https://github.com/lightningdevkit/ldk-c-bindings ${{ inputs.destination }}/ldk-c-bindings
26+
git clone --branch v0.0.115.3 https://github.com/lightningdevkit/ldk-c-bindings ${{ inputs.destination }}/ldk-c-bindings
2727
- name: Install Rust, required targets
2828
if: ${{ inputs.configureRustNightly == 'true' }}
2929
shell: bash
@@ -49,12 +49,3 @@ runs:
4949
pushd ${{ inputs.destination }}/ldk-c-bindings
5050
./genbindings.sh ../rust-lightning true
5151
popd
52-
- name: Generate Swift Bindings
53-
shell: bash
54-
run: |
55-
npm install
56-
# python3 ./
57-
npm run tsc
58-
node ./src/index.mjs
59-
env:
60-
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ${{ inputs.destination }}/ldk-c-bindings/lightning-c-bindings/include/lightning.h

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
human_readable_platform: 'catalyst'
3232
env:
3333
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
34-
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
35-
LDK_C_BINDINGS_BINARY_DIRECTORY: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/bin
34+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/bindings/artifacts/ldk-c-bindings
35+
LDK_C_BINDINGS_BINARY_DIRECTORY: ${{ github.workspace }}/bindings/artifacts/bin
3636
steps:
3737
- name: Configure Xcode
3838
uses: maxim-lobanov/setup-xcode@v1
@@ -64,7 +64,7 @@ jobs:
6464
needs: [ build-xcarchives ]
6565
env:
6666
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
67-
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
67+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/bindings/artifacts/ldk-c-bindings
6868
steps:
6969
- name: Configure Xcode
7070
uses: maxim-lobanov/setup-xcode@v1

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: macos-12
2020
env:
2121
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
22-
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
22+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/bindings/artifacts/ldk-c-bindings
2323
strategy:
2424
fail-fast: true
2525
matrix:
@@ -74,7 +74,7 @@ jobs:
7474
runs-on: macos-12
7575
env:
7676
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
77-
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
77+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/bindings/artifacts/ldk-c-bindings
7878
steps:
7979
- name: Configure Xcode
8080
uses: maxim-lobanov/setup-xcode@v1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: macos-12
2020
env:
2121
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
22-
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
22+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/bindings/artifacts/ldk-c-bindings
2323
steps:
2424
- name: Configure Xcode
2525
uses: maxim-lobanov/setup-xcode@v1

.github/workflows/release-framework.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: macos-12
2020
env:
2121
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer
22-
LDK_C_BINDINGS_BASE: /Users/runner/work/ldk-swift/ldk-swift/bindings/artifacts/ldk-c-bindings
22+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/bindings/artifacts/ldk-c-bindings
2323
steps:
2424
- name: Configure Xcode
2525
uses: maxim-lobanov/setup-xcode@v1

.github/workflows/swift.yml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ jobs:
1515
steps:
1616
- name: Checkout source code
1717
uses: actions/checkout@v3
18-
- name: Install native Rust toolchain, Valgrind, and build utilities
18+
- name: Install native Rust toolchain and build utilities
1919
run: |
2020
# sudo apt-get purge grub\*
2121
# sudo apt-get --only-upgrade install grub-efi-amd64-signed
2222
# sudo apt-get autoremove
2323
# sudo update-grub
2424
sudo apt-get update
2525
# sudo apt-get -y upgrade
26-
sudo apt-get -y install cargo valgrind lld git g++ clang curl
26+
sudo apt-get -y install cargo lld git g++ clang curl
2727
- name: Install Dependencies
2828
uses: ./.github/actions/install-dependencies
2929
with:
@@ -35,18 +35,9 @@ jobs:
3535
run: |
3636
python3 ./scripts/copy_c_files.py
3737
env:
38-
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ci/ldk-c-bindings
39-
H_FILE_OUTPUT_DIRECTORY: /home/runner/work/ldk-swift/ldk-swift/ci/LDKSwift/Sources/LDKHeaders/include
40-
C_FILE_OUTPUT_DIRECTORY: /home/runner/work/ldk-swift/ldk-swift/ci/LDKSwift/Sources/LDKHeaders
41-
- name: Check that the latest auto-generated Swift files are in the repo
42-
run: |
43-
npm install
44-
npm run tsc
45-
node ./src/index.mjs
46-
env:
47-
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ci/ldk-c-bindings/lightning-c-bindings/include/lightning.h
48-
- name: Test bindings parsing and generation
49-
run: npm test
38+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/ci/ldk-c-bindings
39+
H_FILE_OUTPUT_DIRECTORY: ${{ github.workspace }}/ci/LDKSwift/Sources/LDKHeaders/include
40+
C_FILE_OUTPUT_DIRECTORY: ${{ github.workspace }}/ci/LDKSwift/Sources/LDKHeaders
5041
- name: Install Swift Toolchain
5142
run: |
5243
curl --verbose -L -o swift-5.7.2-RELEASE-ubuntu22.04.tar.gz https://download.swift.org/swift-5.7.2-release/ubuntu2204/swift-5.7.2-RELEASE/swift-5.7.2-RELEASE-ubuntu22.04.tar.gz
@@ -59,27 +50,48 @@ jobs:
5950
tar xvvf swift-5.7.2-RELEASE-ubuntu22.04.tar.gz
6051
env:
6152
EXPECTED_SWIFT_SHASUM: e729912846b0cff98bf8e0e5ede2e17bc2d1098de3cdb6fa13b3ff52c36ee5d6
53+
- name: Install Swift Formatter
54+
run: |
55+
git clone https://github.com/apple/swift-format.git
56+
cd swift-format
57+
git checkout "tags/$VERSION"
58+
swift build -c release
59+
env:
60+
VERSION: 508.0.1
61+
- name: Regenerate Swift files
62+
run: |
63+
npm install
64+
npm run tsc
65+
node ./src/index.mjs
66+
env:
67+
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ci/ldk-c-bindings/lightning-c-bindings/include/lightning.h
68+
SWIFT_FORMAT_PATH: ${{ github.workspace }}/swift-format/.build/release/swift-format
69+
- name: Test bindings parsing and generation
70+
run: npm test
71+
- name: Verify generated output recency
72+
run: |
73+
git diff --exit-code out/ ':(exclude)out/VersionDescriptor.swift'
6274
- name: Build Swift bindings package
6375
run: |
6476
cd ci/LDKSwift
6577
../../swift-5.7.2-RELEASE-ubuntu22.04/usr/bin/swift build
6678
env:
67-
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ci/ldk-c-bindings
79+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/ci/ldk-c-bindings
6880
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan-x86_64.a
6981
RUST_BACKTRACE: 1
7082
- name: Test Swift bindings package without address sanitizer
7183
run: |
7284
cd ci/LDKSwift
7385
../../swift-5.7.2-RELEASE-ubuntu22.04/usr/bin/swift test -v
7486
env:
75-
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ci/ldk-c-bindings
87+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/ci/ldk-c-bindings
7688
RUST_BACKTRACE: 1
7789
- name: Test Swift bindings package with address sanitizer
7890
continue-on-error: true
7991
run: |
8092
cd ci/LDKSwift
8193
../../swift-5.7.2-RELEASE-ubuntu22.04/usr/bin/swift test -v
8294
env:
83-
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ci/ldk-c-bindings
95+
LDK_C_BINDINGS_BASE: ${{ github.workspace }}/ci/ldk-c-bindings
8496
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan-x86_64.a
8597
RUST_BACKTRACE: 1

.swift-format

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentation" : {
6+
"tabs" : 1
7+
},
8+
"indentConditionalCompilationBlocks" : true,
9+
"indentSwitchCaseLabels" : true,
10+
"lineBreakAroundMultilineExpressionChainComponents" : true,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineLength" : 120,
15+
"maximumBlankLines" : 2,
16+
"prioritizeKeepingFunctionOutputTogether" : false,
17+
"respectsExistingLineBreaks" : true,
18+
"rules" : {
19+
"AllPublicDeclarationsHaveDocumentation" : false,
20+
"AlwaysUseLowerCamelCase" : true,
21+
"AmbiguousTrailingClosureOverload" : true,
22+
"BeginDocumentationCommentWithOneLineSummary" : false,
23+
"DoNotUseSemicolons" : true,
24+
"DontRepeatTypeInStaticProperties" : true,
25+
"FileScopedDeclarationPrivacy" : true,
26+
"FullyIndirectEnum" : true,
27+
"GroupNumericLiterals" : true,
28+
"IdentifiersMustBeASCII" : true,
29+
"NeverForceUnwrap" : false,
30+
"NeverUseForceTry" : false,
31+
"NeverUseImplicitlyUnwrappedOptionals" : false,
32+
"NoAccessLevelOnExtensionDeclaration" : true,
33+
"NoAssignmentInExpressions" : true,
34+
"NoBlockComments" : false,
35+
"NoCasesWithOnlyFallthrough" : true,
36+
"NoEmptyTrailingClosureParentheses" : true,
37+
"NoLabelsInCasePatterns" : true,
38+
"NoLeadingUnderscores" : false,
39+
"NoParensAroundConditions" : true,
40+
"NoVoidReturnOnFunctionSignature" : true,
41+
"OneCasePerLine" : true,
42+
"OneVariableDeclarationPerLine" : true,
43+
"OnlyOneTrailingClosureArgument" : true,
44+
"OrderedImports" : true,
45+
"ReturnVoidInsteadOfEmptyTuple" : true,
46+
"UseEarlyExits" : false,
47+
"UseLetInEveryBoundCaseVariable" : true,
48+
"UseShorthandTypeNames" : true,
49+
"UseSingleLinePropertyGetter" : true,
50+
"UseSynthesizedInitializer" : true,
51+
"UseTripleSlashForDocumentationComments" : true,
52+
"UseWhereClausesInForLoops" : false,
53+
"ValidateDocumentationComments" : false
54+
},
55+
"spacesAroundRangeFormationOperators" : false,
56+
"tabWidth" : 4,
57+
"version" : 1
58+
}

0 commit comments

Comments
 (0)