diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..10caeb4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,65 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + - cheri-tests + +# cancel in-progress job when a new push is performed +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + strategy: + matrix: + version: [4.14.1] + + + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + + # clang-15 seems to be required for ClangConfig.cmake + # libclang-14-dev and libclang-cpp14-dev seem to be for the opam conf-libclang package + # llvm-15-dev seems to be for the LLVM cmake files/package + - name: System dependencies (ubuntu) + run: | + sudo apt-get install clang-15 cmake libclang-14-dev libclang-15-dev libclang-cpp14-dev llvm-15-dev opam python3 + + - name: Restore cached opam + id: cache-opam-restore + uses: actions/cache/restore@v4 + with: + path: ~/.opam + key: ${{ matrix.version }} + + - name: Setup opam + if: steps.cache-opam-restore.outputs.cache-hit != 'true' + run: | + opam init --yes --no-setup --shell=sh --compiler=${{ matrix.version }} + opam install --with-test --deps-only --yes . + + - name: Save cached opam + if: steps.cache-opam-restore.outputs.cache-hit != 'true' + id: cache-opam-save + uses: actions/cache/save@v4 + with: + path: ~/.opam + key: ${{ steps.cache-opam-restore.outputs.cache-primary-key }} + + - name: Install c-tree-carver + run: | + opam switch ${{ matrix.version }} + eval $(opam env --switch=${{ matrix.version }}) + opam install --with-test --yes . + + - name: Run CI tests + run: | + opam switch ${{ matrix.version }} + eval $(opam env --switch=${{ matrix.version }}) + dune runtest && cd cpp && python3 ./test/run_test.py make && python3 ./test/run_test.py for --carver clang-tree-carve.exe diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 08b0bb4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,97 +0,0 @@ -#################################################################################### -# The following parts of c-tree-carver contain new code released under the # -# BSD 2-Clause License: # -# * `bin` # -# * `cpp/src/debug.hpp` # -# * `cpp/src/debug_printers.cpp` # -# * `cpp/src/debug_printers.hpp` # -# * `cpp/src/source_range_hash.hpp` # -# * `lib` # -# * `test` # -# # -# Copyright (c) 2022 Dhruv Makwana # -# All rights reserved. # -# # -# This software was developed by the University of Cambridge Computer # -# Laboratory as part of the Rigorous Engineering of Mainstream Systems # -# (REMS) project. This project has been partly funded by an EPSRC # -# Doctoral Training studentship. This project has been partly funded by # -# Google. This project has received funding from the European Research # -# Council (ERC) under the European Union's Horizon 2020 research and # -# innovation programme (grant agreement No 789108, Advanced Grant # -# ELVER). # -# # -# BSD 2-Clause License # -# # -# Redistribution and use in source and binary forms, with or without # -# modification, are permitted provided that the following conditions # -# are met: # -# 1. Redistributions of source code must retain the above copyright # -# notice, this list of conditions and the following disclaimer. # -# 2. Redistributions in binary form must reproduce the above copyright # -# notice, this list of conditions and the following disclaimer in # -# the documentation and/or other materials provided with the # -# distribution. # -# # -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' # -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR # -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF # -# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT # -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # -# SUCH DAMAGE. # -# # -# All other parts involve adapted code, with the new code subject to the # -# above BSD 2-Clause licence and the original code subject to its MIT # -# licence. # -# # -# The MIT License (MIT) # -# # -# Copyright (c) 2016 Takaaki Hiragushi # -# # -# Permission is hereby granted, free of charge, to any person obtaining a copy # -# of this software and associated documentation files (the "Software"), to deal # -# in the Software without restriction, including without limitation the rights # -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # -# copies of the Software, and to permit persons to whom the Software is # -# furnished to do so, subject to the following conditions: # -# # -# The above copyright notice and this permission notice shall be included in all # -# copies or substantial portions of the Software. # -# # -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # -# SOFTWARE. # -#################################################################################### - -language: c -install: - - test -e .travis-opam.sh || wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh -script: - - bash -ex .travis-opam.sh - - opam install . - - dune runtest - - cd cpp && ./test/run_test.py for -env: - - OCAML_VERSION=4.12 - - PACKAGE=c-tree-carver -os: - - linux - - osx -arch: - - amd64 -dist: focal -addons: - apt: - packages: - - llvm-12-dev - - libclang-12-dev diff --git a/c-tree-carver.opam b/c-tree-carver.opam index b8059f9..b4dd715 100644 --- a/c-tree-carver.opam +++ b/c-tree-carver.opam @@ -7,14 +7,15 @@ authors: ["Dhruv Makwana = "3.7"} - "ocaml" {>= "4.12.0"} + "ocaml" {>= "4.14.1"} "conf-c++" "conf-cmake" {dev} - "conf-llvm" {= "12.0.1"} - "conf-python3" {with-test} + "conf-libclang" {= "15"} + "conf-python-3" {with-test} "fileutils" {>= "0.6.4"} "shexp" {>= "v0.15.0"} "ocamlformat" {>= "0.25.1" & dev} diff --git a/conf-libclang-12-dev.opam b/conf-libclang-12-dev.opam deleted file mode 100644 index 014036f..0000000 --- a/conf-libclang-12-dev.opam +++ /dev/null @@ -1,28 +0,0 @@ -# This file is generated by dune, edit dune-project instead -dev-repo: "git+https://github.com/rems-project/c-tree-carver.git" -# Adapted from https://github.com/ocaml/opam-repository/blob/master/packages/conf-libclang/conf-libclang.12/opam -# Because `["libclang-dev" "llvm-dev"] {os-family = "debian"}` does not actually guarantee version 12 -opam-version: "2.0" -maintainer: "https://github.com/rems-project/c-tree-carver/pulls" -authors: "The LLVM team" -homepage: "http://llvm.org" -bug-reports: "https://llvm.org/bugs/" -license: "MIT" -build-env: [ - [HOMEBREW_NO_AUTO_UPDATE = "1"] -] -build: [ - ["bash" "-ex" "files/configure.sh" version] -] -depends: [ - "conf-bash" {build} -] -depexts: [ - ["libclang-12-dev"] {os-family = "debian"} -] -extra-files: [[ - "configure.sh" "sha512=f7f3bedd554da272d3a14d631481bfed0fecce52054cd35fedf41a4493bcc7973fc28abeb305755fb546927785a6f69d1cf2d15b306da35777b471d2bc770864" -]] -synopsis: "Virtual package relying on libclang-12-dev library" -description: "This package can only install if the libclang-12-dev library is installed on the system." -flags: conf diff --git a/conf-libclang-12-dev.opam.template b/conf-libclang-12-dev.opam.template deleted file mode 100644 index 88023ed..0000000 --- a/conf-libclang-12-dev.opam.template +++ /dev/null @@ -1,26 +0,0 @@ -# Adapted from https://github.com/ocaml/opam-repository/blob/master/packages/conf-libclang/conf-libclang.12/opam -# Because `["libclang-dev" "llvm-dev"] {os-family = "debian"}` does not actually guarantee version 12 -opam-version: "2.0" -maintainer: "https://github.com/rems-project/c-tree-carver/pulls" -authors: "The LLVM team" -homepage: "http://llvm.org" -bug-reports: "https://llvm.org/bugs/" -license: "MIT" -build-env: [ - [HOMEBREW_NO_AUTO_UPDATE = "1"] -] -build: [ - ["bash" "-ex" "files/configure.sh" version] -] -depends: [ - "conf-bash" {build} -] -depexts: [ - ["libclang-12-dev"] {os-family = "debian"} -] -extra-files: [[ - "configure.sh" "sha512=f7f3bedd554da272d3a14d631481bfed0fecce52054cd35fedf41a4493bcc7973fc28abeb305755fb546927785a6f69d1cf2d15b306da35777b471d2bc770864" -]] -synopsis: "Virtual package relying on libclang-12-dev library" -description: "This package can only install if the libclang-12-dev library is installed on the system." -flags: conf diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index e0c5286..524f792 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -42,7 +42,16 @@ cmake_minimum_required(VERSION 3.16.3) project(clang-tree-carver) -find_package(LLVM "12.0.0" REQUIRED CONFIG) +find_package(LLVM "15.0.7" REQUIRED CONFIG) +# Not sure what the correct/idiomatic CMake is for a situation where packages +# aren't version but CMake defaults to a wrong but earlier one instead of a +# correct later one. +# /usr/lib/cmake/clang-12/ClangConfig.cmake, version: unknown +# /usr/lib/cmake/clang-15/ClangConfig.cmake, version: unknown +# /lib/cmake/clang-12/ClangConfig.cmake, version: unknown +# /lib/cmake/clang-15/ClangConfig.cmake, version: unknown +# So I'm hard-coding it. +set(Clang_DIR "/usr/lib/cmake/clang-15") find_package(Clang REQUIRED CONFIG) set(CLANG_LIBS diff --git a/dune-project b/dune-project index a879e20..8c933d4 100644 --- a/dune-project +++ b/dune-project @@ -13,18 +13,18 @@ (license MIT BSD-2-Clause) -; (documentation https://url/to/documentation) +(documentation https://github.com/rems-project/c-tree-carver) (package (name c-tree-carver) (synopsis "Clang-based tool for tree-carving C source trees") (description "") (depends - (ocaml (>= 4.12.0)) + (ocaml (>= 4.14.1)) conf-c++ (conf-cmake :dev) - (conf-llvm (= 12.0.1)) - (conf-python3 :with-test) + (conf-libclang (= 15)) + (conf-python-3 :with-test) (fileutils (>= 0.6.4)) (shexp (>= v0.15.0)) (ocamlformat (and (>= 0.25.1) :dev)) @@ -34,11 +34,6 @@ (tags (topics c clang tool tree-carving))) -(package - (name conf-libclang-12-dev) - (allow_empty)) - - (formatting) ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/files/configure.sh b/files/configure.sh deleted file mode 100644 index 5273c67..0000000 --- a/files/configure.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -ex - -# Adapted from https://github.com/ocaml/opam-repository/blob/master/packages/conf-libclang/conf-libclang.12/files/configure.sh - -clean_tempdir () { - rm -f "$tempdir/test_libclang.c" "$tempdir/test_libclang.o" \ - "$tempdir/test_libclang" - rmdir "$tempdir" -} - -shopt -s nullglob -for version in default 12; do - if [ "$version" = default ]; then - llvm_config=llvm-config - llvm_version="$($llvm_config --version)" || continue - if [ $(printf "${llvm_version%%.*}\n13" | sort -n | head -n1) = 13 ]; then - continue - fi - else - if hash brew 2>/dev/null; then - brew_llvm_config="$(brew --cellar)"/llvm*/${version}*/bin/llvm-config - fi - for llvm_config in \ - llvm-config-${version} llvm-config-${version}.0 \ - llvm-config${version}0 llvm-config${version} \ - llvm-config-${version}-32 llvm-config-${version}-64 \ - llvm-config-mp-$version \ - llvm-config-mp-${version}.0 $brew_llvm_config \ - /usr/lib64/llvm/${version}/bin/llvm-config \ - /usr/lib/llvm/${version}/bin/llvm-config; do - llvm_version="$($llvm_config --version)" || continue - break - done - if [ -z "$llvm_version" ]; then - continue - fi - fi - - if [ "$llvm_version" = "12.0.1" ]; then - clangml440_configure_options="--with-llvm-version=12.0.0" # clangml.4.4.0 does not recognize 12.0.1 - else - clangml440_configure_options="" # rely on clangml's ./configure autodetection - fi - - LLVM_CFLAGS="$($llvm_config --cflags)" - LLVM_LDFLAGS="$($llvm_config --ldflags)" - LLVM_LIBDIR="$($llvm_config --libdir)" - - # These filters enable compilation with gcc. - # Filter -Wstring-conversion for OpenSUSE - LLVM_CFLAGS="$(echo $LLVM_CFLAGS | sed 's/-Wstring-conversion //')" - - # Filter -Werror=unguarded-availability-new and -Wcovered-switch-default - # (which appear with LLVM 7) - LLVM_CFLAGS="$(echo $LLVM_CFLAGS | sed 's/-Werror=unguarded-availability-new //')" - LLVM_CFLAGS="$(echo $LLVM_CFLAGS | sed 's/-Wcovered-switch-default //')" - - # Filter "-Wdelete-non-virtual-dtor" (warning only) - LLVM_CFLAGS="$(echo $LLVM_CFLAGS | sed 's/-Wdelete-non-virtual-dtor //')" - - tempdir="$(mktemp -d)" - cat >"$tempdir/test_libclang.c" < -#include - -int -main(int argc, char *argv[]) -{ - CXIndex idx = clang_createIndex(1, 1); - clang_disposeIndex(idx); - return EXIT_SUCCESS; -} -EOF - - CC=cc - if "$CC" -o "$tempdir/test_libclang.o" -c $LLVM_CFLAGS \ - "$tempdir/test_libclang.c" && - "$CC" -o "$tempdir/test_libclang" \ - $LLVM_LDFLAGS "$tempdir/test_libclang.o" \ - "-lclang" "-Wl,-rpath,$LLVM_LIBDIR" && - "$tempdir/test_libclang"; then - true - else - clean_tempdir - continue - fi - - clean_tempdir - - echo "config: \"$llvm_config\"" >> conf-libclang.config - echo "version: \"$llvm_version\"" >> conf-libclang.config - echo "clangml440_configure_options: \"$clangml440_configure_options\"" >> conf-libclang.config - exit 0 -done - -echo "Error: No usable version of LLVM <=12.0.x found." -exit 1 -