{"id":18396167,"url":"https://github.com/lightningdevkit/ldk-swift","last_synced_at":"2025-08-20T07:30:42.722Z","repository":{"id":37925810,"uuid":"357316100","full_name":"lightningdevkit/ldk-swift","owner":"lightningdevkit","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-11T16:50:05.000Z","size":9126,"stargazers_count":48,"open_issues_count":11,"forks_count":12,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-12-06T05:03:03.202Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lightningdevkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-12T19:31:37.000Z","updated_at":"2024-09-11T16:50:10.000Z","dependencies_parsed_at":"2023-10-11T03:30:20.325Z","dependency_job_id":"bde49b88-2271-4753-ada1-e318d34fd0d2","html_url":"https://github.com/lightningdevkit/ldk-swift","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningdevkit%2Fldk-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningdevkit%2Fldk-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningdevkit%2Fldk-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightningdevkit%2Fldk-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lightningdevkit","download_url":"https://codeload.github.com/lightningdevkit/ldk-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230400616,"owners_count":18219831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:13:01.399Z","updated_at":"2025-08-20T07:30:42.710Z","avatar_url":"https://github.com/lightningdevkit.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ldk-swift\n\nAutomatic Swift bindings generation for [`rust-lightning`](https://github.com/lightningdevkit/rust-lightning).\n\n## Installation\n\n### Swift Package Manager\nTo install using Swift Package Manager, add the following line to the depedencies array of your `Package.swift`:\n```\n.package(url: \"https://github.com/lightningdevkit/ldk-swift/\", exact: \"0.0.118\")\n```\nBe sure to also include \"LightningDevKit\" into your packages target like so:\n\n```\ntargets: [\n    .target(\n        name: \"YourPackage\",\n        dependencies: [\n            .product(name: \"LightningDevKit\", package: \"ldk-swift\")\n        ]),\n    ...\n]\n```\n\nIf you're importing directly into Xcode, just copy and paste `https://github.com/lightningdevkit/ldk-swift/` into the system dialog when you click \"Add Package...\"\n\n### Manual Installation\nIn order to use the automatically generated bindings, simply drag `*.xcframework` file into an Xcode project.\n\nThe `*.xcframework` files are either available on\nthe [Releases](https://github.com/lightningdevkit/ldk-swift/releases) page, or can be [compiled](#Compilation)\nfrom scratch.\n\n## Compilation\n\n### Prerequisites\n\n-   A machine running macOS\n-   [Xcode](https://xcodereleases.com/)\n-   [Python3](https://programwithus.com/learn/python/install-python3-mac)\n-   [Rust](https://www.rust-lang.org/tools/install)\n-\t[NPM](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)\n-   [GNU sed](https://formulae.brew.sh/formula/gnu-sed) (optional, but will cut your compile times significantly!)\n\nFor Rust specifically, there are a couple additional requirements that can be installed once the Rust toolchain\nis set up:\n\n```shell\nrustup toolchain install nightly\nrustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-ios\ncargo install cbindgen\n```\n\n### Cloning Dependencies\n\nIn order to generate these bindings from scratch, you will need to clone two dependency repositories:\n\n**[rust-lightning](https://github.com/lightningdevkit/rust-lightning)**, (a specific branch built for bindings compatibility):\n\n```shell\ngit clone --branch 0.0.125-bindings https://github.com/lightningdevkit/rust-lightning /path/to/rust-lightning\n```\n\n**[ldk-c-bindings](https://github.com/lightningdevkit/ldk-c-bindings)**:\n\n```shell\ngit clone --branch main https://github.com/lightningdevkit/ldk-c-bindings /path/to/ldk-c-bindings\n```\n\nTake note of where you clone these directories, it's best you save the absolute path somewhere handy for the rest of the remaining steps.\n\n### Generating Rust-to-C-bindings\n\nNow, navigate to the `ldk-c-bindings` directory and run the `genbindings.sh` script:\n\n```shell\npushd path/to/ldk-c-bindings\n./genbindings.sh /path/to/rust-lightning true\npopd\n```\n\n### Generating C-to-Swift-bindings\n\n\u003cdetails\u003e\n\u003csummary\u003eIf using Docker\u003c/summary\u003e\n\nIf you're using Docker to generate the Swift bindings, navigate (if you're not already there from the\nprevious step) to the `ldk-c-bindings` directory and open the file located here:\n\n`/path/to/ldk-c-bindings/lightning-c-bindings/Cargo.toml`\n\nIn that file, you will see four lines specifying the `lightning`, `lightning-persister`, `lightning-invoice`, and\n`lightning-background-processor` dependencies. They will most likely show local paths to the `rust-lightning`\nfolder due to the previous `genbindings.sh` step. As Docker won't have access to local paths,\nreplace those lines with the following:\n\n```yaml\nlightning = { git = \"https://github.com/thebluematt/rust-lightning\", branch = \"2023-07-0.0.116-java-bindings\", default-features = false }\nlightning-persister = { git = \"https://github.com/thebluematt/rust-lightning\", branch = \"2023-07-0.0.116-java-bindings\", default-features = false }\nlightning-invoice = { git = \"https://github.com/thebluematt/rust-lightning\", branch = \"2023-07-0.0.116-java-bindings\", default-features = false }\nlightning-background-processor = { git = \"https://github.com/thebluematt/rust-lightning\", branch = \"2023-07-0.0.116-java-bindings\", default-features = false }\nlightning-rapid-gossip-sync = { git = \"https://github.com/thebluematt/rust-lightning\", branch = \"2023-07-0.0.116-java-bindings\", default-features = false }\n```\n\nYou will note that the revision is unspecified and is currently just placeholder `xxx`s. To obtain the revision,\njust navigate to the just clone custom `rust-lightning` directory and run:\n\n```shell\ncd /path/to/rust-lightning\ngit rev-parse HEAD\n```\n\nTake that commit hash and replace the `xxx` instances with it.\n\n\u003c/details\u003e\n\n#### Generating the Swift files\n\nTo generate the Swift files, navigate to the `ldk-swift` repository and run the following:\n\n```shell\nexport LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH=\"/path/to/ldk-c-bindings/lightning-c-bindings/include/lightning.h\"\nnpm i \u0026\u0026 npm run tsc \u0026\u0026 node ./src/index.mjs\n```\n\nNow, the contents of `./ci/LDKSwift/Sources/LDKSwift/bindings` will have been completely regenerated.\n\n#### Updating Swift files in Xcode project\n\nTo make sure the correct bindings files are referenced in the project, open `./xcode/LDKFramework/LDK.xcodeproj`.\n\nIn the sidebar, navigate to the `LDK/bindings` group, and delete it by removing references.\n\n![](https://user-images.githubusercontent.com/927534/178599884-36737de9-ae57-4d13-9617-5c12af2a7d5e.png)\n\n![](https://user-images.githubusercontent.com/927534/178600008-9baa0d92-7c3f-499d-88b8-c86b19ab057f.png)\n\nThen, open a Finder window, and drag the `bindings` folder (`./ci/LDKSwift/Sources/LDKSwift/bindings`) into the same location in Xcode that you just deleted.\n\n![](https://user-images.githubusercontent.com/927534/178600978-9221e3e1-d227-450e-8937-dd2ad486975e.png)\n\nFinally, make sure you leave the \"Copy items if needed\" box unchecked, and pick at least `LightningDevKit` as a target to add the references to. Depending on what you intend to do later on, it's easiest to simply add it to all the targets.\n\n![](https://user-images.githubusercontent.com/927534/178601275-7688b088-8349-4dcb-ac1b-a56c2dffdaa2.png)\n\n### Building requisite binaries\n\nNavigate (`cd`) to the `./scripts` folder, and run the following Python script:\n\n```shell\npython3 ./build_bulk_libldks.py /path/to/ldk-c-bindings\n```\n\nThis command will take a while, but it will eventually produce a set of binaries for all the\nplatform/architecture combinations we're trying to support. Those binaries should adhere to the\n`./bindings/bin/release/\u003cplatform\u003e/` folder pattern.\n\nEach of those folders will contain an `architectures` directory with subdirectories such as `arm64`\nor `x86_64`, as well as a `libldk.a` file, which is the `lipo` product of all the targeted\narchitectures.\n\n### Generating the \\*.xcframework files\n\nWith all the binaries generated, still in the `./src/scripts` directory, you just need to run one\nlast Python script to produce the framework:\n\n```shell\npython3 ./generate_xcframework.py /path/to/ldk-c-bindings\n```\n\nOnce the script finishes running, you should see `LightningDevKit.xcframework` in the\n`./bindings/bin/release` folder. Drag that into your project, and you're done!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightningdevkit%2Fldk-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flightningdevkit%2Fldk-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightningdevkit%2Fldk-swift/lists"}