From 41197bc85d6b95de3345f5a09d321469c2bba58e Mon Sep 17 00:00:00 2001
From: Jordan Moore <lockbox@struct.foo>
Date: Mon, 2 Jun 2025 16:36:27 -0400
Subject: [PATCH 1/5] fix: cstdint explicitly included when used

* fixes error in gcc15 where this header is no longer
  implicitly included
---
 llvm/include/llvm/ADT/STLExtras.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 3346de93..a2adf853 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -21,6 +21,7 @@
 #include <algorithm> // for std::all_of
 #include <cassert>
 #include <cstddef> // for std::size_t
+#include <cstdint>
 #include <cstdlib> // for qsort
 #include <functional>
 #include <iterator>

From f3f792cc05080a4bcc3c2886c0c7cee9294c4a05 Mon Sep 17 00:00:00 2001
From: Jordan Moore <lockbox@struct.foo>
Date: Mon, 2 Jun 2025 16:58:31 -0400
Subject: [PATCH 2/5] fix: build with modern cmake

---
 CMakeLists.txt        | 19 +------------------
 kstool/CMakeLists.txt |  2 +-
 llvm/CMakeLists.txt   | 15 +--------------
 3 files changed, 3 insertions(+), 33 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 938d4983..9ce08362 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 # Keystone Assembler Engine (www.keystone-engine.org)
 # By Nguyen Anh Quynh, 2016
 
-cmake_minimum_required(VERSION 2.8.7)
+cmake_minimum_required(VERSION 3.10.0)
 project(keystone)
 
 set(KEYSTONE_VERSION_MAJOR 0)
@@ -15,23 +15,6 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
   set(CMAKE_BUILD_TYPE "Debug")
 endif()
 
-if (POLICY CMP0022)
-  cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
-endif()
-
-if (POLICY CMP0051)
-  # CMake 3.1 and higher include generator expressions of the form
-  # $<TARGETLIB:obj> in the SOURCES property.  These need to be
-  # stripped everywhere that access the SOURCES property, so we just
-  # defer to the OLD behavior of not including generator expressions
-  # in the output for now.
-  cmake_policy(SET CMP0051 OLD)
-endif()
-
-if (POLICY CMP0063)
-  set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # automatic when 3.3.2 is required
-endif()
-
 if (CMAKE_VERSION VERSION_LESS 3.1.20141117)
   set(cmake_3_2_USES_TERMINAL)
 else()
diff --git a/kstool/CMakeLists.txt b/kstool/CMakeLists.txt
index d28da481..25113821 100644
--- a/kstool/CMakeLists.txt
+++ b/kstool/CMakeLists.txt
@@ -1,7 +1,7 @@
 # Kstool for Keystone assembler engine.
 # By Nguyen Anh Quynh, 2016
 
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.10.0)
 
 project(kstool)
 
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index d926b082..518613a5 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1,6 +1,6 @@
 # See docs/CMake.html for instructions about how to build LLVM with CMake.
 
-cmake_minimum_required(VERSION 2.8.7)
+cmake_minimum_required(VERSION 3.10.0)
 
 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON)
 
@@ -9,19 +9,6 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
   set(CMAKE_BUILD_TYPE "Debug")
 endif()
 
-if(POLICY CMP0022)
-  cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
-endif()
-
-if (POLICY CMP0051)
-  # CMake 3.1 and higher include generator expressions of the form
-  # $<TARGETLIB:obj> in the SOURCES property.  These need to be
-  # stripped everywhere that access the SOURCES property, so we just
-  # defer to the OLD behavior of not including generator expressions
-  # in the output for now.
-  cmake_policy(SET CMP0051 OLD)
-endif()
-
 if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
   set(cmake_3_2_USES_TERMINAL)
 else()

From 4e2fcaa8fad81fc6016bd4d7d245d04719195381 Mon Sep 17 00:00:00 2001
From: Jordan Moore <lockbox@struct.foo>
Date: Mon, 2 Jun 2025 17:49:30 -0400
Subject: [PATCH 3/5] fix: bindings: rust: moderize and format

---
 bindings/rust/Cargo.toml              |  1 +
 bindings/rust/keystone-sys/Cargo.toml |  1 +
 bindings/rust/keystone-sys/build.rs   |  2 +-
 bindings/rust/keystone-sys/src/lib.rs | 14 ++------------
 bindings/rust/src/lib.rs              |  2 +-
 5 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/bindings/rust/Cargo.toml b/bindings/rust/Cargo.toml
index 3342e5a1..013a6e9d 100644
--- a/bindings/rust/Cargo.toml
+++ b/bindings/rust/Cargo.toml
@@ -1,6 +1,7 @@
 [package]
 name = "keystone"
 version = "0.9.2"
+edition = "2018"
 authors = [
   "Remco Verhoef <remco.verhoef@dutchcoders.io>",
   "Tasuku SUENAGA a.k.a. gunyarakun <tasuku-s-github@titech.ac>"
diff --git a/bindings/rust/keystone-sys/Cargo.toml b/bindings/rust/keystone-sys/Cargo.toml
index a836c305..7b88aff6 100644
--- a/bindings/rust/keystone-sys/Cargo.toml
+++ b/bindings/rust/keystone-sys/Cargo.toml
@@ -1,6 +1,7 @@
 [package]
 name = "keystone-sys"
 version = "0.9.2"
+edition = "2018"
 authors = [
   "Remco Verhoef <remco.verhoef@dutchcoders.io>",
   "Tasuku SUENAGA a.k.a. gunyarakun <tasuku-s-github@titech.ac>"
diff --git a/bindings/rust/keystone-sys/build.rs b/bindings/rust/keystone-sys/build.rs
index 9670fcb3..a92a41f2 100644
--- a/bindings/rust/keystone-sys/build.rs
+++ b/bindings/rust/keystone-sys/build.rs
@@ -17,7 +17,7 @@ fn build_with_cmake() {
         // This only happens when using the crate via a `git` reference as the
         // published version already embeds keystone's source.
         let pwd = std::env::current_dir().unwrap();
-        let keystone_dir = pwd.ancestors().skip(3).next().unwrap();
+        let keystone_dir = pwd.ancestors().nth(3).unwrap();
         symlink(keystone_dir, "keystone").expect("failed to symlink keystone");
     }
 
diff --git a/bindings/rust/keystone-sys/src/lib.rs b/bindings/rust/keystone-sys/src/lib.rs
index 6eb282a6..8bd5eefd 100644
--- a/bindings/rust/keystone-sys/src/lib.rs
+++ b/bindings/rust/keystone-sys/src/lib.rs
@@ -10,19 +10,9 @@ extern crate libc;
 
 pub mod keystone_const;
 
+use ::libc::{c_char, c_int, c_uchar, c_uint, size_t};
+use ::std::{ffi::CStr, fmt, ptr};
 use keystone_const::{Arch, Error, Mode, OptionType, OptionValue};
-use ::std::{
-    ffi::CStr,
-    fmt,
-    ptr,
-};
-use ::libc::{
-    c_char,
-    c_uchar,
-    c_int,
-    c_uint,
-    size_t,
-};
 
 /// Opaque type representing the Keystone engine
 #[repr(C)]
diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs
index dd5bd042..dc8cd5e0 100644
--- a/bindings/rust/src/lib.rs
+++ b/bindings/rust/src/lib.rs
@@ -90,7 +90,7 @@ impl Keystone {
         let err = unsafe { ffi::ks_open(arch, mode, &mut handle) };
         if err == Error::OK {
             Ok(Keystone {
-                handle: handle.expect("Got NULL engine from ks_open()")
+                handle: handle.expect("Got NULL engine from ks_open()"),
             })
         } else {
             Err(err)

From bf3b00fba5a32bba3b3f7fb1d54e374338614a96 Mon Sep 17 00:00:00 2001
From: Jordan Moore <lockbox@struct.foo>
Date: Mon, 2 Jun 2025 17:50:07 -0400
Subject: [PATCH 4/5] fix: only attempt to publish bindings on master

---
 .github/workflows/python-publish.yml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml
index 6f5e8554..cb0d2d5c 100644
--- a/.github/workflows/python-publish.yml
+++ b/.github/workflows/python-publish.yml
@@ -1,6 +1,9 @@
 name: PyPI 📦 Distribution
 
-on: [push]
+on:
+  push:
+    branches:
+      - master
 
 jobs:
   build:

From 667cce956ce9c3b2ec7eb30d23198deb9596b427 Mon Sep 17 00:00:00 2001
From: Jordan Moore <lockbox@struct.foo>
Date: Mon, 2 Jun 2025 17:50:50 -0400
Subject: [PATCH 5/5] feat: basic CI

---
 .github/workflows/cmake-build.yml | 31 +++++++++++++++++++++++++++++++
 .github/workflows/rust-build.yml  | 31 +++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 .github/workflows/cmake-build.yml
 create mode 100644 .github/workflows/rust-build.yml

diff --git a/.github/workflows/cmake-build.yml b/.github/workflows/cmake-build.yml
new file mode 100644
index 00000000..4de36eab
--- /dev/null
+++ b/.github/workflows/cmake-build.yml
@@ -0,0 +1,31 @@
+# Builds the codebase with cmake
+
+name: CMake CI
+on:
+  pull_request:
+  push:
+    branches:
+      - master
+
+jobs:
+  linux-build:
+    name: Linux
+    runs-on: ubuntu-24.04
+    steps:
+      - name: Checkout source code
+        uses: actions/checkout@v4
+      - name: Install prerequisites
+        shell: bash
+        run: |
+          sudo apt-get -y update
+          sudo apt-get install -y \
+              cmake \
+              gcc
+      - name: Configure
+        shell: bash
+        run: |
+          cmake -B build
+      - name: Bulid
+        shell: bash
+        run: |
+          cmake --build build
diff --git a/.github/workflows/rust-build.yml b/.github/workflows/rust-build.yml
new file mode 100644
index 00000000..7f7c8e01
--- /dev/null
+++ b/.github/workflows/rust-build.yml
@@ -0,0 +1,31 @@
+# Builds the codebase with cmake on ubuntu, windows and macos.
+#
+name: Rust CI
+on:
+  pull_request:
+  push:
+    branches:
+      - master
+
+jobs:
+  linux-test:
+    name: Linux
+    runs-on: ubuntu-24.04
+    steps:
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
+
+      - name: Install prerequisites
+        shell: bash
+        run: |
+          sudo apt-get -y update
+          sudo apt-get install -y \
+              cmake \
+              libclang-dev \
+              pkg-config \
+              gcc
+      - name: Build and test rust
+        shell: bash
+        run: |
+          cd bindings/rust
+          cargo test
