From 6744f8369e333b9ddba1a4bfccb6df26df966151 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 3 Dec 2024 03:35:32 +0900 Subject: [PATCH 01/23] fix(#14): build script does not rebuild when the LLVM prefix has been corrected from an invalid path to a valid one --- llvm-plugin/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-plugin/build.rs b/llvm-plugin/build.rs index aa3796d..b9d1689 100644 --- a/llvm-plugin/build.rs +++ b/llvm-plugin/build.rs @@ -4,6 +4,7 @@ fn main() { let (major, minor) = *llvm_sys::LLVM_VERSION_FROM_FEATURES; println!("cargo:rustc-env=LLVM_VERSION_MAJOR={}{}", major, minor); + println!("cargo:rerun-if-env-changed={}", &*llvm_sys::ENV_LLVM_PREFIX); if llvm_sys::LLVM_CONFIG_PATH.is_none() { println!("cargo:rustc-cfg=LLVM_NOT_FOUND"); return; @@ -54,7 +55,6 @@ fn main() { } println!("cargo:rerun-if-changed=cpp"); - println!("cargo:rerun-if-env-changed={}", &*llvm_sys::ENV_LLVM_PREFIX); } // Most code from this module was taken from the `llvm-sys` crate. From e03dde05d2649296b5011ed627054d07d0ffc044 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 10 Jan 2025 10:03:33 +0100 Subject: [PATCH 02/23] refactor: fix rust 1.82 `unused_must_use` lint --- llvm-plugin/src/analysis.rs | 4 ++-- llvm-plugin/src/pass_builder.rs | 20 ++++++++++---------- llvm-plugin/src/pass_manager.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/llvm-plugin/src/analysis.rs b/llvm-plugin/src/analysis.rs index b408ab3..e207080 100644 --- a/llvm-plugin/src/analysis.rs +++ b/llvm-plugin/src/analysis.rs @@ -128,7 +128,7 @@ impl FunctionAnalysisManager { *res_deleter = result_deleter::; } - Box::into_raw(pass); + let _ = Box::into_raw(pass); #[allow(forgetting_copy_types)] std::mem::forget(function); } @@ -282,7 +282,7 @@ impl ModuleAnalysisManager { *res_deleter = result_deleter::; } - Box::into_raw(pass); + let _ = Box::into_raw(pass); std::mem::forget(module); } diff --git a/llvm-plugin/src/pass_builder.rs b/llvm-plugin/src/pass_builder.rs index 3afa1e2..a535ab8 100644 --- a/llvm-plugin/src/pass_builder.rs +++ b/llvm-plugin/src/pass_builder.rs @@ -49,7 +49,7 @@ impl PassBuilder { let res = cb(name, &mut manager); - Box::into_raw(cb); + let _ = Box::into_raw(cb); matches!(res, PipelineParsing::Parsed) } @@ -93,7 +93,7 @@ impl PassBuilder { let res = cb(name, &mut manager); - Box::into_raw(cb); + let _ = Box::into_raw(cb); matches!(res, PipelineParsing::Parsed) } @@ -130,7 +130,7 @@ impl PassBuilder { cb(&mut manager); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -166,7 +166,7 @@ impl PassBuilder { cb(&mut manager); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -211,7 +211,7 @@ impl PassBuilder { cb(&mut manager, opt); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -254,7 +254,7 @@ impl PassBuilder { cb(&mut manager, opt); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -297,7 +297,7 @@ impl PassBuilder { cb(&mut manager, opt); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -341,7 +341,7 @@ impl PassBuilder { cb(&mut manager, opt); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -384,7 +384,7 @@ impl PassBuilder { cb(&mut manager, opt); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { @@ -427,7 +427,7 @@ impl PassBuilder { cb(&mut manager, opt); - Box::into_raw(cb); + let _ = Box::into_raw(cb); } unsafe { diff --git a/llvm-plugin/src/pass_manager.rs b/llvm-plugin/src/pass_manager.rs index 3d1e083..cd96eb8 100644 --- a/llvm-plugin/src/pass_manager.rs +++ b/llvm-plugin/src/pass_manager.rs @@ -48,7 +48,7 @@ impl ModulePassManager { let preserve = pass.run_pass(&mut module, &manager); - Box::into_raw(pass); + let _ = Box::into_raw(pass); std::mem::forget(module); preserve @@ -110,7 +110,7 @@ impl FunctionPassManager { let preserve = pass.run_pass(&mut function, &manager); - Box::into_raw(pass); + let _ = Box::into_raw(pass); #[allow(forgetting_copy_types)] std::mem::forget(function); From 2d4df38c20358d17bbf23df7052ba70888e878bc Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 10 Jan 2025 10:36:54 +0100 Subject: [PATCH 03/23] fix: rename feature `llvm18-0` to `llvm18-1` LLVM 18.0 doesn't exist for some reason. A side-effect is that we can no longer use the convenient macro `inkwell_internals::llvm_versions` (which only works if the feature is named "llvm18-0"). --- .github/workflows/linux.yml | 4 +- .github/workflows/macos.yml | 2 +- .github/workflows/windows.yml | 4 +- README.md | 4 +- examples/strings.rs | 12 ++--- llvm-plugin/Cargo.toml | 3 +- llvm-plugin/build.rs | 4 +- llvm-plugin/src/ffi.rs | 74 ++++++++++++++++++++++++---- llvm-plugin/src/pass_builder.rs | 54 +++++++++++++++++--- llvm-plugin/src/pass_manager.rs | 21 ++++++-- tests/plugins/plugin1-lld/Cargo.toml | 2 +- tests/plugins/plugin1/Cargo.toml | 2 +- tests/plugins/plugin2/Cargo.toml | 2 +- tests/plugins/plugin3/Cargo.toml | 2 +- tests/plugins/plugin4/Cargo.toml | 2 +- tests/plugins/plugin5/Cargo.toml | 2 +- tests/plugins/plugin6/Cargo.toml | 2 +- tests/plugins/plugin6/src/lib.rs | 8 +-- tests/plugins/plugin7/Cargo.toml | 2 +- tests/plugins/plugin7/src/lib.rs | 4 +- 20 files changed, 158 insertions(+), 52 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 80c3fa5..22d46f7 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -23,7 +23,7 @@ jobs: - ["15", "15-0", "v15.0.0-rust-1.65/llvm-lld-15.0.0-rust-1.65-linux-x86_64.tar.gz", "libLLVM-15.so"] - ["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-0", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-linux-x86_64.tar.gz", "libLLVM.so.18.1"] + - ["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"] steps: - name: Checkout Repo uses: actions/checkout@v2 @@ -113,7 +113,7 @@ jobs: - ["15", "15-0", "1.65", "v15.0.0-rust-1.65/llvm-lld-15.0.0-rust-1.65-linux-x86_64.tar.gz", "libLLVM-15.so"] - ["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-0", "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"] + - ["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"] steps: - name: Checkout Repo uses: actions/checkout@v2 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 3e0b4db..ea2fd58 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -22,7 +22,7 @@ jobs: - ["15", "15-0", "v15.0.0-rust-1.65/llvm-lld-15.0.0-rust-1.65-macos-x86_64.tar.gz", "macos-13"] - ["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-0", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-macos-arm64.tar.gz", "macos-latest"] + - ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-macos-arm64.tar.gz", "macos-latest"] steps: - name: Checkout Repo uses: actions/checkout@v2 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3ef98f8..c38f613 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -22,7 +22,7 @@ jobs: - ["15", "15-0", "v15.0.0-rust-1.65/llvm-lld-15.0.0-rust-1.65-windows-x86_64.7z"] - ["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-0", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-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"] steps: - name: Checkout Repo uses: actions/checkout@v2 @@ -111,7 +111,7 @@ jobs: - ["15", "15-0", "1.65", "v15.0.0-rust-1.65/llvm-lld-15.0.0-rust-1.65-windows-x86_64.7z"] - ["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-0", "1.78", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-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"] steps: - name: Checkout Repo uses: actions/checkout@v2 diff --git a/README.md b/README.md index 1576437..725a64c 100644 --- a/README.md +++ b/README.md @@ -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-0"] } +llvm-plugin = { version = "0.6", features = ["llvm18-1"] } ``` -Supported versions: LLVM 10-18 mapping to a cargo feature flag `llvm*-0` where `*` corresponds to the LLVM major version. +Supported versions: LLVM 10-18 mapping to a cargo feature flag `llvmX-Y` where `X` and `Y` are the LLVM major and minor versions. ## Getting Started diff --git a/examples/strings.rs b/examples/strings.rs index 8a75f46..7b8cfb8 100644 --- a/examples/strings.rs +++ b/examples/strings.rs @@ -155,7 +155,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", )))] let var10 = unsafe { builder.build_gep( @@ -169,7 +169,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] let var10 = unsafe { builder.build_gep( @@ -184,14 +184,14 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-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-0", + feature = "llvm18-1", ))] let var11 = builder .build_load(cx.i8_type(), phi1.as_basic_value().into_pointer_value(), "") @@ -253,7 +253,7 @@ fn create_decode_stub<'a>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", )))] let s = builder .build_struct_gep(gs.as_pointer_value(), id, "") @@ -262,7 +262,7 @@ fn create_decode_stub<'a>( feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] let s = { let i8_ty_ptr = cx.i8_type().ptr_type(AddressSpace::default()); diff --git a/llvm-plugin/Cargo.toml b/llvm-plugin/Cargo.toml index 794c6d6..ac49a8f 100644 --- a/llvm-plugin/Cargo.toml +++ b/llvm-plugin/Cargo.toml @@ -32,7 +32,7 @@ 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-0 = ["inkwell/llvm18-0-no-llvm-linking"] +llvm18-1 = ["inkwell/llvm18-0-no-llvm-linking"] target-x86 = ["inkwell/target-x86"] target-arm = ["inkwell/target-arm"] @@ -54,7 +54,6 @@ target-all = ["inkwell/target-all"] [dependencies] inkwell = "0.5" -inkwell_internals = "0.10.0" llvm-plugin-macros = { path = "../llvm-plugin-macros", version = "0.2", optional = true } [build-dependencies] diff --git a/llvm-plugin/build.rs b/llvm-plugin/build.rs index b9d1689..6ca43b5 100644 --- a/llvm-plugin/build.rs +++ b/llvm-plugin/build.rs @@ -215,8 +215,8 @@ mod llvm_sys { (16, 0) } else if cfg!(feature = "llvm17-0") { (17, 0) - } else if cfg!(feature = "llvm18-0") { - (18, 0) + } else if cfg!(feature = "llvm18-1") { + (18, 1) } else { panic!("Missing llvm* feature") } diff --git a/llvm-plugin/src/ffi.rs b/llvm-plugin/src/ffi.rs index ea9fed5..59d1f05 100644 --- a/llvm-plugin/src/ffi.rs +++ b/llvm-plugin/src/ffi.rs @@ -1,12 +1,15 @@ use std::ffi::c_void; -use inkwell_internals::llvm_versions; - pub type AnalysisKey = *const u8; #[link(name = "llvm-plugin-cpp")] extern "C" { - #[llvm_versions(15..)] + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn passBuilderAddFullLinkTimeOptimizationLastEPCallback( builder: *mut c_void, cb: *const c_void, @@ -14,7 +17,12 @@ extern "C" { cb_sys: extern "C" fn(*const c_void, *mut c_void, crate::OptimizationLevel), ); - #[llvm_versions(15..)] + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn passBuilderAddFullLinkTimeOptimizationEarlyEPCallback( builder: *mut c_void, cb: *const c_void, @@ -22,7 +30,12 @@ extern "C" { cb_sys: extern "C" fn(*const c_void, *mut c_void, crate::OptimizationLevel), ); - #[llvm_versions(15..)] + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn passBuilderAddOptimizerEarlyEPCallback( builder: *mut c_void, cb: *const c_void, @@ -30,7 +43,16 @@ extern "C" { cb_sys: extern "C" fn(*const c_void, *mut c_void, crate::OptimizationLevel), ); - #[llvm_versions(11..)] + #[cfg(any( + feature = "llvm11-0", + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn passBuilderAddOptimizerLastEPCallback( builder: *mut c_void, cb: *const c_void, @@ -38,7 +60,15 @@ extern "C" { cb_sys: extern "C" fn(*const c_void, *mut c_void, crate::OptimizationLevel), ); - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn passBuilderAddPipelineEarlySimplificationEPCallback( builder: *mut c_void, cb: *const c_void, @@ -46,7 +76,15 @@ extern "C" { cb_sys: extern "C" fn(*const c_void, *mut c_void, crate::OptimizationLevel), ); - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn passBuilderAddPipelineStartEPCallback( builder: *mut c_void, cb: *const c_void, @@ -110,7 +148,15 @@ extern "C" { pass_sys: extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> crate::PreservedAnalyses, ); - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn modulePassManagerIsEmpty(manager: *mut c_void) -> bool; pub(crate) fn functionPassManagerAddPass( @@ -120,7 +166,15 @@ extern "C" { pass_sys: extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> crate::PreservedAnalyses, ); - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub(crate) fn functionPassManagerIsEmpty(manager: *mut c_void) -> bool; pub(crate) fn moduleAnalysisManagerRegisterPass( diff --git a/llvm-plugin/src/pass_builder.rs b/llvm-plugin/src/pass_builder.rs index a535ab8..7efe9b1 100644 --- a/llvm-plugin/src/pass_builder.rs +++ b/llvm-plugin/src/pass_builder.rs @@ -1,7 +1,5 @@ use std::ffi::c_void; -use inkwell_internals::llvm_versions; - use super::{ FunctionAnalysisManager, FunctionPassManager, ModuleAnalysisManager, ModulePassManager, }; @@ -318,7 +316,15 @@ impl PassBuilder { /// This extension point allows adding optimization once at the start /// of the pipeline. This does not apply to 'backend' compiles (LTO and /// ThinLTO link-time pipelines). - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn add_pipeline_start_ep_callback(&mut self, cb: T) where T: Fn(&mut ModulePassManager, OptimizationLevel) + 'static, @@ -361,7 +367,15 @@ impl PassBuilder { /// /// This extension point allows adding optimization right after passes /// that do basic simplification of the input IR. - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn add_pipeline_early_simplification_ep_callback(&mut self, cb: T) where T: Fn(&mut ModulePassManager, OptimizationLevel) + 'static, @@ -404,7 +418,16 @@ impl PassBuilder { /// /// This extension point allows adding passes that run after everything /// else. - #[llvm_versions(11..)] + #[cfg(any( + feature = "llvm11-0", + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn add_optimizer_last_ep_callback(&mut self, cb: T) where T: Fn(&mut ModulePassManager, OptimizationLevel) + 'static, @@ -447,7 +470,12 @@ impl PassBuilder { /// /// This extension point allow adding passes that run at Link Time, /// before Full Link Time Optimization. - #[llvm_versions(15..)] + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn add_full_lto_early_ep_callback(&mut self, cb: T) where T: Fn(&mut ModulePassManager, OptimizationLevel) + 'static, @@ -490,7 +518,12 @@ impl PassBuilder { /// /// This extensions point allow adding passes that run at Link Time, /// after Full Link Time Optimization. - #[llvm_versions(15..)] + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn add_full_lto_last_ep_callback(&mut self, cb: T) where T: Fn(&mut ModulePassManager, OptimizationLevel) + 'static, @@ -533,7 +566,12 @@ impl PassBuilder { /// /// This extension point allows adding passes just before the main /// module-level optimization passes. - #[llvm_versions(15..)] + #[cfg(any( + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn add_optimizer_early_ep_callback(&mut self, cb: T) where T: Fn(&mut ModulePassManager, OptimizationLevel) + 'static, diff --git a/llvm-plugin/src/pass_manager.rs b/llvm-plugin/src/pass_manager.rs index cd96eb8..c3e6251 100644 --- a/llvm-plugin/src/pass_manager.rs +++ b/llvm-plugin/src/pass_manager.rs @@ -2,7 +2,6 @@ use std::ffi::c_void; use inkwell::module::Module; use inkwell::values::FunctionValue; -use inkwell_internals::llvm_versions; use super::{ FunctionAnalysisManager, LlvmFunctionPass, LlvmModulePass, ModuleAnalysisManager, @@ -65,7 +64,15 @@ impl ModulePassManager { } /// Returns if the pass manager contains any passes. - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn is_empty(&self) -> bool { unsafe { super::modulePassManagerIsEmpty(self.inner) } } @@ -128,7 +135,15 @@ impl FunctionPassManager { } /// Returns if the pass manager contains any passes. - #[llvm_versions(12..)] + #[cfg(any( + feature = "llvm12-0", + feature = "llvm13-0", + feature = "llvm14-0", + feature = "llvm15-0", + feature = "llvm16-0", + feature = "llvm17-0", + feature = "llvm18-1", + ))] pub fn is_empty(&self) -> bool { unsafe { super::functionPassManagerIsEmpty(self.inner) } } diff --git a/tests/plugins/plugin1-lld/Cargo.toml b/tests/plugins/plugin1-lld/Cargo.toml index 155881c..1b4c90a 100644 --- a/tests/plugins/plugin1-lld/Cargo.toml +++ b/tests/plugins/plugin1-lld/Cargo.toml @@ -17,7 +17,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin1/Cargo.toml b/tests/plugins/plugin1/Cargo.toml index a415336..aa50e4d 100644 --- a/tests/plugins/plugin1/Cargo.toml +++ b/tests/plugins/plugin1/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin2/Cargo.toml b/tests/plugins/plugin2/Cargo.toml index 6cc5538..11a2a9a 100644 --- a/tests/plugins/plugin2/Cargo.toml +++ b/tests/plugins/plugin2/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin3/Cargo.toml b/tests/plugins/plugin3/Cargo.toml index a703fdd..246c5f6 100644 --- a/tests/plugins/plugin3/Cargo.toml +++ b/tests/plugins/plugin3/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin4/Cargo.toml b/tests/plugins/plugin4/Cargo.toml index 62deea3..a024b40 100644 --- a/tests/plugins/plugin4/Cargo.toml +++ b/tests/plugins/plugin4/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin5/Cargo.toml b/tests/plugins/plugin5/Cargo.toml index c162e63..a10c583 100644 --- a/tests/plugins/plugin5/Cargo.toml +++ b/tests/plugins/plugin5/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin6/Cargo.toml b/tests/plugins/plugin6/Cargo.toml index 0ec75fa..3a34fc4 100644 --- a/tests/plugins/plugin6/Cargo.toml +++ b/tests/plugins/plugin6/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin6/src/lib.rs b/tests/plugins/plugin6/src/lib.rs index 3a4c4e2..c1b54e6 100644 --- a/tests/plugins/plugin6/src/lib.rs +++ b/tests/plugins/plugin6/src/lib.rs @@ -29,7 +29,7 @@ fn plugin_registrar(builder: &mut PassBuilder) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] builder.add_pipeline_start_ep_callback(|manager, opt| { assert!(matches!(opt, OptimizationLevel::O3)); @@ -43,7 +43,7 @@ fn plugin_registrar(builder: &mut PassBuilder) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] builder.add_pipeline_early_simplification_ep_callback(|manager, opt| { assert!(matches!(opt, OptimizationLevel::O3)); @@ -58,7 +58,7 @@ fn plugin_registrar(builder: &mut PassBuilder) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] builder.add_optimizer_last_ep_callback(|manager, opt| { assert!(matches!(opt, OptimizationLevel::O3)); @@ -69,7 +69,7 @@ fn plugin_registrar(builder: &mut PassBuilder) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] builder.add_optimizer_early_ep_callback(|manager, opt| { assert!(matches!(opt, OptimizationLevel::O3)); diff --git a/tests/plugins/plugin7/Cargo.toml b/tests/plugins/plugin7/Cargo.toml index 1943c8a..f9b5ab1 100644 --- a/tests/plugins/plugin7/Cargo.toml +++ b/tests/plugins/plugin7/Cargo.toml @@ -18,7 +18,7 @@ llvm14-0 = ["llvm-plugin/llvm14-0"] llvm15-0 = ["llvm-plugin/llvm15-0"] llvm16-0 = ["llvm-plugin/llvm16-0"] llvm17-0 = ["llvm-plugin/llvm17-0"] -llvm18-0 = ["llvm-plugin/llvm18-0"] +llvm18-1 = ["llvm-plugin/llvm18-1"] target-x86 = ["llvm-plugin/target-x86"] target-arm = ["llvm-plugin/target-arm"] diff --git a/tests/plugins/plugin7/src/lib.rs b/tests/plugins/plugin7/src/lib.rs index fae2d09..9baa749 100644 --- a/tests/plugins/plugin7/src/lib.rs +++ b/tests/plugins/plugin7/src/lib.rs @@ -7,7 +7,7 @@ fn plugin_registrar(builder: &mut PassBuilder) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] builder.add_full_lto_early_ep_callback(|manager, opt| { assert!(matches!(opt, llvm_plugin::OptimizationLevel::O3)); @@ -18,7 +18,7 @@ fn plugin_registrar(builder: &mut PassBuilder) { feature = "llvm15-0", feature = "llvm16-0", feature = "llvm17-0", - feature = "llvm18-0", + feature = "llvm18-1", ))] builder.add_full_lto_last_ep_callback(|manager, opt| { assert!(matches!(opt, llvm_plugin::OptimizationLevel::O3)); From cc6469a4a9e604bcc68ae823d4e2d842096c652c Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 12 Jan 2025 14:58:47 +0100 Subject: [PATCH 04/23] ci: check PR formatting (#19) --- .github/pull_request_template.md | 1 + .github/workflows/check-pr.yml | 85 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/check-pr.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..e918f36 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1 @@ + diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml new file mode 100644 index 0000000..1b3a2a8 --- /dev/null +++ b/.github/workflows/check-pr.yml @@ -0,0 +1,85 @@ +name: Check Pull Requests + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + - labeled + - unlabeled + merge_group: + +permissions: + pull-requests: write + +jobs: + check-title: + runs-on: ubuntu-latest + steps: + - name: Check PR title + if: github.event_name == 'pull_request_target' + uses: amannn/action-semantic-pull-request@v5 + id: check_pr_title + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Add comment indicating we require pull request titles to follow conventional commits specification + - uses: marocchino/sticky-pull-request-comment@v2 + if: always() && (steps.check_pr_title.outputs.error_message != null) + with: + header: pr-title-lint-error + message: | + Thank you for opening this pull request! + + We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. + + Details: + + > ${{ steps.check_pr_title.outputs.error_message }} + # Delete a previous comment when the issue has been resolved + - if: ${{ steps.check_pr_title.outputs.error_message == null }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: pr-title-lint-error + delete: true + + check-breaking-change-label: + runs-on: ubuntu-latest + env: + # use an environment variable to pass untrusted input to the script + # see https://securitylab.github.com/research/github-actions-untrusted-input/ + PR_TITLE: ${{ github.event.pull_request.title }} + steps: + - name: Check breaking change label + id: check_breaking_change + run: | + pattern='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!:' + # Check if pattern matches + if echo "${PR_TITLE}" | grep -qE "$pattern"; then + echo "breaking_change=true" >> $GITHUB_OUTPUT + else + echo "breaking_change=false" >> $GITHUB_OUTPUT + fi + - name: Add label + if: steps.check_breaking_change.outputs.breaking_change == 'true' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['Type: Breaking Change'] + }) + + do-not-merge: + if: ${{ contains(github.event.*.labels.*.name, 'do not merge') }} + name: Prevent Merging + runs-on: ubuntu-latest + steps: + - name: Check for label + run: | + echo "Pull request is labeled as 'do not merge'" + echo "This workflow fails so that the pull request cannot be merged" + exit 1 From a4aa6e4f0daa739d7743701da8026db3f9ed209d Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 12 Jan 2025 15:09:54 +0100 Subject: [PATCH 05/23] chore: add issue templates (#20) --- .github/ISSUE_TEMPLATE/bug_report.md | 52 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 32 ++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..1c81720 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,52 @@ +--- +name: Bug report +about: Create an issue about a bug you encountered +title: '' +labels: 'Type: Bug' +assignees: '' +--- + + + +## Description + + +## To Reproduce + + +## Expected behavior + + +## Screenshots + + +## Environment + + +- OS: +- Crate version: +- LLVM version: + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..7b95452 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,32 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'Type: Enhancement' +assignees: '' + +--- + +## Problem + + +## Solution + + +## Alternatives + + +## Additional context + From 14d8a3caa35a046e007b3bfd939a98f0779a9a10 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 13 Jan 2025 15:31:30 +0100 Subject: [PATCH 06/23] chore(changelog): use `git-cliff` to generate changelog (#21) [`git-cliff`](https://git-cliff.org): configurable changelog generator that follows the conventional commits specification. --- .cz.toml | 77 ++++++++++++++++++++++ .github/CONTRIBUTING.md | 12 ++++ CHANGELOG.md | 6 ++ cliff.toml | 137 ++++++++++++++++++++++++++++++++++++++++ committed.toml | 37 +++++++++++ 5 files changed, 269 insertions(+) create mode 100644 .cz.toml create mode 100644 CHANGELOG.md create mode 100644 cliff.toml create mode 100644 committed.toml diff --git a/.cz.toml b/.cz.toml new file mode 100644 index 0000000..3495de7 --- /dev/null +++ b/.cz.toml @@ -0,0 +1,77 @@ +# configuration for https://github.com/commitizen-tools/commitizen + +[tool.commitizen] +name = "cz_customize" +tag_format = "$version" +version_type = "semver" +version_provider = "cargo" +update_changelog_on_bump = true +major_version_zero = true +use_shortcuts = true + +[tool.commitizen.customize] +message_template = """{{change_type}}{% if scope %}({{scope}}){% endif %}{% if is_breaking_change %}!{% endif %}: {{subject}} + +{% if body %}\ +{{body}}\ +{% endif %} + +{%if is_breaking_change %}\ +BREAKING_CHANGE: \ +{% endif %}\ +{{footer}}\ +""" +example = "feature: this feature enable customize through config file" +schema = "(): \n\n\n\n