Skip to content
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

Rebase on LLVM 16 #76

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
39 changes: 18 additions & 21 deletions .github/workflows/dist_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@ jobs:
path: llvm/install
# TODO: would be really better to add the hash of the LLVM commit cloned
# TODO: add "14.16" as a variable easy to replace
key: ${{ runner.os }}-llvm-release-13-msvc1416
key: ${{ runner.os }}-llvm-release-16-msvc1416
- name: Get LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: 'llvm/llvm-project'
ref: 'release/13.x'
ref: 'release/16.x'
path: 'llvm'
- uses: ilammy/msvc-dev-cmd@v1
if: steps.cache-llvm.outputs.cache-hit != 'true'
with:
toolset: "14.16"
vsversion: "2022"
- name: Build LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
choco install ninja
mkdir llvm/build
mkdir llvm/install
cd llvm/build
cmake ../llvm -DLLVM_BUILD_EXAMPLES=OFF -DCLANG_ENABLE_ARCMT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DLLVM_BUILD_TOOLS=ON -DCLANG_BUILD_TOOLS=OFF -DLLVM_INSTALL_UTILS=ON -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_BINDINGS=OFF -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/../install" -DLLVM_ENABLE_THREADS=OFF -DLLVM_ENABLE_ZLIB=OFF -G Ninja
cmake ../llvm -DLLVM_BUILD_EXAMPLES=OFF -DCLANG_ENABLE_ARCMT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DLLVM_BUILD_TOOLS=ON -DCLANG_BUILD_TOOLS=OFF -DLLVM_INSTALL_UTILS=ON -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_BINDINGS=OFF -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/../install" -DLLVM_ENABLE_THREADS=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_ZSTD=OFF -G Ninja
ninja install

build_llvm_manylinux:
name: Build LLVM release for Linux
strategy:
matrix:
include:
- tag: "manylinux2010_x86_64"
- tag: "manylinux2014_x86_64"
docker_host: quay.io/pypa
- tag: "manylinux2010_i686"
- tag: "manylinux2014_i686"
docker_host: quay.io/pypa
- tag: "manylinux2014_aarch64_cross_x64"
docker_host: aguinet
Expand All @@ -60,15 +60,15 @@ jobs:
uses: actions/cache@v2
with:
path: llvm/install
key: ${{ runner.os }}-llvm-release-13-${{ matrix.tag }}
key: ${{ runner.os }}-llvm-release-16-${{ matrix.tag }}
- uses: actions/checkout@v2
if: steps.cache-llvm.outputs.cache-hit != 'true'
- name: Get LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: 'llvm/llvm-project'
ref: 'release/13.x'
ref: 'release/16.x'
path: 'llvm'
- name: Set up QEMU
if: matrix.tag == 'manylinux2014_aarch64_cross_x64' && steps.cache-llvm.outputs.cache-hit != 'true'
Expand All @@ -95,16 +95,13 @@ jobs:
strategy:
matrix:
tag:
- "manylinux2010_x86_64"
- "manylinux2010_i686"
- "manylinux2014_x86_64"
- "manylinux2014_i686"
- "manylinux2014_aarch64_cross_x64"
py_vers:
- "cp36-cp36m cp37-cp37m"
- "cp38-cp38 cp39-cp39"
- "cp310-cp310"
exclude:
- tag: "manylinux2014_aarch64_cross_x64"
py_vers: "cp310-cp310"
- "cp37-cp37m cp38-cp38 "
- "cp39-cp39 cp310-cp310"
- "cp311-cp311"

env:
PY_VERS: ${{ matrix.py_vers }}
Expand All @@ -116,7 +113,7 @@ jobs:
uses: actions/cache@v2
with:
path: llvm/install
key: Linux-llvm-release-13-${{ matrix.tag }}
key: Linux-llvm-release-16-${{ matrix.tag }}
- name: Set up QEMU
if: matrix.tag == 'manylinux2014_aarch64_cross_x64'
id: qemu
Expand All @@ -142,7 +139,7 @@ jobs:

strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
os:
- macos-latest
- windows-latest
Expand All @@ -154,7 +151,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: "14.16"
vsversion: "2022"
if: runner.os == 'Windows'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
Expand All @@ -166,7 +163,7 @@ jobs:
uses: actions/cache@v2
with:
path: llvm/install
key: ${{ runner.os }}-llvm-release-13-msvc1416
key: ${{ runner.os }}-llvm-release-16-msvc1416
- name: Python dependencies
run: |
pip install wheel
Expand All @@ -181,7 +178,7 @@ jobs:
- name: Install OSX dependencies
run: |
brew install cmake ninja
sudo $CONDA/bin/conda install -c conda-forge llvmdev==13.0.0 clangdev==13.0.0
sudo $CONDA/bin/conda install -c conda-forge llvmdev==16.0.6 clangdev==16.0.6
echo "LLVM_CONFIG=$CONDA/bin/llvm-config" >> $GITHUB_ENV
if: runner.os == 'macOS'
- name: Build wheel
Expand Down
22 changes: 6 additions & 16 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
jobs:
build:

runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
Expand All @@ -22,20 +22,10 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
# Github's ubuntu 18 docker image provides broken clang/llvm 8
# packages from whatever sources...
# Remove the mess it has, purge every thing we don't need from
# sources.list and reinstall the proper and clean clang/llvm packages
# from ubuntu 18.
sudo apt-get purge clang-8 llvm-8-dev libclang1-8 llvm-8 llvm-8-runtime libclang-common-8-dev llvm-8-dev libllvm8 liblldb-8
sudo rm /etc/apt/sources.list.d/*
echo "deb http://archive.ubuntu.com/ubuntu bionic main multiverse restricted universe" | sudo tee /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe " | sudo tee -a /etc/apt/sources.list
echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-13 main" | sudo tee -a /etc/apt/sources.list
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" | sudo tee -a /etc/apt/sources.list
curl -sSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update && sudo apt-get install -y clang-13 llvm-13-tools llvm-13-dev libclang-13-dev ninja-build cmake libarchive-dev libfftw3-dev
python -m pip install lit
sudo apt-get update && sudo apt-get install -y clang-16 llvm-16-tools llvm-16-dev libclang-16-dev ninja-build cmake libarchive-dev libfftw3-dev
python -m pip install lit
python -m pip install purectypes==0.2 six
mkdir build
- name: CMake
Expand All @@ -45,7 +35,7 @@ jobs:
-DBUILD_SHARED_LIBS=ON \
-DPYTHON_BINDINGS=ON \
-DBUILD_TESTS=ON \
-DLLVM_CONFIG=$(which llvm-config-13) \
-DLLVM_CONFIG=$(which llvm-config-16) \
-DCMAKE_BUILD_TYPE=debug \
-G Ninja ..
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install system dependencies
run: |
brew install cmake ninja
sudo $CONDA/bin/conda install -c conda-forge llvmdev==13.0.0 clangdev==13.0.0
sudo $CONDA/bin/conda install -c conda-forge llvmdev==16.0.0 clangdev==16.0.0
python -m pip install --upgrade pip
python -m pip install lit purectypes==0.2 six psutil
mkdir build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
Expand All @@ -25,17 +25,17 @@ jobs:
choco install ninja
C:\Miniconda\condabin\conda.bat activate base
C:\Miniconda\condabin\conda.bat update -c conda-forge python
C:\Miniconda\condabin\conda.bat install -c conda-forge llvmdev==13.0.0 clangdev==13.0.0
C:\Miniconda\condabin\conda.bat install -c conda-forge llvmdev==16.0.0 clangdev==16.0.0
python -m pip install --upgrade pip
python -m pip install lit purectypes==0.2 six
mkdir build
- uses: ilammy/msvc-dev-cmd@v1
with:
toolset: "14.16"
vsversion: "2022"
- name: CMake + build
working-directory: build
run: |
cmake -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DPYTHON_BINDINGS=ON -DBUILD_TESTS=ON -DLLVM_CONFIG=C:/Miniconda/Library/bin/llvm-config.exe -DCMAKE_BUILD_TYPE=release -DCMAKE_PREFIX_PATH="C:/Miniconda/Library/lib/" -G Ninja ..
cmake -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DPYTHON_BINDINGS=ON -DBUILD_TESTS=ON -DLLVM_CONFIG=C:/Miniconda/Library/bin/llvm-config.exe -DCMAKE_BUILD_TYPE=release -DCMAKE_PREFIX_PATH="C:/Miniconda/Library/lib/" -G Ninja .. -DLLVM_ENABLE_ZSTD=OFF -DLLVM_ENABLE_ZLIB=OFF
ninja
- name: Native & Python tests
working-directory: build
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ message(STATUS "LLVM cmake: ${LLVM_CMAKE}")

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand All @@ -49,7 +49,7 @@ set(Clang_DIR "${LLVM_PREFIX}/lib/cmake/clang")
message(STATUS "Clang cmake directory: ${Clang_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${LLVM_CMAKE}" "${Clang_DIR}")
set(LLVM_DIR "${LLVM_CMAKE}")
find_package(LLVM 13.0 REQUIRED)
find_package(LLVM 16 REQUIRED)

# Clang
include(ClangConfig)
Expand Down
1 change: 1 addition & 0 deletions bindings/python/tests/test_anon_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class AnonStructTest(DFFITest):
def test_anon_struct(self):
CU = self.FFI.compile('''
#include <stdio.h>
struct A {
struct {
int a;
Expand Down
4 changes: 3 additions & 1 deletion bindings/python/tests/test_buffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def test_buffers(self):
CU = self.FFI.compile('''
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>

void print(const char* msg) {
puts(msg);
Expand All @@ -33,7 +35,7 @@ def test_buffers(self):
printf("%02X ", buf[i]);
}
printf("\\n");
}
}

void bytesupper(uint8_t* S) {
const size_t Len = strlen(S);
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/tests/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_cast(self):

# Array/pointer casts
CU = FFI.compile('''
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/tests/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_str(self):
J=self.FFI

CU = J.compile('''
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

bool check_str0(const char* msg) {
Expand Down
1 change: 1 addition & 0 deletions ci/build_llvm_manylinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $CMAKE_BIN ../llvm/ \
-DCMAKE_INSTALL_PREFIX=$PWD/../install \
-DLLVM_ENABLE_THREADS=OFF \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ZSTD=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DPython3_EXECUTABLE=/opt/python/cp38-cp38/bin/python \
$CMAKE_OPTS
Expand Down
10 changes: 5 additions & 5 deletions lib/dffi_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/MC/TargetRegistry.h>
#include <llvm/Object/ObjectFile.h>
#include <llvm/Option/Arg.h>
#include <llvm/Option/ArgList.h>
Expand All @@ -48,7 +49,6 @@
#include <llvm/Support/Process.h>
#include <llvm/Support/Program.h>
#include <llvm/Support/Signals.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/VirtualFileSystem.h>
#include <llvm/Support/raw_ostream.h>
Expand Down Expand Up @@ -119,8 +119,8 @@ std::string CCOpts::getSysroot() const
return Sysroot;
}
auto OEnv = sys::Process::GetEnv("DFFI_SYSROOT");
if (OEnv.hasValue()) {
return std::move(OEnv.getValue());
if (OEnv) {
return std::move(*OEnv);
}
return {};
}
Expand Down Expand Up @@ -176,7 +176,7 @@ DFFIImpl::DFFIImpl(CCOpts const& Opts):
// Add an overleay with our virtual file system on top of the system!
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> Overlay(new llvm::vfs::OverlayFileSystem{vfs::getRealFileSystem()});
Overlay->pushOverlay(VFS_);
// Finally add clang's ressources
// Finally add clang's resources
Overlay->pushOverlay(getClangResFileSystem());

const auto TripleStr = llvm::sys::getProcessTriple();
Expand Down Expand Up @@ -614,7 +614,7 @@ void* DFFIImpl::getWrapperAddress(FunctionType const* FTy)
std::string Buf;
llvm::raw_string_ostream ss(Buf);
TypePrinter P;
genFuncTypeWrapper(P, WIdx, ss, FTy, None);
genFuncTypeWrapper(P, WIdx, ss, FTy, std::nullopt);
compileWrappers(P, ss.str());
}
std::string TName = getWrapperName(WIdx);
Expand Down
4 changes: 2 additions & 2 deletions lib/dffi_llvm_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std::unique_ptr<llvm::Module> isolateFunc(llvm::Function* F, const char* FuncNam

std::string FunctionType::getWrapperLLVM(const char* FuncName) const
{
llvm::Function* F = getDFFI().getWrapperLLVMFunc(this, llvm::None);
llvm::Function* F = getDFFI().getWrapperLLVMFunc(this, std::nullopt);
auto M = isolateFunc(F, FuncName);
std::string Ret;
llvm::raw_string_ostream ss(Ret);
Expand All @@ -49,7 +49,7 @@ std::string FunctionType::getWrapperLLVM(const char* FuncName) const

std::string FunctionType::getWrapperLLVMStr(const char* FuncName) const
{
llvm::Function* F = getDFFI().getWrapperLLVMFunc(this, llvm::None);
llvm::Function* F = getDFFI().getWrapperLLVMFunc(this, std::nullopt);
auto M = isolateFunc(F, FuncName);
std::string Ret;
llvm::raw_string_ostream ss(Ret);
Expand Down
1 change: 1 addition & 0 deletions tests/anon_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int main()

std::string Err;
auto CU = Jit.compile(R"(
#include <stdio.h>
typedef struct {
char a;
struct {
Expand Down
5 changes: 1 addition & 4 deletions tests/anon_union.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ int main()

std::string Err;
auto CU = Jit.compile(R"(
#include <stdio.h>
typedef struct {
char a;
union {
Expand All @@ -49,10 +50,6 @@ typedef struct {
void dump(A a) {
printf("u.a=%d, u.b=%d\n", a.u.a, a.u.b);
}

/*void dump_anon(struct { int a; int b; } s) {
printf("a=%d, b=%d\n", s.a, s.b);
}*/
)", Err);
if (!CU) {
std::cerr << Err << std::endl;
Expand Down
2 changes: 2 additions & 0 deletions tests/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ int main(int argc, char** argv)

std::string Err;
auto CU = Jit.compile(R"(
#include <string.h>
#include <stdio.h>
struct A
{
char buf[256];
Expand Down
1 change: 1 addition & 0 deletions tests/asm_redirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main(int argc, char** argv)
std::string Err;
// This trick comes directly from stdio.h under Debian! Enjoy' :)
auto CU = Jit.compile(R"(
#include <stdio.h>
void myfunc() __asm__ ("" "redirected_myfunc");
void myfunc() { puts("toto"); }
)", Err);
Expand Down
Loading