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

Making codebase macOS compatible #637

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/scripts/macos-12/compile_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Compile dependencies that cannot be acquired via the official repositories

mkdir -p ${INSTALL_PATH}

## Compile Thrift
CXXFLAGS_OLD=$CXXFLAGS
LDFLAGS_OLD=$LDFLAGS
export CXXFLAGS="$CXXFLAGS -I/opt/homebrew/include"
export LDFLAGS="$LDFLAGS -L/opt/homebrew/lib"
export CXXFLAGS="$CXXFLAGS -Wno-error"

tar -xvf ${DOWNLOAD_PATH}/thrift-0.16.0.tar.gz
cd thrift-0.16.0
./configure --prefix=${INSTALL_PATH}/thrift --silent --without-python \
--enable-libtool-lock --enable-tutorial=no --enable-tests=no \
--with-libevent --with-zlib --without-nodejs --without-lua \
--without-ruby --without-csharp --without-erlang --without-perl \
--without-php --without-php_extension --without-dart \
--without-haskell --without-go --without-rs --without-haxe \
--without-dotnetcore --without-d --without-qt4 --without-qt5 \
--without-java --without-swift \
--with-openssl=/opt/homebrew/opt/openssl

make install -j $(nproc)

export CXXFLAGS=$CXXFLAGS_OLD
export LDFLAGS=$LDFLAGS_OLD

## Compile build2

sh "${DOWNLOAD_PATH}/install_latest_build2.sh" ${INSTALL_PATH}/build2

## Compile libodb runtime libraries
mkdir -p ${DOWNLOAD_PATH}/libodb
cd ${DOWNLOAD_PATH}/libodb
${INSTALL_PATH}/build2/bin/bpkg create --quiet --jobs $(nproc) cc \
config.cxx=g++ \
config.cc.coptions=-O3 \
config.bin.rpath=${INSTALL_PATH}/odb/lib \
config.install.root=${INSTALL_PATH}/odb

### Getting the source
${INSTALL_PATH}/build2/bin/bpkg add https://pkg.cppget.org/1/beta --trust-yes
${INSTALL_PATH}/build2/bin/bpkg fetch --trust-yes

### Building ODB runtime library
${INSTALL_PATH}/build2/bin/bpkg build libodb --yes
${INSTALL_PATH}/build2/bin/bpkg build libodb-sqlite --yes
${INSTALL_PATH}/build2/bin/bpkg build libodb-pgsql --yes
${INSTALL_PATH}/build2/bin/bpkg install --all --recursive

## Compile odb compiler
mkdir -p ${DOWNLOAD_PATH}/odb
cd ${DOWNLOAD_PATH}/odb
bpkg create --quiet --jobs $(nproc) cc \
config.cxx=g++-13 \
config.cc.poptions=-I/opt/homebrew/include \
config.cc.coptions=-O3 \
config.bin.rpath=${INSTALL_PATH}/odb/lib \
config.install.root=${INSTALL_PATH}/odb

### Getting the source
bpkg add https://pkg.cppget.org/1/beta --trust-yes
bpkg fetch --trust-yes

### Building ODB Compiler
bpkg build odb --yes
bpkg install odb
36 changes: 36 additions & 0 deletions .github/scripts/macos-12/download_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Download installers for compiled dependencies

mkdir -p "${DOWNLOAD_PATH}"

## Thrift 0.16

wget -O ${DOWNLOAD_PATH}/thrift-0.16.0.tar.gz "http://archive.apache.org/dist/thrift/0.16.0/thrift-0.16.0.tar.gz"

## ODB

wget -O "${DOWNLOAD_PATH}/install_latest_build2.sh" "https://github.com/Ericsson/CodeCompass/raw/master/scripts/install_latest_build2.sh"
build2_version=$(sh "${DOWNLOAD_PATH}/install_latest_build2.sh" --version)
odb_signature=$(wget -qO- https://pkg.cppget.org/1/beta/signature.manifest)

# Calculate hash of dependencies for Github Cache Action

dependencies_to_hash=("thrift-0.16.0.tar.gz")

concatenated_hashes=""
for file in "${dependencies_to_hash[@]}"; do
file_hash=$(md5sum "${DOWNLOAD_PATH}/${file}" | awk '{print $1}')
concatenated_hashes="${concatenated_hashes}${file_hash}"
done
concatenated_hashes="${concatenated_hashes}${build2_version}${odb_signature}"

hash_value=$(echo -n "$concatenated_hashes" | md5sum | awk '{print $1}')

## Save said hash

### Restore action
echo "macos-12-compile-hash-key=${hash_value}" >> "$GITHUB_OUTPUT"

### Save action
echo "CACHE_KEY=${hash_value}" >> "$GITHUB_ENV"
6 changes: 6 additions & 0 deletions .github/scripts/macos-12/postcompile_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Post compilation configuration for building (environmental variables, library location settings etc..)

echo "${INSTALL_PATH}/odb/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${INSTALL_PATH}/odb:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV
21 changes: 21 additions & 0 deletions .github/scripts/macos-12/setup_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Install available dependencies from HomeBrew
brew install wget
brew install node
brew install sqlite
brew install cmake
brew install llvm@15
brew install gcc
brew install boost
brew install bison
brew install graphviz
brew install googletest
brew install libgit2
brew install libmagic
brew install openssl@3
brew install gnu-sed
brew install coreutils

# Place Bison on the PATH
echo "/opt/homebrew/opt/bison/bin" >> $GITHUB_PATH
4 changes: 4 additions & 0 deletions .github/scripts/macos-12/setup_postgresql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Install PostgreSQL
brew install postgresql@14
4 changes: 4 additions & 0 deletions .github/scripts/macos-12/setup_sqlite3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Install SQLite3
brew install sqlite
4 changes: 0 additions & 4 deletions .github/scripts/ubuntu-20.04/postcompile_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@

echo "${INSTALL_PATH}/thrift/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${INSTALL_PATH}/thrift:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV

# Clean up dependency sources and intermediate binaries to save space
rm -f ${DOWNLOAD_PATH}/thrift-0.16.0.tar.gz
rm -rf ${DOWNLOAD_PATH}/thrift-0.16.0/
14 changes: 12 additions & 2 deletions .github/scripts/ubuntu-20.04/setup_build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/bin/bash

# Update package repository
sudo apt-get update

# Add official LLVM repositories
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo tee /etc/apt/sources.list.d/llvm.list
echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo tee -a /etc/apt/sources.list.d/llvm.list
sudo apt-get update

# Install required packages for CodeCompass build
sudo apt-get install -y git cmake make g++ libboost-all-dev llvm-11-dev clang-11 \
libclang-11-dev odb libodb-dev default-jdk libssl-dev \
sudo apt-get install -y git cmake make g++ libboost-all-dev \
llvm-15-dev clang-15 libclang-15-dev odb \
libodb-dev default-jdk libssl-dev \
libgraphviz-dev libmagic-dev libgit2-dev ctags doxygen libgtest-dev npm libldap2-dev
3 changes: 0 additions & 3 deletions .github/scripts/ubuntu-22.04/postcompile_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

echo "${INSTALL_PATH}/odb/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${INSTALL_PATH}/odb:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV

# Clean up dependency sources and intermediate binaries to save space
rm -rf ${DOWNLOAD_PATH}/odb
5 changes: 4 additions & 1 deletion .github/scripts/ubuntu-22.04/setup_build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash

# Update package repository
sudo apt-get update

# Install required packages for CodeCompass build
sudo apt install git cmake make g++ libboost-all-dev \
llvm-11-dev clang-11 libclang-11-dev \
llvm-15-dev clang-15 libclang-15-dev \
gcc-11-plugin-dev thrift-compiler libthrift-dev \
default-jdk libssl-dev libgraphviz-dev libmagic-dev libgit2-dev exuberant-ctags doxygen \
libldap2-dev libgtest-dev
14 changes: 4 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
BUILD_TYPE: RelWithDebInfo
## For locally compiled dependencies
INSTALL_PATH: ${{github.workspace}}/dependencies/install
## Temp directory for installers of the downloaded dependencies
# Temp directory for installers of the downloaded dependencies
DOWNLOAD_PATH: ${{github.workspace}}/dependencies/download

permissions: read-all
Expand All @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
db: [postgresql, sqlite3]
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-20.04, ubuntu-22.04, macos-12]
fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -45,9 +45,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Update apt-get
run: sudo apt-get update

- name: Install required packages for build
run: ./.github/scripts/${{ matrix.os }}/setup_build.sh

Expand Down Expand Up @@ -137,8 +134,8 @@ jobs:
-DCMAKE_INSTALL_PREFIX=$HOME/${{ matrix.os }}/${{ matrix.db }}/cc-install
-DDATABASE=$DB_TYPE
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
-DLLVM_DIR=/usr/lib/llvm-11/cmake
-DClang_DIR=/usr/lib/cmake/clang-11
-DLLVM_DIR=/usr/lib/llvm-15/cmake
-DClang_DIR=/usr/lib/cmake/clang-15
-DTEST_DB=$DB_CONNSTRING

- name: Build
Expand Down Expand Up @@ -209,9 +206,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Update apt-get
run: sudo apt-get update

# We need build dependencies for CodeCompass, as it will parsed as well
- name: Install required packages for build
run: ./.github/scripts/${{ matrix.os }}/setup_build.sh
Expand Down
8 changes: 4 additions & 4 deletions .gitlab/build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ export PATH=$DEPS_INSTALL_RUNTIME_DIR/python-install/bin:$PATH

if [ ! -f $DEPS_INSTALL_RUNTIME_DIR/llvm-install/bin/clang ]; then
cd $PACKAGES_DIR
wget --no-verbose --no-clobber https://github.com/llvm/llvm-project/archive/llvmorg-11.1.0.tar.gz
tar -xf llvmorg-11.1.0.tar.gz
mv llvm-project-llvmorg-11.1.0 llvm-project
wget --no-verbose --no-clobber https://github.com/llvm/llvm-project/archive/llvmorg-15.0.7.tar.gz
tar -xf llvmorg-15.0.7.tar.gz
mv llvm-project-llvmorg-15.0.7 llvm-project
mkdir llvm-project/build
cd llvm-project/build

Expand All @@ -264,7 +264,7 @@ if [ ! -f $DEPS_INSTALL_RUNTIME_DIR/llvm-install/bin/clang ]; then
-DLLVM_ENABLE_RTTI=ON

make install --quiet --jobs $(nproc)
rm -f $PACKAGES_DIR/llvmorg-11.1.0.tar.gz
rm -f $PACKAGES_DIR/llvmorg-15.0.7.tar.gz
else
echo "Found LLVM/Clang in cache."
fi
Expand Down
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ include(Functions.cmake)
# Do some sanity check on the testing setup and enable testing if applicable.
include(Testing.cmake)

find_package(Boost REQUIRED COMPONENTS filesystem log program_options regex system thread)
find_package(Java REQUIRED)
find_package(ODB REQUIRED)
find_package(Threads REQUIRED)
find_package(Thrift REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem log program_options regex system thread)
find_package(Java REQUIRED)
find_package(ODB REQUIRED)
find_package(Threads REQUIRED)
find_package(Thrift REQUIRED)
find_package(Graphviz REQUIRED)
find_package(LibMagic REQUIRED)
find_package(GTest)

include(UseJava)
Expand Down
83 changes: 83 additions & 0 deletions FindGraphviz.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# - Try to find Graphviz
# Once done this will define
#
# GRAPHVIZ_FOUND - system has Graphviz
# GRAPHVIZ_INCLUDE_DIRS - Graphviz include directories
# GRAPHVIZ_CDT_LIBRARY - Graphviz CDT library
# GRAPHVIZ_GVC_LIBRARY - Graphviz GVC library
# GRAPHVIZ_CGRAPH_LIBRARY - Graphviz CGRAPH library
# GRAPHVIZ_PATHPLAN_LIBRARY - Graphviz PATHPLAN library
# GRAPHVIZ_VERSION - Graphviz version
#
# This module reads hints about search locations from the following cmake variables:
# GRAPHVIZ_ROOT - Graphviz installation prefix
# (containing bin/, include/, etc.)

# Copyright (c) 2009, Adrien Bustany, <[email protected]>
# Copyright (c) 2013-2014 Kevin Funk <[email protected]>

# Version computation and some cleanups by Allen Winter <[email protected]>
# Copyright (c) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>

# Simplified script by Dogan Can <[email protected]>
# Copyright (c) 2014 University of Southern California

# Redistribution and use is allowed according to the terms of the GPLv3+ license.
# Source: https://github.com/usc-sail/barista/blob/master/cmake/FindGraphviz.cmake

if(GRAPHVIZ_ROOT)
set(_GRAPHVIZ_INCLUDE_DIR ${GRAPHVIZ_ROOT}/include)
set(_GRAPHVIZ_LIBRARY_DIR ${GRAPHVIZ_ROOT}/lib)
endif()

find_path(GRAPHVIZ_INCLUDE_DIR NAMES graphviz/cgraph.h
HINTS ${_GRAPHVIZ_INCLUDE_DIR})
find_library(GRAPHVIZ_CDT_LIBRARY NAMES cdt
HINTS ${_GRAPHVIZ_LIBRARY_DIR})
find_library(GRAPHVIZ_GVC_LIBRARY NAMES gvc
HINTS ${_GRAPHVIZ_LIBRARY_DIR})
find_library(GRAPHVIZ_CGRAPH_LIBRARY NAMES cgraph
HINTS ${_GRAPHVIZ_LIBRARY_DIR})
find_library(GRAPHVIZ_PATHPLAN_LIBRARY NAMES pathplan
HINTS ${_GRAPHVIZ_LIBRARY_DIR})

if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_GVC_LIBRARY
AND GRAPHVIZ_CGRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY)
set(GRAPHVIZ_FOUND TRUE)
else()
set(GRAPHVIZ_FOUND FALSE)
endif()

# Ok, now compute the version
if(GRAPHVIZ_FOUND)
set(FIND_GRAPHVIZ_VERSION_SOURCE
"#include <graphviz/graphviz_version.h>\n#include <stdio.h>\n int main()\n {\n printf(\"%s\",PACKAGE_VERSION);return 1;\n }\n")
set(FIND_GRAPHVIZ_VERSION_SOURCE_FILE ${CMAKE_BINARY_DIR}/CMakeTmp/FindGRAPHVIZ.cxx)
file(WRITE "${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}" "${FIND_GRAPHVIZ_VERSION_SOURCE}")

set(FIND_GRAPHVIZ_VERSION_ADD_INCLUDES
"-DINCLUDE_DIRECTORIES:STRING=${GRAPHVIZ_INCLUDE_DIR}")

try_run(RUN_RESULT COMPILE_RESULT
${CMAKE_BINARY_DIR}
${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}
CMAKE_FLAGS "${FIND_GRAPHVIZ_VERSION_ADD_INCLUDES}"
RUN_OUTPUT_VARIABLE GRAPHVIZ_VERSION)

if(COMPILE_RESULT AND RUN_RESULT EQUAL 1)
message(STATUS "Graphviz version: ${GRAPHVIZ_VERSION}")
else()
message(FATAL_ERROR "Unable to compile or run the graphviz version detection program.")
endif()

set(GRAPHVIZ_INCLUDE_DIRS ${GRAPHVIZ_INCLUDE_DIR} ${GRAPHVIZ_INCLUDE_DIR}/graphviz)

if(NOT Graphviz_FIND_QUIETLY)
message(STATUS "Graphviz include: ${GRAPHVIZ_INCLUDE_DIRS}")
message(STATUS "Graphviz libraries: ${GRAPHVIZ_CDT_LIBRARY} ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_CGRAPH_LIBRARY} ${GRAPHVIZ_PATHPLAN_LIBRARY}")
endif()
endif()

if(Graphviz_FIND_REQUIRED AND NOT GRAPHVIZ_FOUND)
message(FATAL_ERROR "Could not find GraphViz.")
endif()
Loading
Loading