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 cac1c15 commit 8bb28ae
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 17 deletions.
39 changes: 33 additions & 6 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,55 @@ 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 update
sudo apt-get install zlib1g-dev libzstd-dev libboost-program-options-dev cppcheck clang-tidy clang-format llvm-18 llvm-18-dev
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
run: make 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-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"
3 changes: 2 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +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 update
sudo apt-get install zlib1g-dev libzstd-dev llvm-18 llvm-18-dev
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
53 changes: 50 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +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 update
sudo apt-get install llvm-18 llvm-18-dev zlib1g-dev libzstd-dev
sudo apt-get install llvm-15 llvm-15-dev zlib1g-dev libzstd-dev
- name: Code quality
run: |
cargo fmt --all -- --check
Expand All @@ -32,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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(DEFINED $ENV{NYXSTONE_LLVM_PREFIX})
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
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
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
14 changes: 13 additions & 1 deletion cmake/FindLLVM-Wrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ 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 8bb28ae

Please sign in to comment.