Skip to content

Commit 29ceca7

Browse files
committed
initiate CI integration
1 parent 8ef52a6 commit 29ceca7

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

.github/workflows/swift.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Continuous Integration Checks
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
check_bindings:
7+
runs-on: ubuntu-20.04
8+
env:
9+
TOOLCHAIN: stable
10+
steps:
11+
- name: Install native Rust toolchain, Valgrind, and build utilitis
12+
run: |
13+
sudo apt-get update
14+
sudo apt-get -y dist-upgrade
15+
sudo apt-get -y install cargo valgrind lld git g++ clang curl
16+
- name: Checkout source code
17+
uses: actions/checkout@v2
18+
- name: Install cbindgen
19+
run: cargo install --force cbindgen
20+
- name: Checkout Rust-Lightning and LDK-C-Bindings git
21+
run: |
22+
git config --global user.email "[email protected]"
23+
git config --global user.name "LDK CI"
24+
# Note this is a different endpoint, as we need one non-upstream commit!
25+
git clone https://git.bitcoin.ninja/rust-lightning
26+
cd rust-lightning
27+
git checkout origin/2021-03-java-bindings-base
28+
cd ..
29+
git clone https://github.com/lightningdevkit/ldk-c-bindings
30+
- name: Install Swift Toolchain
31+
run: |
32+
curl https://swift.org/builds/swift-5.4.2-release/ubuntu2004/swift-5.4.2-RELEASE/swift-5.4.2-RELEASE-ubuntu20.04.tar.gz > swift-5.4.2-RELEASE-ubuntu20.04.tar.gz
33+
if [ "$(sha256sum swift-5.4.2-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')" != "86b849d9f6ba2eda4e12ea5eafaa0748bffcd6272466b514c2b0fd4a829c63a4" ]; then
34+
echo "Bad hash"
35+
exit 1
36+
fi
37+
tar xvvf swift-5.4.2-RELEASE-ubuntu20.04.tar.gz
38+
- name: Rebuild C bindings
39+
run: |
40+
cd ldk-c-bindings
41+
./genbindings.sh ../rust-lightning true
42+
cd ..
43+
- name: Copy new headers into bindings
44+
run: |
45+
cp ldk-c-bindings/lightning-c-bindings/include/*.h ci/LDKCHeaders/Headers/
46+
cp ldk-c-bindings/ldk-net/ldk_net.h ci/LDKCHeaders/Headers/
47+
- name: Fix header files
48+
run: |
49+
python ci/fix_header_includes.py
50+
- name: Copy Swift bindings into sources
51+
run: |
52+
cp -a bindings/LDK/. ci/LDKSwift/Sources/LDKSwift
53+
cp -R bindings/batteries ci/LDKSwift/Sources/LDKSwift
54+
- name: Build and test bindings
55+
run: |
56+
cd ci/LDKSwift
57+
LDK_C_BINDINGS_BASE="../ldk-c-bindings" RUST_BACKTRACE=1 ../swift-5.4.2-RELEASE-ubuntu20.04/usr/bin/swift test
58+
- name: Check that the latest headers are in the swift repo
59+
run: |
60+
git diff --exit-code

ci/fix_header_includes.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
3+
directory_path = os.path.dirname(os.path.realpath(__file__))
4+
header_directory = f'{directory_path}/LDKCHeaders/Headers'
5+
6+
header_files = []
7+
8+
# Create a collection of local header files
9+
for current_header_file in os.listdir(header_directory):
10+
current_file_path = f'{header_directory}/{current_header_file}'
11+
if not os.path.isfile(current_file_path):
12+
continue
13+
if not current_header_file.endswith('.h'):
14+
continue
15+
16+
header_files.append({'name': current_header_file, 'path': current_file_path})
17+
18+
for current_header_file in header_files:
19+
file_name = current_header_file['name']
20+
path = current_header_file['path']
21+
file_in = open(path, 'rt')
22+
original_contents = file_in.read()
23+
file_in.close()
24+
25+
fixed_contents = original_contents
26+
for other_header_file in header_files:
27+
other_file_name = other_header_file['name']
28+
if other_file_name == file_name:
29+
continue
30+
# TODO: use regex to detect multi-space or other whitespace-altered includes and fix them correctly, too
31+
# Fix each local file's import by replacing angular brackets with quotes
32+
fixed_contents = fixed_contents.replace(f'#include <{other_file_name}>', f'#include "{other_file_name}"')
33+
if fixed_contents != original_contents:
34+
# Only save updated file if a change occurred
35+
file_out = open(path, 'wt')
36+
file_out.write(fixed_contents)
37+
file_out.close()
38+

0 commit comments

Comments
 (0)