Skip to content

Commit

Permalink
Allow llvm version >= 15
Browse files Browse the repository at this point in the history
  • Loading branch information
stuxnot committed Oct 30, 2024
1 parent ccb107f commit 014cfd1
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 25 deletions.
101 changes: 96 additions & 5 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,117 @@ env:
CARGO_TERM_COLOR: always

jobs:
linux:
linux-llvm-15:
runs-on: ubuntu-latest
env:
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
steps:
- uses: actions/checkout@v3
- name: Packages
run: sudo apt-get install zlib1g-dev libzstd-dev libboost-program-options-dev cppcheck clang-tidy clang-format
run: |
sudo apt-get update
sudo apt-get install zlib1g-dev libzstd-dev cppcheck clang-tidy clang-format llvm-15 llvm-15-dev
- name: Code quality - fmt
run: ./tool/format.sh check
run: ./tool/format.sh check
- name: Code quality - cppcheck
run: ./tool/static-analysis-cppcheck.sh
- name: Code quality - clang-tidy
run: ./tool/static-analysis-tidy.sh
- name: Build
run: mkdir build/ && cd build && cmake .. && make
run: |
mkdir build
cd build
cmake ..
make
- name: Test
working-directory: build/
run: make test
- name: cli
working-directory: build/
run: |
./nyxstone "mov rax, rbx"
./nyxstone "jmp label" --labels "label=0x1000"
mac-llvm-15:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@15
- name: Build
run: |
mkdir build
cd build
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@15)" cmake ..
make
- name: Test
working-directory: build/
run: make test
- name: cli
working-directory: build/
run: |
./nyxstone "mov rax, rbx" &&
./nyxstone "mov rax, rbx"
./nyxstone "jmp label" --labels "label=0x1000"
mac-llvm-16:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@16
- name: Build
run: |
mkdir build
cd build
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@16)" cmake ..
make
- name: Test
working-directory: build/
run: make test
- name: cli
working-directory: build/
run: |
./nyxstone "mov rax, rbx"
./nyxstone "jmp label" --labels "label=0x1000"
mac-llvm-17:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@17
- name: Build
run: |
mkdir build
cd build
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@17)" cmake ..
make
- name: Test
working-directory: build/
run: make test
- name: cli
working-directory: build/
run: |
./nyxstone "mov rax, rbx"
./nyxstone "jmp label" --labels "label=0x1000"
mac-llvm-18:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@18
- name: Build
run: |
mkdir build
cd build
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@18)" cmake ..
make
- name: Test
working-directory: build/
run: make test
- name: cli
working-directory: build/
run: |
./nyxstone "mov rax, rbx"
./nyxstone "jmp label" --labels "label=0x1000"
5 changes: 4 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ jobs:
runs-on: ubuntu-latest
env:
working-dir: ./bindings/python
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"

steps:
- uses: actions/checkout@v3
- name: Packages
run: sudo apt-get install zlib1g-dev libzstd-dev
run: |
sudo apt-get update
sudo apt-get install zlib1g-dev libzstd-dev llvm-15 llvm-15-dev
- name: Build
run: pip install .
working-directory: ${{ env.working-dir }}
Expand Down
55 changes: 52 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ env:
CARGO_TERM_COLOR: always

jobs:
linux:
linux-llvm-15:
runs-on: ubuntu-latest
env:
working-dir: ./bindings/rust
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
NYXSTONE_LINK_FFI: "1"
steps:
- uses: actions/checkout@v3
- name: Packages
run: sudo apt-get install zlib1g-dev libzstd-dev
run: |
sudo apt-get update
sudo apt-get install llvm-15 llvm-15-dev zlib1g-dev libzstd-dev
- name: Code quality
run: |
cargo fmt --all -- --check
Expand All @@ -30,7 +34,52 @@ jobs:
run: cargo test
working-directory: ${{ env.working-dir }}

mac:
mac-llvm-15:
runs-on: macos-latest
env:
working-dir: ./bindings/rust
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@15
- name: Build
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@15)" NYXSTONE_LINK_FFI=1 cargo build
working-directory: ${{ env.working-dir }}
- name: Run tests
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@15)" NYXSTONE_LINK_FFI=1 cargo test
working-directory: ${{ env.working-dir }}

mac-llvm-16:
runs-on: macos-latest
env:
working-dir: ./bindings/rust
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@16
- name: Build
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@16)" NYXSTONE_LINK_FFI=1 cargo build
working-directory: ${{ env.working-dir }}
- name: Run tests
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@16)" NYXSTONE_LINK_FFI=1 cargo test
working-directory: ${{ env.working-dir }}

mac-llvm-17:
runs-on: macos-latest
env:
working-dir: ./bindings/rust
steps:
- uses: actions/checkout@v3
- name: Packages
run: brew install llvm@17
- name: Build
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@17)" NYXSTONE_LINK_FFI=1 cargo build
working-directory: ${{ env.working-dir }}
- name: Run tests
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@17)" NYXSTONE_LINK_FFI=1 cargo test
working-directory: ${{ env.working-dir }}

mac-llvm-18:
runs-on: macos-latest
env:
working-dir: ./bindings/rust
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ option(NYXSTONE_SANITIZERS "Enable sanitizers" OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if(DEFINED $ENV{NYXSTONE_LLVM_PREFIX})
if(DEFINED ENV{NYXSTONE_LLVM_PREFIX})
# Ignore LLVM_ROOT variables
set(CMAKE_FIND_USE_PACKAGE_ROOT_PATH OFF)
set(CMAKE_PREFIX_PATH $ENV{NYXSTONE_LLVM_PREFIX})
endif()

find_package(LLVM-Wrapper REQUIRED COMPONENTS
find_package(LLVM-Wrapper COMPONENTS
core
mc
AllTargetsCodeGens
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Nyxstone is a powerful assembly and disassembly library based on LLVM. It doesn

## Core Features

* Assembles and disassembles code for all architectures supported by LLVM 15, including x86, ARM, MIPS, RISC-V and others.
* Assembles and disassembles code for all architectures supported by the linked LLVM, including x86, ARM, MIPS, RISC-V and others.

* C++ library based on LLVM with Rust and Python bindings.

Expand All @@ -50,18 +50,18 @@ This section provides instructions on how to get started with Nyxstone, covering

### Prerequisites

Before building Nyxstone, ensure clang and LLVM 18 are present on your system. Nyxstone looks for `llvm-config` in your system's `$PATH` or the specified environment variable `$NYXSTONE_LLVM_PREFIX/bin`.
Before building Nyxstone, ensure clang and LLVM (version >= 15) are present on your system. Nyxstone looks for `llvm-config` in your system's `$PATH` or the specified environment variable `$NYXSTONE_LLVM_PREFIX/bin`.

Installation Options for LLVM 18:
Installation Options for LLVM versions 15-18:

* Ubuntu
```bash
sudo apt install llvm-18 llvm-18-dev
sudo apt install llvm-${version} llvm-${version}-dev
```

* Debian
LLVM 18 is currently only available via the testing repositories.
Refer to [https://apt.llvm.org/](https://apt.llvm.org/) for install instructions.
LLVM version 15 and 16 are available through debian repositories. Installation is the same as for Ubuntu.
For versions 17 or 18 refer to [https://apt.llvm.org/](https://apt.llvm.org/) for installation instructions.

* Arch
```bash
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## Installation

You need to have LLVM 18 installed to build the nyxstone bindings. The `setup.py` searches for LLVM in the `PATH` or in the directory set in the environment variable `NYXSTONE_LLVM_PREFIX`. Specifically, it searches for the binary `$NYXSTONE_LLVM_PREFIX/bin/llvm-config` and uses it to set the required libraries and cpp flags.
You need to have LLVM (with at least version 15) installed to build the nyxstone bindings. The `setup.py` searches for LLVM in the `PATH` or in the directory set in the environment variable `NYXSTONE_LLVM_PREFIX`. Specifically, it searches for the binary `$NYXSTONE_LLVM_PREFIX/bin/llvm-config` and uses it to set the required libraries and cpp flags.

Running

Expand Down
6 changes: 3 additions & 3 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def __init__(self):
print(f"Could not find llvm-config in ${LLVM_PREFIX_NAME} or $PATH")
exit(1)

major_version = version.split(".")[0]
major_version = int(version.split(".")[0])

if major_version != "18":
if major_version < 15:
print(
f"LLVM Major version must be 18, found {major_version}! Try setting the env variable ${LLVM_PREFIX_NAME} to tell nyxstone about the install location of LLVM 18."
f"LLVM Major version must be at least 15, found {major_version}! Set the environment variable ${LLVM_PREFIX_NAME} to tell nyxstone about the install location of LLVM."
)
exit(1)

Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Official bindings for the Nyxstone assembler/disassembler engine.

## Building

The project can be build via `cargo build`, as long as LLVM 18 is installed in the `$PATH` or the environment variable `$NYXSTONE_LLVM_PREFIX` points to the installation location of a LLVM 18 library.
The project can be build via `cargo build`, as long as LLVM (with at least version 15) is installed in the `$PATH` or the environment variable `$NYXSTONE_LLVM_PREFIX` points to the installation location of a LLVM library.

LLVM might be linked against FFI, but not correctly report this fact via `llvm-config`. If your LLVM does link FFI and
Nyxstone fails to run, set the `NYXSTONE_LINK_FFI` environment variable to some value, which will ensure that Nyxstone
Expand Down
6 changes: 4 additions & 2 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main() {
// === The following code is adapted from llvm-sys, see below for licensing ===
let llvm_config_path = match search_llvm_config() {
Ok(config) => config,
Err(e) => panic!("{e} Please either install LLVM 18 with static libs into your PATH or supply the location via $NYXSTONE_LLVM_PREFIX"),
Err(e) => panic!("{e} Please either install LLVM version >= 15 into your PATH or supply the location via $NYXSTONE_LLVM_PREFIX"),
};

// Tell cargo about the library directory of llvm.
Expand Down Expand Up @@ -129,7 +129,9 @@ fn search_llvm_config() -> Result<PathBuf> {
continue;
};

if version != "18" {
let version = version.parse::<u32>().context("Parsing LLVM version")?;

if version < 15 {
return Err(anyhow!("LLVM major version is {}, must be 18.", version));
}

Expand Down
13 changes: 12 additions & 1 deletion cmake/FindLLVM-Wrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ if(LLVM-Wrapper_FIND_REQUIRED)
list(APPEND FIND_ARGS "REQUIRED")
endif()

set(ALLOWED_LLVM_VERSIONS 15 16 17 18.0 18.1)

# Find LLVM
find_package(LLVM ${FIND_ARGS})
foreach(VERSION ${ALLOWED_LLVM_VERSIONS})
find_package(LLVM ${VERSION} QUIET ${FIND_ARGS})
if(${LLVM_FOUND})
break()
endif()
endforeach()
unset(FIND_ARGS)

if(NOT ${LLVM_FOUND})
message(FATAL_ERROR "Did not find LLVM that has a compatible version. Allowed versions are 15-18.")
endif()

if(NOT LLVM-Wrapper_FIND_QUIETLY)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
Expand Down

0 comments on commit 014cfd1

Please sign in to comment.