{"id":13477722,"url":"https://github.com/chinedufn/swift-bridge","last_synced_at":"2025-05-14T20:07:08.040Z","repository":{"id":37646298,"uuid":"427836269","full_name":"chinedufn/swift-bridge","owner":"chinedufn","description":"swift-bridge facilitates Rust and Swift interop.","archived":false,"fork":false,"pushed_at":"2025-02-11T07:29:32.000Z","size":7095,"stargazers_count":917,"open_issues_count":85,"forks_count":64,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-13T14:06:56.094Z","etag":null,"topics":["ffi","interop","ios","rust","swift"],"latest_commit_sha":null,"homepage":"https://chinedufn.github.io/swift-bridge","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chinedufn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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-11-14T04:24:28.000Z","updated_at":"2025-04-12T08:47:07.000Z","dependencies_parsed_at":"2024-01-16T09:54:48.244Z","dependency_job_id":"988e2e83-6e21-4c44-b19e-b3b5a38d4fc9","html_url":"https://github.com/chinedufn/swift-bridge","commit_stats":{"total_commits":348,"total_committers":17,"mean_commits":"20.470588235294116","dds":"0.13218390804597702","last_synced_commit":"9e09fcefbd2581fc6e44cb4207c99d25eb175b4d"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinedufn%2Fswift-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinedufn%2Fswift-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinedufn%2Fswift-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinedufn%2Fswift-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chinedufn","download_url":"https://codeload.github.com/chinedufn/swift-bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724639,"owners_count":21151561,"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":["ffi","interop","ios","rust","swift"],"created_at":"2024-07-31T16:01:46.645Z","updated_at":"2025-04-13T14:07:03.705Z","avatar_url":"https://github.com/chinedufn.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# swift-bridge [![Actions Status](https://github.com/chinedufn/swift-bridge/workflows/test/badge.svg)](https://github.com/chinedufn/swift-bridge/actions) [![docs](https://docs.rs/swift-bridge/badge.svg)](https://docs.rs/swift-bridge) [![crates.io](https://img.shields.io/crates/v/swift-bridge)](https://crates.io/crates/swift-bridge)\n\n\u003e `swift-bridge` facilitates Rust and Swift interop.\n\n`swift-bridge` makes it easy to pass and share high-level types between Rust and Swift,\nsuch as `String`, `Option\u003cT\u003e`,  `Result\u003cT, E\u003e`, `struct`, `class` and more.\n\nIt also helps you bridge higher level language features, such as async functions and generics.\n\nUsing `swift-bridge` should be safer, more performant and more ergonomic than managing Rust and Swift\nFFI by hand.\n\n## Installation\n\n```toml\n# In your Cargo.toml\n\n[build-dependencies]\nswift-bridge-build = \"0.1\"\n\n[dependencies]\nswift-bridge = \"0.1\"\n```\n\n## Book\n\nYou can find information about using Rust and Swift together in [The `swift-bridge` Book](https://chinedufn.github.io/swift-bridge).\n\n## Quick Peek\n\nYou use `swift-bridge` by declaring the types and functions that you want to import and export\nin a \"bridge module\", and then annotating that bridge module with the `#[swift_bridge::bridge]`\nmacro.\n\nThen, at build time, you use either the `swift-bridge-build` API or the `swift-bridge-cli` CLI to\nparse your annotated bridge modules and generate the `Swift` and `C` side of the FFI layer.\n\nHere's a quick peek at how you might describe an FFI boundary between Swift and Rust using a bridge module.\n\n\u003c!-- ANCHOR: bridge-module-example --\u003e\n```rust\n// We use the `swift_bridge::bridge` macro to declare a bridge module.\n// Then at build time the `swift-bridge-build` crate is used to generate\n// the corresponding Swift and C FFI glue code.\n#[swift_bridge::bridge]\nmod ffi {\n    // Create \"transparent\" structs where both Rust and Swift can directly access the fields.\n    struct AppConfig {\n        file_manager: CustomFileManager,\n    }\n\n    // Transparent enums are also supported.\n    enum UserLookup {\n        ById(UserId),\n        ByName(String),\n    }\n\n    // Export opaque Rust types, functions and methods for Swift to use.\n    extern \"Rust\" {\n        type RustApp;\n\n        #[swift_bridge(init)]\n        fn new(config: AppConfig) -\u003e RustApp;\n        \n        fn get_user(\u0026self, lookup: UserLookup) -\u003e Option\u003c\u0026User\u003e;\n    }\n\n    extern \"Rust\" {\n        type User;\n        type MessageBoard;\n\n        #[swift_bridge(get(\u0026nickname))]\n        fn informal_name(self: \u0026User) -\u003e \u0026str;\n    }\n\n    // Import opaque Swift classes and functions for Rust to use.\n    extern \"Swift\" {\n        type CustomFileManager;\n        fn save_file(\u0026self, name: \u0026str, contents: \u0026[u8]);\n    }\n}\n\nstruct User {\n    nickname: String\n}\n```\n\u003c!-- ANCHOR_END: bridge-module-example --\u003e\n\n## Quick Start\n\nThe `swift-bridge` repository contains [example applications](examples) that you use to quickly try out the library,\nor as a starting point for your own `Swift` + `Rust` based application.\n\nFor example, here's how to run the [`codegen-visualizer`](examples/codegen-visualizer) example project locally.\n\n```sh\ngit clone https://github.com/chinedufn/swift-bridge\ncd swift-bridge/examples/codegen-visualizer\n\nopen CodegenVisualizer/CodegenVisualizer.xcodeproj\n# *** Click the \"Run\" button at the top left of Xcode ***\n```\n\n---\n\nYou can find information about using Rust and Swift together in [The `swift-bridge` Book](https://chinedufn.github.io/swift-bridge).\n\n## Built-In Types\n\nIn addition to allowing you to share your own custom structs, enums and classes between Rust and Swift,\n`swift-bridge` comes with support for a number of Rust and Swift standard library types.\n\n\u003c!-- ANCHOR: built-in-types-table --\u003e\n| name in Rust                                                    | name in Swift                                                    | notes                                                                              |\n| ---                                                             | ---                                                              | ---                                                                                |\n| u8, i8, u16, i16... etc                                         | UInt8, Int8, UInt16, Int16 ... etc                               |                                                                                    |\n| bool                                                            | Bool                                                             |                                                                                    |\n| String, \u0026String, \u0026mut String                                    | RustString, RustStringRef, RustStringRefMut                      |                                                                                    |\n| \u0026str                                                            | RustStr                                                          |                                                                                    |\n| Vec\\\u003cT\u003e                                                         | RustVec\\\u003cT\u003e                                                      |                                                                                    |\n| SwiftArray\\\u003cT\u003e                                                  | Array\\\u003cT\u003e                                                        | Not yet implemented                                                                |\n| \u0026[T]                                                            |                                                                  | Not yet implemented                                                                |\n| \u0026mut [T]                                                        |                                                                  | Not yet implemented                                                                |\n| Box\\\u003cT\u003e                                                         |                                                                  | Not yet implemented                                                                |\n| Box\u003cdyn FnOnce(A,B,C) -\u003e D\u003e                                     | (A, B, C) -\u003e D                                                   | Passing from Rust to Swift is supported, but Swift to Rust is not yet implemented. |\n| Box\u003cdyn Fn(A,B,C) -\u003e D\u003e                                         | (A, B, C) -\u003e D                                                   | Not yet implemented                                                                |\n| Arc\\\u003cT\u003e                                                         |                                                                  | Not yet implemented                                                                |\n| [T; N]                                                          |                                                                  | Not yet implemented                                                                |\n| *const T                                                        | UnsafePointer\\\u003cT\u003e                                                |                                                                                    |\n| *mut T                                                          | UnsafeMutablePointer\\\u003cT\u003e                                         |                                                                                    |\n| Option\\\u003cT\u003e                                                      | Optional\\\u003cT\u003e                                                     |                                                                                    |\n| fn x() -\u003e Result\\\u003cT, E\u003e                                         | func x() throws -\u003e T                                             |                                                                                    |\n| fn x(arg: Result\\\u003cT, E\u003e)                                        | func x(arg: RustResult\\\u003cT, E\u003e)                                   |                                                                                    |\n| (A, B, C, ...)| (A, B, C, ...)\n| Have a Rust standard library type in mind?\u003cbr /\u003e Open an issue! |                                                                  |                                                                                    |\n|                                                                 | Have a Swift standard library type in mind?\u003cbr /\u003e Open an issue! |                                                                                    |\n\u003c!-- ANCHOR_END: built-in-types-table --\u003e\n\n## Performance\n\n`swift-bridge` aims to be useful in performance critical environments.\n\nNone of its generated FFI code uses object serialization, cloning, synchronization or any other form of unnecessary overhead.\n\n## To Test\n\nTo run the test suite.\n\n```sh\n# Clone the repository\ngit clone git@github.com:chinedufn/swift-bridge.git\ncd swift-bridge\n\n# Run tests\ncargo test --all \u0026\u0026 ./test-swift-rust-integration.sh \u0026\u0026 ./test-swift-packages.sh \n```\n\n## Contributing\n\nIf you're interesting in contributing to `swift-bridge`, check out the [contributor's guide](https://chinedufn.github.io/swift-bridge/contributing/index.html).\n\nAfter getting familiar with the contribution process, try looking at some of the [good first issues](https://github.com/chinedufn/swift-bridge/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)\nto see if any peak your interest.\n\nThese issues come with step-by-step instructions that should help guide you towards implementing your first patch.\n\n## Minimum Supported Swift Version (MSSV)\n\n`swift-bridge` currently guarantees that the Swift code that it generates will work on Swift `6.0` and later.\nThis is known the project's \"Minimum Supported Swift Version\" (MSSV).\n\n`swift-bridge`'s current policy is that the minimum required Swift version can be increased at any time to\nany Swift version that is at least one month old.\n\nFor instance, if Swift `9.10.11` is released on April 5, 2035, then on May 5, 2035 the `swift-bridge` project is allowed\nto begin emitting Swift code that relies on Swift `9.10.11`.\n\nWe will increase our support windows when one or both of the following happen:\n\n- We are no longer waiting for Swift features that increase the safety, performance and ergonomics of the Swift code that `swift-bridge` emits.\n  - For instance, Swift recently introduced the `~Copyable` protocol, which we plan to use enforce ownership when Swift code uses opaque Rust types.\n\n- The short support window is disrupting projects that use `swift-bridge` today.\n  - Please open an issue if our MSSV policy impacts your project\n\n## Acknowledgements\n\n- [cxx](https://github.com/dtolnay/cxx) inspired the idea of using a bridge module to describe the FFI boundary.\n\n---\n\n#### License\n\n_Licensed under [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE)._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinedufn%2Fswift-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchinedufn%2Fswift-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinedufn%2Fswift-bridge/lists"}