From fa16a2aa5cdfd8bcc2b2a2b3dd3c7201aebc33f0 Mon Sep 17 00:00:00 2001 From: Francois Kritzinger Date: Thu, 13 Jul 2023 09:29:01 +0200 Subject: [PATCH] Create build2 project --- .gitattributes | 19 +++++++++++++ .gitignore | 31 +++++++++++++++++++++ README.md | 3 +++ build/.gitignore | 4 +++ build/bootstrap.build | 7 +++++ build/export.build | 6 +++++ build/root.build | 20 ++++++++++++++ buildfile | 5 ++++ include/asio/asio.hxx | 15 +++++++++++ include/asio/buildfile | 14 ++++++++++ include/asio/export.hxx | 39 +++++++++++++++++++++++++++ manifest | 13 +++++++++ repositories.manifest | 11 ++++++++ src/asio.cxx | 17 ++++++++++++ src/buildfile | 54 +++++++++++++++++++++++++++++++++++++ tests/.gitignore | 8 ++++++ tests/basics/buildfile | 3 +++ tests/basics/driver.cxx | 34 +++++++++++++++++++++++ tests/build/.gitignore | 4 +++ tests/build/bootstrap.build | 5 ++++ tests/build/root.build | 20 ++++++++++++++ tests/buildfile | 1 + 22 files changed, 333 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 README.md create mode 100644 build/.gitignore create mode 100644 build/bootstrap.build create mode 100644 build/export.build create mode 100644 build/root.build create mode 100644 buildfile create mode 100644 include/asio/asio.hxx create mode 100644 include/asio/buildfile create mode 100644 include/asio/export.hxx create mode 100644 manifest create mode 100644 repositories.manifest create mode 100644 src/asio.cxx create mode 100644 src/buildfile create mode 100644 tests/.gitignore create mode 100644 tests/basics/buildfile create mode 100644 tests/basics/driver.cxx create mode 100644 tests/build/.gitignore create mode 100644 tests/build/bootstrap.build create mode 100644 tests/build/root.build create mode 100644 tests/buildfile diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1631641 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# This is a good default: files that are auto-detected by git to be text are +# converted to the platform-native line ending (LF on Unix, CRLF on Windows) +# in the working tree and to LF in the repository. +# +* text=auto + +# Use `eol=crlf` for files that should have the CRLF line ending both in the +# working tree (even on Unix) and in the repository. +# +#*.bat text eol=crlf + +# Use `eol=lf` for files that should have the LF line ending both in the +# working tree (even on Windows) and in the repository. +# +#*.sh text eol=lf + +# Use `binary` to make sure certain files are never auto-detected as text. +# +#*.png binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c96e1ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +.bdep/ + +# Local default options files. +# +.build2/local/ + +# Compiler/linker output. +# +*.d +*.t +*.i +*.i.* +*.ii +*.ii.* +*.o +*.obj +*.gcm +*.pcm +*.ifc +*.so +*.dylib +*.dll +*.a +*.lib +*.exp +*.pdb +*.ilk +*.exe +*.exe.dlls/ +*.exe.manifest +*.pc diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdd7dc4 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# libasio + +C++ library diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..974e01d --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +/config.build +/root/ +/bootstrap/ +build/ diff --git a/build/bootstrap.build b/build/bootstrap.build new file mode 100644 index 0000000..35cb1b6 --- /dev/null +++ b/build/bootstrap.build @@ -0,0 +1,7 @@ +project = libasio + +using version +using config +using test +using install +using dist diff --git a/build/export.build b/build/export.build new file mode 100644 index 0000000..69af93d --- /dev/null +++ b/build/export.build @@ -0,0 +1,6 @@ +$out_root/ +{ + include src/ +} + +export $out_root/src/$import.target diff --git a/build/root.build b/build/root.build new file mode 100644 index 0000000..ae3d2a6 --- /dev/null +++ b/build/root.build @@ -0,0 +1,20 @@ +# Uncomment to suppress warnings coming from external libraries. +# +#cxx.internal.scope = current + +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx + +# Assume headers are importable unless stated otherwise. +# +hxx{*}: cxx.importable = true + +# The test target for cross-testing (running tests under Wine, etc). +# +test.target = $cxx.target diff --git a/buildfile b/buildfile new file mode 100644 index 0000000..9a5145b --- /dev/null +++ b/buildfile @@ -0,0 +1,5 @@ +./: {*/ -build/} doc{README.md} manifest + +# Don't install tests. +# +tests/: install = false diff --git a/include/asio/asio.hxx b/include/asio/asio.hxx new file mode 100644 index 0000000..8568f0b --- /dev/null +++ b/include/asio/asio.hxx @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include + +namespace asio +{ + // Print a greeting for the specified name into the specified + // stream. Throw std::invalid_argument if the name is empty. + // + ASIO_SYMEXPORT void + say_hello (std::ostream&, const std::string& name); +} diff --git a/include/asio/buildfile b/include/asio/buildfile new file mode 100644 index 0000000..f347575 --- /dev/null +++ b/include/asio/buildfile @@ -0,0 +1,14 @@ +pub_hdrs = {hxx ixx txx}{**} + +./: $pub_hdrs + +hxx{export}@./: cxx.importable = false + +# Install into the asio/ subdirectory of, say, /usr/include/ +# recreating subdirectories. +# +{hxx ixx txx}{*}: +{ + install = include/asio/ + install.subdirs = true +} diff --git a/include/asio/export.hxx b/include/asio/export.hxx new file mode 100644 index 0000000..fa394e7 --- /dev/null +++ b/include/asio/export.hxx @@ -0,0 +1,39 @@ +#pragma once + +// Normally we don't export class templates (but do complete specializations), +// inline functions, and classes with only inline member functions. Exporting +// classes that inherit from non-exported/imported bases (e.g., std::string) +// will end up badly. The only known workarounds are to not inherit or to not +// export. Also, MinGW GCC doesn't like seeing non-exported functions being +// used before their inline definition. The workaround is to reorder code. In +// the end it's all trial and error. + +#if defined(ASIO_STATIC) // Using static. +# define ASIO_SYMEXPORT +#elif defined(ASIO_STATIC_BUILD) // Building static. +# define ASIO_SYMEXPORT +#elif defined(ASIO_SHARED) // Using shared. +# ifdef _WIN32 +# define ASIO_SYMEXPORT __declspec(dllimport) +# else +# define ASIO_SYMEXPORT +# endif +#elif defined(ASIO_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define ASIO_SYMEXPORT __declspec(dllexport) +# else +# define ASIO_SYMEXPORT +# endif +#else +// If none of the above macros are defined, then we assume we are being used +// by some third-party build system that cannot/doesn't signal the library +// type. Note that this fallback works for both static and shared libraries +// provided the library only exports functions (in other words, no global +// exported data) and for the shared case the result will be sub-optimal +// compared to having dllimport. If, however, your library does export data, +// then you will probably want to replace the fallback with the (commented +// out) error since it won't work for the shared case. +// +# define ASIO_SYMEXPORT // Using static or shared. +//# error define ASIO_STATIC or ASIO_SHARED preprocessor macro to signal libasio library type being linked +#endif diff --git a/manifest b/manifest new file mode 100644 index 0000000..0ffb704 --- /dev/null +++ b/manifest @@ -0,0 +1,13 @@ +: 1 +name: libasio +version: 0.1.0-a.0.z +language: c++ +summary: asio C++ library +license: other: proprietary ; Not free/open source. +description-file: README.md +url: https://example.org/libasio +email: francois@codesynthesis.com +#build-error-email: francois@codesynthesis.com +depends: * build2 >= 0.16.0 +depends: * bpkg >= 0.16.0 +#depends: libhello ^1.0.0 diff --git a/repositories.manifest b/repositories.manifest new file mode 100644 index 0000000..121112f --- /dev/null +++ b/repositories.manifest @@ -0,0 +1,11 @@ +: 1 +summary: libasio project repository + +#: +#role: prerequisite +#location: https://pkg.cppget.org/1/stable +#trust: ... + +#: +#role: prerequisite +#location: https://git.build2.org/hello/libhello.git diff --git a/src/asio.cxx b/src/asio.cxx new file mode 100644 index 0000000..7dd420f --- /dev/null +++ b/src/asio.cxx @@ -0,0 +1,17 @@ +#include + +#include +#include + +using namespace std; + +namespace asio +{ + void say_hello (ostream& o, const string& n) + { + if (n.empty ()) + throw invalid_argument ("empty name"); + + o << "Hello, " << n << '!' << endl; + } +} diff --git a/src/buildfile b/src/buildfile new file mode 100644 index 0000000..2ef554b --- /dev/null +++ b/src/buildfile @@ -0,0 +1,54 @@ +intf_libs = # Interface dependencies. +impl_libs = # Implementation dependencies. +#import xxxx_libs += libhello%lib{hello} + +# Public headers. +# +pub = [dir_path] ../include/asio/ + +include $pub + +pub_hdrs = $($pub/ pub_hdrs) + +lib{asio}: $pub/{$pub_hdrs} + +# Private headers and sources as well as dependencies. +# +lib{asio}: {hxx ixx txx cxx}{**} $impl_libs $intf_libs + +# Build options. +# +out_pfx_inc = [dir_path] $out_root/include/ +src_pfx_inc = [dir_path] $src_root/include/ +out_pfx_src = [dir_path] $out_root/src/ +src_pfx_src = [dir_path] $src_root/src/ + +cxx.poptions =+ "-I$out_pfx_src" "-I$src_pfx_src" \ + "-I$out_pfx_inc" "-I$src_pfx_inc" + +{hbmia obja}{*}: cxx.poptions += -DASIO_STATIC_BUILD +{hbmis objs}{*}: cxx.poptions += -DASIO_SHARED_BUILD + +# Export options. +# +lib{asio}: +{ + cxx.export.poptions = "-I$out_pfx_inc" "-I$src_pfx_inc" + cxx.export.libs = $intf_libs +} + +liba{asio}: cxx.export.poptions += -DASIO_STATIC +libs{asio}: cxx.export.poptions += -DASIO_SHARED + +# For pre-releases use the complete version to make sure they cannot be used +# in place of another pre-release or the final version. See the version module +# for details on the version.* variable values. +# +if $version.pre_release + lib{asio}: bin.lib.version = "-$version.project_id" +else + lib{asio}: bin.lib.version = "-$version.major.$version.minor" + +# Don't install private headers. +# +{hxx ixx txx}{*}: install = false diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..662178d --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,8 @@ +# Test executables. +# +driver + +# Testscript output directories (can be symlinks). +# +test +test-* diff --git a/tests/basics/buildfile b/tests/basics/buildfile new file mode 100644 index 0000000..3b108d7 --- /dev/null +++ b/tests/basics/buildfile @@ -0,0 +1,3 @@ +import libs = libasio%lib{asio} + +exe{driver}: {hxx ixx txx cxx}{**} $libs testscript{**} diff --git a/tests/basics/driver.cxx b/tests/basics/driver.cxx new file mode 100644 index 0000000..849fc91 --- /dev/null +++ b/tests/basics/driver.cxx @@ -0,0 +1,34 @@ +#include +#include + +#include + +#undef NDEBUG +#include + +int main () +{ + using namespace std; + using namespace asio; + + // Basics. + // + { + ostringstream o; + say_hello (o, "World"); + assert (o.str () == "Hello, World!\n"); + } + + // Empty name. + // + try + { + ostringstream o; + say_hello (o, ""); + assert (false); + } + catch (const invalid_argument& e) + { + assert (e.what () == string ("empty name")); + } +} diff --git a/tests/build/.gitignore b/tests/build/.gitignore new file mode 100644 index 0000000..974e01d --- /dev/null +++ b/tests/build/.gitignore @@ -0,0 +1,4 @@ +/config.build +/root/ +/bootstrap/ +build/ diff --git a/tests/build/bootstrap.build b/tests/build/bootstrap.build new file mode 100644 index 0000000..a07b5ea --- /dev/null +++ b/tests/build/bootstrap.build @@ -0,0 +1,5 @@ +project = # Unnamed tests subproject. + +using config +using test +using dist diff --git a/tests/build/root.build b/tests/build/root.build new file mode 100644 index 0000000..8fafbfe --- /dev/null +++ b/tests/build/root.build @@ -0,0 +1,20 @@ +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx + +# Assume headers are importable unless stated otherwise. +# +hxx{*}: cxx.importable = true + +# Every exe{} in this subproject is by default a test. +# +exe{*}: test = true + +# The test target for cross-testing (running tests under Wine, etc). +# +test.target = $cxx.target diff --git a/tests/buildfile b/tests/buildfile new file mode 100644 index 0000000..aeeab15 --- /dev/null +++ b/tests/buildfile @@ -0,0 +1 @@ +./: {*/ -build/}