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

Update 3.0.4 #1

Open
wants to merge 3 commits into
base: pr/windows-msvc
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakTemplateDeclarations: Yes
BasedOnStyle: LLVM
BreakConstructorInitializers: BeforeComma
ColumnLimit: 100
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentWidth: 4
IndentAccessModifiers: false
AccessModifierOffset: -4
PointerAlignment: Left
IncludeCategories:
- Regex: '^"\.\./'
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cmake-build-debug/
.cquery_cache/
.cxx/
.cache/
build_pvs_studio/

# Dependencies
node_modules
Expand All @@ -26,11 +27,18 @@ lib/protobuf
# Generated files
jni/cpp/generated
jni/java/wallet/core/jni
jni/java/wallet/core/proto
swift/Sources/Generated
swift/wallet-core/
src/Generated
src/Generated/*.cpp
include/TrustWalletCore/TWHRP.h
include/TrustWalletCore/TW*Proto.h
include/TrustWalletCore/TWDerivation.h
include/TrustWalletCore/TWEthereumChainID.h

# Wasm
emsdk/
wasm-build/

# Code coverage files
coverage.info
Expand Down
146 changes: 66 additions & 80 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
# Copyright © 2017-2022 Trust Wallet.
#
# This file is part of Trust. The full Trust copyright notice, including
# terms governing use, modification, and redistribution, is contained in the
# file LICENSE at the root of the source code distribution tree.

project(TrustWalletCore)

include(GNUInstallDirs)
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)

# Configure warnings
if(NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC"))
set(TW_CXX_WARNINGS "-Wshorten-64-to-32")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TW_CXX_WARNINGS}")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)
project(TrustWalletCore)

if((NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")))
message(FATAL_ERROR "You should use clang or msvc compiler")
endif()

if ("$ENV{PREFIX}" STREQUAL "")
set(PREFIX "${CMAKE_SOURCE_DIR}/build/local")
else()
else ()
set(PREFIX "$ENV{PREFIX}")
endif()
endif ()

# Configure CCache if available
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
include(GNUInstallDirs)
include(cmake/StandardSettings.cmake)
include(cmake/CompilerWarnings.cmake)
include(cmake/StaticAnalyzers.cmake)
include(cmake/FindHostPackage.cmake)

include_directories(${PREFIX}/include)
link_directories(${PREFIX}/lib)
add_library(${PROJECT_NAME}_INTERFACE INTERFACE)
target_include_directories(${PROJECT_NAME}_INTERFACE INTERFACE ${PREFIX}/include)
target_link_directories(${PROJECT_NAME}_INTERFACE INTERFACE ${PREFIX}/lib)
set_project_warnings(${PROJECT_NAME}_INTERFACE)

if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Disable strcpy warnings
endif()

add_subdirectory(trezor-crypto)

macro(find_host_package)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
find_package(${ARGN})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endmacro(find_host_package)
if (TW_COMPILE_WASM)
message(STATUS "Wasm build enabled")
add_subdirectory(wasm)
endif ()

find_host_package(Boost REQUIRED)

Expand All @@ -75,41 +61,16 @@ if(WIN32)
endif()
endif()

option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
endif()

option(CLANG_TIDY "Enable static code analysis with (clang-tidy)" OFF)
if(CLANG_TIDY)
find_program(CLANG_TIDY_BIN NAMES clang-tidy-11)
if(CLANG_TIDY_BIN)
set(CMAKE_CXX_CLANG_TIDY clang-tidy-11;)
message("clang-tidy ${CMAKE_CXX_CLANG_TIDY} ${CLANG_TIDY_BIN}")
else()
message(FATAL_ERROR "Could not find clang-tidy")
endif()
endif()

option(CLANG_ASAN "Enable ASAN dynamic address sanitizer" OFF)
if(CLANG_ASAN)
# https://clang.llvm.org/docs/AddressSanitizer.html
# https://github.com/trustwallet/wallet-core/issues/1170
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
message("CLANG_ASAN on, ${CMAKE_CXX_FLAGS_DEBUG}")
endif()

# Source files
if(${ANDROID})
# Source files **
if (${ANDROID})
message("Configuring for JNI")
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h jni/cpp/*.c jni/cpp/*.cpp jni/cpp/*.h jni/cpp/*.c)
add_library(TrustWalletCore SHARED ${sources} ${PROTO_SRCS} ${PROTO_HDRS})

find_library(log-lib log)
target_link_libraries(TrustWalletCore PRIVATE TrezorCrypto ${Protobuf_LIBRARIES} ${log-lib} Boost::boost)
else()
target_link_libraries(TrustWalletCore PUBLIC ${PROJECT_NAME}_INTERFACE PRIVATE TrezorCrypto ${Protobuf_LIBRARIES} ${log-lib} Boost::boost)
else ()
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h)
if(WIN32)
file(GLOB_RECURSE headers include/TrustWalletCore/*.h)
Expand All @@ -121,39 +82,62 @@ else()
add_library(TrustWalletCore SHARED ${sources} ${headers} ${PROTO_SRCS} ${PROTO_HDRS})
target_compile_definitions(TrustWalletCore PRIVATE TW_EXPORT_LIBRARY)
endif()
else()
else()
message("Configuring standalone")
add_library(TrustWalletCore ${sources} ${PROTO_SRCS} ${PROTO_HDRS})
endif()

target_link_libraries(TrustWalletCore PRIVATE TrezorCrypto ${Protobuf_LIBRARIES} Boost::boost)
endif()
target_link_libraries(TrustWalletCore PUBLIC ${PROJECT_NAME}_INTERFACE PRIVATE TrezorCrypto ${Protobuf_LIBRARIES} Boost::boost)
endif ()

if (TW_CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_enable_coverage(TrustWalletCore)
endif ()

if(NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC"))
target_compile_options(TrustWalletCore PRIVATE "-Wall")
endif()

set_target_properties(TrustWalletCore
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
if (TW_CLANG_ASAN)
target_enable_asan(TrustWalletCore)
endif ()

# Define headers for this library. PUBLIC headers are used for compiling the
# library, and will be added to consumers' build paths.
target_include_directories(TrustWalletCore
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/jni/cpp
${CMAKE_CURRENT_SOURCE_DIR}/build/local/include
)
)

if(NOT ANDROID AND NOT IOS_PLATFORM AND NOT (WIN32 AND NOT TW_STATIC_LIBRARY))
if (TW_UNIT_TESTS AND NOT (WIN32 AND NOT TW_STATIC_LIBRARY))
add_subdirectory(tests)
endif ()

if (TW_BUILD_EXAMPLES AND NOT (WIN32 AND NOT TW_STATIC_LIBRARY))
add_subdirectory(walletconsole/lib)
add_subdirectory(walletconsole)
endif ()

if (TW_ENABLE_PVS_STUDIO)
tw_add_pvs_studio_target(TrustWalletCore)
endif ()

if (TW_ENABLE_CLANG_TIDY)
tw_add_clang_tidy_target(TrustWalletCore)
endif ()

if (NOT ANDROID AND TW_UNITY_BUILD)
set_target_properties(TrustWalletCore PROPERTIES UNITY_BUILD ON)
file(GLOB_RECURSE PROTOBUF_SOURCE_FILES CONFIGURE_DEPENDS src/Cosmos/Protobuf/*.pb.cc src/proto/*.pb.cc)
foreach(file ${PROTOBUF_SOURCE_FILES})
set_property(SOURCE ${file} PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
endforeach()
message(STATUS "Unity build activated")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig @ONLY)
Expand All @@ -167,8 +151,10 @@ install(TARGETS TrustWalletCore
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/WalletCore
FILES_MATCHING PATTERN "*.h")
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/WalletCore
FILES_MATCHING PATTERN "*.h"
)

install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

39 changes: 28 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

Expand All @@ -17,26 +17,27 @@ RUN apt-get update \
# Add latest cmake/boost
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key add - \
&& apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' \
&& apt-add-repository -y ppa:mhier/libboost-latest
&& apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'


RUN wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb && dpkg -i ./libssl1.1_1.1.0g-2ubuntu4_amd64.deb
# Install required packages for dev
RUN apt-get update \
&& apt-get install -y \
build-essential \
libtool autoconf pkg-config \
ninja-build \
ruby-full \
clang-10 \
llvm-10 \
clang-14 \
llvm-14 \
libc++-dev libc++abi-dev \
cmake \
libboost1.74-dev \
cmake \
libboost-all-dev \
ccache \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

ENV CC=/usr/bin/clang-10
ENV CXX=/usr/bin/clang++-10
ENV CC=/usr/bin/clang-14
ENV CXX=/usr/bin/clang++-14

# ↑ Setup build environment
# ↓ Build and compile wallet core
Expand All @@ -47,9 +48,25 @@ WORKDIR /wallet-core
# Install dependencies
RUN tools/install-dependencies

# Build: generate, cmake, and make
# Build: generate, cmake, and make lib
RUN tools/generate-files \
&& cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug \
&& make -Cbuild -j12
&& make -Cbuild -j12 TrustWalletCore

# Build unit tester
RUN make -Cbuild -j12 tests

# Download and Install Go
ENV GO_VERSION=1.16.12
ENV GO_ARCH=amd64
RUN wget "https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz" \
&& tar -xf "go${GO_VERSION}.linux-${GO_ARCH}.tar.gz" \
&& chown -R root:root ./go \
&& mv -v ./go /usr/local \
&& ls /usr/local/go \
&& /usr/local/go/bin/go version \
&& rm "go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"

# Building GoLang sample app: cd samples/go && /usr/local/go/bin/go build -o main && ./main

CMD ["/bin/bash"]
17 changes: 7 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "WalletCore",
platforms: [.iOS(.v13)],
products: [
.library(
name: "WalletCore", targets: ["WalletCore", "SwiftProtobuf"]
)
],
dependencies: [
.library(name: "WalletCore", targets: ["WalletCore"]),
.library(name: "SwiftProtobuf", targets: ["SwiftProtobuf"])
],
dependencies: [],
targets: [
.binaryTarget(
name: "WalletCore",
url: "https://github.com/trustwallet/wallet-core/releases/download/2.6.31/WalletCore.xcframework.zip",
checksum: "29d88807485f88992e00a5b7ed1ddf53ca57dacb89ba5e5368dc931102600879"
url: "https://github.com/trustwallet/wallet-core/releases/download/3.0.6/WalletCore.xcframework.zip",
checksum: "a3df0c2b30fc59ede0a2600266fc19b8c0cf655dbef3fb832488c8ddedcb6b93"
),
.binaryTarget(
name: "SwiftProtobuf",
url: "https://github.com/trustwallet/wallet-core/releases/download/2.6.31/SwiftProtobuf.xcframework.zip",
checksum: "d1035aa8a32f2483305bbe9cd3d5774bf6c1a65ce5a37213c9ee651c78873a55"
url: "https://github.com/trustwallet/wallet-core/releases/download/3.0.6/SwiftProtobuf.xcframework.zip",
checksum: "61fa8483d4bd43f1898db6997eff0279426f15f9e518e12db0d762ec5f927a9b"
)
]
)
Loading