Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7b622a7
feature: coding of aggregate
xDimon Jan 24, 2025
2b2969e
refactor: use concepts
xDimon Jan 25, 2025
397f5db
fix: incomplete concepts
xDimon Jan 27, 2025
6baec5c
fix: SomeSpan concept
xDimon Jan 28, 2025
9a01004
update: version of used hunter
xDimon Jan 28, 2025
c4c2383
fix: CI
xDimon Jan 28, 2025
fdc1663
fix: CI
xDimon Jan 28, 2025
b81ba08
fix: CI
xDimon Jan 28, 2025
f325334
update: hunter and qtils
xDimon Jan 28, 2025
eb74ac4
refactor: used macros
xDimon Jan 28, 2025
3bb4394
fix: try to fix CI (update macos)
xDimon Jan 28, 2025
c997a5c
update: qtils
xDimon Jan 28, 2025
a401adc
refactor: rename as_decomposed
xDimon Jan 30, 2025
0a74ea0
feature: generate aggregate.hpp in according MAX_AGGREGATE_FIELDS cma…
xDimon Jan 30, 2025
7eaee7f
update: qtils
xDimon Jan 30, 2025
c5349eb
update: qtils
xDimon Jan 30, 2025
8a0e43c
fix: redundant decay_t using
xDimon Jan 30, 2025
965bf3f
feature: custom discomposing
xDimon Jan 30, 2025
9ea5b57
fix: review issues
xDimon Jan 30, 2025
4d35097
don't overwrite aggregate.hpp
turuslan Jan 30, 2025
5769acc
fix constructible on macos
turuslan Jan 30, 2025
f89839d
Revert "don't overwrite aggregate.hpp"
turuslan Jan 30, 2025
88988d4
don't overwrite aggregate.hpp
turuslan Jan 30, 2025
1461bb4
fix makefile
turuslan Jan 30, 2025
fb0a319
update: qtils
xDimon Jan 30, 2025
6bdc80b
configure_file definitions
turuslan Jan 30, 2025
08122a3
update: qtils
xDimon Feb 3, 2025
7a418d9
update: qtils hunter config
xDimon Feb 3, 2025
04bea1a
update: qtils
xDimon Feb 3, 2025
2dde730
update: qtils
xDimon Feb 3, 2025
6dbe202
update: qtils
xDimon Feb 3, 2025
e31f904
refactor: complete support fixed-width and compact integers
xDimon Feb 5, 2025
c30e4a7
feature: CompactReflection for coding int value as compact
xDimon Feb 5, 2025
9576c5d
fix: review issues
xDimon Feb 6, 2025
312aaae
update: qtils
xDimon Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:

jobs:
MacOS:
runs-on: macos-13
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -33,9 +33,9 @@ jobs:
fail-fast: false
matrix:
options:
- name: "Linux: gcc-12"
run: ./scripts/build.sh -DCMAKE_CXX_COMPILER=g++-12
- name: "Linux: clang-14"
- name: "Linux: gcc"
run: ./scripts/build.sh -DCMAKE_CXX_COMPILER=g++
- name: "Linux: clang"
run: ./scripts/build.sh -DCMAKE_CXX_COMPILER=clang++
name: "${{ matrix.options.name }}"
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
**/build-*/
**/cmake-build-*/
Testing

# Auto generated files
/include/scale/definitions.hpp
33 changes: 11 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.12)

option(JAM_COMPATIBLE "Build compatible with JAM-codec" OFF)
option(CUSTOM_CONFIG_SUPPORT "Support custom config of streams" OFF)
set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation")

option(BUILD_TESTS "Whether to include the test suite in build" OFF)

Expand All @@ -32,11 +33,7 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
endif ()

if (PACKAGE_MANAGER STREQUAL "hunter")
include(cmake/HunterGate.cmake)
HunterGate(
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm28.tar.gz
SHA1 a4f1b0f42464e07790b7f90b783a822d71be6c6d
)
include("cmake/Hunter/init.cmake")
endif ()

if(BUILD_TESTS)
Expand All @@ -56,7 +53,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (PACKAGE_MANAGER STREQUAL "hunter")
hunter_add_package(Boost)
find_package(Boost)
else()
else()
find_package(Boost CONFIG REQUIRED COMPONENTS endian multiprecision)
endif ()

Expand All @@ -65,22 +62,9 @@ if (PACKAGE_MANAGER STREQUAL "hunter")
endif ()
find_package(qtils CONFIG REQUIRED)

set(DEFINITION_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include/scale/definitions.hpp")
if (NOT EXISTS "${CMAKE_BINARY_DIR}/definition.d" OR NOT EXISTS "${DEFINITION_PATH}")
get_filename_component(LABEL "${CMAKE_BINARY_DIR}" NAME)
file(WRITE "${DEFINITION_PATH}.${LABEL}"
"// This header was generated by cmake (${LABEL})\n"
"// IMPORTANT: Dont modify this file manually!\n")
if (JAM_COMPATIBLE)
file(APPEND "${DEFINITION_PATH}.${LABEL}" "#define JAM_COMPATIBILITY_ENABLED\n")
endif ()
if (CUSTOM_CONFIG_SUPPORT)
file(APPEND "${DEFINITION_PATH}.${LABEL}" "#define CUSTOM_CONFIG_ENABLED\n")
endif ()
file(RENAME "${DEFINITION_PATH}.${LABEL}" "${DEFINITION_PATH}")
message(STATUS "include/scale/definitions.hpp has generated")
file(WRITE "${CMAKE_BINARY_DIR}/definition.d" "include/scale/definitions.hpp has generated")
endif ()
SET(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}")
set(CUSTOM_CONFIG_ENABLED "${CUSTOM_CONFIG_SUPPORT}")
configure_file("${CMAKE_SOURCE_DIR}/include/scale/definitions.hpp.in" "${CMAKE_BINARY_DIR}/include/scale/definitions.hpp")

add_subdirectory(src)

Expand All @@ -107,6 +91,11 @@ install(TARGETS scale EXPORT scaleConfig
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/scale
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/include/scale
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

include(CMakePackageConfigHelpers)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ try {
## Convenience functions
Convenience functions
```c++
template<class T>
template <typename T>
outcome::result<std::vector<uint8_t>> encode(T &&t);

template <class T>
template <typename T>
outcome::result<T> decode(const RangeOfBytes auto& span)

template <class T>
template <typename T>
outcome::result<T> decode(ScaleDecoderStream &s)
```
are wrappers over ```<<``` and ```>>``` operators described above.
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Template for a custom hunter configuration Useful when there is a need for a
# non-default version or arguments of a dependency, or when a project not
# registered in soramitsu-hunter should be added.
#
# hunter_config(
# package-name
# VERSION 0.0.0-package-version
# CMAKE_ARGS
# CMAKE_VARIABLE=value
# )
#
# hunter_config(
# package-name
# URL https://github.com/organization/repository/archive/hash.tar.gz
# SHA1 1234567890abcdef1234567890abcdef12345678
# CMAKE_ARGS
# CMAKE_VARIABLE=value
# )

hunter_config(
qtils
URL https://github.com/qdrvm/qtils/archive/16e7c819dd50af2f64e2d319b918d0d815332266.tar.gz
SHA1 71989938b5c8b7650eaf1a8195c2b52c5a8c250b
)
5 changes: 5 additions & 0 deletions cmake/Hunter/hunter-gate-url.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HunterGate(
URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm29.tar.gz
SHA1 025920fa980ba81a150deaa534a0248dde25fd54
LOCAL
)
42 changes: 42 additions & 0 deletions cmake/Hunter/init.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# specify GITHUB_HUNTER_TOKEN and GITHUB_HUNTER_USERNAME to automatically upload binary cache to github.com/qdrvm/hunter-binary-cache
# https://hunter.readthedocs.io/en/latest/user-guides/hunter-user/github-cache-server.html
string(COMPARE EQUAL "$ENV{GITHUB_HUNTER_USERNAME}" "" username_is_empty)
string(COMPARE EQUAL "$ENV{GITHUB_HUNTER_TOKEN}" "" password_is_empty)

# binary cache can be uploaded to qdrvm/hunter-binary-cache so others will not build same dependencies twice
if (NOT password_is_empty AND NOT username_is_empty)
option(HUNTER_RUN_UPLOAD "Upload cache binaries" YES)
message("Binary cache uploading is ENABLED.")
else ()
option(HUNTER_RUN_UPLOAD "Upload cache binaries" NO)
message(AUTHOR_WARNING " Binary cache uploading is DISABLED.
Define environment variables GITHUB_HUNTER_USERNAME and GITHUB_HUNTER_TOKEN
for binary cache activation. To generate github token follow the instructions:
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
Make sure `read:packages` and `write:packages` permissions are granted (step 7 in instructions).")
endif ()

set(HUNTER_PASSWORDS_PATH
"${CMAKE_CURRENT_LIST_DIR}/passwords.cmake"
CACHE FILEPATH "Hunter passwords"
)

set(HUNTER_CACHE_SERVERS
"https://github.com/qdrvm/hunter-binary-cache"
CACHE STRING "Binary cache server"
)

# https://hunter.readthedocs.io/en/latest/reference/user-variables.html#hunter-use-cache-servers
# set(
# HUNTER_USE_CACHE_SERVERS NO
# CACHE STRING "Disable binary cache"
# )

# https://hunter.readthedocs.io/en/latest/reference/user-variables.html#hunter-status-debug
# set(
# HUNTER_STATUS_DEBUG ON
# CACHE STRING "Enable output lot of info for debugging"
# )

include(${CMAKE_CURRENT_LIST_DIR}/HunterGate.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/hunter-gate-url.cmake)
11 changes: 11 additions & 0 deletions cmake/Hunter/passwords.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
hunter_upload_password(
# REPO_OWNER + REPO = https://github.com/forexample/hunter-cache
REPO_OWNER "qdrvm"
REPO "hunter-binary-cache"

# USERNAME = warchant
USERNAME "$ENV{GITHUB_HUNTER_USERNAME}"

# PASSWORD = GitHub token saved as a secure environment variable
PASSWORD "$ENV{GITHUB_HUNTER_TOKEN}"
)
17 changes: 17 additions & 0 deletions include/scale/definitions.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cstdlib>

#cmakedefine JAM_COMPATIBILITY_ENABLED
#cmakedefine CUSTOM_CONFIG_ENABLED

namespace scale::detail {
// clang-format off
constexpr static size_t MAX_FIELD_NUM = @MAX_AGGREGATE_FIELDS@;
// clang-format on
} // namespace scale::detail
5 changes: 5 additions & 0 deletions include/scale/detail/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignored because part of this file is generated by CMake.
# If changes to the base content need to be committed, they must be committed explicitly,
# except for the section between `-BEGIN-GENERATED-SECTION-` and `-END-GENERATED-SECTION-`,
# which is automatically generated and should not be committed.
aggregate.hpp
31 changes: 31 additions & 0 deletions include/scale/detail/aggregate.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <scale/definitions.hpp>
#include <scale/detail/custom_decomposing.hpp>
#include <scale/types.hpp>

namespace scale::detail {

template <typename F>
decltype(auto) decompose_and_apply(SimpleCodeableAggregate auto &&v,
const F &f) {
constexpr auto N = field_number_of<decltype(v)>;
// clang-format off
if constexpr (N == 0) {
return f();
// -BEGIN-GENERATED-SECTION-
// -END-GENERATED-SECTION-
} else {
// We mustn't fall in here
static_assert(N <= MAX_FIELD_NUM, "Inconsistent value of MAX_FIELD_NUM");
static_assert(N > MAX_FIELD_NUM, "No code for cover aggregate with such big amount of fields");
}
// clang-format on
}

} // namespace scale::detail
Loading
Loading