Skip to content

Commit

Permalink
Merge pull request #15 from dr8co/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dr8co authored Feb 21, 2024
2 parents 5923ce6 + 5e81e8a commit 59e9f0e
Show file tree
Hide file tree
Showing 32 changed files with 1,234 additions and 854 deletions.
144 changes: 95 additions & 49 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@ jobs:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
fail-fast: false

matrix:
os: [ ubuntu-latest, macos-13 ]
build_type: [ Debug, Release ]
c_compiler: [ gcc, clang ]
c_compiler: [ clang ]
include:
- os: macos-13
c_compiler: gcc
cpp_compiler: g++-13
c_compiler: clang
cpp_compiler: clang++
env:
- LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
- CPPFLAGS="-I/usr/local/opt/llvm/include"
- LD_LIBRARY_PATH="/usr/local/opt/llvm/lib"
- DYLD_LIBRARY_PATH="/usr/local/opt/llvm/lib"

- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++-13
LDFLAGS=: "-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
CPPFLAGS: "-I/usr/local/opt/llvm/include I/usr/local/opt/llvm/include/c++/v1"
LD_LIBRARY_PATH: "/usr/local/opt/llvm/lib"
DYLD_LIBRARY_PATH: "/usr/local/opt/llvm/lib"

# - os: macos-13
# c_compiler: gcc
# cpp_compiler: g++-13
#
# - os: ubuntu-latest
# c_compiler: gcc
# cpp_compiler: g++-13

- os: ubuntu-latest
c_compiler: clang
Expand All @@ -38,75 +42,117 @@ jobs:
# Don't include the following configurations in the matrix
exclude:
- os: macos-13
c_compiler: clang # LLVM Clang17+ required, and building it from the source will take longer
build_type: Debug

steps:
# Install dependencies: cmake, ninja, gcc, libgcrypt, openssl, readline, and libsodium
- name: Install Dependencies
if: matrix.os == 'macos-13'
run: |
brew update
brew install cmake ninja gcc libgcrypt openssl@3 readline libsodium
brew install llvm cmake ninja gcc libgcrypt openssl@3 readline libsodium gnupg pinentry
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/gcc@13/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/gcc@13/lib/gcc/13:$PATH"' >> ~/.bash_profile
- name: Install Dependencies
if: matrix.os == 'ubuntu-latest'
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo add-apt-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/ppa
sudo apt update
sudo apt install -y cmake ninja-build gcc-13 g++-13 clang-17 lldb-17 lld-17 libc++-17-dev libc++abi-17-dev \
libomp-17-dev libgcrypt20 openssl libreadline8 libsodium23 libsodium-dev
# - name: Install Dependencies
# if: matrix.os == 'ubuntu-latest'
# run: |
# wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
# sudo add-apt-repository -y "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
# sudo add-apt-repository -y ppa:ubuntu-toolchain-r/ppa
# sudo apt update
# sudo apt install -y cmake ninja-build gcc-13 g++-13 clang-17 lldb-17 lld-17 libc++-17-dev libc++abi-17-dev \
# libomp-17-dev libgcrypt20 openssl libreadline8 libsodium23 libsodium-dev


- uses: actions/checkout@v4

# Install BLAKE3
- name: Build BLAKE3
run: |
OS=${{ matrix.os }}
COMMAND="./scripts/install-blake3.sh ${{ matrix.c_compiler }}"
if [ "$OS" == "macos-13" ]; then
$COMMAND
elif [ "$OS" == "ubuntu-latest" ]; then
sudo $COMMAND
fi
- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
# Build project
- name: Build PrivacyShield
if: matrix.os == 'ubuntu-latest'
run: |
sudo ./scripts/buildscript.sh
# OS=${{ matrix.os }}
# COMMAND="./scripts/install-blake3.sh ${{ matrix.c_compiler }}"
# if [ "$OS" == "macos-13" ]; then
# $COMMAND
# elif [ "$OS" == "ubuntu-latest" ]; then
# sudo $COMMAND
# fi
#

- name: Install Blake3
if: matrix.os == 'macos-13'
run: |
./scripts/install-blake3.sh ${{ matrix.c_compiler }}
- name: Configure CMake
if: matrix.os == 'macos-13'
run: >
export LDFLAGS="-L/usr/local/opt/gcc@13/lib/gcc/13 -Wl,-rpath,/usr/local/opt/gcc@13/lib/gcc/13";
export CPPFLAGS="-I/usr/local/opt/gcc@13/include/c++/13 -I/usr/local/opt/gcc@13/include/c++/13/x86_64-apple-darwin22";
export LD_LIBRARY_PATH="/usr/local/opt/gcc@13/lib/gcc/13";
export DYLD_LIBRARY_PATH="/usr/local/opt/gcc@13/lib/gcc/13";
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++
-DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang
-DCMAKE_CXX_FLAGS="-I/usr/local/opt/gcc@13/include/c++/13 -I/usr/local/opt/gcc@13/include/c++/13/x86_64-apple-darwin22 -L/usr/local/opt/gcc@13/lib/gcc/13 -Wl,-rpath,/usr/local/opt/gcc@13/lib/gcc/13 -stdlib=libstdc++"
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }} -G Ninja
- name: Build
if: matrix.os == 'macos-13'
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 4

- name: Test
#
# - name: Test
# working-directory: ${{ steps.strings.outputs.build-output-dir }}
# # Execute tests defined by the CMake configuration
# run: ctest --build-config ${{ matrix.build_type }}
#
- name: Package
if: matrix.os == 'macos-13' && matrix.build_type == 'Release'
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration
run: ctest --build-config ${{ matrix.build_type }}

# Add execution permission to the binary and tar it
run: |
cpack -G DragNDrop
- name: Package
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'Release'
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: |
chmod +x privacyShield
tar -czvf privacyShield.tar.gz privacyShield
# Upload the built artifacts
sudo cpack
sudo chown -R $USER:$USER "${{ github.workspace }}/Packages"
- name: Import GPG Key
if: matrix.build_type == 'Release'
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
passphrase: ${{ secrets.GPG_PASS }}
trust_level: 5

- name: Sign Package
if: matrix.build_type == 'Release'
working-directory: ${{ github.workspace }}
run: |
for file in Packages/*; do
gpg --batch --status-file ~/gpg_log.txt --passphrase ${{ secrets.GPG_PASS }} --default-key [email protected] \
--pinentry-mode=loopback --detach-sign "$file" || (cat ~/gpg_log.txt && exit 1)
done
#
# # Upload the built artifacts
- name: Upload Artifacts
if: matrix.build_type == 'Release'
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os }}-${{ matrix.build_type }}.tar.gz"
path: "${{ steps.strings.outputs.build-output-dir }}/privacyShield.tar.gz"
name: "${{ matrix.os }}-${{ matrix.build_type }}"
path: "${{ github.workspace }}/Packages"
overwrite: true

if-no-files-found: 'warn'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.idea/**/dictionaries
.idea/**/shelf
.idea/**/Project_Default.xml
.idea/**/editor.xml

# AWS User-specific
.idea/**/aws.xml
Expand Down Expand Up @@ -617,3 +618,5 @@ Network Trash Folder
Temporary Items
.apdisk

# Generated packages
Packages/
47 changes: 31 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,37 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses.

cmake_minimum_required(VERSION 3.25)
# CMake 3.28+ is required for C++20 modules
cmake_minimum_required(VERSION 3.28)

project(privacyShield
VERSION 1.0.0
VERSION 2.0.0
DESCRIPTION "A suite of tools for privacy and security"
LANGUAGES CXX)

# If the user is not on a unix-like system, fail the build
set(CMAKE_PROJECT_HOMEPAGE_URL "https://shield.boujee.tech")

# C++23 support is required for this project
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# If the target system is not UNIX, fail the build
if (NOT UNIX)
message(FATAL_ERROR "This project is only supported on unix-like systems.")
endif ()

# If the user does not specify a build type, default to Release
# If the build type is not specified, default to Release
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()

# Set the path to additional CMake modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")

# C++23 is required for this project
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Additional checks for the Debug build
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wpedantic")

# Check for extra compiler warnings and errors in debug config
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic")

# Find dependencies
# Find the required packages
find_package(OpenSSL REQUIRED)
find_package(Sodium REQUIRED)
find_package(Readline REQUIRED)
Expand All @@ -53,21 +56,33 @@ add_executable(privacyShield)

# Add sources for the target
file(GLOB_RECURSE PRIVACY_SHIELD_SOURCES
"${CMAKE_SOURCE_DIR}/src/*.cpp"
"${CMAKE_SOURCE_DIR}/src/*.hpp")
"${CMAKE_SOURCE_DIR}/src/*.cpp")

target_sources(privacyShield PRIVATE ${PRIVACY_SHIELD_SOURCES})

# Link dependencies
# C++20 Modules
file(GLOB_RECURSE PRIVACY_SHIELD_MODULES
"${CMAKE_SOURCE_DIR}/src/*.cppm")

target_sources(privacyShield
PRIVATE
FILE_SET CXX_MODULES FILES
${PRIVACY_SHIELD_MODULES}
)

# Link libraries
target_link_libraries(privacyShield
PRIVATE OpenSSL::Crypto
PRIVATE Readline::Readline
PRIVATE Sodium::sodium
PRIVATE Gcrypt::Gcrypt
PRIVATE BLAKE3::blake3)

# Install the binary (optional)
# Install the binary (optional), with 0755 permissions
include(GNUInstallDirs)
install(TARGETS privacyShield
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)

include(Packing)
50 changes: 40 additions & 10 deletions CMakeModules/FindGcrypt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@
#
#################################################################################
#
# A CMake module to find a local installation of Gcrypt
# A CMake module to find a local installation of Gcrypt and Gpg-error

# This module sets the following variables:
# This module sets the following variables for Gcrypt:
# GCRYPT_FOUND - True if Gcrypt is found
# GCRYPT_INCLUDE_DIR - Include directories for Gcrypt
# GCRYPT_LIBRARIES - Linker flags for Gcrypt
# GCRYPT_VERSION - Version of Gcrypt

# This module also provides the imported target Gcrypt::Gcrypt
# This module also sets the following variables for Gpg-error:
# GPG_ERROR_FOUND - True if Gpg-error is found
# GPG_ERROR_INCLUDE_DIR - Include directories for Gpg-error
# GPG_ERROR_LIBRARIES - Linker flags for Gpg-error
# GPG_ERROR_VERSION - Version of Gpg-error

# Find the pkg-config package for Gcrypt
# This module also provides the imported targets Gcrypt::Gcrypt and Gcrypt::Gpg_error

# Find the pkg-config package for Gcrypt & Gpg-error
find_package(PkgConfig REQUIRED)
pkg_check_modules(GCRYPT REQUIRED libgcrypt)
pkg_check_modules(GPG_ERROR gpg-error)

# Set the Gcrypt variables
set(GCRYPT_FOUND TRUE)
Expand All @@ -38,27 +45,50 @@ set(GCRYPT_VERSION ${GCRYPT_VERSION})

# Provide imported target for Gcrypt
add_library(Gcrypt::Gcrypt UNKNOWN IMPORTED)

set_target_properties(Gcrypt::Gcrypt PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GCRYPT_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${GCRYPT_LIBRARIES}"
)
INTERFACE_LINK_LIBRARIES "${GCRYPT_LIBRARIES}")

# Set the Gpg-error variables
add_library(Gcrypt::Gpg_error UNKNOWN IMPORTED)
set_target_properties(Gcrypt::Gpg_error PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GPG_ERROR_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${GPG_ERROR_LIBRARIES}")

# Find the actual location of the Gcrypt library file
find_library(GCRYPT_LIBRARY
NAMES libgcrypt.so libgcrypt.dylib libgcrypt.a
HINTS ${GCRYPT_LIBRARY_DIRS}
)
HINTS ${GCRYPT_LIBRARY_DIRS})

# Find the actual location of the Gpg-error library file
find_library(GPG_ERROR_LIBRARY
NAMES libgpg-error.so libgpg-error.dylib libgpg-error.a
HINTS ${GPG_ERROR_LIBRARY_DIRS})

# Set the imported location dynamically
if (GCRYPT_LIBRARY)
set_target_properties(Gcrypt::Gcrypt PROPERTIES
IMPORTED_LOCATION "${GCRYPT_LIBRARY}"
)
IMPORTED_LOCATION "${GCRYPT_LIBRARY}")
else ()
message(FATAL_ERROR "Gcrypt library not found")
endif ()


# Set the imported location dynamically
if (GPG_ERROR_LIBRARY)
set_target_properties(Gcrypt::Gpg_error PROPERTIES
IMPORTED_LOCATION "${GPG_ERROR_LIBRARY}")
else ()
message(FATAL_ERROR "Gpg-error library not found")
endif ()

# Print Gcrypt information
message(STATUS "Found Gcrypt ${GCRYPT_VERSION}")
message(STATUS "Gcrypt include directories: ${GCRYPT_INCLUDE_DIR}")
message(STATUS "Gcrypt libraries: ${GCRYPT_LIBRARIES}")

# Print Gpg-error information
message(STATUS "Found Gpg-error ${GPG_ERROR_VERSION}")
message(STATUS "Gpg-error include directories: ${GPG_ERROR_INCLUDE_DIR}")
message(STATUS "Gpg-error libraries: ${GPG_ERROR_LIBRARIES}")
Loading

0 comments on commit 59e9f0e

Please sign in to comment.