Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on: [ push, pull_request ]

env:
CARGO_TERM_COLOR: always
DOC_LLVM_FEATURE: llvm21-1
DOC_LLVM_VERSION: "21.1"
DOC_LLVM_FEATURE: llvm23-1
DOC_LLVM_VERSION: "23.1"
DOC_PATH: target/doc

jobs:
Expand All @@ -28,25 +28,37 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
llvm-version:
- [ "12.0", "12-0" ]
- [ "13.0", "13-0" ]
- [ "14.0", "14-0" ]
- [ "15.0", "15-0" ]
- [ "16.0", "16-0" ]
- [ "17.0", "17-0" ]
- [ "18.1", "18-1" ]
- [ "19.1", "19-1", "19" ]
- [ "20.1", "20-1", "20" ]
- [ "21.1", "21-1", "21" ]
- [ "22.1", "22-1", "22" ]
include:
- os: ubuntu-22.04
- llvm-version: [ "12.0", "12-0" ]
os: ubuntu-22.04
- llvm-version: [ "13.0", "13-0" ]
os: ubuntu-22.04
- llvm-version: [ "14.0", "14-0" ]
os: ubuntu-22.04
- llvm-version: [ "15.0", "15-0" ]
os: ubuntu-22.04
- llvm-version: [ "16.0", "16-0" ]
os: ubuntu-22.04
- llvm-version: [ "17.0", "17-0" ]
os: ubuntu-22.04
- llvm-version: [ "18.1", "18-1" ]
os: ubuntu-22.04
- llvm-version: [ "19.1", "19-1", "19" ]
os: ubuntu-latest
- llvm-version: [ "20.1", "20-1", "20" ]
os: ubuntu-latest
- llvm-version: [ "21.1", "21-1", "21" ]
os: ubuntu-latest
- llvm-version: [ "22.1", "22-1", "22" ]
os: ubuntu-latest
- llvm-version: [ "23.1", "23-1", "23" ]
os: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Install libtinfo5
run: sudo apt update && sudo apt install -y libtinfo5
- name: Install libtinfo5 (LLVM < 19)
if: ${{ matrix.llvm-version[0] < 19 }}
run: sudo apt-get update && sudo apt-get install -y libtinfo5
- name: Install LLVM and Clang (LLVM >= 19.1)
if: ${{ matrix.llvm-version[0] >= 19 }}
run: |
Expand All @@ -61,9 +73,9 @@ jobs:
llvm-${{ matrix.llvm-version[2] }}-runtime \
libpolly-${{ matrix.llvm-version[2] }}-dev
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${{ matrix.llvm-version[2] }} 10
- name: Install LLVM and Clang (12 <= LLVM <= 19)
- name: Install LLVM and Clang (12 <= LLVM < 19)
uses: KyleMayes/install-llvm-action@v2
if: ${{ matrix.llvm-version[0] >= 12 && matrix.llvm-version[0] <= 19 }}
if: ${{ matrix.llvm-version[0] >= 12 && matrix.llvm-version[0] < 19 }}
with:
version: ${{ matrix.llvm-version[0] }}
- name: llvm-config
Expand All @@ -89,7 +101,7 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
env:
LLVM_SYS_211_PREFIX: ${{ github.workspace }}/llvm
LLVM_SYS_231_PREFIX: ${{ github.workspace }}/llvm
needs: [ lint, tests ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
Expand Down
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ llvm19-1 = ["llvm-sys-191"]
llvm20-1 = ["llvm-sys-201"]
llvm21-1 = ["llvm-sys-211"]
llvm22-1 = ["llvm-sys-221"]
llvm23-1 = ["llvm-sys-231"]

# Don't link against LLVM libraries. This is useful if another dependency is
# installing LLVM. See llvm-sys for more details. We can't enable a single
Expand All @@ -44,6 +45,7 @@ llvm19-1-no-llvm-linking = ["llvm19-1", "llvm-sys-191/no-llvm-linking"]
llvm20-1-no-llvm-linking = ["llvm20-1", "llvm-sys-201/no-llvm-linking"]
llvm21-1-no-llvm-linking = ["llvm21-1", "llvm-sys-211/no-llvm-linking"]
llvm22-1-no-llvm-linking = ["llvm22-1", "llvm-sys-221/no-llvm-linking"]
llvm23-1-no-llvm-linking = ["llvm23-1", "llvm-sys-231/no-llvm-linking"]

# Linking preference.
# If none of these are enabled, it defaults to force static linking.
Expand All @@ -60,6 +62,7 @@ llvm19-1-force-dynamic = ["llvm19-1", "llvm-sys-191/force-dynamic"]
llvm20-1-force-dynamic = ["llvm20-1", "llvm-sys-201/force-dynamic"]
llvm21-1-force-dynamic = ["llvm21-1", "llvm-sys-211/force-dynamic"]
llvm22-1-force-dynamic = ["llvm22-1", "llvm-sys-221/force-dynamic"]
llvm23-1-force-dynamic = ["llvm23-1", "llvm-sys-231/force-dynamic"]

# Prefer dynamic linking against LLVM libraries. See llvm-sys for more details
llvm12-0-prefer-dynamic = ["llvm12-0", "llvm-sys-120/prefer-dynamic"]
Expand All @@ -73,6 +76,7 @@ llvm19-1-prefer-dynamic = ["llvm19-1", "llvm-sys-191/prefer-dynamic"]
llvm20-1-prefer-dynamic = ["llvm20-1", "llvm-sys-201/prefer-dynamic"]
llvm21-1-prefer-dynamic = ["llvm21-1", "llvm-sys-211/prefer-dynamic"]
llvm22-1-prefer-dynamic = ["llvm22-1", "llvm-sys-221/prefer-dynamic"]
llvm23-1-prefer-dynamic = ["llvm23-1", "llvm-sys-231/prefer-dynamic"]

# Force static linking against LLVM libraries. See llvm-sys for more details
llvm12-0-force-static = ["llvm12-0", "llvm-sys-120/force-static"]
Expand All @@ -86,6 +90,7 @@ llvm19-1-force-static = ["llvm19-1", "llvm-sys-191/force-static"]
llvm20-1-force-static = ["llvm20-1", "llvm-sys-201/force-static"]
llvm21-1-force-static = ["llvm21-1", "llvm-sys-211/force-static"]
llvm22-1-force-static = ["llvm22-1", "llvm-sys-221/force-static"]
llvm23-1-force-static = ["llvm23-1", "llvm-sys-231/force-static"]

# Prefer static linking against LLVM libraries. See llvm-sys for more details
llvm12-0-prefer-static = ["llvm12-0", "llvm-sys-120/prefer-static"]
Expand All @@ -99,6 +104,7 @@ llvm19-1-prefer-static = ["llvm19-1", "llvm-sys-191/prefer-static"]
llvm20-1-prefer-static = ["llvm20-1", "llvm-sys-201/prefer-static"]
llvm21-1-prefer-static = ["llvm21-1", "llvm-sys-211/prefer-static"]
llvm22-1-prefer-static = ["llvm22-1", "llvm-sys-221/prefer-static"]
llvm23-1-prefer-static = ["llvm23-1", "llvm-sys-231/prefer-static"]

# Don't force linking to libffi on non-windows platforms. Without this feature
# inkwell always links to libffi on non-windows platforms.
Expand Down Expand Up @@ -157,6 +163,7 @@ llvm-sys-191 = { package = "llvm-sys", version = "191.0.0", optional = true }
llvm-sys-201 = { package = "llvm-sys", version = "201.0.0", optional = true }
llvm-sys-211 = { package = "llvm-sys", version = "211.0.0", optional = true }
llvm-sys-221 = { package = "llvm-sys", version = "221.0.0", optional = true }
llvm-sys-231 = { package = "llvm-sys", version = "231.0.0-rc2", optional = true }

libc = "0.2"
thiserror = "2.0.11"
Expand All @@ -176,7 +183,7 @@ version = "0.62.2"
features = ["Win32_System_SystemInformation", "Win32_System_Memory"]

[package.metadata.docs.rs]
features = ["llvm22-1-no-llvm-linking"]
features = ["llvm23-1-no-llvm-linking"]

[badges]
codecov = { repository = "TheDan64/inkwell" }
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ Inkwell aims to help you pen your own programming languages by safely wrapping l
## Requirements

* Rust 1.85+
* One of LLVM 12-22
* One of LLVM 12-23

## Usage

You'll need to point your Cargo.toml to use a single LLVM version feature flag corresponding to your LLVM version as such:

```toml
[dependencies]
inkwell = { version = "0.10.0", features = ["llvm22-1"] }
inkwell = { version = "0.10.0", features = ["llvm23-1"] }
```

Supported versions:
LLVM 12-22 mapping to a cargo feature flag `llvmM-N` where `M` and `N` correspond to the LLVM major and minor version, e.g. `llvm18-1` for LLVM 18.1.x.
LLVM 12-23 mapping to a cargo feature flag `llvmM-N` where `M` and `N` correspond to the LLVM major and minor version, e.g. `llvm18-1` for LLVM 18.1.x.

Please be aware that we may make breaking changes on master from time to time since we are
pre-v1.0.0, in compliance with semver. Please prefer a crates.io release whenever possible!
Expand Down
4 changes: 2 additions & 2 deletions internal_macros/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use syn::{Lit, RangeLimits};

// This array should match the LLVM features in the top level Cargo manifest
const FEATURE_VERSIONS: &[&str] = &[
"llvm12-0", "llvm13-0", "llvm14-0", "llvm15-0", "llvm16-0", "llvm17-0", "llvm18-1", "llvm19-1",
"llvm20-1", "llvm21-1", "llvm22-1",
"llvm12-0", "llvm13-0", "llvm14-0", "llvm15-0", "llvm16-0", "llvm17-0", "llvm18-1", "llvm19-1", "llvm20-1",
"llvm21-1", "llvm22-1", "llvm23-1",
];

pub struct VersionRange {
Expand Down
4 changes: 2 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3730,9 +3730,9 @@ impl<'ctx> Builder<'ctx> {
/// let i32_ptr_param = fn_value.get_first_param().unwrap().into_pointer_value();
/// let builder = context.create_builder();
/// builder.position_at_end(entry);
/// #[cfg(any(feature = "llvm21-1", feature = "llvm22-1"))]
/// #[cfg(any(feature = "llvm21-1", feature = "llvm22-1", feature = "llvm23-1"))]
/// builder.build_atomicrmw(AtomicRMWBinOp::Add, i32_ptr_param, i32_seven, AtomicOrdering::Monotonic).unwrap();
/// #[cfg(not(any(feature = "llvm21-1", feature = "llvm22-1")))]
/// #[cfg(not(any(feature = "llvm21-1", feature = "llvm22-1", feature = "llvm23-1")))]
/// builder.build_atomicrmw(AtomicRMWBinOp::Add, i32_ptr_param, i32_seven, AtomicOrdering::AcquireRelease).unwrap();
/// builder.build_return(None).unwrap();
/// ```
Expand Down
8 changes: 4 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ impl ContextImpl {
let mut module = ptr::null_mut();
let mut err_str = ptr::null_mut();

#[cfg(not(feature = "llvm22-1"))]
#[cfg(not(any(feature = "llvm22-1", feature = "llvm23-1")))]
let code =
unsafe { LLVMParseIRInContext(self.as_mut_ptr(), memory_buffer.as_mut_ptr(), &mut module, &mut err_str) };
#[cfg(feature = "llvm22-1")]
#[cfg(any(feature = "llvm22-1", feature = "llvm23-1"))]
let code =
unsafe { LLVMParseIRInContext2(self.as_mut_ptr(), memory_buffer.as_mut_ptr(), &mut module, &mut err_str) };

Expand Down Expand Up @@ -618,7 +618,7 @@ impl Context {
/// builder.build_call(callable_value, params, "exit").unwrap();
/// }
///
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1", feature = "llvm22-1"))]
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1", feature = "llvm22-1", feature = "llvm23-1"))]
/// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap();
///
/// builder.build_return(None).unwrap();
Expand Down Expand Up @@ -1480,7 +1480,7 @@ impl<'ctx> ContextRef<'ctx> {
/// builder.build_call(callable_value, params, "exit").unwrap();
/// }
///
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1", feature = "llvm22-1"))]
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", feature = "llvm18-1", feature = "llvm19-1", feature = "llvm20-1", feature = "llvm21-1", feature = "llvm22-1", feature = "llvm23-1"))]
/// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap();
///
/// builder.build_return(None).unwrap();
Expand Down
18 changes: 12 additions & 6 deletions src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm19-1",
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1"
feature = "llvm22-1",
feature = "llvm23-1"
))]
{
// In LLVM 19+, the insert... functions return a DbgRecord, not a Value.
Expand All @@ -941,7 +942,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm19-1",
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1"
feature = "llvm22-1",
feature = "llvm23-1"
)))]
{
unsafe { InstructionValue::new(value_ref) }
Expand Down Expand Up @@ -972,7 +974,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm19-1",
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1"
feature = "llvm22-1",
feature = "llvm23-1"
))]
{
// In LLVM 19+, the insert... functions return a DbgRecord, not a Value.
Expand All @@ -985,7 +988,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm19-1",
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1"
feature = "llvm22-1",
feature = "llvm23-1"
)))]
{
unsafe { InstructionValue::new(value_ref) }
Expand Down Expand Up @@ -1032,7 +1036,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm19-1",
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1"
feature = "llvm22-1",
feature = "llvm23-1"
))]
{
// In LLVM 19+, the insert... functions return a DbgRecord, not a Value.
Expand All @@ -1045,7 +1050,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm19-1",
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1"
feature = "llvm22-1",
feature = "llvm23-1"
)))]
{
unsafe { InstructionValue::new(value_ref) }
Expand Down
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub extern crate llvm_sys_201 as llvm_sys;
pub extern crate llvm_sys_211 as llvm_sys;
#[cfg(feature = "llvm22-1")]
pub extern crate llvm_sys_221 as llvm_sys;
#[cfg(feature = "llvm23-1")]
pub extern crate llvm_sys_231 as llvm_sys;

use llvm_sys::target_machine::LLVMCodeGenOptLevel;
use llvm_sys::{
Expand Down Expand Up @@ -118,7 +120,8 @@ assert_unique_used_features! {
"llvm19-1",
"llvm20-1",
"llvm21-1",
"llvm22-1"
"llvm22-1",
"llvm23-1"
}

#[cfg(all(
Expand Down Expand Up @@ -387,6 +390,14 @@ pub enum AtomicRMWBinOp {
#[llvm_versions(21..)]
#[llvm_variant(LLVMAtomicRMWBinOpFMinimum)]
FMinimum,

#[llvm_versions(23..)]
#[llvm_variant(LLVMAtomicRMWBinOpFMaximumNum)]
FMaximumNum,

#[llvm_versions(23..)]
#[llvm_variant(LLVMAtomicRMWBinOpFMinimumNum)]
FMinimumNum,
}

/// Defines the optimization level used to compile a [`Module`](crate::module::Module).
Expand Down
1 change: 1 addition & 0 deletions src/types/array_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl<'ctx> ArrayType<'ctx> {
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1",
),
deprecated(
note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead."
Expand Down
20 changes: 18 additions & 2 deletions src/types/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,16 @@ impl<'ctx> AnyTypeEnum<'ctx> {
// FIXME: should inkwell support metadata as AnyType?
LLVMTypeKind::LLVMMetadataTypeKind => panic!("Metadata type is not supported as AnyType."),

#[cfg(not(any(feature = "llvm20-1", feature = "llvm21-1", feature = "llvm22-1")))]
#[cfg(not(any(
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1"
)))]
LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"),
LLVMTypeKind::LLVMX86_AMXTypeKind => panic!("FIXME: Unsupported type: AMX"),
#[cfg(feature = "llvm23-1")]
LLVMTypeKind::LLVMByteTypeKind => panic!("FIXME: Unsupported type: Byte"),
LLVMTypeKind::LLVMTokenTypeKind => panic!("FIXME: Unsupported type: Token"),
#[cfg(any(
feature = "llvm16-0",
Expand All @@ -278,6 +285,7 @@ impl<'ctx> AnyTypeEnum<'ctx> {
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1",
))]
LLVMTypeKind::LLVMTargetExtTypeKind => panic!("FIXME: Unsupported type: TargetExt"),
}
Expand Down Expand Up @@ -448,10 +456,17 @@ impl<'ctx> BasicTypeEnum<'ctx> {
},
LLVMTypeKind::LLVMMetadataTypeKind => panic!("Unsupported basic type: Metadata"),
// see https://llvm.org/docs/LangRef.html#x86-mmx-type
#[cfg(not(any(feature = "llvm20-1", feature = "llvm21-1", feature = "llvm22-1")))]
#[cfg(not(any(
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1"
)))]
LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("Unsupported basic type: MMX"),
// see https://llvm.org/docs/LangRef.html#x86-amx-type
LLVMTypeKind::LLVMX86_AMXTypeKind => unreachable!("Unsupported basic type: AMX"),
#[cfg(feature = "llvm23-1")]
LLVMTypeKind::LLVMByteTypeKind => unreachable!("Unsupported basic type: Byte"),
LLVMTypeKind::LLVMLabelTypeKind => unreachable!("Unsupported basic type: Label"),
LLVMTypeKind::LLVMVoidTypeKind => unreachable!("Unsupported basic type: VoidType"),
LLVMTypeKind::LLVMFunctionTypeKind => unreachable!("Unsupported basic type: FunctionType"),
Expand All @@ -464,6 +479,7 @@ impl<'ctx> BasicTypeEnum<'ctx> {
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1",
))]
LLVMTypeKind::LLVMTargetExtTypeKind => unreachable!("Unsupported basic type: TargetExt"),
}
Expand Down
1 change: 1 addition & 0 deletions src/types/float_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ impl<'ctx> FloatType<'ctx> {
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1",
),
deprecated(
note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead."
Expand Down
1 change: 1 addition & 0 deletions src/types/fn_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl<'ctx> FunctionType<'ctx> {
feature = "llvm20-1",
feature = "llvm21-1",
feature = "llvm22-1",
feature = "llvm23-1",
),
deprecated(
note = "Starting from version 15.0, LLVM doesn't differentiate between pointer types. Use Context::ptr_type instead."
Expand Down
Loading
Loading