Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LLVM 17 #460

Merged
merged 3 commits into from
Jan 13, 2024
Merged
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
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ on: [push, pull_request]

env:
CARGO_TERM_COLOR: always
DOC_LLVM_FEATURE: llvm16-0
DOC_LLVM_VERSION: '16.0'
DOC_LLVM_FEATURE: llvm17-0
DOC_LLVM_VERSION: '17.0'
DOC_PATH: target/doc

jobs:
typos:
name: Typos
runs-on: ubuntu-latest
steps:
- name: Install Rust Stable
run: rustup toolchain install stable
- name: Install typos
run: cargo install typos-cli
- name: Run typos
run: typos .
tests:
name: "LLVM ${{ matrix.llvm-version[0] }}: ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
needs: typos
strategy:
matrix:
llvm-version:
Expand All @@ -37,11 +38,14 @@ jobs:
- ["14.0", "14-0"]
- ["15.0", "15-0"]
- ["16.0", "16-0"]
- ["17.0", "17-0"]
# only use ubuntu-22.04 for llvm 16 and higher
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
llvm-version: ["16.0", "16-0"]
- os: ubuntu-22.04
llvm-version: ["17.0", "17-0"]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
Expand All @@ -58,7 +62,7 @@ jobs:
doc:
name: Documentation
runs-on: ubuntu-latest
needs: tests
needs: [typos, tests]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ llvm13-0 = ["llvm-sys-130"]
llvm14-0 = ["llvm-sys-140"]
llvm15-0 = ["llvm-sys-150"]
llvm16-0 = ["llvm-sys-160"]
llvm17-0 = ["llvm-sys-170"]
# 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
# `no-llvm-linking` feature across the board of llvm versions, as it'll cause
Expand All @@ -45,6 +46,7 @@ llvm13-0-no-llvm-linking = ["llvm13-0", "llvm-sys-130/no-llvm-linking"]
llvm14-0-no-llvm-linking = ["llvm14-0", "llvm-sys-140/no-llvm-linking"]
llvm15-0-no-llvm-linking = ["llvm15-0", "llvm-sys-150/no-llvm-linking"]
llvm16-0-no-llvm-linking = ["llvm16-0", "llvm-sys-160/no-llvm-linking"]
llvm17-0-no-llvm-linking = ["llvm17-0", "llvm-sys-170/no-llvm-linking"]

# Linking preference.
# If none of these are enabled, it defaults to force static linking.
Expand All @@ -55,27 +57,31 @@ llvm13-0-force-dynamic = ["llvm13-0", "llvm-sys-130/force-dynamic"]
llvm14-0-force-dynamic = ["llvm14-0", "llvm-sys-140/force-dynamic"]
llvm15-0-force-dynamic = ["llvm15-0", "llvm-sys-150/force-dynamic"]
llvm16-0-force-dynamic = ["llvm16-0", "llvm-sys-160/force-dynamic"]
llvm17-0-force-dynamic = ["llvm17-0", "llvm-sys-170/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"]
llvm13-0-prefer-dynamic = ["llvm13-0", "llvm-sys-130/prefer-dynamic"]
llvm14-0-prefer-dynamic = ["llvm14-0", "llvm-sys-140/prefer-dynamic"]
llvm15-0-prefer-dynamic = ["llvm15-0", "llvm-sys-150/prefer-dynamic"]
llvm16-0-prefer-dynamic = ["llvm16-0", "llvm-sys-160/prefer-dynamic"]
llvm17-0-prefer-dynamic = ["llvm17-0", "llvm-sys-170/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"]
llvm13-0-force-static = ["llvm13-0", "llvm-sys-130/force-static"]
llvm14-0-force-static = ["llvm14-0", "llvm-sys-140/force-static"]
llvm15-0-force-static = ["llvm15-0", "llvm-sys-150/force-static"]
llvm16-0-force-static = ["llvm16-0", "llvm-sys-160/force-static"]
llvm17-0-force-static = ["llvm17-0", "llvm-sys-170/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"]
llvm13-0-prefer-static = ["llvm13-0", "llvm-sys-130/prefer-static"]
llvm14-0-prefer-static = ["llvm14-0", "llvm-sys-140/prefer-static"]
llvm15-0-prefer-static = ["llvm15-0", "llvm-sys-150/prefer-static"]
llvm16-0-prefer-static = ["llvm16-0", "llvm-sys-160/prefer-static"]
llvm17-0-prefer-static = ["llvm17-0", "llvm-sys-170/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 @@ -137,6 +143,7 @@ llvm-sys-130 = { package = "llvm-sys", version = "130.0.4", optional = true }
llvm-sys-140 = { package = "llvm-sys", version = "140.0.2", optional = true }
llvm-sys-150 = { package = "llvm-sys", version = "150.0.3", optional = true }
llvm-sys-160 = { package = "llvm-sys", version = "160.1.0", optional = true }
llvm-sys-170 = { package = "llvm-sys", version = "170.0.1", optional = true }
once_cell = "1.16"
static-alloc = { version = "0.2", optional = true }
thiserror = "1.0.48"
Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Inkwell aims to help you pen your own programming languages by safely wrapping l
## Requirements

* Rust 1.56+ (Stable, Beta, or Nightly)
* LLVM 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, or 16.0
* One of LLVM 4-17

## Usage

Expand All @@ -23,26 +23,11 @@ branch with a corresponding LLVM feature flag:

```toml
[dependencies]
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm12-0"] }
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm17-0"] }
```

Supported versions:

| LLVM Version | Cargo Feature Flag |
| :----------: | :-----------: |
| 4.0.x | llvm4-0 |
| 5.0.x | llvm5-0 |
| 6.0.x | llvm6-0 |
| 7.0.x | llvm7-0 |
| 8.0.x | llvm8-0 |
| 9.0.x | llvm9-0 |
| 10.0.x | llvm10-0 |
| 11.0.x | llvm11-0 |
| 12.0.x | llvm12-0 |
| 13.0.x | llvm13-0 |
| 14.0.x | llvm14-0 |
| 15.0.x | llvm15-0 |
| 16.0.x | llvm16-0 |
LLVM 4-17 mapping to a cargo feature flag `llvmM-0` where `M` corresponds to the LLVM major version.

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/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use syn::{parse_macro_input, parse_quote};
use syn::{Attribute, Field, Ident, Item, LitFloat, Token, Variant};

// This array should match the LLVM features in the top level Cargo manifest
const FEATURE_VERSIONS: [&str; 13] = [
const FEATURE_VERSIONS: [&str; 14] = [
"llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0", "llvm12-0", "llvm13-0",
"llvm14-0", "llvm15-0", "llvm16-0",
"llvm14-0", "llvm15-0", "llvm16-0", "llvm17-0",
];

/// Gets the index of the feature version that represents `latest`
Expand Down
28 changes: 14 additions & 14 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ impl<'ctx> Builder<'ctx> {
/// both a power of 2 and under 2^64.
///
/// The final argument should be a pointer-sized integer.
///
///
/// Returns an `Err(BuilderError::AlignmentError)` if the source or destination alignments are not a power of 2.
///
/// [`TargetData::ptr_sized_int_type_in_context`](https://thedan64.github.io/inkwell/inkwell/targets/struct.TargetData.html#method.ptr_sized_int_type_in_context) will get you one of those.
Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl<'ctx> Builder<'ctx> {
/// both a power of 2 and under 2^64.
///
/// The final argument should be a pointer-sized integer.
///
///
/// Returns an `Err(BuilderError::AlignmentError)` if the source or destination alignments are not a power of 2 under 2^64.
///
/// [`TargetData::ptr_sized_int_type_in_context`](https://thedan64.github.io/inkwell/inkwell/targets/struct.TargetData.html#method.ptr_sized_int_type_in_context) will get you one of those.
Expand Down Expand Up @@ -1557,7 +1557,7 @@ impl<'ctx> Builder<'ctx> {
/// both a power of 2 and under 2^64.
///
/// The final argument should be a pointer-sized integer.
///
///
/// Returns an `Err(BuilderError::AlignmentError)` if the source alignment is not a power of 2 under 2^64.
///
/// [`TargetData::ptr_sized_int_type_in_context`](https://thedan64.github.io/inkwell/inkwell/targets/struct.TargetData.html#method.ptr_sized_int_type_in_context) will get you one of those.
Expand Down Expand Up @@ -2669,7 +2669,7 @@ impl<'ctx> Builder<'ctx> {
// REVIEW: What if instruction and basic_block are completely unrelated?
// It'd be great if we could get the BB from the instruction behind the scenes
/// Set the position of the builder to after an instruction.
///
///
/// Be sure to call one of the `position_*` methods or all `build_*` methods will return `Err(BuilderError::UnsetPosition)`.
pub fn position_at(&self, basic_block: BasicBlock<'ctx>, instruction: &InstructionValue<'ctx>) {
self.positioned.set(PositionState::Set);
Expand All @@ -2678,7 +2678,7 @@ impl<'ctx> Builder<'ctx> {
}

/// Set the position of the builder to before an instruction.
///
///
/// Be sure to call one of the `position_*` methods or all `build_*` methods will return `Err(BuilderError::UnsetPosition)`.
pub fn position_before(&self, instruction: &InstructionValue<'ctx>) {
self.positioned.set(PositionState::Set);
Expand All @@ -2687,7 +2687,7 @@ impl<'ctx> Builder<'ctx> {
}

/// Set the position of the builder to the end of a basic block.
///
///
/// Be sure to call one of the `position_*` methods or all `build_*` methods will return `Err(BuilderError::UnsetPosition)`.
pub fn position_at_end(&self, basic_block: BasicBlock<'ctx>) {
self.positioned.set(PositionState::Set);
Expand All @@ -2699,7 +2699,7 @@ impl<'ctx> Builder<'ctx> {

/// Builds an extract value instruction which extracts a `BasicValueEnum`
/// from a struct or array.
///
///
/// Returns `Err(BuilderError::ExtractOutOfRange)` if the provided index is out of bounds of the aggregate value length.
///
/// # Example
Expand Down Expand Up @@ -2738,7 +2738,7 @@ impl<'ctx> Builder<'ctx> {
/// feature = "llvm14-0"
/// ))]
/// let array = builder.build_load(array_alloca, "array_load").unwrap().into_array_value();
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0"))]
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))]
/// let array = builder.build_load(i32_type, array_alloca, "array_load").unwrap().into_array_value();
///
/// let const_int1 = i32_type.const_int(2, false);
Expand Down Expand Up @@ -2782,7 +2782,7 @@ impl<'ctx> Builder<'ctx> {

/// Builds an insert value instruction which inserts a `BasicValue` into a struct
/// or array and returns the resulting aggregate value.
///
///
/// Returns `Err(BuilderError::ExtractOutOfRange)` if the provided index is out of bounds of the aggregate value length.
///
/// # Example
Expand Down Expand Up @@ -2821,7 +2821,7 @@ impl<'ctx> Builder<'ctx> {
/// feature = "llvm14-0"
/// ))]
/// let array = builder.build_load(array_alloca, "array_load").unwrap().into_array_value();
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0"))]
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))]
/// let array = builder.build_load(i32_type, array_alloca, "array_load").unwrap().into_array_value();
///
/// let const_int1 = i32_type.const_int(2, false);
Expand Down Expand Up @@ -3215,7 +3215,7 @@ impl<'ctx> Builder<'ctx> {
/// May return of the following errors:
/// - `Err(BuilderError::BitwidthError)` if the bitwidth of the value is not a power of 2 and less than 8
/// - `Err(BuilderError:PointeeTypeMismatch)` if the pointee type does not match the value's type
///
///
/// # Example
///
/// ```
Expand Down Expand Up @@ -3256,7 +3256,7 @@ impl<'ctx> Builder<'ctx> {
));
}

#[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0")))]
#[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))]
if ptr.get_type().get_element_type() != value.get_type().into() {
return Err(BuilderError::PointeeTypeMismatch(
"Pointer's pointee type must match the value's type.",
Expand All @@ -3278,7 +3278,7 @@ impl<'ctx> Builder<'ctx> {
}

/// Builds a cmpxchg instruction. It allows you to atomically compare and replace memory.
///
///
/// May return one of the following errors:
/// - `Err(BuilderError::PointeeTypeMismatch)` if the pointer does not point to an element of the value type
/// - `Err(BuilderError::ValueTypeMismatch)` if the value to compare and the new values are not of the same type, or if
Expand Down Expand Up @@ -3334,7 +3334,7 @@ impl<'ctx> Builder<'ctx> {
));
}

#[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0")))]
#[cfg(not(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0")))]
if ptr.get_type().get_element_type().to_basic_type_enum() != cmp.get_type() {
return Err(BuilderError::PointeeTypeMismatch(
"The pointer does not point to an element of the value type.",
Expand Down
4 changes: 2 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl Context {
/// builder.build_call(callable_value, params, "exit").unwrap();
/// }
///
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0"))]
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))]
/// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap();
///
/// builder.build_return(None).unwrap();
Expand Down Expand Up @@ -1417,7 +1417,7 @@ impl<'ctx> ContextRef<'ctx> {
/// builder.build_call(callable_value, params, "exit").unwrap();
/// }
///
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0"))]
/// #[cfg(any(feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0"))]
/// builder.build_indirect_call(asm_fn, asm, params, "exit").unwrap();
///
/// builder.build_return(None).unwrap();
Expand Down
24 changes: 17 additions & 7 deletions src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
sysroot: &str,
#[cfg(any(
Expand All @@ -201,7 +202,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
sdk: &str,
) -> (Self, DICompileUnit<'ctx>) {
Expand Down Expand Up @@ -238,7 +240,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
sysroot,
#[cfg(any(
Expand All @@ -247,7 +250,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
sdk,
);
Expand Down Expand Up @@ -292,7 +296,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
sysroot: &str,
#[cfg(any(
Expand All @@ -301,7 +306,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
sdk: &str,
) -> DICompileUnit<'ctx> {
Expand Down Expand Up @@ -341,7 +347,8 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
feature = "llvm13-0",
feature = "llvm14-0",
feature = "llvm15-0",
feature = "llvm16-0"
feature = "llvm16-0",
feature = "llvm17-0"
))]
{
LLVMDIBuilderCreateCompileUnit(
Expand Down Expand Up @@ -1585,5 +1592,8 @@ mod flags {
#[llvm_versions(16.0..=latest)]
#[llvm_variant(LLVMDWARFSourceLanguageAda2012)]
Ada2012,
#[llvm_versions(17.0..=latest)]
#[llvm_variant(LLVMDWARFSourceLanguageMojo)]
Mojo,
}
}
Loading