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

Generate .deb package from build #15

Open
wants to merge 9 commits into
base: master
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ cmake_install.cmake

# vcpkg
vcpkg_installed/

# debian packaging
*.deb
deb/opt
deb/usr
84 changes: 53 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ get_directory_property(HAS_PARENT PARENT_DIRECTORY)
if(HAS_PARENT)
message(STATUS "Configuring as a subproject.")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../out/${CMAKE_BUILD_TYPE}/bin/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../out/${CMAKE_BUILD_TYPE}/lib/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/../out/${CMAKE_BUILD_TYPE}/lib/)
set(BINARY_DIR ${CMAKE_SOURCE_DIR}/../out/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BINARY_DIR}/bin/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BINARY_DIR}/lib/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BINARY_DIR}/lib/)
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/../env/)

if(DEFINED ENV{WORKSPACE})
Expand All @@ -31,9 +32,10 @@ if(HAS_PARENT)
else()
message(STATUS "Configuring as a standalone project.")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/bin/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/lib/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/lib/)
set(BINARY_DIR ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BINARY_DIR}/bin/)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BINARY_DIR}/lib/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BINARY_DIR}/lib/)
endif()

#======== Find dependencies ========#
Expand Down Expand Up @@ -73,38 +75,58 @@ target_link_libraries(aedile PRIVATE
plog::plog
websocketpp::websocketpp
)
target_include_directories(aedile PUBLIC ${INCLUDE_DIR})
target_include_directories(aedile PUBLIC $<BUILD_INTERFACE:${INCLUDE_DIR}/>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what the BUILD_INTERFACE part means here?

set_target_properties(aedile PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)

#======== Build the tests ========#
enable_testing()
include(GoogleTest)
file(COPY include DESTINATION ${BINARY_DIR})

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
#======== Install Support ========#
# Specify the version of the project
set_target_properties(aedile PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(aedile PROPERTIES SOVERSION 0)

# Install the library
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Install the headers
install(DIRECTORY include/ DESTINATION include)

enable_testing()
#======== Package Support ========#

set(TEST_DIR ./test)
set(TEST_SOURCES
${TEST_DIR}/nostr_service_test.cpp
# Create a package configuration file
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

add_executable(aedile_test ${TEST_SOURCES} ${HEADERS})
target_link_libraries(aedile_test PRIVATE
GTest::gmock
GTest::gtest
GTest::gtest_main
aedile
plog::plog
websocketpp::websocketpp
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
)

# Install the package configuration files
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION lib/cmake/${PROJECT_NAME}
)
target_include_directories(aedile_test PUBLIC ${INCLUDE_DIR})
set_target_properties(aedile_test PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)

gtest_add_tests(TARGET aedile_test)
# Export targets for use by other projects
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME})

if(${ENABLE_TESTS})
enable_testing()
add_subdirectory(test)
else()
add_subdirectory(test EXCLUDE_FROM_ALL)
endif()
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build/linux",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_INSTALL_PREFIX": "$env{INSTALL_DIR}"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ To build the SDK on Linux, run the following commands from the project root:

```bash
export VCPKG_ROOT=/path/to/vcpkg/installation
cmake --preset=linux # configuration step
cmake --preset=linux -DENABLE_TESTS=1 # configuration step with tests enabled
SilberWitch marked this conversation as resolved.
Show resolved Hide resolved
cmake --build build/linux # compilation or build step
```

To run unit tests, use the following command:

```bash
ctest --preset linux
```
```
5 changes: 5 additions & 0 deletions cmake/aedileConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake")

check_required_components(${PROJECT_NAME})
6 changes: 6 additions & 0 deletions deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Package: libaedile
Version: 0.0.2
Maintainer: MichaelJ
Architecture: amd64
Description: Plug-and-play Nostr Development Kit
Pre-Depends: dpkg ( >= 1.16.1), libwebsocketpp-dev ( >= 0.8.1-7), nlohmann-json3-dev ( >= 3.7.3-1), libssl-dev ( >= 3.0), libplog-dev ( >= 1.1.10)
31 changes: 31 additions & 0 deletions gen_deb.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be in dos format, needed to convert to unix line endings before running on Debian.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure?
I'm pretty sure it's unix line endings

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your probably right. Pulled a clean version and ran dos2unix then git diff and no changes were detected this time. It looks like git might have changed it to crlf and staged it without me noticing, which is why when I converted it last time it showed up in the diff. Not sure.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#! /bin/bash

export PACKAGE_NAME="libaedile-dev"
export VERSION="0.0.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be centralizing the build version somehow so we don't need to remember to increment versions at every location? Or will this be the entry-point for the entire package? I assume some users will be building from cmake directly.

Copy link
Collaborator Author

@finrodfelagund97 finrodfelagund97 Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, this is a util script.

Ideally, the build will be done on a jenkins job, and there we can set these variables as env variables for the job.


export SRC_ROOT_DIR=$(dirname $(readlink -f ${0}))
export DEB_PACKAGE_ROOT="${SRC_ROOT_DIR}/deb"
export INSTALL_DIR="${DEB_PACKAGE_ROOT}/opt/${PACKAGE_NAME}/usr"


rm -rf $INSTALL_DIR
mkdir -p $INSTALL_DIR

cd "${SRC_ROOT_DIR}"
cmake --preset=linux
cmake --build build/linux
cmake --install build/linux

rm -rf ${DEB_PACKAGE_ROOT}/usr/

mkdir -p ${DEB_PACKAGE_ROOT}/usr/include/aedile/client
mkdir -p ${DEB_PACKAGE_ROOT}/usr/lib

ln -s ${INSTALL_DIR}/include/nostr.h ${DEB_PACKAGE_ROOT}/usr/include/aedile/nostr.h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding this nostr.h file?

Copy link
Contributor

@VnUgE VnUgE Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we ditched it between master and note_signing. It probably shouldn't exist as it just does some C++ header imports.

#include <nostr.hpp>
#include <client/web_socket_client.hpp>

Edit: I'm retarded, it was added below. I'll wait for explanation :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do need to get note_signing up to speed and merge it into master, it's been divergent from master for too long at this point.

My guess is that nostr.h is acting as a whole-library "entrypoint" header file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It made me realize we need to prune up some of our public api headers too. I don't think they need to be including all the headers listed at the moment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will eventually have just a nostr.hpp that, in turn, imports everything from the project internals. But we're not there yet.

ln -s ${INSTALL_DIR}/include/nostr.hpp ${DEB_PACKAGE_ROOT}/usr/include/aedile/nostr.hpp
ln -s ${INSTALL_DIR}/include/client/web_socket_client.hpp ${DEB_PACKAGE_ROOT}/usr/include/aedile/client/web_socket_client.hpp
ln -s ${INSTALL_DIR}/lib/libaedile.a ${DEB_PACKAGE_ROOT}/usr/lib/libaedile.a

cd "${SRC_ROOT_DIR}"

dpkg-deb --build deb deb/$PACKAGE_NAME-${VERSION}.deb
2 changes: 2 additions & 0 deletions include/nostr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <nostr.hpp>
#include <client/web_socket_client.hpp>
1 change: 1 addition & 0 deletions src/client/websocketpp_client.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "web_socket_client.hpp"
#include <unordered_map>

using std::error_code;
using std::function;
Expand Down
32 changes: 32 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#======== Build the tests ========#
enable_testing()
include(GoogleTest)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

set(TEST_DIR ./)
set(TEST_SOURCES
${TEST_DIR}/nostr_service_test.cpp
)

add_executable(aedile_test ${TEST_SOURCES} ${HEADERS})
target_link_libraries(aedile_test PRIVATE
GTest::gmock
GTest::gtest
GTest::gtest_main
aedile
plog::plog
websocketpp::websocketpp
)
target_include_directories(aedile_test PUBLIC ${INCLUDE_DIR})
set_target_properties(aedile_test PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)

gtest_add_tests(TARGET aedile_test)