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

Llvm 16 compatibility. #430

Open
wants to merge 18 commits into
base: llvm-head-unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
239 changes: 239 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
name: CI

# Trigger the workflow on push or pull request
on:
# workflow_dispatch:
pull_request:
# branches: [master]
types: [synchronize, opened, reopened]
push:
# branches: [main]
paths:
- '.github/workflows/ci.yml'
- 'cabal.project'
- 'stack.yaml'
- 'llvm-hs/llvm-hs.cabal'
- 'llvm-hs/src/**'
- 'llvm-hs/test/**'
- 'llvm-hs-pure/llvm-hs-pure.cabal'
- 'llvm-hs-pure/src/**'
- 'llvm-hs-pure/test/**'
schedule:
# additionally run once per week (At 00:00 on Sunday) to maintain cache
- cron: '0 0 * * 0'

jobs:
cabal:
name: cabal | ${{ matrix.sys.os }}-${{ matrix.arch }} ghc-${{ matrix.ghc }}
runs-on: ${{ matrix.sys.os }}
strategy:
fail-fast: false
matrix:
sys:
- { os: 'ubuntu-latest', shell: 'bash' }
- { os: 'macOS-latest', shell: 'bash' }
- { os: 'windows-latest', shell: 'msys2 {0}' }
arch:
- 'x64'
- 'ARM64'
ghc:
- 'latest'
- '9.6'
- '9.4'
- '9.2'
- '9.0'
- '8.10'
exclude:
- arch: 'ARM64'
defaults:
run:
shell: ${{ matrix.sys.shell }}
env:
CABAL_FLAGS: --enable-tests --test-show-details=direct

steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: actions/cache
path: .github/actions/cache-always
ref: v3

# Tweak `action.yml` of `actions/cache@v3` to remove the `post-if`
# condition, making it default to `post-if: always ()`.
- name: Run actions/cache-always@v3
run: |
sed -i -e '/ post-if: /d' .github/actions/cache-always/action.yml
shell: bash

- uses: msys2/setup-msys2@v2
if: matrix.sys.os == 'windows-latest'
with:
path-type: inherit
msystem: clang64

- uses: haskell/actions/setup@v2
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: latest

- name: Set up environment (ubuntu)
if: matrix.sys.os == 'ubuntu-latest'
run: |
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"
sudo apt-get update
sudo apt-get -y install llvm-15-dev libpolly-15-dev

- name: Set up environment (macOS)
if: matrix.sys.os == 'macOS-latest'
run: |
brew install llvm@15
mkdir -p $HOME/.local/bin
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/llvm-config-15
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Set up environment (windows)
if: matrix.sys.os == 'windows-latest'
run: |
# https://stackoverflow.com/questions/33969803/how-to-obtain-older-versions-of-packages-using-msys2
# https://packages.msys2.org/package/mingw-w64-clang-x86_64-llvm
curl -LO https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst

- name: Configure
run: cabal configure $CABAL_FLAGS

- name: Freeze
run: cabal freeze

- name: actions/cache-always@v3
uses: ./.github/actions/cache-always
with:
path: |
${{ steps.setup-haskell.outputs.cabal-store }}
dist-newstyle
key: ${{ runner.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}
restore-keys: |
${{ runner.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}
${{ runner.os }}-${{ matrix.arch }}-${{ matrix.ghc }}-cabal-

- name: Build dependencies
run: cabal build all --only-dependencies

- name: Build llvm-hs-pure
run: cabal build llvm-hs-pure

- name: Build llvm-hs
run: cabal build llvm-hs

- name: Test llvm-hs-pure
run: cabal test llvm-hs-pure

- name: Test llvm-hs
run: cabal test llvm-hs

- name: Haddock llvm-hs-pure
run: cabal haddock llvm-hs-pure

- name: Haddock llvm-hs
run: cabal haddock llvm-hs

stack:
name: stack | ${{ matrix.sys.os }}-${{ matrix.arch }}
runs-on: ${{ matrix.sys.os }}
strategy:
fail-fast: false
matrix:
sys:
- { os: 'ubuntu-latest', shell: 'bash' }
- { os: 'macOS-latest', shell: 'bash' }
- { os: 'windows-latest', shell: 'msys2 {0}' }
arch:
- 'x64'
- 'ARM64'
exclude:
- arch: 'ARM64'
defaults:
run:
shell: ${{ matrix.sys.shell }}
env:
CABAL_FLAGS: --enable-tests --test-show-details=direct

steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: actions/cache
path: .github/actions/cache-always
ref: v3

# Tweak `action.yml` of `actions/cache@v3` to remove the `post-if`
# condition, making it default to `post-if: always ()`.
- name: Run actions/cache-always@v3
run: |
sed -i -e '/ post-if: /d' .github/actions/cache-always/action.yml
shell: bash

- uses: msys2/setup-msys2@v2
if: matrix.sys.os == 'windows-latest'
with:
path-type: inherit
msystem: clang64

- uses: haskell/actions/setup@v2
id: setup-haskell
with:
enable-stack: true
stack-no-global: true

- name: actions/cache-always@v3
uses: ./.github/actions/cache-always
with:
path: |
${{ steps.setup-haskell.outputs.stack-root }}
.stack-work
key: ${{ runner.os }}-${{ matrix.arch }}-stack-${{ hashFiles('stack.yaml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.arch }}-stack-${{ hashFiles('stack.yaml') }}
${{ runner.os }}-${{ matrix.arch }}-stack-

- name: Set up environment (ubuntu)
if: matrix.sys.os == 'ubuntu-latest'
run: |
curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main"
sudo apt-get update
sudo apt-get -y install llvm-15-dev libpolly-15-dev

- name: Set up environment (macOS)
if: matrix.sys.os == 'macOS-latest'
run: |
brew install llvm@15
mkdir -p $HOME/.local/bin
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/llvm-config-15
ln -s $(brew --prefix llvm@15)/bin/llvm-config $HOME/.local/bin/
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Set up environment (windows)
if: matrix.sys.os == 'windows-latest'
run: |
# https://stackoverflow.com/questions/33969803/how-to-obtain-older-versions-of-packages-using-msys2
# https://packages.msys2.org/package/mingw-w64-clang-x86_64-llvm
curl -LO https://mirror.msys2.org/mingw/clang64/mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-clang-x86_64-llvm-15.0.7-3-any.pkg.tar.zst

- name: Setup
run: stack setup

- name: Build dependencies
run: stack build --only-dependencies

- name: Build
run: stack build

# vi: nospell
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# llvm-hs - Haskell bindings for LLVM

[![Build Status](https://travis-ci.org/llvm-hs/llvm-hs.svg?branch=llvm-6)](https://travis-ci.org/llvm-hs/llvm-hs) [![Hackage](https://img.shields.io/hackage/v/llvm-hs.svg)](https://hackage.haskell.org/package/llvm-hs)
[![Build Status](https://github.com/llvm-hs/llvm-hs/actions/workflows/ci.yml/badge.svg)](https://github.com/llvm-hs/llvm-hs/actions/workflows/ci.yml) [![Hackage](https://img.shields.io/hackage/v/llvm-hs.svg)](https://hackage.haskell.org/package/llvm-hs)

This project aims to provide a relatively complete set of bindings for
the LLVM API. If you find that anything is missing please open an
Expand Down
6 changes: 3 additions & 3 deletions llvm-hs-pure/llvm-hs-pure.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: llvm-hs-pure
version: 15.0.0
version: 16.0.0
license: BSD-3-Clause
license-file: LICENSE
author: Anthony Cowley, Stephen Diehl, Moritz Kiefer <moritz.kiefer@purelyfunctional.org>, Benjamin S. Scarlet
Expand Down Expand Up @@ -30,9 +30,9 @@ library
build-depends:
base >= 4.9 && < 5,
attoparsec >= 0.13,
bytestring >= 0.10 && < 0.11,
bytestring >= 0.11,
fail,
transformers >= 0.3 && < 0.6,
transformers >= 0.3,
mtl >= 2.1,
template-haskell >= 2.5.0.0,
containers >= 0.4.2.1,
Expand Down
7 changes: 4 additions & 3 deletions llvm-hs-pure/src/LLVM/IRBuilder/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-} -- For MonadState s (IRBuilderT m) instance

module LLVM.IRBuilder.Module where

import Prelude hiding (and, or)
import LLVM.Prelude

import Control.Applicative
import Control.Monad.Cont
import Control.Monad.Fix
import Control.Monad.Except
import qualified Control.Monad.Fail as Fail
import Control.Monad.Identity
Expand All @@ -34,7 +36,7 @@ import Control.Monad.Fail (MonadFail)
#endif

import Data.Bifunctor
import Data.ByteString.Short as BS
import Data.ByteString.Short (ShortByteString)
import Data.Char
import Data.Data
import Data.Foldable
Expand All @@ -47,7 +49,6 @@ import GHC.Generics(Generic)
import LLVM.AST hiding (function)
import LLVM.AST.Global
import LLVM.AST.Linkage
import LLVM.AST.Type (ptr)
import qualified LLVM.AST.Constant as C

import LLVM.IRBuilder.Internal.SnocList
Expand Down
2 changes: 2 additions & 0 deletions llvm-hs-pure/src/LLVM/IRBuilder/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-} -- For MonadState s (ModuleBuilderT m) instance

module LLVM.IRBuilder.Monad where

import LLVM.Prelude

import Control.Monad.Cont
import Control.Monad.Fix
import Control.Monad.Except
import qualified Control.Monad.Fail as Fail
import Control.Monad.Identity
Expand Down
1 change: 1 addition & 0 deletions llvm-hs-pure/src/LLVM/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Prelude hiding (
minimum, maximum, sum, product, all, any, and, or,
concatMap,
elem, notElem,
unzip
)
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)
Expand Down
2 changes: 1 addition & 1 deletion llvm-hs-pure/src/LLVM/Triple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Control.Monad.Trans.Except
import Data.Attoparsec.ByteString
import Data.Attoparsec.ByteString.Char8
import Data.ByteString.Char8 as ByteString hiding (map, foldr)
import Data.ByteString.Short hiding (pack)
import Data.ByteString.Short hiding (pack, foldr)

import Data.Map (Map, (!))
import qualified Data.Map as Map
Expand Down
17 changes: 10 additions & 7 deletions llvm-hs/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import System.Environment
#if MIN_VERSION_Cabal(2,0,0)
#define MIN_VERSION_Cabal_2_0_0
#endif
#if MIN_VERSION_Cabal(3,8,1)
#define MIN_VERSION_Cabal_3_8_1
#endif
#endif

-- define these selectively in C files (we are _not_ using HsFFI.h),
Expand Down Expand Up @@ -135,12 +138,8 @@ main = do
libDirs <- liftM lines $ llvmConfig ["--libdir"]
[llvmVersion] <- liftM lines $ llvmConfig ["--version"]
let getLibs = liftM (map (fromJust . stripPrefix "-l") . words) . llvmConfig
flags = configConfigurationsFlags confFlags
linkFlag = case lookupFlagAssignment (mkFlagName "shared-llvm") flags of
Nothing -> "--link-shared"
Just shared -> if shared then "--link-shared" else "--link-static"
libs <- getLibs ["--libs", linkFlag]
systemLibs <- getLibs ["--system-libs", linkFlag]
libs_static <- getLibs ["--libs", "--system-libs", "--link-static"]
libs_shared <- getLibs ["--libs", "--system-libs", "--link-shared"]

let genericPackageDescription' = genericPackageDescription {
condLibrary = do
Expand All @@ -150,7 +149,8 @@ main = do
libBuildInfo =
mempty {
ccOptions = llvmCxxFlags,
extraLibs = libs ++ stdLib : systemLibs
extraLibs = stdLib : libs_static,
extraGHCiLibs = libs_shared
}
}
}
Expand All @@ -171,6 +171,9 @@ main = do
#endif
PreProcessor {
platformIndependent = platformIndependent (origHsc buildInfo),
#ifdef MIN_VERSION_Cabal_3_8_1
ppOrdering = \_ _ modules -> pure modules,
#endif
runPreProcessor = \inFiles outFiles verbosity -> do
llvmConfig <- getLLVMConfig (configFlags localBuildInfo)
llvmCFlags <- do
Expand Down