Skip to content

Commit

Permalink
feat: support vcpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteCat6142 committed Aug 13, 2024
1 parent 48d0018 commit ecb78ba
Show file tree
Hide file tree
Showing 26 changed files with 208 additions and 531 deletions.
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.20)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")

project(cpp_nostr)

set(CMAKE_CPP_STANDARD 20)
set(CMAKE_CXX_STANDARD 20)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

find_package(OpenSSL 3.1.1 REQUIRED COMPONENTS SSL Crypto)

find_package(fmt CONFIG REQUIRED)
find_package(nameof CONFIG REQUIRED)
find_package(yyjson CONFIG REQUIRED)
find_package(unofficial-secp256k1 CONFIG REQUIRED)
find_package(libhv CONFIG REQUIRED)

find_package(cpp_yyjson CONFIG REQUIRED)
find_package(libbech32 CONFIG REQUIRED)

add_executable(main src/main.cpp)

target_compile_options(main PUBLIC -O2 -Wall)

target_include_directories(main
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
${OPENSSL_INCLUDE_DIR}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)

target_link_libraries(main PUBLIC Threads::Threads)
target_link_libraries(main PUBLIC ${OPENSSL_LIBRARIES})
target_link_libraries(main PUBLIC fmt::fmt)
target_link_libraries(main PUBLIC nameof::nameof)
target_link_libraries(main PUBLIC yyjson::yyjson)
target_link_libraries(main PUBLIC unofficial::secp256k1_precomputed unofficial::secp256k1)
target_link_libraries(main PUBLIC hv_static)
target_link_libraries(main PUBLIC cpp_yyjson::cpp_yyjson)
target_link_libraries(main PUBLIC bech32::bech32)
13 changes: 13 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 2,
"configurePresets": [
{
"name": "default",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
85 changes: 0 additions & 85 deletions meson.build

This file was deleted.

21 changes: 21 additions & 0 deletions my-ports/cpp-yyjson/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO yosh-matsuda/cpp-yyjson
REF 506d59a8627ae58de92d9934113245ba83872a4c
SHA512 d4ab75dbf490e087e9a6b5edb12816a28848e7d6661dcd69944927d8a264d9d229d3b690138277a22e496fbc453bb9aa657bbd1d9835e2f832d3eac65500f112
HEAD_REF main
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DCPPYYJSON_BUILD_TEST=OFF
)

vcpkg_cmake_install()

vcpkg_fixup_pkgconfig()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

vcpkg_copy_pdbs()
26 changes: 26 additions & 0 deletions my-ports/cpp-yyjson/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "cpp-yyjson",
"version-date": "2024-08-03",
"port-version": 2,
"description": "Ultra-fast and intuitive C++ JSON reader/writer with yyjson backend",
"homepage": "https://github.com/yosh-matsuda/cpp-yyjson",
"license": "MIT",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"yyjson",
"fmt",
"nameof"
],
"features": {
"examples": {
"description": "Build examples"
}
}
}
26 changes: 26 additions & 0 deletions my-ports/libbech32/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO dcdpr/libbech32
REF d77814708d5afe8d0c7bd42eb9ea7c85916b3ac2
SHA512 6780c407eb4247bd8e8d106f2104e7c3c511804d29330f8d9bec5c849c701082e8268716e90d0b162d2c591a2700abcaf62f4bb3fdff43edbdac2ae35b952405
HEAD_REF master
)


vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
examples LIBBECH32_BUILD_EXAMPLES
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
)
vcpkg_cmake_install()

vcpkg_fixup_pkgconfig()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

vcpkg_copy_pdbs()
23 changes: 23 additions & 0 deletions my-ports/libbech32/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "libbech32",
"version-date": "2024-05-16",
"port-version": 1,
"description": "a C++ implementation of Bech32",
"homepage": "https://github.com/dcdpr/libbech32",
"license": "BSD-3-Clause",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
],
"features": {
"examples": {
"description": "Build examples"
}
}
}
15 changes: 8 additions & 7 deletions main.cpp → src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include <rx_nostr.hpp>
#include <logger_stdout.hpp>
//#include <rx_nostr.hpp>
//#include <logger_stdout.hpp>
#include <thread>
#include <iostream>

#include <src/nostr_event_sign_yyjson.hpp>
#include <src/utils.hpp>
#include <nostr_event_sign_yyjson.hpp>
#include <utils.hpp>

#include <bech32.h>
#include <libbech32/bech32.h>

#include <ctime>

using namespace std::chrono_literals;
using namespace cpp_nostr;

static const int MAX_EVENTS = 300;
static LoggerInterface *logger = nullptr;
//static LoggerInterface *logger = nullptr;
static int count = 0;

void callback(const NostrEvent &event)
Expand Down Expand Up @@ -128,6 +128,7 @@ int main(int argc, char *argv[])

if (argc > 1)
std::cout << sign(argv[1]) << std::endl;
/*
logger = new LoggerStdout();
RxNostr rx_nostr(logger);
Expand Down Expand Up @@ -166,7 +167,7 @@ int main(int argc, char *argv[])
if (logger != nullptr)
{
delete logger;
}
}*/

return 0;
}
17 changes: 9 additions & 8 deletions src/nostr_event_sign_yyjson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "./nostr_event_sign_interface.hpp"

#include "./utils.hpp"
#include <include/secp256k1.h>
#include <include/secp256k1_schnorrsig.h>
#include <secp256k1.h>
#include <secp256k1_schnorrsig.h>

using namespace yyjson;

Expand All @@ -18,9 +18,9 @@ namespace cpp_nostr
{
private:
static const std::string writeJson(const NostrEvent &ev)
{/*
const auto a = array{0,ev.pubkey,ev.created_at,ev.kind,ev.tags,ev.content};*/
return "";
{
const auto a = array{0,ev.pubkey,ev.created_at,ev.kind,ev.tags,ev.content};
return std::string(a.write());
}

public:
Expand Down Expand Up @@ -62,6 +62,7 @@ namespace cpp_nostr
uint8_t aux[32];
if (!fill_random(aux, sizeof(aux)))
goto FAIL;
std::cout << "fail" << std::endl;

uint8_t sig[64] = {0};
if (!secp256k1_schnorrsig_sign32(ctx, sig, digest, &keypair, aux))
Expand All @@ -73,7 +74,7 @@ namespace cpp_nostr
}

const std::string encode(const NostrEvent &ev) const
{/*
{
const auto a = object{
{"id", ev.id},
{"pubkey", ev.pubkey},
Expand All @@ -82,8 +83,8 @@ namespace cpp_nostr
{"tags", ev.tags},
{"content", ev.content},
{"sig", ev.sig}
};*/
return "";
};
return std::string(a.write());
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int fill_random(unsigned char* data, size_t size) {
std::random_device rng;
for(auto it=data;it<data+size;++it)
*it=rng();
return 0;
return 1;
}

}
Expand Down
5 changes: 0 additions & 5 deletions subprojects/cpp-yyjson.wrap

This file was deleted.

5 changes: 0 additions & 5 deletions subprojects/fmt.wrap

This file was deleted.

5 changes: 0 additions & 5 deletions subprojects/libbech32.wrap

This file was deleted.

5 changes: 0 additions & 5 deletions subprojects/libhv.wrap

This file was deleted.

5 changes: 0 additions & 5 deletions subprojects/nameof.wrap

This file was deleted.

4 changes: 0 additions & 4 deletions subprojects/packagefiles/rx-nostr/meson.build

This file was deleted.

Loading

0 comments on commit ecb78ba

Please sign in to comment.