{"id":16373134,"url":"https://github.com/bbqsrc/swift-rust-bindings-example","last_synced_at":"2025-10-26T08:30:21.986Z","repository":{"id":185423387,"uuid":"673528538","full_name":"bbqsrc/swift-rust-bindings-example","owner":"bbqsrc","description":"The most cursed thing I think I've ever made.","archived":false,"fork":false,"pushed_at":"2023-08-01T20:59:27.000Z","size":3,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T17:11:32.835Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/bbqsrc.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}},"created_at":"2023-08-01T20:50:00.000Z","updated_at":"2023-08-14T05:45:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"959e5a77-28b9-4764-9887-c21ad450f20d","html_url":"https://github.com/bbqsrc/swift-rust-bindings-example","commit_stats":null,"previous_names":["bbqsrc/swift-rust-bindings-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fswift-rust-bindings-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fswift-rust-bindings-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fswift-rust-bindings-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fswift-rust-bindings-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbqsrc","download_url":"https://codeload.github.com/bbqsrc/swift-rust-bindings-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238293186,"owners_count":19448137,"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-10-11T03:13:27.020Z","updated_at":"2025-10-26T08:30:21.677Z","avatar_url":"https://github.com/bbqsrc.png","language":"Shell","readme":"## Prereqs:\n\n- You're on macOS with Xcode\n- You have Rust (https://rustup.rs)\n- You have `cargo-cocoapods` (`cargo install --git https://github.com/bbqsrc/cargo-cocoapods`)\n\n## Anatomy:\n\n- `src/lib.rs` contains the Rust code\n- `bindings.h` contains the C interface to the Rust code\n- `lib.swift` describes the safe Swift interface to the Rust code. It is imported as `Example_Private`\n\n## Process:\n\n`run.sh` does a bunch of crazy things:\n\n- Use `cargo-cocoapods` to build the Rust `example_sys` static library for all relevant targets\n- Creates the stubs of an `Example.framework` for each of the targets, creating an empty modulemap and a private modulemap specifying to link against `Example` and pointing to the header that is now copied to the `PrivateHeader` directory\n- Iterates over each triple, building the safe wrapper directly with `swiftc`\n- The absolute crime: taking the Rust `.a` file and embedding the compiled Swift static module's `.o` file into it, and placing it into the framework directory\n- Copying all the related Swift module metadata into the `Modules` directory of the framework\n- Using `lipo` to merge the various architectures on the various platforms so we can do the next thing\n- Creating an `.xcframework` with `xcodebuild`\n\nAt the end of this, you have a self-contained, static, redistributable binary library for all relevant Apple platforms.\n\n## Example:\n\n```\n$ swiftc -F Example.xcframework/macos-arm64_x86_64 example.swift -o example\n$ otool -L ./example \n./example:\n        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)\n        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1500.65.0)\n        /usr/lib/swift/libswiftCore.dylib (compatibility version 1.0.0, current version 5.8.0)\n$  ./example\nHello Rust!\n\n```\n\nIf you run `run.sh`, you should see this .xcframework created, amongst other things:\n\n```\nExample.xcframework\n├── Info.plist\n├── ios-arm64\n│   └── Example.framework\n│       ├── Example\n│       ├── Modules\n│       │   ├── Example.swiftmodule\n│       │   │   ├── arm64.abi.json\n│       │   │   ├── arm64.swiftdoc\n│       │   │   ├── arm64.swiftinterface\n│       │   │   └── arm64.swiftsourceinfo\n│       │   ├── module.modulemap\n│       │   └── module.private.modulemap\n│       └── PrivateHeaders\n│           └── example_sys.h\n├── ios-arm64_x86_64-simulator\n│   └── Example.framework\n│       ├── Example\n│       ├── Modules\n│       │   ├── Example.swiftmodule\n│       │   │   ├── arm64.abi.json\n│       │   │   ├── arm64.swiftdoc\n│       │   │   ├── arm64.swiftinterface\n│       │   │   ├── arm64.swiftsourceinfo\n│       │   │   ├── x86_64.abi.json\n│       │   │   ├── x86_64.swiftdoc\n│       │   │   ├── x86_64.swiftinterface\n│       │   │   └── x86_64.swiftsourceinfo\n│       │   ├── module.modulemap\n│       │   └── module.private.modulemap\n│       └── PrivateHeaders\n│           └── example_sys.h\n└── macos-arm64_x86_64\n    └── Example.framework\n        ├── Example\n        ├── Modules\n        │   ├── Example.swiftmodule\n        │   │   ├── arm64.abi.json\n        │   │   ├── arm64.swiftdoc\n        │   │   ├── arm64.swiftinterface\n        │   │   ├── arm64.swiftsourceinfo\n        │   │   ├── x86_64.abi.json\n        │   │   ├── x86_64.swiftdoc\n        │   │   ├── x86_64.swiftinterface\n        │   │   └── x86_64.swiftsourceinfo\n        │   ├── module.modulemap\n        │   └── module.private.modulemap\n        └── PrivateHeaders\n            └── example_sys.h\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbqsrc%2Fswift-rust-bindings-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbqsrc%2Fswift-rust-bindings-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbqsrc%2Fswift-rust-bindings-example/lists"}