{"id":19347471,"url":"https://github.com/mrlsd/llvm-api-swift","last_synced_at":"2026-02-07T14:01:33.498Z","repository":{"id":213889380,"uuid":"735180936","full_name":"mrLSD/llvm-api-swift","owner":"mrLSD","description":"Swift LLVM API is a library and utils set fully compatible with LLVM-C API. The library can be used to create compilers backend based on LLVM","archived":false,"fork":false,"pushed_at":"2024-10-07T10:00:08.000Z","size":152,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-15T06:23:56.594Z","etag":null,"topics":["compilers","llvm","llvm-bindings","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/mrLSD.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-24T00:30:15.000Z","updated_at":"2024-10-07T10:00:11.000Z","dependencies_parsed_at":"2024-01-04T12:26:45.352Z","dependency_job_id":"c381f4a1-3c87-44d8-8081-e8b6fbe7cfe7","html_url":"https://github.com/mrLSD/llvm-api-swift","commit_stats":null,"previous_names":["mrlsd/llvm-codegen","mrlsd/llvm-api-swift"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mrLSD/llvm-api-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrLSD%2Fllvm-api-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrLSD%2Fllvm-api-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrLSD%2Fllvm-api-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrLSD%2Fllvm-api-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrLSD","download_url":"https://codeload.github.com/mrLSD/llvm-api-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrLSD%2Fllvm-api-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266019657,"owners_count":23864916,"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":["compilers","llvm","llvm-bindings","swift"],"created_at":"2024-11-10T04:16:35.364Z","updated_at":"2026-02-07T14:01:28.516Z","avatar_url":"https://github.com/mrLSD.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Swift CI](https://github.com/mrLSD/llvm-api-swift/actions/workflows/swift.yaml/badge.svg)](https://github.com/mrLSD/llvm-api-swift/actions/workflows/swift.yaml)\n\n\u003ccenter\u003e\n    \u003ch1\u003emrLSD\u003ccode\u003e/llvm-api-swift\u003c/code\u003e\u003c/h1\u003e\n\u003c/center\u003e\n\n`llvm-api-swift` is a library representing Swift LLVM API, a pure Swift interface to the [LLVM API](https://llvm.org/docs/) and its associated libraries. \nIt provides native, easy-to-use components to create compilers codegen backend. It contains LLVM bindings,\ncomponents and toolset for efficiently use LLVM as compilers backend implementation on Swift.\n\n## Overview\n\nThe `llvm-api-swift` provides a robust and comprehensive interface to the LLVM Compiler Infrastructure,\nleveraging the `LLVM-C API` to offer a blend of safety, flexibility, and extendability. This library\nis designed to serve as a powerful tool for developers looking to create backends for compilers, enabling\nthem to harness the full potential of **LLVM** in a secure and user-friendly manner.\n\n## Safety\n\nSafety is a paramount concern in the design of this library. By building on the `LLVM-C API`, we ensure that\ninteractions\nwith the **LLVM** infrastructure are conducted in a type-safe and memory-safe manner. The library employs Swift’s\nstringent\nsafety guarantees to prevent common issues such as null pointer dereferencing, buffer overflows, and memory leaks. This\ncommitment to safety allows developers to focus on the functionality of their compiler backends without worrying about\nunderlying security vulnerabilities.\n\n## Flexibility\n\nFlexibility is another core attribute of the `llvm-api-swift`. The library provides a rich set of APIs that cover a wide\nrange of LLVM’s capabilities, from module management and inline assembly to debugging metadata and function iteration.\nDevelopers can easily access and manipulate **LLVM** constructs, enabling the creation of highly customized and\noptimized\ncompiler backends. The library’s design ensures that it can adapt to various use cases and requirements, making it an\nideal choice for a diverse set of compiler development projects based on Swift.\n\n## Extendability\n\nThe 'llvm-api-swift' is built with extendability in mind. It is designed to be easily extendable, allowing developers to\nadd\nnew functionalities and support for additional **LLVM** features as needed. The modular structure of the library\nfacilitates\nthe incorporation of new components, ensuring that it can grow and evolve alongside the **LLVM** ecosystem. This\nextendability ensures that the library remains relevant and useful as **LLVM** continues to advance and expand its\ncapabilities.\n\n## Why LLVM?\n\n**LLVM** (Low-Level Virtual Machine) is a powerful and versatile compiler infrastructure that provides a collection of\nmodular and reusable compiler and toolchain technologies. It is widely used in the development of modern compilers,\nproviding a framework for optimizing intermediate representations and generating machine code for various target\narchitectures. LLVM’s ability to support multiple languages and platforms, coupled with its extensive optimization\ncapabilities, makes it an essential tool for compiler developers. By leveraging **LLVM**, developers can create highly\nefficient and portable compilers that meet the demands of today’s diverse computing environments.\n\n## Design\n\nThe `llvm-api-awift` library adheres to the structure of the `LLVM C API`, ensuring easy navigation through the extensive LLVM\nfunctions. Logical elements are grouped into modules, providing a clear organizational structure. Within these modules,\nRust structures are introduced to wrap LLVM types, implementing corresponding functions for the wrapped LLVM types. This\napproach enhances flexibility and usability while maintaining the original LLVM code structure. The design avoids\nunnecessary complexity in the code and documentation, remaining fully aligned with the `LLVM API`. This alignment allows\ndevelopers to easily navigate the `llvm-api-swift` library using existing LLVM-C documentation.\n\n### Compatibility with LLVM-C API\n\nWhen creating the library, we were guided by **full compatibility** with [LLVM-C API](https://llvm.org/doxygen/group__LLVMC.html).\nFor this reason, structurally the library tries to inherit the `LLVM-C API` tree, thereby dividing the library structure into subdirectories. \nAnd filling the components also with the appropriate `LLVM-C API`.\nWhen implementing Swift types, we were guided by the approach of abstracting away from C types, completely transforming them into Swift types. \nAt the same time adhering to the principles of a safety and reliability implementation - without explicit memory management, means of safe techniques, functions provided by Swift.\n\n## Requirements\n\n- Supported OS: MacOS 12.0 or above\n\n- Swift lang: 5.9 or above\n\n- Install latest LLVM:\n```\nbrew install llvm\n```\n\n- Set Environment variables, that provided during `brew` llvm install\n\n- You don't need additional configurations like `pkg-config` files, if your LLVM installation is correct and you successfully set environment variables. `Package.swift` **automatically configure** all needed things to build correctly and you don't need care more.\n\n:arrow_right: If you have problems, just check [Troubleshooting](#troubleshooting).\n\n### Supported LLVM versions\n\n- [x] v17.0\n- [x] v18.0\n\n### XCode support\n\nTo develop correctly with XCode it's necessary to generate package-config: `llvm.pc`:\n- `sh utils/llvm-pkg.swift` - will generate package config and copy to your default `pkg-config` path.\n\nAfter that XCode should correctly recognize LLVM headers path, and can build project.\n\n### Troubleshooting\n\nIf `LLVM-C` head files during compilation doesn't found, make sure that you are:\n\n- installed LLVM correctly\n```\nllc --version\n```\n\n- Set environment variables for your terminal (for example in `.zshrc`). To get instruction about variables run:\n```\nbrew info llvm\n```\n\n- **conditional build**: `Package.swift` supports conditional builds:\n  - for CLI build: `CLI_BUILD swift build` - it get's LLVM veriabels form Environment sets.\n  - `swift build` - if presented `llvm.pc` package config\n- To get more insights take a look current project [Github CI config](.github/workflows/swift.yaml).\n\n### LICENS: [MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrlsd%2Fllvm-api-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrlsd%2Fllvm-api-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrlsd%2Fllvm-api-swift/lists"}