Skip to content

Commit

Permalink
Merge pull request #4307 from Rohde-Schwarz/ci/amalgamation-example
Browse files Browse the repository at this point in the history
CI: Amalgamation Linkage Test and Fixes
  • Loading branch information
FAlbertDev authored Oct 14, 2024
2 parents 05f4053 + 120398b commit 7e02c5c
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 7 deletions.
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,8 @@ def link_headers(headers, visibility, directory):
build_paths.lib_sources = amalg_cpp_files
template_vars['generated_files'] = ' '.join(amalg_cpp_files + amalg_headers)

link_headers(amalg_headers, 'public', build_paths.public_include_dir)

# Inserting an amalgamation generated using DLL visibility flags into a
# binary project will either cause errors (on Windows) or unnecessary overhead.
# Provide a hint
Expand Down
13 changes: 13 additions & 0 deletions src/examples/amalgamation_header.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#if __has_include(<botan/botan_all.h>)
#include <botan/botan_all.h>
#else
// if the amalgamation header isn't available, you have to IWYU.
#include <botan/hex.h>
#endif

int main() {
std::cout << "With an amalgamation build you can include everything using the botan_all header.\n";
std::cout << "That's " << Botan::hex_encode(std::vector<uint8_t>{0xC0, 0x01}) << "\n";
return 0;
}
5 changes: 5 additions & 0 deletions src/examples/hybrid_key_encapsulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class Hybrid_PublicKey : public virtual Botan::Public_Key {
std::unique_ptr<Botan::Public_Key> m_kem_pk;
};

BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

/**
* This is the private key class for the custom public-key algorithm.
*/
Expand Down Expand Up @@ -147,6 +150,8 @@ class Hybrid_PrivateKey : public virtual Botan::Private_Key,
std::unique_ptr<Botan::Private_Key> m_kem_sk;
};

BOTAN_DIAGNOSTIC_POP

namespace {

/**
Expand Down
8 changes: 8 additions & 0 deletions src/examples/tls_ssl_key_log_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#endif
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
#include <unistd.h>
#endif

namespace {

Expand Down Expand Up @@ -142,6 +145,8 @@ class DtlsConnection : public Botan::TLS::Callbacks {
remote_addr.sin_family = AF_INET;
inet_aton(r_addr.c_str(), &remote_addr.sin_addr);
remote_addr.sin_port = htons(r_port);
#else
BOTAN_UNUSED(r_addr, r_port);
#endif
auto tls_callbacks_proxy = std::make_shared<BotanTLSCallbacksProxy>(*this);
auto rng = std::make_shared<Botan::AutoSeeded_RNG>();
Expand Down Expand Up @@ -169,6 +174,7 @@ class DtlsConnection : public Botan::TLS::Callbacks {
#if defined(BOTAN_TARGET_OS_HAS_SOCKETS)
sendto(fd, data.data(), data.size(), 0, reinterpret_cast<const sockaddr*>(&remote_addr), sizeof(sockaddr_in));
#else
BOTAN_UNUSED(data);
// send data to the other side
// ...
#endif
Expand Down Expand Up @@ -201,7 +207,9 @@ class DtlsConnection : public Botan::TLS::Callbacks {
if(fd) {
#if defined(BOTAN_TARGET_OS_HAS_SOCKETS)
shutdown(fd, SHUT_RDWR);
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
::close(fd);
#endif
#endif
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/examples/tls_stream_coroutine_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// in clang 14 and newer. Older versions of Boost might work with other
// compilers, though.
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_ASIO_VERSION) && BOOST_VERSION >= 108100
#define BOOST_VERSION_IS_COMPATIBLE
#endif

#if defined(BOOST_VERSION_IS_COMPATIBLE) && defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)

#include <botan/asio_stream.h>
#include <botan/version.h>
Expand Down Expand Up @@ -106,8 +110,13 @@ int main(int argc, char* argv[]) {
#else

int main() {
#if !defined(BOOST_VERSION_IS_COMPATIBLE)
std::cout << "Your boost version is too old, sorry.\n"
<< "Or did you compile Botan without --with-boost?\n";
#endif
#if !defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
std::cout << "Your system needs an auto seeded RNG and a certificate store.\n";
#endif
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/asio/asio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Stream {
std::shared_ptr<StreamCallbacks> callbacks = std::make_shared<StreamCallbacks>()) :
Stream(std::move(context), std::move(callbacks), std::forward<Arg>(arg)) {}

#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
#if defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
/**
* @brief Conveniently construct a new Stream with default settings
*
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/ci/setup_gh_actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if type -p "apt-get"; then
sudo apt-get -qq install libboost-dev "${tpm2_specific_packages[@]}"
echo "BOTAN_TPM2_ENABLED=${ci_support_of_tpm2}" >> "$GITHUB_ENV"

elif [ "$TARGET" = "examples" ] || [ "$TARGET" = "tlsanvil" ] || [ "$TARGET" = "clang-tidy" ] ; then
elif [ "$TARGET" = "examples" ] || [ "$TARGET" = "amalgamation" ] || [ "$TARGET" = "tlsanvil" ] || [ "$TARGET" = "clang-tidy" ] ; then
sudo apt-get -qq install libboost-dev libtss2-dev
build_and_install_jitterentropy

Expand Down Expand Up @@ -186,7 +186,7 @@ else
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
brew install ccache

if [ "$TARGET" = "shared" ]; then
if [ "$TARGET" = "shared" ] || [ "$TARGET" = "amalgamation" ] ; then
brew install boost

# On Apple Silicon we need to specify the include directory
Expand Down
4 changes: 3 additions & 1 deletion src/scripts/ci/setup_gh_actions_after_vcvars.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#
# Botan is released under the Simplified BSD License (see license.txt)

if ($args[0] -in @('shared')) {
$targets_with_boost = @("shared", "amalgamation")

if ($targets_with_boost -contains $args[0]) {
nuget install -NonInteractive -OutputDirectory $env:DEPENDENCIES_LOCATION -Version 1.79.0 boost

$boostincdir = Join-Path -Path $env:DEPENDENCIES_LOCATION -ChildPath "boost.1.79.0/lib/native/include"
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/ci_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def build_targets(target, target_os):
yield 'bogo_shim'
if target in ['sanitizer'] and target_os not in ['windows']:
yield 'bogo_shim'
if target in ['examples']:
if target in ['examples', 'amalgamation']:
yield 'examples'
if target in ['valgrind', 'valgrind-full']:
yield 'ct_selftest'
Expand Down Expand Up @@ -425,7 +425,7 @@ def sanitize_kv(some_string):
flags += ['--with-commoncrypto']

def add_boost_support(target, target_os):
if target in ['coverage', 'shared']:
if target in ['coverage', 'shared', 'amalgamation']:
return True

if target == 'sanitizer' and target_os == 'linux':
Expand Down Expand Up @@ -803,7 +803,7 @@ def main(args=None):
if target in ['coverage', 'fuzzers']:
make_targets += ['fuzzer_corpus_zip', 'fuzzers']

if target in ['examples']:
if target in ['examples', 'amalgamation']:
make_targets += ['examples']

if target in ['valgrind', 'valgrind-full']:
Expand Down

0 comments on commit 7e02c5c

Please sign in to comment.