Skip to content

feat: add llvm 19 support #27

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
runs-on: ubuntu-latest
env:
LLVM_INSTALL_PATH: ~/llvm
LLVM_VERSION: "18"
LLVM_VERSION_IN_FEATURE: "18-1"
LLVM_LIB_NAME: "libLLVM.so.18.1"
LLVM_VERSION: "19"
LLVM_VERSION_IN_FEATURE: "19-1"
LLVM_LIB_NAME: "libLLVM.so.19.1"
steps:
- name: Checkout Repo
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- ["16", "16-0", "v16.0.2-rust-1.71/llvm-lld-16.0.2-rust-1.71-linux-x86_64.tar.gz", "libLLVM-16.so"]
- ["17", "17-0", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-linux-x86_64.tar.gz", "libLLVM-17.so"]
- ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-linux-x86_64.tar.gz", "libLLVM.so.18.1"]
- ["19", "19-1", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-linux-x86_64.tar.gz", "libLLVM.so.19.1"]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -114,6 +115,7 @@ jobs:
- ["16", "16-0", "1.71", "v16.0.2-rust-1.71/llvm-lld-16.0.2-rust-1.71-linux-x86_64.tar.gz", "libLLVM-16.so"]
- ["17", "17-0", "1.75", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-linux-x86_64.tar.gz", "libLLVM-17.so"]
- ["18", "18-1", "1.78", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-linux-x86_64.tar.gz", "libLLVM.so.18.1"]
- ["19", "19-1", "1.84", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-linux-x86_64.tar.gz", "libLLVM.so.19.1"]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- ["16", "16-0", "v16.0.2-rust-1.71/llvm-lld-16.0.2-rust-1.71-macos-x86_64.tar.gz", "macos-13"]
- ["17", "17-0", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-macos-x86_64.tar.gz", "macos-13"]
- ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-macos-arm64.tar.gz", "macos-latest"]
- ["19", "19-1", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-macos-arm64.tar.gz", "macos-latest"]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
runs-on: ubuntu-latest
env:
LLVM_INSTALL_PATH: ~/llvm
LLVM_VERSION: "18"
LLVM_VERSION_IN_FEATURE: "18-1"
LLVM_LIB_NAME: "libLLVM.so.18.1"
LLVM_VERSION: "19"
LLVM_VERSION_IN_FEATURE: "19-1"
LLVM_LIB_NAME: "libLLVM.so.19.1"
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- ["16", "16-0", "v16.0.2-rust-1.71/llvm-lld-16.0.2-rust-1.71-windows-x86_64.7z"]
- ["17", "17-0", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-windows-x86_64.7z"]
- ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-windows-x86_64.7z"]
- ["19", "19-1", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-windows-x86_64.7z"]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
Expand Down Expand Up @@ -112,6 +113,7 @@ jobs:
- ["16", "16-0", "1.71", "v16.0.2-rust-1.71/llvm-lld-16.0.2-rust-1.71-windows-x86_64.7z"]
- ["17", "17-0", "1.75", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-windows-x86_64.7z"]
- ["18", "18-1", "1.78", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-windows-x86_64.7z"]
- ["19", "19-1", "1.84", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-windows-x86_64.7z"]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
resolver = "2"
members = ["llvm-plugin", "llvm-plugin-macros"]

[patch.crates-io]
inkwell = { git = "https://github.com/stevefan1999-personal/inkwell" }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ When importing this crate in your `Cargo.toml`, you will need to specify the LLV

```toml
[dependencies]
llvm-plugin = { version = "0.6", features = ["llvm18-1"] }
llvm-plugin = { version = "0.6", features = ["llvm19-1"] }
```

Supported versions: LLVM 10-18 mapping to a cargo feature flag `llvmX-Y` where `X` and `Y` are the LLVM major and minor versions.
Supported versions: LLVM 10-19 mapping to a cargo feature flag `llvmX-Y` where `X` and `Y` are the LLVM major and minor versions.

## Getting Started

Expand Down
10 changes: 8 additions & 2 deletions examples/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ fn encode_global_strings<'a>(module: &mut Module<'a>) -> Vec<GlobalString<'a>> {
_ => None,
})
.filter(|(_, _, arr)| {
// needs to be called before `get_string_constant`, otherwise it may crash
// needs to be called before `as_const_string`, otherwise it may crash
arr.is_const_string()
})
.filter_map(|(global, stru, arr)| {
// we ignore non-UTF8 strings, since they are probably not human-readable
let s = arr.get_string_constant().and_then(|s| s.to_str().ok())?;
let s = arr.as_const_string().and_then(|s| str::from_utf8(s).ok())?;
let encoded_str = s.bytes().map(|c| c + 1).collect::<Vec<_>>();
Some((global, stru, encoded_str))
})
Expand Down Expand Up @@ -156,6 +156,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
)))]
let var10 = unsafe {
builder.build_gep(
Expand All @@ -170,6 +171,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
let var10 = unsafe {
builder.build_gep(
Expand All @@ -185,13 +187,15 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
)))]
let var11 = builder.build_load(phi1.as_basic_value().into_pointer_value(), "");
#[cfg(any(
feature = "llvm15-0",
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
let var11 = builder
.build_load(cx.i8_type(), phi1.as_basic_value().into_pointer_value(), "")
Expand Down Expand Up @@ -254,6 +258,7 @@ fn create_decode_stub<'a>(
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
)))]
let s = builder
.build_struct_gep(gs.as_pointer_value(), id, "")
Expand All @@ -263,6 +268,7 @@ fn create_decode_stub<'a>(
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
let s = {
let i8_ty_ptr = cx.i8_type().ptr_type(AddressSpace::default());
Expand Down
5 changes: 3 additions & 2 deletions llvm-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ llvm14-0 = ["inkwell/llvm14-0-no-llvm-linking"]
llvm15-0 = ["inkwell/llvm15-0-no-llvm-linking"]
llvm16-0 = ["inkwell/llvm16-0-no-llvm-linking"]
llvm17-0 = ["inkwell/llvm17-0-no-llvm-linking"]
llvm18-1 = ["inkwell/llvm18-0-no-llvm-linking"]
llvm18-1 = ["inkwell/llvm18-1-no-llvm-linking"]
llvm19-1 = ["inkwell/llvm19-1-no-llvm-linking"]

target-x86 = ["inkwell/target-x86"]
target-arm = ["inkwell/target-arm"]
Expand All @@ -53,7 +54,7 @@ target-riscv = ["inkwell/target-riscv"]
target-all = ["inkwell/target-all"]

[dependencies]
inkwell = "0.5"
inkwell = "0.6"
llvm-plugin-macros = { path = "../llvm-plugin-macros", version = "0.2", optional = true }

[build-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions llvm-plugin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ mod llvm_sys {
(17, 0)
} else if cfg!(feature = "llvm18-1") {
(18, 1)
} else if cfg!(feature = "llvm19-1") {
(19, 1)
} else {
panic!("Missing llvm* feature")
}
Expand Down
6 changes: 5 additions & 1 deletion llvm-plugin/cpp/.clang-tidy
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# https://github.com/llvm/llvm-project/blob/main/.clang-tidy
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,readability-identifier-naming'
Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-const-correctness,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,-misc-use-anonymous-namespace,readability-identifier-naming,-misc-include-cleaner'
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
# Exclude from scanning as this is an exported symbol used for fuzzing
# throughout the code base.
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: "LLVMFuzzerTestOneInput"
- key: readability-identifier-naming.MemberCase
value: CamelCase
- key: readability-identifier-naming.ParameterCase
Expand Down
8 changes: 8 additions & 0 deletions llvm-plugin/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn passBuilderAddFullLinkTimeOptimizationLastEPCallback(
builder: *mut c_void,
Expand All @@ -22,6 +23,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn passBuilderAddFullLinkTimeOptimizationEarlyEPCallback(
builder: *mut c_void,
Expand All @@ -35,6 +37,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn passBuilderAddOptimizerEarlyEPCallback(
builder: *mut c_void,
Expand All @@ -52,6 +55,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn passBuilderAddOptimizerLastEPCallback(
builder: *mut c_void,
Expand All @@ -68,6 +72,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn passBuilderAddPipelineEarlySimplificationEPCallback(
builder: *mut c_void,
Expand All @@ -84,6 +89,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn passBuilderAddPipelineStartEPCallback(
builder: *mut c_void,
Expand Down Expand Up @@ -156,6 +162,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn modulePassManagerIsEmpty(manager: *mut c_void) -> bool;

Expand All @@ -174,6 +181,7 @@ extern "C" {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub(crate) fn functionPassManagerIsEmpty(manager: *mut c_void) -> bool;

Expand Down
6 changes: 6 additions & 0 deletions llvm-plugin/src/pass_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ impl PassBuilder {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn add_pipeline_start_ep_callback<T>(&mut self, cb: T)
where
Expand Down Expand Up @@ -375,6 +376,7 @@ impl PassBuilder {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn add_pipeline_early_simplification_ep_callback<T>(&mut self, cb: T)
where
Expand Down Expand Up @@ -427,6 +429,7 @@ impl PassBuilder {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn add_optimizer_last_ep_callback<T>(&mut self, cb: T)
where
Expand Down Expand Up @@ -475,6 +478,7 @@ impl PassBuilder {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn add_full_lto_early_ep_callback<T>(&mut self, cb: T)
where
Expand Down Expand Up @@ -523,6 +527,7 @@ impl PassBuilder {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn add_full_lto_last_ep_callback<T>(&mut self, cb: T)
where
Expand Down Expand Up @@ -571,6 +576,7 @@ impl PassBuilder {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn add_optimizer_early_ep_callback<T>(&mut self, cb: T)
where
Expand Down
2 changes: 2 additions & 0 deletions llvm-plugin/src/pass_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl ModulePassManager {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn is_empty(&self) -> bool {
unsafe { super::modulePassManagerIsEmpty(self.inner) }
Expand Down Expand Up @@ -143,6 +144,7 @@ impl FunctionPassManager {
feature = "llvm16-0",
feature = "llvm17-0",
feature = "llvm18-1",
feature = "llvm19-1",
))]
pub fn is_empty(&self) -> bool {
unsafe { super::functionPassManagerIsEmpty(self.inner) }
Expand Down
3 changes: 3 additions & 0 deletions tests/plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ members = [
"plugin6",
"plugin7",
]

[patch.crates-io]
inkwell = { git = "https://github.com/stevefan1999-personal/inkwell" }
1 change: 1 addition & 0 deletions tests/plugins/plugin1-lld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/plugin1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/plugin2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/plugin3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/plugin4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/plugin5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
1 change: 1 addition & 0 deletions tests/plugins/plugin6/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ llvm15-0 = ["llvm-plugin/llvm15-0"]
llvm16-0 = ["llvm-plugin/llvm16-0"]
llvm17-0 = ["llvm-plugin/llvm17-0"]
llvm18-1 = ["llvm-plugin/llvm18-1"]
llvm19-1 = ["llvm-plugin/llvm19-1"]

target-x86 = ["llvm-plugin/target-x86"]
target-arm = ["llvm-plugin/target-arm"]
Expand Down
Loading