@@ -6,7 +6,7 @@ Automatic Swift bindings generation for [`rust-lightning`](https://github.com/li
6
6
7
7
In order to use the automatically generated bindings, simply drag ` *.xcframework ` file into an Xcode project.
8
8
9
- The ` *.xcframework ` files are either available on
9
+ The ` *.xcframework ` files are either available on
10
10
the [ Releases] ( https://github.com/lightningdevkit/ldk-swift/releases ) page, or can be [ compiled] ( #Compilation )
11
11
from scratch.
12
12
@@ -15,54 +15,60 @@ from scratch.
15
15
16
16
### Prerequisites
17
17
18
- - A Mac with Xcode
18
+ - A Mac with Xcode 13.2.1 or lower (this is because there is a bug with ` cc ` that prevents it from compiling for Mac Catalyst targets with clang 13)
19
19
- Python3
20
20
- Rust
21
+ - ` gnu-sed ` (optional; but will cut your compile times significantly!)
21
22
22
23
For Rust specifically, there are a couple additional requirements that can be installed once the Rust toolchain
23
24
is set up:
24
25
25
26
``` shell
27
+ rustup toolchain install nightly
26
28
rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-ios
27
- cargo install cargo-lipo
28
29
cargo install cbindgen
29
30
```
30
31
31
32
### Cloning Dependencies
32
33
34
+ Before you get started, make sure you ` cd ` to the ` ldk-swift ` directory.
35
+
33
36
In order to generate these bindings from scratch, you will need to clone two dependency repositories:
34
37
35
- ** rust-lightning** , (a specific branch built for bindings compatibility)
38
+ ** rust-lightning** , (a specific branch built for bindings compatibility)
36
39
``` shell
37
- git clone --branch 2021-03-java-bindings-base git@ github.com: TheBlueMatt/rust-lightning.git
40
+ git clone --branch 2021-03-java-bindings-base https:// github.com/ TheBlueMatt/rust-lightning bindings/artifacts/rust-lightning
38
41
```
39
42
40
43
** ldk-c-bindings**
41
44
``` shell
42
- git clone git@ github.com: lightningdevkit/ldk-c-bindings.git
45
+ git clone https:// github.com/ lightningdevkit/ldk-c-bindings bindings/artifacts/ldk-c-bindings
43
46
```
44
47
48
+ For compilation to work properly, make sure that both ` rust-lightning ` and ` ldk-c-bindings ` are present in ` ldk-swift/bindings/artifacts ` .
49
+
45
50
### Generating Rust-to-C-bindings
46
51
47
52
Now, navigate to the ` ldk-c-bindings ` directory and run the ` genbindings.sh ` script:
48
53
49
54
``` shell
50
- cd /path/to /ldk-c-bindings
55
+ pushd bindings/artifacts /ldk-c-bindings
51
56
./genbindings.sh /path/to/rust-lightning true
57
+ popd
52
58
```
53
59
54
60
### Generating C-to-Swift-bindings
55
61
56
62
<details >
57
63
<summary >If using Docker</summary >
58
64
59
- If you're using Docker to generate the Swift bindings, navigate (if you're not already there from the
65
+ If you're using Docker to generate the Swift bindings, navigate (if you're not already there from the
60
66
previous step) to the ` ldk-c-bindings ` directory and open the file located here:
61
67
62
68
` /path/to/ldk-c-bindings/lightning-c-bindings/Cargo.toml `
63
69
64
- In that file, you will see four lines specifying the ` lightning ` , ` lightning-persister ` , ` lightning-invoice ` , and
65
- ` lightning-background-processor ` dependencies. They will most likely show local paths to the ` rust-lightning `
70
+ In that file, you will see four lines specifying the ` lightning ` , ` lightning-persister ` , ` lightning-invoice ` , and
71
+ ` lightning-background-processor ` dependencies. They will most likely show local paths to the ` rust-lightning `
66
72
folder due to the previous ` genbindings.sh ` step. As Docker won't have access to local paths,
67
73
replace those lines with the following:
68
74
@@ -73,48 +79,35 @@ lightning-invoice = { git = "https://github.com/thebluematt/rust-lightning", bra
73
79
lightning-background-processor = { git = "https://github.com/thebluematt/rust-lightning", branch = "2021-03-java-bindings-base", default-features = false }
74
80
```
75
81
76
- You will note that the revision is unspecified and is currently just placeholder ` xxx ` s. To obtain the revision,
82
+ You will note that the revision is unspecified and is currently just placeholder ` xxx ` s. To obtain the revision,
77
83
just navigate to the just clone custom ` rust-lightning ` directory and run:
78
84
79
85
``` shell
80
86
cd /path/to/rust-lightning
81
87
git rev-parse HEAD
82
88
```
83
89
84
- Take that commit hash and replace the ` xxx ` instances with it.
90
+ Take that commit hash and replace the ` xxx ` instances with it.
85
91
</details >
86
92
87
93
#### Generating the Swift files
88
94
89
95
To generate the Swift files, navigate to the ` ldk-swift ` repository and run the following:
90
96
91
97
``` shell
92
- EXPORT LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH=" /path/to /ldk-c-bindings/lightning-c-bindings/include/lightning.h"
98
+ export LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH=" $( pwd ) /bindings/artifacts /ldk-c-bindings/lightning-c-bindings/include/lightning.h"
93
99
python3 ./
94
100
```
95
101
96
102
Now, the contents of the ` bindings/LDK ` folder will have been completely regenerated.
97
103
98
104
#### Generating the * .xcframework files
99
105
100
- With the Swift files completely regenerated, you will need to make sure the Xcode projects that serve as bases
101
- for the ` *.xcframework ` s reference them correctly. So navigate here:
102
-
103
- ` path/to/ldk-swift/xcode `
104
-
105
- and open the respective ` *.xcodeproj ` files located in the ` LDKFramework ` and ` LDKFramework_Mac ` directories.
106
- Do the following steps for _ both_ projects:
107
-
108
- 1 . Remove the ` LDK ` references in the Xcode file tree
109
- 2 . Drag the ` path/to/ldk-swift/bindings/LDK ` folder to that same location in the file tree
110
- 3 . Check ` Copy items if needed ` and pick ` Create groups ` in the dialog box
111
-
112
- Next, navigate back to the ` xcode ` directory, and run the following scripts:
106
+ With all the bindings generated, you will just have to run two commands to generate the xcframework:
113
107
114
108
``` shell
115
- ./compile_dependency_binaries.sh /path/to/ldk-c-bindings
116
- ./build_framework.sh
109
+ cd xcode
110
+ ./build_framework.sh
117
111
```
118
112
119
- Finally, navigate to ` path/to/ldk-swift/bindings/bin ` , and you should find multiple ` *.xcframework ` files
120
- waiting for you there.
113
+ Once the script finishes running, you should see ` LDKFramework.xcframework ` in the ` xcode/build ` folder. Drag that into your project, and you're done!
0 commit comments