Skip to content

Commit dd68852

Browse files
committed
Port to matrix-rust-sdk-crypto
1 parent 99775a9 commit dd68852

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+7651
-4864
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
run: |
5858
sudo apt-get -qq update
5959
sudo apt-get -q install \
60-
ninja-build clang$CLANG_VERSION qtkeychain-qt6-dev libsecret-1-dev libolm-dev gnome-keyring
60+
ninja-build clang$CLANG_VERSION qtkeychain-qt6-dev libsecret-1-dev libolm-dev gnome-keyring rustc cargo
6161
gnome-keyring-daemon -d --unlock <<<'' # Create a login keyring with no password
6262
6363
- name: Install Qt and necessary tools
@@ -124,6 +124,25 @@ jobs:
124124
cmake -E make_directory ${{ runner.workspace }}/build
125125
echo "BUILD_PATH=${{ runner.workspace }}/build/libQuotient" >>$GITHUB_ENV
126126
127+
- name: Install Rustup using win.rustup.rs
128+
if: startsWith(matrix.os, 'windows')
129+
run: |
130+
# Disable the download progress bar which can cause perf issues
131+
$ProgressPreference = "SilentlyContinue"
132+
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
133+
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc
134+
del rustup-init.exe
135+
rustup target add x86_64-pc-windows-msvc
136+
rustup --version
137+
shell: powershell
138+
139+
- name: Install Rustup
140+
if: startsWith(matrix.os, 'macos')
141+
run: |
142+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh
143+
sh rustup-init.sh -y --default-toolchain none
144+
rustup target add "x86_64-apple-darwin"
145+
127146
- name: Setup MSVC
128147
uses: ilammy/msvc-dev-cmd@v1
129148
if: startsWith(matrix.os, 'windows')
@@ -135,21 +154,29 @@ jobs:
135154
if: matrix.static-analysis == 'sonar'
136155
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v5
137156

138-
- name: Build and install QtKeychain
139-
if: "!startsWith(matrix.os, 'ubuntu')"
157+
158+
- name: Build and install QtKeychain (mac)
159+
if: startsWith(matrix.os, 'macos')
160+
run: |
161+
cd ..
162+
git clone -b v0.13.0 https://github.com/frankosterfeld/qtkeychain.git
163+
cmake -S qtkeychain -B qtkeychain/build -DBUILD_WITH_QT6=ON -DBUILD_TRANSLATIONS=OFF $CMAKE_ARGS
164+
cmake --build qtkeychain/build --target install
165+
166+
- name: Build and install QtKeychain (not mac)
167+
if: "!startsWith(matrix.os, 'macos')"
140168
run: |
141169
cd ..
142170
git clone -b 0.15.0 https://github.com/frankosterfeld/qtkeychain.git
143171
cmake -S qtkeychain -B qtkeychain/build -DBUILD_WITH_QT6=ON -DBUILD_TRANSLATIONS=OFF $CMAKE_ARGS
144172
cmake --build qtkeychain/build --target install
145173
146-
- name: Build and install Olm (non-Linux)
147-
if: "!startsWith(matrix.os, 'ubuntu')"
174+
- name: Build and install Corrosion
148175
run: |
149176
cd ..
150-
git clone https://gitlab.matrix.org/matrix-org/olm.git
151-
cmake -S olm -B olm/build $CMAKE_ARGS
152-
cmake --build olm/build --target install
177+
git clone -b v0.5.2 https://github.com/corrosion-rs/corrosion
178+
cmake -S corrosion -B corrosion/build $CMAKE_ARGS
179+
cmake --build corrosion/build --target install
153180
154181
- name: Get CS API definitions; clone and build GTAD
155182
if: matrix.update-api
@@ -182,13 +209,13 @@ jobs:
182209
run: cmake --build $BUILD_PATH --target update-api
183210

184211
- name: Build and install libQuotient
212+
shell: pwsh # The Rust toolchain chooses the wrong linker on bash, for some reason
185213
run: |
186-
if [[ '${{ matrix.static-analysis }}' == 'sonar' ]]; then
187-
BUILD_WRAPPER="${{ steps.sonar.outputs.build-wrapper-binary }} --out-dir $SONAR_DIR"
188-
fi
189-
$BUILD_WRAPPER cmake --build $BUILD_PATH --target all
190-
cmake --build $BUILD_PATH --target install
191-
ls ~/.local$BIN_DIR/quotest
214+
${{ matrix.static-analysis == 'sonar'
215+
&& format('{0} --out-dir {1}/sonar ', steps.sonar.outputs.build-wrapper-binary,
216+
env.BUILD_PATH)
217+
|| ''}}cmake --build $env:BUILD_PATH --target all
218+
cmake --build $env:BUILD_PATH --target install
192219
193220
- name: Run tests
194221
env:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ compile_commands.json
3232
# Created by doxygen
3333
html/
3434
latex/
35+
36+
Quotient/crypto-sdk/target
37+
.kateproject.build

CMakeLists.txt

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ else()
4343
endif ()
4444
endforeach ()
4545
foreach (FLAG unused-parameter gnu-zero-variadic-macro-arguments
46-
subobject-linkage) # Switch these off
46+
subobject-linkage dollar-in-identifier-extension) # Switch these off
4747
CHECK_CXX_COMPILER_FLAG("-Wno-${FLAG}" Wno-${FLAG}_SUPPORTED)
4848
if (Wno-${FLAG}_SUPPORTED AND
4949
NOT CMAKE_CXX_FLAGS MATCHES "W(no-)?${FLAG}($| )")
@@ -90,28 +90,23 @@ set(${PROJECT_NAME}_INSTALL_INCLUDEDIR
9090
set(CMAKE_AUTOMOC ON)
9191
set(CMAKE_AUTORCC ON)
9292

93-
find_package(${Qt} ${QtMinVersion} REQUIRED Core Network Gui Test Sql)
93+
find_package(${Qt} ${QtMinVersion} REQUIRED COMPONENTS Core Network Gui Test Sql)
94+
find_package(${Qt} ${QtMinVersion} COMPONENTS CorePrivate)
9495
get_filename_component(Qt_Prefix "${${Qt}_DIR}/../../../.." ABSOLUTE)
9596

9697
if(${Qt}Core_VERSION VERSION_GREATER_EQUAL 6.10)
9798
find_package(${Qt} ${QtMinVersion} REQUIRED COMPONENTS CorePrivate)
9899
endif()
99100

100101
find_package(${Qt}Keychain REQUIRED)
102+
find_package(Corrosion REQUIRED)
101103

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

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

116111
add_library(${QUOTIENT_LIB_NAME})
117112

@@ -143,6 +138,7 @@ target_sources(${QUOTIENT_LIB_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS .
143138
Quotient/eventitem.h
144139
Quotient/accountregistry.h
145140
Quotient/mxcreply.h
141+
Quotient/rust_util.h
146142
Quotient/events/event.h
147143
Quotient/events/roomevent.h
148144
Quotient/events/stateevent.h
@@ -176,23 +172,13 @@ target_sources(${QUOTIENT_LIB_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS .
176172
Quotient/jobs/syncjob.h
177173
Quotient/jobs/mediathumbnailjob.h
178174
Quotient/jobs/downloadfilejob.h
179-
Quotient/database.h
180-
Quotient/connectionencryptiondata_p.h
181175
Quotient/keyverificationsession.h
182176
Quotient/e2ee/e2ee_common.h
183-
Quotient/e2ee/qolmaccount.h
184-
Quotient/e2ee/qolmsession.h
185-
Quotient/e2ee/qolminboundsession.h
186-
Quotient/e2ee/qolmoutboundsession.h
187-
Quotient/e2ee/qolmutility.h
188-
Quotient/e2ee/qolmsession.h
189-
Quotient/e2ee/qolmmessage.h
190-
Quotient/e2ee/cryptoutils.h
191-
Quotient/e2ee/sssshandler.h
192177
Quotient/events/keyverificationevent.h
193178
Quotient/keyimport.h
194179
Quotient/qt_connection_util.h
195180
Quotient/thread.h
181+
Quotient/e2ee/sssshandler.h
196182
# The following headers are not included from public headers and so excluded from distribution
197183
PRIVATE FILE_SET private_headers TYPE HEADERS BASE_DIRS . FILES
198184
Quotient/logging_categories_p.h
@@ -218,6 +204,7 @@ target_sources(${QUOTIENT_LIB_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS .
218204
Quotient/eventitem.cpp
219205
Quotient/accountregistry.cpp
220206
Quotient/mxcreply.cpp
207+
Quotient/rust_util.cpp
221208
Quotient/events/event.cpp
222209
Quotient/events/roomevent.cpp
223210
Quotient/events/stateevent.cpp
@@ -239,21 +226,11 @@ target_sources(${QUOTIENT_LIB_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS .
239226
Quotient/jobs/syncjob.cpp
240227
Quotient/jobs/mediathumbnailjob.cpp
241228
Quotient/jobs/downloadfilejob.cpp
242-
Quotient/database.cpp
243-
Quotient/connectionencryptiondata_p.cpp
244229
Quotient/keyverificationsession.cpp
245230
Quotient/e2ee/e2ee_common.cpp
246-
Quotient/e2ee/qolmaccount.cpp
247-
Quotient/e2ee/qolmsession.cpp
248-
Quotient/e2ee/qolminboundsession.cpp
249-
Quotient/e2ee/qolmoutboundsession.cpp
250-
Quotient/e2ee/qolmutility.cpp
251-
Quotient/e2ee/qolmsession.cpp
252-
Quotient/e2ee/qolmmessage.cpp
253-
Quotient/e2ee/cryptoutils.cpp
254-
Quotient/e2ee/sssshandler.cpp
255231
Quotient/keyimport.cpp
256232
Quotient/thread.cpp
233+
Quotient/e2ee/sssshandler.cpp
257234
libquotientemojis.qrc
258235
)
259236

@@ -374,9 +351,22 @@ target_include_directories(${QUOTIENT_LIB_NAME} PUBLIC
374351
$<BUILD_INTERFACE:$<$<NOT:$<BOOL:${QUOTIENT_FORCE_NAMESPACED_INCLUDES}>>:${CMAKE_CURRENT_SOURCE_DIR}/Quotient>>
375352
)
376353

354+
find_package(OpenSSL REQUIRED)
355+
377356
target_link_libraries(${QUOTIENT_LIB_NAME}
378-
PUBLIC ${Qt}::Core ${Qt}::Network ${Qt}::Gui qt${${Qt}Core_VERSION_MAJOR}keychain Olm::Olm ${Qt}::Sql
379-
PRIVATE OpenSSL::Crypto ${Qt}::CorePrivate)
357+
PUBLIC ${Qt}::Core ${Qt}::Network ${Qt}::Gui qt${${Qt}Core_VERSION_MAJOR}keychain ${Qt}::Sql
358+
PRIVATE ${Qt}::CorePrivate matrix_rust_sdk_crypto_cpp OpenSSL::Crypto)
359+
360+
if(NOT WIN32)
361+
target_link_libraries(${QUOTIENT_LIB_NAME} PRIVATE PkgConfig::SQLITE)
362+
else()
363+
target_link_libraries(${QUOTIENT_LIB_NAME} PRIVATE Bcrypt.lib)
364+
endif()
365+
366+
target_include_directories(${QUOTIENT_LIB_NAME} PRIVATE
367+
${CMAKE_BINARY_DIR}/cargo/build/${Rust_CARGO_TARGET}/cxxbridge/matrix-rust-sdk-crypto/src/)
368+
369+
380370

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

@@ -401,6 +391,7 @@ write_basic_package_version_file(
401391
COMPATIBILITY SameMajorVersion
402392
)
403393

394+
install(TARGETS matrix_rust_sdk_crypto_cpp EXPORT ${QUOTIENT_LIB_NAME}Targets)
404395
export(PACKAGE ${QUOTIENT_LIB_NAME})
405396
export(EXPORT ${QUOTIENT_LIB_NAME}Targets
406397
FILE "${CMAKE_CURRENT_BINARY_DIR}/${QUOTIENT_LIB_NAME}/${QUOTIENT_LIB_NAME}Targets.cmake")
@@ -444,8 +435,6 @@ message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
444435
message(STATUS " Header files install prefix: ${CMAKE_INSTALL_PREFIX}/${${PROJECT_NAME}_INSTALL_INCLUDEDIR}")
445436
message(STATUS "Using Qt ${${Qt}_VERSION} at ${Qt_Prefix}")
446437
message(STATUS "Using QtKeychain ${${Qt}Keychain_VERSION} at ${${Qt}Keychain_DIR}")
447-
message(STATUS "Using libOlm ${Olm_VERSION} at ${Olm_DIR}")
448-
message(STATUS "Using OpenSSL libcrypto ${OPENSSL_VERSION} at ${OPENSSL_CRYPTO_LIBRARY}")
449438
message(STATUS)
450439
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
451440
FATAL_ON_MISSING_REQUIRED_PACKAGES)

0 commit comments

Comments
 (0)