From d54cc0b4a952ee3625fe70544ebfc347d222b538 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Mon, 6 Feb 2023 16:16:17 +0100 Subject: [PATCH] add NMakefile for Windows support --- .codespellrc | 4 +-- NMakefile | 31 +++++++++++++++++++ README.md | 78 +++++++++++++++++++++++++++++------------------ local.mak.example | 6 ++++ 4 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 NMakefile create mode 100644 local.mak.example diff --git a/.codespellrc b/.codespellrc index 7c65f7a..223f36f 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,3 +1,3 @@ [codespell] -skip = *.bin,*.gpg,*.pgp,./.git,data,highlight.js,*/target,Makefile,*.html,*/cargo,*.xml,*.xmlv2, -ignore-words-list = crate,ede,iff,mut,nd,te,uint,KeyServer,keyserver,Keyserver,keyservers,Keyservers,keypair,keypairs,KeyPair,fpr,dedup,ba, +skip = *.bin,*.gpg,*.pgp,./.git,data,highlight.js,*/target,Makefile,NMakefile,*.html,*/cargo,*.xml,*.xmlv2, +ignore-words-list = crate,ede,iff,mut,nd,te,uint,KeyServer,keyserver,Keyserver,keyservers,Keyservers,keypair,keypairs,KeyPair,fpr,dedup,ba,alle, diff --git a/NMakefile b/NMakefile new file mode 100644 index 0000000..e71e12b --- /dev/null +++ b/NMakefile @@ -0,0 +1,31 @@ +# Copyleft 2023, pEp Foundation +# This file is part of pEpEngineSequoiaBackend +# This file may be used under the terms of the GNU General Public License version 3 +# see COPYING + +# Build config defaults +# To get a debug build define DEBUG in local.mak +#DEBUG=debug +CARGO=cargo + +# Build config overrides +!IF EXISTS(local.mak) +!include .\local.mak +!ENDIF + +# Define build target and flags +!IFDEF DEBUG +TARGET=target\debug\pep_engine_sequoia_backend.dll +CARGOFLAGS= +!ELSE +TARGET=target\release\pep_engine_sequoia_backend.dll +CARGOFLAGS=--release +!ENDIF + +build: + $(CARGO) build --features crypto-cng --no-default-features $(CARGOFLAGS) + @echo. + @echo Built $(TARGET) + +clean: + rd /s /q target diff --git a/README.md b/README.md index 6d83905..31eb14f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@ -This library provides an implementation of the [p≡p Engine]'s +This library provides an implementation of the [pEp Engine]'s [cryptotech] interface using [Sequoia]. - [p≡p Engine]: https://gitea.pep.foundation/pEp.foundation/pEpEngine + [pEp Engine]: https://gitea.pep.foundation/pEp.foundation/pEpEngine [cryptotech]: https://gitea.pep.foundation/pEp.foundation/pEpEngine/src/branch/master/src/cryptotech.h [Sequoia]: https://sequoia-pgp.org -Building -======== +# Building + +## Linux and MacOS You need at least version 1.60 of `rustc` and `cargo`. @@ -15,39 +16,58 @@ You can build this library as follows: ``` $ git clone https://gitea.pep.foundation/pEp.foundation/pEpEngineSequoiaBackend.git $ cd pEpEngineSequoiaBackend -$ mkdir -p /tmp/pep_engine_sequoia_backend -$ CARGO_TARGET_DIR=/tmp/pep_engine_sequoia_backend cargo build # Add --release for a release build -$ CARGO_TARGET_DIR=/tmp/pep_engine_sequoia_backend cargo test +$ make +$ make install ``` -This will generate, among others -`/tmp/pep_engine_sequoia_backend/debug/pep_engine_sequoia_backend.pc`. -This can be used to easily link to the library *in place*. That is, -no installation is required. +To configure how this library is built, edit `local.conf`. -Hence to build and test the engine, we can do: +When built in debug mode, the library always generates trace output. +If you encounter problems in release mode, you can get a trace of the +library's execution by setting the `PEP_TRACE` environment +variable. -``` -$ cd ~/src/pEpEngine -$ export PKG_CONFIG_PATH=/tmp/pep_engine_sequoia_backend/debug${PKG_CONFIG_PATH+:$PKG_CONFIG_PATH} -$ make -$ LD_LIBRARY_PATH=$(for p in $(pkg-config pep_engine_sequoia_backend --libs-only-L); do echo ${p#-L}; done | paste -sd ':')${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH} RUST_BACKTRACE=1 make -C test test +## Windows + +On Windows, the Sequoia PGP backend for the pEp engine uses the CNG +backend. + +### Use the Visual Studio compatible Rust compiler + +You can check this by trying: + +```text +C:\Users\vb\source\repos\pEpEngineSequoiaBackend> rustup show active-toolchain +1.60.0-x86_64-pc-windows-msvc (default) ``` -Of course when installing the engine, we'll need to distribute the -generated library. +### Call NMake with the delivered NMakefile -Note: when profiling the library (or doing a release), be sure to -build in release mode! That is, build the library with `cargo build ---release` and replace `debug` with `release` in the second set of -commands. +```text +C:\Users\vb\source\repos\pEpEngineSequoiaBackend> nmake /F NMakefile -When built in debug mode, the library always generates trace output. -If you encounter problems in release mode, you can get a trace of the -library's execution by setting the `PEP_TRACE` environment -variable. For example: +Microsoft (R) Program Maintenance Utility, Version 14.34.31937.0 +Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. + cargo build --features crypto-cng --no-default-features --release + Finished release [optimized] target(s) in 0.20s + +Built target\release\pep_engine_sequoia_backend.dll ``` -$ cd ~/src/pEpEngine/test -$ PKG_CONFIG_PATH=/tmp/pep_engine_sequoia_backend/debug${PKG_CONFIG_PATH+:$PKG_CONFIG_PATH} LD_LIBRARY_PATH=$(for p in $(pkg-config pep_engine_sequoia_backend --libs-only-L); do echo ${p#-L}; done | paste -sd ':')${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH} PEP_TRACE=1 ./EngineTests -- --gtest_filter=DeleteKeyTest.check_delete_single_pubkey + +### To get a debug version instead of the release set environment DEBUG=debug + +```text +C:\Users\vb\source\repos\pEpEngineSequoiaBackend> nmake /F NMakefile /E DEBUG=debug + +Microsoft (R) Program Maintenance Utility, Version 14.34.31937.0 +Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. + + cargo build --features crypto-cng --no-default-features + Finished dev [unoptimized + debuginfo] target(s) in 0.18s + +Built target\debug\pep_engine_sequoia_backend.dll ``` + +Unlike with GNU Make, `DEBUG` must not be defined if you want to build a +release. diff --git a/local.mak.example b/local.mak.example new file mode 100644 index 0000000..fd4bdf0 --- /dev/null +++ b/local.mak.example @@ -0,0 +1,6 @@ +# to get a debug version define the DEBUG macro +# other than with GNU Make DEBUG must not be defined if you want to build a +# release + +#DEBUG=debug + -- GitLab