{"id":13994845,"url":"https://github.com/keith/swift-staticlibs","last_synced_at":"2025-07-22T20:32:51.545Z","repository":{"id":143169499,"uuid":"82434013","full_name":"keith/swift-staticlibs","owner":"keith","description":"Scripts to allow Swift static libraries to be compiled in Xcode","archived":true,"fork":false,"pushed_at":"2017-07-24T17:24:12.000Z","size":57,"stargazers_count":343,"open_issues_count":0,"forks_count":32,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-29T17:37:55.589Z","etag":null,"topics":["ios","static-library","swift","xcode"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-19T04:03:43.000Z","updated_at":"2024-10-29T16:03:18.000Z","dependencies_parsed_at":"2023-04-23T06:08:55.112Z","dependency_job_id":null,"html_url":"https://github.com/keith/swift-staticlibs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/keith/swift-staticlibs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fswift-staticlibs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fswift-staticlibs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fswift-staticlibs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fswift-staticlibs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keith","download_url":"https://codeload.github.com/keith/swift-staticlibs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keith%2Fswift-staticlibs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266567533,"owners_count":23949374,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ios","static-library","swift","xcode"],"created_at":"2024-08-09T14:03:08.424Z","updated_at":"2025-07-22T20:32:48.718Z","avatar_url":"https://github.com/keith.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# swift-staticlibs\n\n**NOTE**: As of Xcode 9 beta 4, Xcode natively supports static libraries\nwith Swift sources, meaning this ~~hack~~ workaround is no longer\nneeded!\n\nThis repo contains a replacement linker script for building iOS static\nframeworks that contain Swift sources from **within Xcode**\n\n## Usage\n\nFor each dynamic framework target in Xcode that you would like to be\nbuild statically:\n\n1. Set the undocumented `LD` Xcode build setting to point to `ld.py`\n2. Add the target to your main target's `Link Binary With Libraries`\n   build phase.\n\nYou can set this setting through a user defined build setting in Xcode,\nor with a [`xcconfig`][xcconfigs] file like this:\n\n```\nLD = $(PROJECT_DIR)/path/to/ld.py\n```\n\n## CocoaPods\n\nThere are a few issues with using this script alongside CocoaPods:\n\n- With the below configuration, there is no differentiation between\n  targets, if for some reason you didn't want to use these scripts for\n  all targets, you would have to handle that\n- You must delete the `[CP] Embed Pods Frameworks` build phase from all\n  targets that depend on CocoaPods. Otherwise your final `.app` bundle\n  will contain frameworks that are not referenced and just bloating your\n  app size\n- If you have any pre-compiled dynamic frameworks that are included with\n  CocoaPods, deleting the Embed Pods Frameworks phase will mean these\n  are no longer included\n- Resources that pods vendor are not handled by these scripts, there are\n  2 different ways CocoaPods handles resources:\n  - If your pods use the [`resources`][resources] directive\n    (which is [not recommended][resources]), your must handle copying\n    the resources, **and any conflicts** caused by duplicate naming\n  - If your pods are using the recommended [`resource_bundles`][bundles]\n    directive, you still have to handle copying the resource bundle into\n    your targets, otherwise it is ignored\n\nIf you feel comfortable working around these issues, you can add\nsomething like this to your `Podfile`:\n\n```ruby\npost_install do |installer|\n  installer.pods_project.targets.each do |target|\n    target.build_configurations.each do |config|\n      config.build_settings['LD'] = '$(PROJECT_DIR)/path/to/ld.py'\n    end\n  end\nend\n```\n\nIf you need a more elaborate configuration in CocoaPods, you can use the\n[`xcodeproj`](https://github.com/CocoaPods/xcodeproj/) gem in order to\nmake decisions based on project configuration.\n\n## Why?\n\n1. Xcode has [never supported][radar] building static libraries (and\n   definitely not static frameworks) containing Swift sources (although\n   this has always been supported by [Swift Package Manager][swiftpm])\n\n2. Dynamic frameworks cause an [impact][eigen] [on][loaf]\n   [launch][mjtsai] [times][wwdc]. While this has improved since the\n   original issues, there's still significant overhead when you have a\n   large amount of modules\n\n3. By using static libraries (or, in this case, static frameworks), you\n   don't have to deal with all the overhead of dynamic framework\n   loading. See [this session][wwdc] from WWDC 2016 for more details\n   around this.\n\n## How?\n\nBy replacing the `libtool` invocation from Xcode, this script hijacks\nthe passed arguments, and transforms them into the arguments necessary\nfor building static _frameworks_, instead of dynamic frameworks. Then\nsince the product ends up existing in the same place as the dynamic\nframework that would have otherwise been included, Xcode happily links\nthe static framework instead.\n\nStatic _frameworks_ are very similar to dynamic frameworks, except the\nbinary contained within the framework ends up being linked statically,\ninstead of dynamically (see [this article][staticvsdynamic] for more\ndetails). They differ from traditional static _libraries_ in that they\nhave the `.framework` directory structure identical to dynamic\nframeworks. This makes it easier to integrate from within Xcode since\nXcode already expects the products from dynamic framework targets to\nfollow this structure.\n\n[bundles]: https://guides.cocoapods.org/syntax/podspec.html#resource_bundles\n[eigen]: https://github.com/artsy/eigen/issues/586\n[loaf]: https://useyourloaf.com/blog/slow-app-startup-times\n[mjtsai]: https://mjtsai.com/blog/2015/10/26/dynamic-frameworks-and-app-launch-times\n[radar]: http://www.openradar.me/17233107\n[resources]: https://guides.cocoapods.org/syntax/podspec.html#resources\n[staticvsdynamic]: https://pewpewthespells.com/blog/static_and_dynamic_libraries.html\n[swiftpm]: https://github.com/apple/swift-package-manager/blob/6bb27929727a1b059168aa6600e10621296bc7fa/Documentation/PackageDescriptionV4.md#products\n[wwdc]: https://developer.apple.com/videos/play/wwdc2016/406\n[xcconfigs]: https://pewpewthespells.com/blog/xcconfig_guide.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeith%2Fswift-staticlibs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeith%2Fswift-staticlibs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeith%2Fswift-staticlibs/lists"}