Skip to content

Commit 1fffa85

Browse files
committed
test
1 parent a1dc85c commit 1fffa85

File tree

9 files changed

+31
-688
lines changed

9 files changed

+31
-688
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ jobs:
6868
- uses: msys2/setup-msys2@v2
6969
with:
7070
update: true
71-
install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-libusb mingw-w64-x86_64-unbound git
72-
- shell: msys2 {0}
73-
run: |
74-
curl -O https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-protobuf-c-1.4.1-1-any.pkg.tar.zst
75-
curl -O https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-protobuf-21.9-1-any.pkg.tar.zst
76-
pacman --noconfirm -U mingw-w64-x86_64-protobuf-c-1.4.1-1-any.pkg.tar.zst mingw-w64-x86_64-protobuf-21.9-1-any.pkg.tar.zst
71+
install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-libusb mingw-w64-x86_64-unbound mingw-w64-x86_64-protobuf mingw-w64-x86_64-protoc git
7772
- name: build
7873
run: |
7974
${{env.CCACHE_SETTINGS}}

cmake/CheckTrezor.cmake

Lines changed: 29 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ endfunction()
88
# Define default options via env vars
99
_trezor_default_val(USE_DEVICE_TREZOR ON)
1010
_trezor_default_val(USE_DEVICE_TREZOR_MANDATORY OFF)
11-
_trezor_default_val(USE_DEVICE_TREZOR_PROTOBUF_TEST ON)
1211
_trezor_default_val(USE_DEVICE_TREZOR_LIBUSB ON)
1312
_trezor_default_val(USE_DEVICE_TREZOR_UDP_RELEASE OFF)
1413
_trezor_default_val(USE_DEVICE_TREZOR_DEBUG OFF)
@@ -17,38 +16,11 @@ _trezor_default_val(TREZOR_DEBUG OFF)
1716
# Main options
1817
OPTION(USE_DEVICE_TREZOR "Trezor support compilation" $ENV{USE_DEVICE_TREZOR})
1918
OPTION(USE_DEVICE_TREZOR_MANDATORY "Trezor compilation is mandatory, fail build if Trezor support cannot be compiled" $ENV{USE_DEVICE_TREZOR_MANDATORY})
20-
OPTION(USE_DEVICE_TREZOR_PROTOBUF_TEST "Trezor Protobuf test" $ENV{USE_DEVICE_TREZOR_PROTOBUF_TEST})
2119
OPTION(USE_DEVICE_TREZOR_LIBUSB "Trezor LibUSB compilation" $ENV{USE_DEVICE_TREZOR_LIBUSB})
2220
OPTION(USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" $ENV{USE_DEVICE_TREZOR_UDP_RELEASE})
2321
OPTION(USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" $ENV{USE_DEVICE_TREZOR_DEBUG})
2422
OPTION(TREZOR_DEBUG "Main Trezor debugging switch" $ENV{TREZOR_DEBUG})
2523

26-
# Helper function to fix cmake < 3.6.0 FindProtobuf variables
27-
function(_trezor_protobuf_fix_vars)
28-
if(${CMAKE_VERSION} VERSION_LESS "3.6.0")
29-
foreach(UPPER
30-
PROTOBUF_SRC_ROOT_FOLDER
31-
PROTOBUF_IMPORT_DIRS
32-
PROTOBUF_DEBUG
33-
PROTOBUF_LIBRARY
34-
PROTOBUF_PROTOC_LIBRARY
35-
PROTOBUF_INCLUDE_DIR
36-
PROTOBUF_PROTOC_EXECUTABLE
37-
PROTOBUF_LIBRARY_DEBUG
38-
PROTOBUF_PROTOC_LIBRARY_DEBUG
39-
PROTOBUF_LITE_LIBRARY
40-
PROTOBUF_LITE_LIBRARY_DEBUG
41-
)
42-
if (DEFINED ${UPPER})
43-
string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER})
44-
if (NOT DEFINED ${Camel})
45-
set(${Camel} ${${UPPER}} PARENT_SCOPE)
46-
endif()
47-
endif()
48-
endforeach()
49-
endif()
50-
endfunction()
51-
5224
macro(trezor_fatal_msg msg)
5325
if ($ENV{USE_DEVICE_TREZOR_MANDATORY})
5426
message(FATAL_ERROR
@@ -71,42 +43,25 @@ macro(trezor_fatal_msg msg)
7143
endmacro()
7244

7345
# Use Trezor master switch
74-
if (USE_DEVICE_TREZOR)
75-
# Protobuf is required to build protobuf messages for Trezor
76-
include(FindProtobuf OPTIONAL)
77-
78-
# PkgConfig works better with new Protobuf
79-
find_package(PkgConfig QUIET)
80-
pkg_check_modules(PROTOBUF protobuf)
46+
if (NOT USE_DEVICE_TREZOR)
47+
message(STATUS "Trezor: support disabled by USE_DEVICE_TREZOR")
48+
else()
49+
# Look for ProtobufConfig.cmake, provided by Protobuf
50+
find_package(Protobuf CONFIG)
8151

52+
# Look for FindProtobuf.cmake, provided by CMake
8253
if (NOT Protobuf_FOUND)
83-
FIND_PACKAGE(Protobuf CONFIG)
54+
find_package(Protobuf)
8455
endif()
56+
8557
if (NOT Protobuf_FOUND)
86-
FIND_PACKAGE(Protobuf)
58+
trezor_fatal_msg("Trezor library not found")
8759
endif()
60+
endif()
8861

89-
_trezor_protobuf_fix_vars()
90-
91-
# Early fail for optional Trezor support
92-
if(NOT Protobuf_FOUND AND NOT Protobuf_LIBRARY AND NOT Protobuf_PROTOC_EXECUTABLE AND NOT Protobuf_INCLUDE_DIR)
93-
trezor_fatal_msg("Trezor: Could not find Protobuf")
94-
elseif(${CMAKE_CXX_STANDARD} LESS 17 AND ${Protobuf_VERSION} GREATER 21)
95-
trezor_fatal_msg("Trezor: Unsupported Protobuf version ${Protobuf_VERSION} with C++ ${CMAKE_CXX_STANDARD}. Please, use Protobuf v21.")
96-
elseif(NOT Protobuf_LIBRARY)
97-
trezor_fatal_msg("Trezor: Protobuf library not found: ${Protobuf_LIBRARY}")
98-
unset(Protobuf_FOUND)
99-
elseif(NOT Protobuf_PROTOC_EXECUTABLE OR NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
100-
trezor_fatal_msg("Trezor: Protobuf executable not found: ${Protobuf_PROTOC_EXECUTABLE}")
101-
unset(Protobuf_FOUND)
102-
elseif(NOT Protobuf_INCLUDE_DIR OR NOT EXISTS "${Protobuf_INCLUDE_DIR}")
103-
trezor_fatal_msg("Trezor: Protobuf include dir not found: ${Protobuf_INCLUDE_DIR}")
104-
unset(Protobuf_FOUND)
105-
else()
106-
message(STATUS "Trezor: Protobuf lib: ${Protobuf_LIBRARY}, inc: ${Protobuf_INCLUDE_DIR}, protoc: ${Protobuf_PROTOC_EXECUTABLE}")
107-
set(Protobuf_INCLUDE_DIRS ${Protobuf_INCLUDE_DIR})
108-
set(Protobuf_FOUND 1) # override found if all required info was provided by variables
109-
endif()
62+
# Try to build protobuf messages
63+
if(Protobuf_FOUND AND USE_DEVICE_TREZOR)
64+
find_program(Protobuf_PROTOC_EXECUTABLE protoc REQUIRED)
11065

11166
if(TREZOR_DEBUG)
11267
set(USE_DEVICE_TREZOR_DEBUG 1)
@@ -117,88 +72,28 @@ if (USE_DEVICE_TREZOR)
11772
if (USE_DEVICE_TREZOR_DEBUG)
11873
add_definitions(-DWITH_TREZOR_DEBUGGING=1)
11974
endif()
120-
else()
121-
message(STATUS "Trezor: support disabled by USE_DEVICE_TREZOR")
122-
endif()
123-
124-
if(Protobuf_FOUND AND USE_DEVICE_TREZOR)
125-
if (NOT "$ENV{TREZOR_PYTHON}" STREQUAL "")
126-
set(TREZOR_PYTHON "$ENV{TREZOR_PYTHON}" CACHE INTERNAL "Copied from environment variable TREZOR_PYTHON")
127-
else()
128-
find_package(Python QUIET COMPONENTS Interpreter) # cmake 3.12+
129-
if(Python_Interpreter_FOUND)
130-
set(TREZOR_PYTHON "${Python_EXECUTABLE}")
131-
endif()
132-
endif()
133-
134-
if(NOT TREZOR_PYTHON)
135-
find_package(PythonInterp)
136-
if(PYTHONINTERP_FOUND AND PYTHON_EXECUTABLE)
137-
set(TREZOR_PYTHON "${PYTHON_EXECUTABLE}")
138-
endif()
139-
endif()
14075

141-
if(NOT TREZOR_PYTHON)
142-
trezor_fatal_msg("Trezor: Python not found")
143-
endif()
144-
endif()
145-
146-
# Protobuf compilation test
147-
if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
148-
execute_process(COMMAND ${Protobuf_PROTOC_EXECUTABLE} -I "${CMAKE_CURRENT_LIST_DIR}" -I "${Protobuf_INCLUDE_DIR}" "${CMAKE_CURRENT_LIST_DIR}/test-protobuf.proto" --cpp_out ${CMAKE_BINARY_DIR} RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
149-
if(RET)
150-
trezor_fatal_msg("Trezor: Protobuf test generation failed: ${OUT} ${ERR}")
151-
endif()
152-
153-
if(ANDROID)
154-
set(CMAKE_TRY_COMPILE_LINKER_FLAGS "${CMAKE_TRY_COMPILE_LINKER_FLAGS} -llog")
155-
set(CMAKE_TRY_COMPILE_LINK_LIBRARIES "${CMAKE_TRY_COMPILE_LINK_LIBRARIES} log")
156-
endif()
76+
# .proto files to compile
77+
set(_proto_files "messages.proto"
78+
"messages-common.proto"
79+
"messages-management.proto"
80+
"messages-monero.proto")
81+
if (USE_DEVICE_TREZOR_DEBUG)
82+
list(APPEND _proto_files "messages-debug.proto")
83+
endif ()
15784

158-
if(USE_DEVICE_TREZOR_PROTOBUF_TEST)
159-
if(PROTOBUF_LDFLAGS)
160-
set(PROTOBUF_TRYCOMPILE_LINKER "${PROTOBUF_LDFLAGS}")
161-
else()
162-
set(PROTOBUF_TRYCOMPILE_LINKER "${Protobuf_LIBRARY}")
163-
endif()
164-
165-
try_compile(Protobuf_COMPILE_TEST_PASSED
166-
"${CMAKE_BINARY_DIR}"
167-
SOURCES
168-
"${CMAKE_BINARY_DIR}/test-protobuf.pb.cc"
169-
"${CMAKE_CURRENT_LIST_DIR}/test-protobuf.cpp"
170-
CMAKE_FLAGS
171-
CMAKE_EXE_LINKER_FLAGS ${CMAKE_TRY_COMPILE_LINKER_FLAGS}
172-
"-DINCLUDE_DIRECTORIES=${Protobuf_INCLUDE_DIR};${CMAKE_BINARY_DIR}"
173-
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
174-
LINK_LIBRARIES "${PROTOBUF_TRYCOMPILE_LINKER}" ${CMAKE_TRY_COMPILE_LINK_LIBRARIES}
175-
OUTPUT_VARIABLE OUTPUT
176-
)
177-
if(NOT Protobuf_COMPILE_TEST_PASSED)
178-
trezor_fatal_msg("Trezor: Protobuf Compilation test failed: ${OUTPUT}.")
179-
endif()
180-
else ()
181-
message(STATUS "Trezor: Protobuf Compilation test skipped, build may fail later")
182-
endif()
183-
endif()
85+
set(_include_dir "${CMAKE_CURRENT_LIST_DIR}/../external/trezor-common/protob")
86+
set(_proto_files_absolute)
87+
foreach(file IN LISTS _proto_files)
88+
list(APPEND _proto_files_absolute "${_include_dir}/${file}")
89+
endforeach ()
18490

185-
# Try to build protobuf messages
186-
if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
187-
set(ENV{PROTOBUF_INCLUDE_DIRS} "${Protobuf_INCLUDE_DIR}")
188-
set(ENV{PROTOBUF_PROTOC_EXECUTABLE} "${Protobuf_PROTOC_EXECUTABLE}")
189-
set(TREZOR_PROTOBUF_PARAMS "")
190-
if (USE_DEVICE_TREZOR_DEBUG)
191-
set(TREZOR_PROTOBUF_PARAMS "--debug")
192-
endif()
193-
194-
execute_process(COMMAND ${TREZOR_PYTHON} tools/build_protob.py ${TREZOR_PROTOBUF_PARAMS} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
91+
execute_process(COMMAND ${Protobuf_PROTOC_EXECUTABLE} --cpp_out "${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor/messages" "-I${_include_dir}" ${_proto_files_absolute} RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
19592
if(RET)
196-
trezor_fatal_msg("Trezor: protobuf messages could not be regenerated (err=${RET}, python ${PYTHON})."
197-
"OUT: ${OUT}, ERR: ${ERR}."
198-
"Please read src/device_trezor/trezor/tools/README.md")
93+
trezor_fatal_msg("Trezor: protobuf messages could not be (re)generated (err=${RET}). OUT: ${OUT}, ERR: ${ERR}.")
19994
endif()
20095

201-
message(STATUS "Trezor: protobuf messages regenerated out: \"${OUT}.\"")
96+
message(STATUS "Trezor: protobuf messages regenerated")
20297
set(DEVICE_TREZOR_READY 1)
20398
add_definitions(-DDEVICE_TREZOR_READY=1)
20499
add_definitions(-DPROTOBUF_INLINE_NOT_IN_HEADERS=0)
@@ -236,19 +131,4 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
236131
elseif(USE_DEVICE_TREZOR_LIBUSB AND NOT ANDROID)
237132
trezor_fatal_msg("Trezor: LibUSB not found or test failed, please install libusb-1.0.26")
238133
endif()
239-
240-
if (BUILD_GUI_DEPS)
241-
set(TREZOR_DEP_LIBS "")
242-
set(TREZOR_DEP_LINKER "")
243-
244-
if (Protobuf_LIBRARY)
245-
list(APPEND TREZOR_DEP_LIBS ${Protobuf_LIBRARY})
246-
string(APPEND TREZOR_DEP_LINKER " -lprotobuf")
247-
endif()
248-
249-
if (TREZOR_LIBUSB_LIBRARIES)
250-
list(APPEND TREZOR_DEP_LIBS ${TREZOR_LIBUSB_LIBRARIES})
251-
string(APPEND TREZOR_DEP_LINKER " -lusb-1.0 ${LIBUSB_DEP_LINKER}")
252-
endif()
253-
endif()
254134
endif()

src/device_trezor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ if(DEVICE_TREZOR_READY)
9494
common
9595
${sodium_LIBRARIES}
9696
${Boost_CHRONO_LIBRARY}
97-
${Protobuf_LIBRARY}
97+
protobuf::libprotobuf
9898
${TREZOR_LIBUSB_LIBRARIES}
9999
PRIVATE
100100
${EXTRA_LIBRARIES}

src/device_trezor/trezor/tools/README.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/device_trezor/trezor/tools/build_protob.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)