Giter Site home page Giter Site logo

lichray / macrofree-demo Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 23 KB

Demo for the CppCon 2019 talk "Are We Macro-free Yet?"

License: BSD 2-Clause "Simplified" License

CMake 15.78% C++ 84.22%
cmake cmake-examples modern-cpp cppcon2019 conditional-compilation

macrofree-demo's Introduction

macrofree-demo

This project demos the material covered in the CppCon 2019 talk "Are We Macro-free Yet?" The project includes:

  • two ways of implementing a function with platform-dependent APIs, and
  • how to implement a sha256 class with multiple, conditionally available backends, coexist at runtime

without any use of #if, #ifdef, or #define.

Getting Start

This demo maintains build tools and third-party libraries with Anaconda. Please go to here, download and install the latest version on your platform.

After the conda command is available in your shell, change the working directory to the project root directory and execute:

conda env create -f environment.yml
conda activate macrofree-demo

The rest of the article assumes that you are in the "macrofree-demo" Conda environment.

Linux

The build requires gcc>=7.0 or clang>=4.0.

Build and run the tests:

cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug .
ninja -C build
./build/tests/run

The Conda environment has OpenSSL under Linux. You can verify that the test suite is testing a single sha256_openssl implementation with the following command:

./build/tests/run -ltc

"-ltc" (list test cases) is a command-line option provided by doctest.

Windows

The build requires Visual Studio 2019.

In "Native Tools Command Prompt":

cmake -B build .
msbuild build\macrofree_demo.sln
build\tests\Debug\run.exe

Alternatively, you can specify -DCMAKE_CXX_COMPILER=cl.exe in CMake command-line and keep using Ninja.

Usually, only CNG (Cryptography API: Next Generation) implementation is available at this point. If you install OpenSSL with

conda install -c conda-forge openssl

reconfigure and rebuild

cmake build
msbuild build\macrofree_demo.sln

You will find that the same test case runs against both sha256_cng and sha256_openssl implementations.

macrofree-demo's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.