remove-dependencies #20

Merged
moritz merged 7 commits from remove-dependencies into master 2025-10-19 11:35:01 +00:00
9 changed files with 237 additions and 27 deletions
Showing only changes of commit 6f9bb54611 - Show all commits

View File

@@ -14,7 +14,7 @@ jobs:
- name: install meson - name: install meson
run: apt-get -yq install meson run: apt-get -yq install meson
- name: Install build dependencies - name: Install build dependencies
run: apt-get -yq install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev gcovr run: apt-get -yq install libusb-1.0-0-dev libpango1.0-dev libcairo2-dev gcovr
- name: get build environment versions - name: get build environment versions
run: | run: |
echo "=== Start meson version ===" echo "=== Start meson version ==="
@@ -32,25 +32,19 @@ jobs:
echo "=== Start dependency package version ===" echo "=== Start dependency package version ==="
apt-cache policy libpango1.0-dev apt-cache policy libpango1.0-dev
apt-cache policy libcairo2-dev apt-cache policy libcairo2-dev
apt-cache policy libfmt-dev
apt-cache policy libspdlog-dev
apt-cache policy libusb-1.0-0-dev apt-cache policy libusb-1.0-0-dev
echo "=== End dependency package version ===" echo "=== End dependency package version ==="
- name: setup builddir - name: Build ptprnt debug
run: meson setup builddir -Db_coverage=true run: scripts/build.sh debug --coverage --test
- name: run unit tests
run: ninja -C builddir test
- name: calculate coverage
run: ninja -C builddir coverage-text
- name: Coverage report - name: Coverage report
run: cat ./builddir/meson-logs/coverage.txt run: cat ./builddir-debug/meson-logs/coverage.txt
- name: build and test dist package - name: build and release
run: ninja -C builddir dist run: scripts/build.sh release
- name: upload dist package - name: upload release binary
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: ptprnt name: ptprnt
path: ./builddir/meson-dist/* path: ./builddir/ptprnt
if-no-files-found: error if-no-files-found: error
- name: upload coverage report - name: upload coverage report
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3

2
.gitignore vendored
View File

@@ -1,5 +1,5 @@
# Folder # Folder
builddir/ builddir*/
subprojects/* subprojects/*
.cache/ .cache/
coverageReport/ coverageReport/

View File

@@ -18,17 +18,24 @@ ptprnt --font "NotoMono Nerd Font" --fontsize 32 --text "🖶 ptprnt v0.2.0 🥰
Arch Linux: Arch Linux:
```bash ```bash
pacman -S libusb spdlog pango cairo meson pacman -S libusb pango cairo meson
``` ```
Debian/Ubuntu: Debian/Ubuntu:
```bash ```bash
apt-get install libusb-1.0-0-dev libspdlog-dev libfmt-dev libpango1.0-dev libcairo2-dev meson apt-get install libusb-1.0-0-dev libpango1.0-dev libcairo2-dev meson
``` ```
Note: spdlog is built as a subproject and statically linked, so it's not required as a system dependency.
**Build and run:** **Build and run:**
Clone this repository first and enter the directory. Then build: Clone this repository first and enter the directory. Then build:
```bash ```bash
# Using the build script (recommended)
./scripts/build.sh release
builddir/ptprnt --help
# Or manually with meson
meson setup builddir meson setup builddir
ninja -C builddir ninja -C builddir
builddir/ptprnt --help builddir/ptprnt --help
@@ -181,13 +188,43 @@ ptprnt \
This is a modern C++20 rewrite of [ptouch-print](https://git.familie-radermacher.ch/linux/ptouch-print.git). Credits to Dominic Rademacher for reverse engineering the USB protocol. This is a modern C++20 rewrite of [ptouch-print](https://git.familie-radermacher.ch/linux/ptouch-print.git). Credits to Dominic Rademacher for reverse engineering the USB protocol.
**Build script:**
```bash
# Release build
./scripts/build.sh release
# Debug build
./scripts/build.sh debug
# Debug with tests
./scripts/build.sh debug --test
# Debug with coverage
./scripts/build.sh debug --coverage
# Clean all build directories
./scripts/build.sh clean
# Show all options
./scripts/build.sh --help
```
**Running tests:** **Running tests:**
```bash ```bash
# Using build script
./scripts/build.sh --test
# Or manually
ninja -C builddir test ninja -C builddir test
``` ```
**Coverage reports:** **Coverage reports:**
```bash ```bash
# Using build script
./scripts/build.sh debug --coverage
./scripts/generate_coverage.sh
# Or manually
meson setup builddir -Db_coverage=true meson setup builddir -Db_coverage=true
ninja -C builddir ninja -C builddir
ninja -C builddir test ninja -C builddir test

View File

@@ -20,10 +20,16 @@ project(
) )
usb_dep = dependency('libusb-1.0') usb_dep = dependency('libusb-1.0')
log_dep = dependency('spdlog')
fmt_dep = dependency('fmt')
pangocairo_dep = dependency('pangocairo') pangocairo_dep = dependency('pangocairo')
# spdlog with std::format (C++20) - static library
spdlog_proj = subproject('spdlog', default_options: ['std_format=enabled', 'default_library=static', 'compile_library=true'])
log_dep = spdlog_proj.get_variable('spdlog_dep')
if not log_dep.found()
error('spdlog not found, can not proceed')
endif
# CLI11 # CLI11
cli11_proj = subproject('cli11') cli11_proj = subproject('cli11')
cli11_dep = cli11_proj.get_variable('CLI11_dep') cli11_dep = cli11_proj.get_variable('CLI11_dep')
@@ -50,7 +56,7 @@ ptprnt_exe = executable(
'ptprnt', 'ptprnt',
'src/main.cpp', 'src/main.cpp',
install: true, install: true,
dependencies: [usb_dep, log_dep, fmt_dep, pangocairo_dep, cli11_dep], dependencies: [usb_dep, log_dep, pangocairo_dep, cli11_dep],
include_directories: incdir, include_directories: incdir,
sources: [ptprnt_srcs], sources: [ptprnt_srcs],
cpp_args: cpp_args, cpp_args: cpp_args,

157
scripts/build.sh Executable file
View File

@@ -0,0 +1,157 @@
#!/bin/bash
# Build script for ptprnt - simplifies common build configurations
# Usage: ./scripts/build.sh [release|debug|clean] [options]
set -e
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PROJECT_ROOT="${SCRIPT_PATH}/.."
# Color output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_usage() {
echo "Usage: $0 [build-type] [options]"
echo ""
echo "Build Types:"
echo " release Build optimized release version (default)"
echo " debug Build debug version with symbols"
echo " clean Clean build directories"
echo ""
echo "Options:"
echo " --coverage Enable coverage reporting (debug builds only)"
echo " --reconfigure Force reconfiguration"
echo " --test Run tests after building"
echo " -j N Use N parallel jobs (default: auto)"
echo ""
echo "Examples:"
echo " $0 # Build release"
echo " $0 debug --test # Build debug and run tests"
echo " $0 debug --coverage # Build debug with coverage"
echo " $0 clean # Clean all build directories"
}
# Default values
BUILD_TYPE="release"
BUILDDIR="builddir"
COVERAGE=false
RECONFIGURE=false
RUN_TESTS=false
JOBS=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
release|debug|clean)
BUILD_TYPE="$1"
shift
;;
--coverage)
COVERAGE=true
shift
;;
--reconfigure)
RECONFIGURE=true
shift
;;
--test)
RUN_TESTS=true
shift
;;
-j)
JOBS="-j $2"
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*)
echo -e "${RED}Error: Unknown option: $1${NC}"
print_usage
exit 1
;;
esac
done
cd "${PROJECT_ROOT}"
# Handle clean
if [[ "${BUILD_TYPE}" == "clean" ]]; then
echo -e "${YELLOW}Cleaning build directories...${NC}"
rm -rf builddir builddir-debug
echo -e "${GREEN}Clean complete!${NC}"
exit 0
fi
# Set build directory and options based on build type
if [[ "${BUILD_TYPE}" == "debug" ]]; then
BUILDDIR="builddir-debug"
MESON_OPTS="--buildtype=debug"
if [[ "${COVERAGE}" == true ]]; then
MESON_OPTS="${MESON_OPTS} -Db_coverage=true"
echo -e "${BLUE}Building debug with coverage enabled${NC}"
else
echo -e "${BLUE}Building debug version${NC}"
fi
else
BUILDDIR="builddir"
MESON_OPTS="--buildtype=release"
if [[ "${COVERAGE}" == true ]]; then
echo -e "${YELLOW}Warning: Coverage is only supported for debug builds, ignoring --coverage${NC}"
fi
echo -e "${BLUE}Building release version${NC}"
fi
# Setup or reconfigure build directory
if [[ ! -d "${BUILDDIR}" ]] || [[ "${RECONFIGURE}" == true ]]; then
if [[ "${RECONFIGURE}" == true ]]; then
echo -e "${YELLOW}Reconfiguring build...${NC}"
meson setup "${BUILDDIR}" ${MESON_OPTS} --wipe --reconfigure
else
echo -e "${YELLOW}Setting up build directory...${NC}"
meson setup "${BUILDDIR}" ${MESON_OPTS}
fi
fi
# Build
echo -e "${YELLOW}Building...${NC}"
ninja -C "${BUILDDIR}" ${JOBS}
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}Build successful!${NC}"
echo -e "Binary: ${BUILDDIR}/ptprnt"
else
echo -e "${RED}Build failed!${NC}"
exit 1
fi
# Run tests if requested
if [[ "${RUN_TESTS}" == true ]]; then
echo -e "${YELLOW}Running tests...${NC}"
ninja -C "${BUILDDIR}" test
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}All tests passed!${NC}"
else
echo -e "${RED}Tests failed!${NC}"
exit 1
fi
fi
# Show binary info
echo ""
echo -e "${BLUE}Build Information:${NC}"
echo " Build type: ${BUILD_TYPE}"
echo " Build dir: ${BUILDDIR}"
echo " Binary: $(ls -lh ${BUILDDIR}/ptprnt | awk '{print $5, $9}')"
echo ""
echo -e "${GREEN}Done!${NC}"

View File

@@ -18,7 +18,8 @@
*/ */
#include "PtouchPrint.hpp" #include "PtouchPrint.hpp"
#include <fmt/core.h> #include <format>
#include <iostream>
#include <spdlog/sinks/basic_file_sink.h> #include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
@@ -104,11 +105,11 @@ bool PtouchPrint::handleListDrivers() {
auto driverFactory = std::make_unique<PrinterDriverFactory>(); auto driverFactory = std::make_unique<PrinterDriverFactory>();
auto drivers = driverFactory->listAllDrivers(); auto drivers = driverFactory->listAllDrivers();
fmt::print("Available printer drivers:\n"); std::cout << "Available printer drivers:\n";
for (const auto& driver : drivers) { for (const auto& driver : drivers) {
fmt::print(" - {}\n", driver); std::cout << std::format(" - {}\n", driver);
} }
fmt::print("\nUse with: -p <driver_name> or --printer <driver_name>\n"); std::cout << "\nUse with: -p <driver_name> or --printer <driver_name>\n";
return true; return true;
} }

View File

@@ -19,7 +19,8 @@
#include "CliParser.hpp" #include "CliParser.hpp"
#include <fmt/core.h> #include <format>
#include <iostream>
namespace ptprnt::cli { namespace ptprnt::cli {
@@ -92,7 +93,7 @@ void CliParser::reorderCommandsByArgv(int argc, char** argv) {
void CliParser::setupParser() { void CliParser::setupParser() {
// Version callback // Version callback
auto printVersion = [this](std::size_t) { auto printVersion = [this](std::size_t) {
fmt::print("ptprnt version: {}\n", mVersionString); std::cout << std::format("ptprnt version: {}\n", mVersionString);
throw CLI::CallForVersion(); throw CLI::CallForVersion();
}; };

View File

@@ -25,6 +25,7 @@
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstring>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -274,7 +275,7 @@ bool Label::append(const ILabel& other, uint32_t spacingPx) {
int newStride = mCairoWrapper->cairo_image_surface_get_stride(newSurface.get()); int newStride = mCairoWrapper->cairo_image_surface_get_stride(newSurface.get());
// Clear the new surface (set to transparent/white) // Clear the new surface (set to transparent/white)
std::memset(newData, 0x00, newStride * height); memset(newData, 0x00, newStride * height);
// Copy current label data // Copy current label data
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {

13
subprojects/spdlog.wrap Normal file
View File

@@ -0,0 +1,13 @@
[wrap-file]
directory = spdlog-1.15.3
source_url = https://github.com/gabime/spdlog/archive/refs/tags/v1.15.3.tar.gz
source_filename = spdlog-1.15.3.tar.gz
source_hash = 15a04e69c222eb6c01094b5c7ff8a249b36bb22788d72519646fb85feb267e67
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/spdlog_1.15.3-5/spdlog-1.15.3.tar.gz
patch_filename = spdlog_1.15.3-5_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.15.3-5/get_patch
patch_hash = 5e0eaf0002ff589cd8dac58e1b38c297422e7a0404d7d47ff0d2e285ed18169c
wrapdb_version = 1.15.3-5
[provide]
dependency_names = spdlog