Skip to content

Commit

Permalink
Port to matrix-rust-sdk-crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFella committed Nov 16, 2024
1 parent 4999cf7 commit a07274a
Show file tree
Hide file tree
Showing 58 changed files with 5,480 additions and 6,491 deletions.
51 changes: 35 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Install dependencies (Linux)
if: startsWith(matrix.os, 'ubuntu')
run: |
COMMON_PKGS="libolm-dev ninja-build gnome-keyring g++$GCC_VERSION clang$CLANG_VERSION"
COMMON_PKGS="libolm-dev ninja-build gnome-keyring rustc cargo g++$GCC_VERSION clang$CLANG_VERSION"
# See https://github.com/actions/runner-images/issues/9679
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
# Add LLVM repo for newer Clang
Expand Down Expand Up @@ -123,6 +123,25 @@ jobs:
cmake -E make_directory ${{ runner.workspace }}/build
echo "BUILD_PATH=${{ runner.workspace }}/build/libQuotient" >>$GITHUB_ENV
- name: Install Rustup using win.rustup.rs
if: startsWith(matrix.os, 'windows')
run: |
# Disable the download progress bar which can cause perf issues
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc
del rustup-init.exe
rustup target add x86_64-pc-windows-msvc
rustup --version
shell: powershell

- name: Install Rustup
if: startsWith(matrix.os, 'macos')
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
sh rustup-init.sh -y --default-toolchain none
rustup target add "x86_64-apple-darwin"
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
if: startsWith(matrix.os, 'windows')
Expand All @@ -141,12 +160,12 @@ jobs:
cmake -S qtkeychain -B qtkeychain/build -DBUILD_WITH_QT6=ON $CMAKE_ARGS
cmake --build qtkeychain/build --target install
- name: Build and install Olm
- name: Build and install Corrosion
run: |
cd ..
git clone https://gitlab.matrix.org/matrix-org/olm.git
cmake -S olm -B olm/build $CMAKE_ARGS
cmake --build olm/build --target install
git clone https://github.com/corrosion-rs/corrosion
cmake -S corrosion -B corrosion/build $CMAKE_ARGS
cmake --build corrosion/build --target install
- name: Get CS API definitions; clone and build GTAD
if: matrix.update-api
Expand All @@ -172,20 +191,20 @@ jobs:

- name: Configure libQuotient
run: |
cmake -S $GITHUB_WORKSPACE -B $BUILD_PATH $CMAKE_ARGS -DQuotient_INSTALL_TESTS=ON
cmake -S $GITHUB_WORKSPACE -B build $CMAKE_ARGS -DQuotient_INSTALL_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1
- name: Regenerate API code
if: matrix.update-api
run: cmake --build ../build/libQuotient --target update-api
run: cmake --build build --target update-api

- name: Build and install libQuotient
shell: pwsh
run: |
if [[ '${{ matrix.static-analysis }}' == 'sonar' ]]; then
BUILD_WRAPPER="${{ steps.sonar.outputs.build-wrapper-binary }} --out-dir $BUILD_PATH/sonar"
fi
$BUILD_WRAPPER cmake --build $BUILD_PATH --target all
cmake --build $BUILD_PATH --target install
ls ~/.local$BIN_DIR/quotest
# if [[ '${{ matrix.static-analysis }}' == 'sonar' ]]; then
# BUILD_WRAPPER="${{ steps.sonar.outputs.build-wrapper-binary }} --out-dir build/sonar"
# fi
cmake --build build --target all
cmake --build build --target install
- name: Run tests
env:
Expand All @@ -195,7 +214,7 @@ jobs:
QT_LOGGING_RULES: 'quotient.*.debug=true;quotient.jobs.sync.debug=false;quotient.events.ephemeral.debug=false;quotient.events.state.debug=false;quotient.events.members.debug=false'
QT_MESSAGE_PATTERN: '%{time h:mm:ss.zzz}|%{category}|%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}|%{message}'
run: |
CTEST_ARGS="--test-dir $BUILD_PATH --output-on-failure"
CTEST_ARGS="--test-dir build --output-on-failure"
if [[ '${{ runner.os }}' != 'Linux' ]]; then
CTEST_ARGS="$CTEST_ARGS -E testolmaccount"
else
Expand All @@ -219,14 +238,14 @@ jobs:
SONAR_SERVER_URL: 'https://sonarcloud.io'
run: |
mkdir .coverage && pushd .coverage
find $BUILD_PATH -name '*.gcda' -print0 \
find ../build -name '*.gcda' -print0 \
| xargs -0 gcov$GCC_VERSION -s $GITHUB_WORKSPACE -pr
# Coverage of the test source code is not tracked, as it is always 100%
# (if not, some tests failed and broke the build at an earlier stage)
rm -f quotest* autotests*
popd
${{ steps.sonar.outputs.sonar-scanner-binary }} \
-Dsonar.host.url="$SONAR_SERVER_URL" \
-Dsonar.cfamily.compile-commands="$BUILD_PATH/sonar/compile_commands.json" \
-Dsonar.cfamily.compile-commands="build/compile_commands.json" \
-Dsonar.cfamily.threads=2 \
-Dsonar.cfamily.gcov.reportsPath=.coverage
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ compile_commands.json
# Created by doxygen
html/
latex/

Quotient/crypto-sdk/target
.kateproject.build
60 changes: 22 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,14 @@ find_package(${Qt} ${QtMinVersion} REQUIRED Core Network Gui Test Sql)
get_filename_component(Qt_Prefix "${${Qt}_DIR}/../../../.." ABSOLUTE)

find_package(${Qt}Keychain REQUIRED)
find_package(Corrosion REQUIRED)

find_package(Olm 3.2.5 REQUIRED)
set_package_properties(Olm PROPERTIES
DESCRIPTION "Implementation of the Olm and Megolm cryptographic ratchets"
URL "https://gitlab.matrix.org/matrix-org/olm"
TYPE REQUIRED
)
if(NOT WIN32)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SQLITE sqlite3 REQUIRED IMPORTED_TARGET)
endif()

find_package(OpenSSL 1.1.0 REQUIRED)
set_package_properties(OpenSSL PROPERTIES
DESCRIPTION "Open source SSL and TLS implementation and cryptographic library"
URL "https://www.openssl.org/"
TYPE REQUIRED
)
corrosion_import_crate(MANIFEST_PATH Quotient/crypto-sdk/Cargo.toml)

add_library(${QUOTIENT_LIB_NAME})

Expand Down Expand Up @@ -174,19 +168,8 @@ target_sources(${QUOTIENT_LIB_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS .
Quotient/jobs/syncjob.h
Quotient/jobs/mediathumbnailjob.h
Quotient/jobs/downloadfilejob.h
Quotient/database.h
Quotient/connectionencryptiondata_p.h
Quotient/keyverificationsession.h
Quotient/e2ee/e2ee_common.h
Quotient/e2ee/qolmaccount.h
Quotient/e2ee/qolmsession.h
Quotient/e2ee/qolminboundsession.h
Quotient/e2ee/qolmoutboundsession.h
Quotient/e2ee/qolmutility.h
Quotient/e2ee/qolmsession.h
Quotient/e2ee/qolmmessage.h
Quotient/e2ee/cryptoutils.h
Quotient/e2ee/sssshandler.h
Quotient/events/keyverificationevent.h
Quotient/keyimport.h
Quotient/qt_connection_util.h
Expand Down Expand Up @@ -233,19 +216,8 @@ target_sources(${QUOTIENT_LIB_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS .
Quotient/jobs/syncjob.cpp
Quotient/jobs/mediathumbnailjob.cpp
Quotient/jobs/downloadfilejob.cpp
Quotient/database.cpp
Quotient/connectionencryptiondata_p.cpp
Quotient/keyverificationsession.cpp
Quotient/e2ee/e2ee_common.cpp
Quotient/e2ee/qolmaccount.cpp
Quotient/e2ee/qolmsession.cpp
Quotient/e2ee/qolminboundsession.cpp
Quotient/e2ee/qolmoutboundsession.cpp
Quotient/e2ee/qolmutility.cpp
Quotient/e2ee/qolmsession.cpp
Quotient/e2ee/qolmmessage.cpp
Quotient/e2ee/cryptoutils.cpp
Quotient/e2ee/sssshandler.cpp
Quotient/keyimport.cpp
libquotientemojis.qrc
)
Expand Down Expand Up @@ -362,9 +334,22 @@ target_include_directories(${QUOTIENT_LIB_NAME} PUBLIC
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${QUOTIENT_FORCE_NAMESPACED_INCLUDES}>>:${CMAKE_CURRENT_SOURCE_DIR}/Quotient>>
)

find_package(OpenSSL REQUIRED)

target_link_libraries(${QUOTIENT_LIB_NAME}
PUBLIC ${Qt}::Core ${Qt}::Network ${Qt}::Gui qt${${Qt}Core_VERSION_MAJOR}keychain Olm::Olm ${Qt}::Sql
PRIVATE OpenSSL::Crypto ${Qt}::CorePrivate)
PUBLIC ${Qt}::Core ${Qt}::Network ${Qt}::Gui qt${${Qt}Core_VERSION_MAJOR}keychain ${Qt}::Sql
PRIVATE ${Qt}::CorePrivate matrix_rust_sdk_crypto_cpp OpenSSL::Crypto)

if(NOT WIN32)
target_link_libraries(${QUOTIENT_LIB_NAME} PRIVATE PkgConfig::SQLITE)
else()
target_link_libraries(${QUOTIENT_LIB_NAME} PRIVATE Bcrypt.lib)
endif()

target_include_directories(${QUOTIENT_LIB_NAME} PRIVATE
${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET}/cxxbridge/matrix-rust-sdk-crypto/src/)



configure_file(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${QUOTIENT_LIB_NAME}.pc @ONLY NEWLINE_STYLE UNIX)

Expand All @@ -389,6 +374,7 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion
)

install(TARGETS matrix_rust_sdk_crypto_cpp EXPORT ${QUOTIENT_LIB_NAME}Targets)
export(PACKAGE ${QUOTIENT_LIB_NAME})
export(EXPORT ${QUOTIENT_LIB_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${QUOTIENT_LIB_NAME}/${QUOTIENT_LIB_NAME}Targets.cmake")
Expand Down Expand Up @@ -432,8 +418,6 @@ message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS " Header files install prefix: ${CMAKE_INSTALL_PREFIX}/${${PROJECT_NAME}_INSTALL_INCLUDEDIR}")
message(STATUS "Using Qt ${${Qt}_VERSION} at ${Qt_Prefix}")
message(STATUS "Using QtKeychain ${${Qt}Keychain_VERSION} at ${${Qt}Keychain_DIR}")
message(STATUS "Using libOlm ${Olm_VERSION} at ${Olm_DIR}")
message(STATUS "Using OpenSSL libcrypto ${OPENSSL_VERSION} at ${OPENSSL_CRYPTO_LIBRARY}")
message(STATUS)
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
FATAL_ON_MISSING_REQUIRED_PACKAGES)
Expand Down
Loading

0 comments on commit a07274a

Please sign in to comment.